# How can I use Mathematica to solve a complex truth-teller/liar logic problem?

I have a logic puzzle I want to convert to Mathematica to solve: Person A states, "Exactly two people are truth-tellers," Person B states, "I and Person C are truth-tellers." Person C states, "Person A is a liar or Person B is a liar." (here this is a use of inclusive or) Each person is either a truth-teller or a liar. The full first-order logic formulation of this is as follows:

• A↔[(A∧B∧¬C)∨(A∧¬B∧C)∨(¬A∧B∧C)]
• B↔(B∧C)
• C↔(¬A∨¬B)

I was hoping someone could help me figure out how to create a truth table in Mathematica for this problem and/or solve using Mathematica's logic functions for who is a truth-teller and who is a liar. I tried using Boolean Table but couldn't get the right input. How can I use the solving features in Mathematica to input logical statements and figure out who is telling the truth and who is lying? For a helpful similiar problem, see How to solve the liar problem?

• The last statement is a bit ambiguous, and could instead be interpreted as C↔[(¬A∧B)∨(A∧¬B)] (i.e., exactly one of A and B are liars.) Note that as you've interpreted it, the status of A is undetermined, as Mathematica found below; under this other interpretation, A must be a truth-teller. – Michael Seifert Jan 20 at 13:46
• I was trying to determine if there is enough information to determine who is a liar and who is a truth-teller using Mathematica. The logical statement by Person C is not Xor and instead just normal Or. I hope this clarifies. – Peter Burbery Jan 20 at 15:53

You can enter the logic formulations into Mathematica like this — Copy & paste the following code, and you can see the symbols.

p = a \[Equivalent] ((a \[And]
b \[And] \[Not] c) \[Or] (a \[And] \[Not] b \[And]
c) \[Or] (\[Not] a \[And] b \[And] c));
q = b \[Equivalent] (b \[And] c);
r = c \[Equivalent] (\[Not] a \[Or] \[Not] b);

1. We prefer lowercase variables, since some uppercase variables have special meanings (e.g., E for constant $$e$$, N for numerical value function).

2. Most symbols (in the form of \[...] as you see) have shortcuts to type and have built-in meanings. For example, a \[Equivalent] b can be typed with a Esc equiv Esc b, and it's just a more human-readable form of Equivalent[a, b] internally. That is, there's not any difference from:

p = Equivalent[a, (a && b && !c) || (a && !b && c) || (!a && b && c)];
q = Equivalent[b, b && c];
r = Equivalent[c, !a || !b];


Then you can use any of the following commands to get the result:

p \[And] q \[And] r // BooleanConvert
p \[And] q \[And] r // LogicalExpand
p \[And] q \[And] r // FullSimplify

! b && c


Hence $$P\land Q\land R\equiv\lnot B\land C$$, indicating B must be a liar and C must be a truth-teller. Truth table can be generated with:

TableForm[BooleanTable[{a, b, c, p \[And] q \[And] r}, {a, b, c}],
TableHeadings -> {None, {"A", "B", "C", "P\[And]Q\[And]R"}}]

• Note that the result does not include $A$, which implies that $A$'s status as a truth-teller or liar is not determined by the logical statements given. – Michael Seifert Jan 20 at 16:23
• @MichaelSeifert Yes. This indicates that, from what they say, nothing can be inferred about A. – SneezeFor16Min Jan 20 at 17:16