# Alternative to xor(A,B,C) [closed]

How can we make a comprehensive statement, which will correspond to the truth table of xor (A, B, C) (means that only true if exactly one of A,B,C is true) by combining logical operators AND (&), OR (|), XOR (xor) and NOT (!)?

-

## closed as unclear what you're asking by belisarius, m_goldberg, Yves Klett, Michael E2, KubaApr 8 '14 at 12:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

Markus, welcome to mathematica.stackexchange.com. Could you please show us what you have tried already yourself? –  Jacob Akkerboom Apr 8 '14 at 11:04
And just to make sure, is this a question about the software Mathematica (and not math in general)? –  Yves Klett Apr 8 '14 at 11:05
The built-in (Mathematica) function Xor does what is required btw. –  Jacob Akkerboom Apr 8 '14 at 11:07
@JacobAkkerboom Plus LogicalExpand... –  Michael E2 Apr 8 '14 at 12:16
oneTrue[a_, b_, c_] := Xor[a, b, c] && Not[a && b] && Not[a && c] && Not[b && c] –  Daniel Lichtblau Apr 8 '14 at 14:40

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, h}}]


-

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 && ! b && c)

{{{True, True, True}, False}, {{True, True, False}, False},
{{True, False, True}, False}, {{True, False, False},True},
{{False, True, True}, False}, {{False, True, False},True},
{{False, False, True}, True}, {{False, False, False}, False}}

*)

-
sorry me... deleted comments –  ubpdqn Apr 8 '14 at 11:50
@ubpdqn: No worries, I just wanted to be sure I had not blundered. :-) –  ciao Apr 8 '14 at 11:53