19
$\begingroup$

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?

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Jan 20, 2021 at 13:46
  • $\begingroup$ 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. $\endgroup$ Commented Jan 20, 2021 at 15:53

2 Answers 2

24
$\begingroup$

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"}}]
$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ Commented Jan 20, 2021 at 16:23
  • $\begingroup$ @MichaelSeifert Yes. This indicates that, from what they say, nothing can be inferred about A. $\endgroup$ Commented Jan 20, 2021 at 17:16
  • 1
    $\begingroup$ You can also use SatisfiabilityInstances[p \[And] q \[And] r, {a, b, c}] to find a solution to the problem and SatisfiabilityInstances[p \[And] q \[And] r, {a, b, c}, All] to find all of them. $\endgroup$ Commented Sep 22, 2022 at 8:33
4
$\begingroup$

The other answer already provided a great solution. Alternatively, you can try:

SatisfiabilityInstances[(a \[Equivalent] ((a \[And] 
        b \[And] \[Not] c) \[Or] (a \[And] \[Not] b \[And] 
        c) \[Or] (\[Not] a \[And] b \[And] 
        c))) && (b \[Equivalent] (b \[And] 
      c)) && (c \[Equivalent] (\[Not] a \[Or] \[Not] b)), {a, b, c}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.