Mathematica Asked by Peter Burbery on April 13, 2021
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:
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?
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);
We prefer lowercase variables, since some uppercase variables have special meanings (e.g., E
for constant $e$, N
for numerical value function).
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 $Pland Qland Requivlnot Bland 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"}}]
Correct answer by SneezeFor16Min on April 13, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP