# Tag Info

## Hot answers tagged logic

21

This could provide a good starting point, since the structure of the diagrams is simply a cross with four regions that themselves can contain similar crosses, you can simply define a structure to represent this nesting and a recursive function to draw such structures. In my implementation I just use the head c to indicate a cross: dirs = {{1, 0}, {0, 1}, ...

16

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 ...

12

f[n_] := (n (n + 1) (2 n + 1))/6 Easy. The proof by induction involves two steps: Prove the relation for a starting value. We'll take n=1. So f[1] must equal 1^2: f[1] == 1 True Prove that, if the relation holds for a certain n, it also holds for n+1. In this case, for n+1 we have to add (n+1)^2 to the sum you get for n: f[n] + (n + 1)^2 == f[n + ...

9

I'm not sure if you think it's elegant or not, but you can use LinearProgramming or more simply Minimize to solve this problem. The idea is to minimize an objective function of some decision variables subject to some constraints. The objective function doesn't matter, can be a constant function, the only relevant thing is the constraint satisfaction. First ...

6

f[{a_, b_, c_, d_}] := BooleanFunction[Thread[Tuples[{0, 1}, 2] -> {a, b, c, d}]] Usage f[{True, False, True, False}][0, 1] (* False *)

5

I post this not as elegant but I spent some time and particularly like "unlikely"'s answer. The puzzle: Setting up: housenumber = Range[5]; housecolour = {"red", "green", "ivory", "yellow", "blue"}; country = {"English", "Spaniard", "Ukrainian", "Japanese", "Norwegian"}; drink = {"coffee", "tea", "milk", "orange juice", "water"}; smoke = {"Old ...

5

The possible cardinalities $c+1$ of the set $\{i,j,k,l,m,n\}$ are, of course, $1$ through $6$ inclusive, corresponding to $c=0$ through $5$. Because the question concerns only the relative orders of its elements, then we may--without any loss of generality--replace the elements by their ranks from $0$ (for the smallest) through $c$. Because the answers I ...

4

The Wolfram Alpha example suggests you want to treat $0$ and $1$ as the Boolean values False and True respectively and, with this convention, to parameterize an arbitrary binary Boolean operator $f$ by means of its truth table values $(a,b,c,d)$: f[x_, y_, {a_, b_, c_, d_}] := {1 - x, x} . {{a, b}, {c, d}} . {1 - y, y} (This method exhibits such binary ...

4

Induction has many faces, a straightforward way to prove the equality using induction is 1. RSolve It is superior because we needn't know the formula. Denote s[n] to be the sum 1^2 + 2^2 +...+ n^2 for every natural n, then obviously the axiom of induction is equivalent to : s[n+1] - s[n] == (n+1)^2, and the initial condition is : s[0] == 0, thus : ...

4

Method 1: Resolve The idea is to use the following piece of code: Resolve@Exists[{i, j, k}, i < j && j < k && i < k] (* True *) Resolve@Exists[{i, j, k}, i < j && j == k && i == k] (* False *) Here is a complete solution. lex[{i_, j_}, {k_, l_}] := i < k || i == k && j < l pairCond[{i_, j_}, {k_, ...

4

I don't now that I really understand your question, but from a pure expression manipulation perspective this might be useful: Or @@ And @@@ Tuples[{{a && ! b}, {c, ! c}, {d, ! d}}] (a && ! b && c && d) || (a && ! b && c && ! d) || (a && ! b && ! c && d) || (a ...

4

First convert your conditions to a list of Rules myrules = Apply[List, conditions /. {Equal -> Rule}, {0, 1}] which gives Then Apply those Rules to your List using a pure function and Map (/@) ReplaceAll[{f[x], g[x]}, #] & /@ myrules which produces

3

(from the comments of belisarius & Daniel Lichtblau) Equal[ BooleanTable[Implies[p, q || r], {p, q, r}], BooleanTable[Implies[p && Not[q], r], {p, q, r}] ] (* ==> True *) Or without truth tables: Reduce[Equivalent[Implies[p, q || r], Implies[p && Not[q], r]]] (* ==> True *)

3

Based on ssch suggestion I have come up with a following code: Equivalent[Exists[x, a[x]] && ForAll[{x, y}, a[x] && a[y], x == y], Exists[x, ! a[x]]] // TautologyQ False

3

Actually, ∃! is a standard for "there exists a unique ..." . However, the proposition is false. Consider A(x) where x is greater than 5. There exists lots of x for which x<=5. And surely there is not a unique x, for x>5. To express ∃! in Mathematica one needs Exists[x, A[x]] && ForAll[{a, b}, A[a] && A[b] \[Implies] a == b] Then ...

2

MyLogicalExpand[expr_] := With[{patt = "(" ~~ x : (Except[Characters["()"]] ..) ~~ ")" /; ( Implies[#, ! #2] & @@ ( MemberQ[StringPosition[x, LetterCharacter][[;; , 1]], #] & /@ {2, 1})) }, Module[{ cas = StringCases[expr, patt], pos = StringPosition[expr, patt], ...

2

Cases[Tuples[{True, False}, 2], {a_, b_} /; Equivalent[a, b] && Equivalent[b, Xor[a, b]]] (*{{False, False}}*) FindInstance[Equivalent[a, b] && Equivalent[b, Xor[a, b]], {a, b}, Booleans] (*{{a -> False, b -> False}}*)

2

Since I don't know how to incorporate BooleanConvert here is a walkaround for this case: conv = Or @@ Flatten[Outer[ And, {#1}, Sequence @@ Transpose[{Not /@ #2, #2}]] , 2] & . conv @@ {a && ! b, {c}} (a && ! b && ! c) || (a ...

1

Perhaps xor[ab : {a_String /; StringFreeQ[a, Except["0" | "1"]], b_String /; StringFreeQ[b, Except["0" | "1"]]}] := StringJoin[ MapThread[Xor, Characters[ab] /. {"0" -> False, "1" -> True}] /. {False -> "0", True -> "1"}] Since xor is limited to two strings in the list it will be convenient to support this form: ...

1

The Mathematica documentation makes it clear that the default domain is Complexes. In that domain, Resolve[ForAll[x, Exists[{a, b, c}, a^2 + b^2 + c^2 == x]]] True because, in the complex domain, a^2 + b^2 + c^2 == x is satisfied by a == Sqrt[x], b == 0, c == 0 To work with Integers, you can write resolution = Resolve[Exists[{a, b, c}, a^2 + ...

1

Your definition of Xor is off, but going on what the OP said you want the result to be (only true if exactly one of the three arguments is true): bc = BooleanCountingFunction[{1}, 3][a, b, c]; BooleanConvert[bc] Transpose[{Tuples[{True, False}, {3}], BooleanTable[bc]}] (* (a && ! b && ! c) || (! a && b && ! c) || (! a ...

1

For illustrative purposes: tup = Tuples[{False, True}, 3]; g[x_, y_] := And[Or[x, y], Not[And[x, y]]] h[x_, y_] := And[Or[x, y], Or[Not[x], Not[y]]] g[x_, y__] := Fold[g, x, {y}]; h[x_, y__] := Fold[h, x, {y}]; TableForm[{##, Style[Xor[##], Red], Style[g[##], Blue], Style[h[##], Purple]} & @@@ tup, TableHeadings -> {None, {"", "", "", Xor, g, ...

1

In Mathematica: Reduce[ForAll[{x, y}, x <= y \[Equivalent] x < y + 1], Integers] (* True *) or: Resolve[ForAll[{x, y}, x <= y \[Equivalent] x < y + 1], Integers] (* True *) For a mathematical proof, the direct implication $x \leq y \Rightarrow x < y+1$ has the trivial proof noted by @rcollyer in a comment. The converse ...

1

Assuming[#, Simplify[{f[x], g[x]}]] & /@ List @@ conditions {{f1 (1 + x), g1 x}, {g1 + g0 x, g0 + g1 x}} Which, technically but with switched constants, is what is desired.

1

You can often figure this kind of thing out by looking at the FullForm of the expressions. In this case: {FullForm[{1 -> 2}], FullForm[{1 \[DirectedEdge] 2}]} shows that the first is a Rule while the second is a DirectedEdge and hence they are not equal. On the other hand, when embedded inside Graph, both sides become Graph[List[1, 2], ...

1

I suspect that this has to do with the assumption b > 0 implicitly stating that b is a real, where that is not the case with b != 0. This is, of course, because there is no natural ordering of complex numbers, but they do have a 0-element to compare against. As evidence for this answer, note that Assuming[Element[b, Reals] && b != 0, ...

1

It's not clear to me what you seek, but just in case the plain answer happens to be it: {! x || a, ! y || a} /. Not[n_] :> n != 1 {x != 1 || a, y != 1 || a}

1

Just a different interpretation: func[list_] := If[# <= Length@list, list[[#]], \$Failed] &[1 + FromDigits[{##}, 2]] & func[{a, b, c, d}] @@@ Tuples[{0, 1}, 2] {a, b, c, d}

Only top voted, non community-wiki answers of a minimum length are eligible