# Tag Info

37

Both, And and Or should work for All and Any respectively. You may have to get creative in how you apply them, though. For instance, And @@ {True, False, True} works just like you would expect AllOf @ {True, False, True} to without any additional work. Similarly, Or @@ {False, True, False} works like AnyOf.

35

I'm coming to the party a bit late, but here's my approach. It should work for any two polygons, including non-convex and self-intersecting ones. winding[poly_, pt_] := Round[(Total@ Mod[(# - RotateRight[#]) &@(ArcTan @@ (pt - #) & /@ poly), 2 Pi, -Pi]/2/Pi)] cross[e1_, e2_] /; (N[Det[{Subtract @@ e1, Subtract @@ e2}]] === 0.) = ...

26

SatisfiableQ has three methods: "BDD": converts the expression to a BDD (binary decision diagram), "SAT": uses the Minisat library, "TREE": a branch-and-bound method based on the expression tree. SatisfiabilityCount counts instances by converting the expression to a BDD, so its timing should be close to SatisfiableQ with the "BDD" method (counting ...

25

You can implement equivalents of the any and all functions in MATLAB and python in Mathematica using the MemberQ and FreeQ functions as: any[x_List] := MemberQ[x, True] all[x_List] := FreeQ[x, False] For large lists, these will be about an order of magnitude faster in the worst case to several orders faster in the best case, when compared to the And and Or ...

23

How about RegionPlot? RegionPlot[ { (x - 0.2)^2 + y^2 < 0.5 && 0 < x < 1 && 0 < y < 1, (x - 0.2)^2 + y^2 < 0.5 && ! (0 < x < 1 && 0 < y < 1), ! ((x - 0.2)^2 + y^2 < 0.5) && 0 < x < 1 && 0 < y < 1 }, {x, -1, 1.5}, {y, -1, 1.5}, PlotStyle -> {...

20

I like more : MapThread[ And, {{True, True, False}, {True, False, False}}] {True, False, False} Edit We should test efficiency of various methods for a few different lists. Definitions Argento[l_] := (And @@ # & /@ Transpose[l]; // AbsoluteTiming // First) Brett[l_] := (And @@@ Transpose[l]; // AbsoluteTiming // First) Artes[l_] := (MapThread[...

19

Have you seen, that Mathematica is capable of many boolean computations using special boolean functions? Let's assume someone from the island makes a statement, then when the statment is true, whether or not he tells the statement is true, depends on whether or not he is a truth-teller. When we know, which kind he is, we know the correct statement through ...

19

I prefer using Inner for this, as conceptually, it is a generalized dot of the two Boolean lists with And as the operator. Inner[And, {True, True, False}, {True, False, False}, List] (* {True, False, False} *)

17

The Wolfram Language and Mathematica 10 (available now on the Raspberry Pi) have new functions — AnyTrue, AllTrue, NoneTrue — which take a predicate and test any/all/none on the input list. For example: AnyTrue[Range@5, EvenQ] (* True *) AllTrue[{True, False, False}, TrueQ] (* or Identity in place of TrueQ *) (* False *) These functions can also be turned ...

17

The (undocumented!) function GraphicsPolygonUtilsPolygonIntersection[] (GraphicsMeshPolygonIntersection[] in older versions) seems up to the task. Using Sjoerd's example: polys = {Polygon[{{1, 3}, {3, 4}, {4, 7}, {5, -1}, {3, -3}}], Polygon[{{2, 2}, {3, 3}, {4, 2}, {0, 0}}]}; Graphics[Append[{Gray, polys}, {Blue, GraphicsPolygonUtils...

16

I like Artes' and kguler's answers, but I'd like to point out that in general f @@ # & /@ list can be more concisely written as f @@@ list For example: And @@@ Transpose[{{True, True, False}, {True, False, False}}] (* {True, False, False} *)

15

In addition to the simple form where you already have a list of True|False elements, you may want lazy evaluation in creating that list, short circuiting if the test fails. You can do this with Hold. I include a Print statement so that you can see what actually evaluates: (Print@#; # != 0) & /@ Hold[1, 0, 0, 1, 1, 0, 1, 0] And @@ % (Print@#; # != 0) &...

14

I am not aware of any built-in functionality (I might easily be wrong), but there's an example at MathWorld for calculating intersections of convex polygons. You'd need to approximate the circle with a polygon. Get the notebook from that page: there's an intersection calculation inside that uses the IMTEK Mathematica supplement. Example: << Imtek`...

13

You want to complement bits based on a given length. Easy enough. complementBits[bits_Integer, len_Integer] /; bits >= 0 && len >= 0 := BitXor[bits, 2^len - 1] (If you really want to compliment them, tell them the size is much too big for them..) Quick test. complementBits[43, 8] (* Out= 212 *) Getting back to the question at hand, ...

12

You can use Thread: Thread[And[{True, True, False}, {True, False, False}]] or, Thread with Apply (@@) : Thread[And@@{{True, True, False}, {True, False, False}}] (* {True, False, False} *)

12

Unfortunately, the approach of using Apply[Plus, Flatten[nbhd]] is fatal to your algorithm because summing up the cell-values introduces ambiguities. As an example take these rules from your excel file (White (0), Red (1) and Black (2)). This is in the Excel-file at A43: {{2,2,2},{2,2,0},{0,0,0}} -> 2 And this is in A179: {{1,1,1},{1,2,1},{1,1,1}} ->...

12

Another way for All is to use VectorQ function VectorQ[lis, TrueQ]

12

You can use And and still get what you want: x := 1 If[And @@ {True, False, True, False, (x := 2; True)}, Print["Yes"], Print["No"]]; x (* No 2 *) What happens is that the List and its arguments are evaluated before And is applied to it, hence setting the value of x.

11

tutorial/RealPolynomialSystems claims "Reduce, Resolve, and FindInstance always put real polynomial systems in the prenex normal form, with quantifier-free parts in the disjunctive normal form..." For obtaining Skolem form from prenex, possibly could proceed as described at http://demonstrations.wolfram.com/Skolemization/ or http://mathworld.wolfram.com/...

11

This answer is a modification of my answer given in the discussion Creating Identification/Classification trees. With this solution I am trying to achieve the simplification by using the impurity function applied to the data (the truth table in this case). Make the truth table from the linked Wikipedia article (Binary Decision Diagram): truthTable = {{0, ...

10

Another option is to use image processing features such as ImageCompose: { g1 = Graphics[Rectangle[], PlotRange -> 1], g2 = Graphics[Disk[{0.2, 0}, .5], PlotRange -> 1], ImageCompose[g1, g2, Center, Center, {1, 1, 0}] } The output of the above looks like this: (Note that in this case your Graphics get rasterized and the result is an Image.)

10

v1 = RandomChoice[{-1, 1}, 100]; v2 = RandomChoice[{-1, 1}, 100]; vL = UnitStep[v1]; vL*v1 + (1 - vL)*v2 Using PatoCriollo's comparison (and now updated to include rasher and Mr. Wizard's methods): n = 10^6; v1 = RandomChoice[{-1, 1}, n]; v2 = RandomChoice[{-1, 1}, n]; (bp = Boole[Positive[v1]]; test1 = bp v1 + (1 - bp) v2); // Timing test2 = With[{c = ...

10

BooleanMinimize[BooleanFunction[table]] (* (#1 && ! #2) || (#1 && ! #3) || (#1 && ! #4) || (! #1 && #2 && #3 && #4) & *) Note in the documentation how 1/0 vs True/False are treated here, massage as needed. Quick verification: bf = BooleanFunction[table]; Rule @@@ Transpose[{table[[All, 1]], bf[...

9

Speed here is hindered by the fact that True/False is not a packable type in Mathematica, although I personally think it should be. If it is possible to reformulate your problem to use 1/0 instead, which can be packed, the methods already provided (Pick and SparseArray) each become much faster. You can convert your data using With faster than using Boole, ...

8

In version 10, the new geometric computation functionality supports this. It operates with region objects. Many graphics primitives, including Disk and Rectangle can be used as regions. Boolean operations include RegionUnion, RegionIntersect, RegionDifference, RegionSymmetricDifference and BooleanRegion. Example: RegionPlot[RegionIntersection[Rectangle[]...

8

This happens because Simplify converts the expression to a BooleanFunction representation. Checking the documentation for BooleanFunction you find that: Elements of both inputs and outputs can be specified either as True and False or as 1 and 0.

8

As in the comments above, we see that the HoldAll attribute is causing the "problem". Note that if we unset HoldAll it works: Unprotect@And; ClearAttributes[And, HoldAll]; Protect@And; Then: And[check] True EDIT: based on Oleksandr R.'s comment, I must stress that I showed this only to illustrate the "problem". It is not a good idea to unset HoldAll ...

8

In addition to HoldAll as highlighted by Pinguin Dirk the other component of the behavior is that And directly returns single arguments: And 73 Combined, And[check] spits out check which at the top level evaluates to Sequence[True, . . .]. One problem with your method for checking the matrix is that it does not short-circuit on a non-numeric value, ...

8

It seems I misunderstood the question. Here's an update, which is a considerable improvement, too. It relies on Implies[x, y] being equivalent to Boole[x] (1 - Boole[y]) == 0. falsePattern = Table[False, {15}, {15}]; truePattern = Table[True, {15}, {15}]; SeedRandom; randomPattern = RandomChoice[{True, False}, {15, 15}]; impliesPosition[board_, ...

8

If I'm not mistaken you should be happy to use Array: Array[x, 10, 0, And] x && x && x && x && x && x && x && x && x && x It works on V9, don't know if for previous versions too.

Only top voted, non community-wiki answers of a minimum length are eligible
{"ft_lang_label":"__label__en","ft_lang_prob":0.80470943,"math_prob":0.9159884,"size":12618,"snap":"2019-51-2020-05","text_gpt3_token_len":3700,"char_repetition_ratio":0.14618678,"word_repetition_ratio":0.051144667,"special_character_ratio":0.33499762,"punctuation_ratio":0.18203403,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98270535,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-14T16:24:48Z\",\"WARC-Record-ID\":\"<urn:uuid:d4ed6215-6016-4b28-a4a2-0e1ef37dfec7>\",\"Content-Length\":\"168087\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5d3859e9-5231-4d44-903e-eabccd80a04a>\",\"WARC-Concurrent-To\":\"<urn:uuid:317ac0b5-f696-46f7-85bb-5d84f13dc520>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/tags/boolean-computation/hot\",\"WARC-Payload-Digest\":\"sha1:DF5GPX4WMCDW5FL53WW7KPZHREEZULPI\",\"WARC-Block-Digest\":\"sha1:E5GSH7S35WXDIYW5UNLS33Z6MG4UQ3ER\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575541281438.51_warc_CC-MAIN-20191214150439-20191214174439-00101.warc.gz\"}"}