Tag Info

Hot answers tagged

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


18

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, setup the parameters, sets and clues (in an ...


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 wrote an unification-based program as used in Prolog language. First, I setup a simple unification functions: Clear[unify]; unify[var1_Symbol, var2_Symbol] := If[var1 === var2, {}, {var1 -> var2}]; unify[const1_?StringQ, const2_?StringQ] := If[const1 == const2, {}, $Failed]; unify[var_Symbol, const_?StringQ] := {var -> const}; ...


7

EDIT This edit (I hope corrects the problem identified by Mr. Wizard: (i) there was a typographical error "Kools", should have been "Kool", and the styling of desired targets has now been left to the end). I post this not as elegant but I spent some time and particularly like "unlikely"'s answer. The puzzle: Setting up: housenumber = Range[5]; ...


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 *)


6

TrueQ does not attempt to resolve equivalencies: TrueQ will return True only if the input is explicitly True You can use TrueQ to "assume" that a test fails when its outcome is not clear. Consider: eq = D[Integrate[1/(x^3 + 1), x], x] == 1/(1 + x^3) 1/(3 (1 + x)) - (-1 + 2 x)/(6 (1 - x + x^2)) + 2/(3 (1 + 1/3 (-1 + 2 x)^2)) == 1/(1 + x^3) ...


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


5

Another option, sort of like pattern matching on training wheels. First apply criteria for individual houses. ClearAll@"Global`*"; colors = {red, blue, yellow, ivory, green}; nations = {norway, ukraine, england, spain, japan}; drinks = {water, tea, milk, oj, coffee}; smokes = {kools, chesterfields, golds, luckys, parliaments}; pets = {fox, horse, snails, ...


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

Here's a bitwise approach, using a two-argument definition like @m_goldberg: xor[str1_String, str2_String] := IntegerString[ BitXor[FromDigits[str1, 2], FromDigits[str2, 2]], 2, StringLength[str1]]; The other functions could be implemented with bitwise operators, too.


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

I think it would be simpler to implement the logic directly, with fewer transformations: str2={"11000000","10000001","11111111"}; do[f_]:=StringJoin[ToString/@Boole@MapThread[f,StringSplit[#,""]]]&; not=StringReplace[#,{"1"->"0","0"->"1"}]&; not@str2[[1]] "00111111" or=do[!FreeQ[{##},"1"]&]; or@str2 "11111111" ...


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



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