In [1]:
Copied!
from mathesis.system.classical.truth_table import ConditionalClause
conditional_clause = ConditionalClause()
conditional_clause
from mathesis.system.classical.truth_table import ConditionalClause
conditional_clause = ConditionalClause()
conditional_clause
Out[1]:
P | Q | Conditional(P, Q) |
---|---|---|
1 | 1 | 1 |
1 | 0 | 0 |
0 | 1 | 1 |
0 | 0 | 1 |
Outside Jupyer, you get a plain text table:
In [2]:
Copied!
print(conditional_clause)
print(conditional_clause)
P Q Conditional(P, Q) 1 1 1 1 0 0 0 1 1 0 0 1
Generate truth tables for classical logic¶
mathesis.semantics.truth_table.ClassicalTruthTable
automatically generates the truth table for a given formula.
In [3]:
Copied!
from mathesis.grammars import BasicGrammar
from mathesis.semantics.truth_table import ClassicalTruthTable
grammar = BasicGrammar()
fml = grammar.parse("(¬P∧(P∨Q))→Q")
table = ClassicalTruthTable(fml)
table
from mathesis.grammars import BasicGrammar
from mathesis.semantics.truth_table import ClassicalTruthTable
grammar = BasicGrammar()
fml = grammar.parse("(¬P∧(P∨Q))→Q")
table = ClassicalTruthTable(fml)
table
Out[3]:
P | Q | ¬P | P∨Q | ¬P∧(P∨Q) | (¬P∧(P∨Q))→Q |
---|---|---|---|---|---|
0 | 0 | 1 | 0 | 0 | 1 |
0 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 1 | 0 | 1 |
1 | 1 | 0 | 1 | 0 | 1 |
table.is_valid()
just returns whether the formula is valid.
In [4]:
Copied!
f"Valid: {table.is_valid()}"
f"Valid: {table.is_valid()}"
Out[4]:
'Valid: True'
Generate truth tables for many-valued logics¶
Some many-valued logics are implemented out of the box. They are available from mathesis.semantics.truth_table
.
In [5]:
Copied!
from mathesis.grammars import BasicGrammar
from mathesis.semantics.truth_table import K3TruthTable
grammar = BasicGrammar()
fml = grammar.parse("A∨¬A")
table = K3TruthTable(fml)
table
from mathesis.grammars import BasicGrammar
from mathesis.semantics.truth_table import K3TruthTable
grammar = BasicGrammar()
fml = grammar.parse("A∨¬A")
table = K3TruthTable(fml)
table
Out[5]:
A | ¬A | A∨¬A |
---|---|---|
i | i | i |
0 | 1 | 1 |
1 | 0 | 1 |
In [6]:
Copied!
f"Valid: {table.is_valid()}"
f"Valid: {table.is_valid()}"
Out[6]:
'Valid: False'
Łukasiewicz's Ł3¶
WIP
Three-valued logic LP¶
In [7]:
Copied!
from mathesis.grammars import BasicGrammar
from mathesis.semantics.truth_table import LPTruthTable
grammar = BasicGrammar()
fml = grammar.parse("(A∧¬A)→A")
table = LPTruthTable(fml)
table
from mathesis.grammars import BasicGrammar
from mathesis.semantics.truth_table import LPTruthTable
grammar = BasicGrammar()
fml = grammar.parse("(A∧¬A)→A")
table = LPTruthTable(fml)
table
Out[7]:
A | ¬A | A∧¬A | (A∧¬A)→A |
---|---|---|---|
0 | 1 | 0 | 1 |
1 | 0 | 0 | 1 |
i | i | i | i |
In [8]:
Copied!
f"Valid: {table.is_valid()}"
f"Valid: {table.is_valid()}"
Out[8]:
'Valid: True'
Four-valued logic FDE¶
WIP
Use custom symbols for truth values¶
Subclasses of ConnectiveClause()
and TruthTable()
can have truth_value_symbols
attribute that is a dictionary mapping internal numeric truth values to arbitrary symbols like ⊤, ⊥, T, F, etc.
Define custom truth tables¶
WIP