Exemple #1
0
from logic import TruthTable

#not a
notTable = TruthTable(['a'], ['-a'])
notTable.display()
print("")

#a and b
andTable = TruthTable(['a', 'b'], ['a and b'])
andTable.display()
print("")

#a or b
orTable = TruthTable(['a', 'b'], ['a or b'])
orTable.display()
print("")

#if a then b
ifTable = TruthTable(['a', 'b'], ['a -> b'])
ifTable.display()
print("")

#a if and only b
onlyTable = TruthTable(['a', 'b'], ['a <-> b'])
onlyTable.display()
print()
Exemple #2
0
from logic import TruthTable

notTable = TruthTable(['a'], ['-a'])
notTable.display()

print ""

yesTable = TruthTable(['a', 'b'], ['a and b'])
yesTable.display()

print ""

ONETable = TruthTable(['a', 'b'], ['a or b'])
ONETable.display()

print ""

TWOTable = TruthTable(['a', 'b'], ['a -> b'])
TWOTable.display()

print ""

THREETable = TruthTable(['a', 'b'], ['a <-> b'])
THREETable.display()
Exemple #3
0
from logic import TruthTable

andTable = TruthTable(['p', 'q'], ['p and q'])
orTable = TruthTable(['p', 'q'], ['p or q'])
xorTable = TruthTable(['p', 'q'], ['(p or q) and -(p and q)'])
negTable = TruthTable(['p'], ['-p'])
implyTable = TruthTable(['p', 'q'], ['p -> q'])
iffTable = TruthTable(['p', 'q'], ['p <-> q'])
table1 = TruthTable(['a', 'b'], ['a and -b'])
table2 = TruthTable(['a', 'b', 'c'], ['(a and b) or -c'])

print("AND operation table: ")
andTable.display()
print("\nOR operation table: ")
orTable.display()
print("\nXOR operation table: ")
xorTable.display()
print("\nNOT operation table: ")
negTable.display()
print("\nImplication operation table: ")
implyTable.display()
print("\nIf and only if operation table: ")
iffTable.display()
print("\nTable one: ")
table1.display()
print("\nTable two: ")
table2.display()
Exemple #4
0
from logic import TruthTable
myTable = TruthTable(['-a'])
myTable.display()
print("")
print("")
myTable2 = TruthTable(['a or b'])
myTable2.display()
print("")
print("")
myTable3 = TruthTable(['a and b'])
myTable3.display()
print("")
print("")
myTable4 = TruthTable(['a -> b'])
myTable4.display()
print("")
print("")
myTable5 = TruthTable(['a <-> b'])
myTable5.display()
from logic import TruthTable

myTable1 = TruthTable(['a'], ['-a'])
myTable1.display();

myTable2 = TruthTable(['a', 'b'], ['a and b'])
myTable2.display();

myTable3 = TruthTable(['a', 'b'], ['a or b'])
myTable3.display();

myTable4 = TruthTable(['a', 'b'], ['a -> b'])
myTable4.display();

myTable5 = TruthTable(['a', 'b'], ['a <-> b'])
myTable5.display();
from logic import TruthTable

not_a = TruthTable(['-a'])
not_a.display()

a_and_b = TruthTable(['a and b'])
a_and_b.display()

a_or_b = TruthTable(['a or b'])
a_or_b.display()

if_a_then_b = TruthTable(['a -> b'])
if_a_then_b.display()

a_if_and_only_if_b = TruthTable(['a <-> b'])
a_if_and_only_if_b.display()
Exemple #7
0
from logic import TruthTable
myTable = TruthTable(['p and q']) #Error Here
myTable.display()
myTable2 = TruthTable(['q and p']) #Error Here

print(myTable.table)
print(myTable2.table)
Exemple #8
0
        stop = False
    else:
        print('Not a valid input')
        exit()

tt = TruthTable(props)

print('Your propositions contain the following variables: ' + str(tt.vars)) 

meanings =[]      

for var in tt.vars:
    m = input('Enter meaning of ' + var + ': ')
    meanings.append(m) 

tt.display()


is_consistent = False
for row in tt.table:
    var_values = row[0]
    prop_values = row[1]
    temp = True
    for p in prop_values:
        temp = temp and p
    if temp == True:
        is_consistent = True
        print('Your description is consistent when:')
        for i in range(len(var_values)):
            if var_values[i] == 0:
                print('It is not the case that ' + meanings[i])
Exemple #9
0
        end_it = True

propTable = TruthTable(propList)

consistent = False
for i in range(len(propTable.table)):
    if propTable.table[i][1] == [1] * len(propList):  # double check it
        consistent = True
        break

if consistent:
    print('They are consistent')
else:
    print('They are not consistent')

propTable.display()

#propTable.display()
#print(propTable.table)
#row print(propTable.table[0])
#column propTable.table[0][1] )
#value at index print(t)
#print(propTable.table[1])
#print(propTable.table[1][0], propTable.table[1][1])

#or i in propList:#can't traverse table
#s    if (propTable.table[][] == propTable.table[][]): #how can I traverse the table rows?

#if(table.table == table.table):
#    print("Your description is consistent")
from logic import TruthTable

modusPonens = TruthTable(['p', 'q'], ['((p -> q) and p) -> q'])
modusTollens = TruthTable(['p', 'q'], ['(-q and (p -> q)) -> -p'])
hypoSyllogism = TruthTable(['p', 'q', 'r'],
                           ['((p -> q) and (q -> r)) -> (p -> r)'])
disSyllogism = TruthTable(['p', 'q'], ['((p or q) and -p) -> q'])
addition = TruthTable(['p', 'q'], ['p -> (p or q)'])
simplification = TruthTable(['p', 'q'], ['(p and q) -> p'])
conjunction = TruthTable(['p', 'q'], ['((p) and (q)) -> (p and q)'])
resolution = TruthTable(['p', 'q', 'r'],
                        ['((p or q) and (-p or r)) -> (q or r)'])

print("Modus Ponens verification:")
modusPonens.display()
print("\nModus Tollens verification:")
modusTollens.display()
print("\nHypothetical Syllogism verification:")
hypoSyllogism.display()
print("\nDisjunctive Syllogism verification:")
disSyllogism.display()
print("\nAddition verification:")
addition.display()
print("\nSimplification verification:")
simplification.display()
print("\nConjunction verification:")
conjunction.display()
print("\nResolution verification:")
resolution.display()
Exemple #11
0
from logic import TruthTable

yesTable = TruthTable(['p', 'q', 'r'], ['a -> b'])
yesTable.display()

print ""
Exemple #12
0
def basic():

    print("|1 = not a    || 2 = not b   || 3 = a and b || 4 = b and a |")
    print("|5 = a or b   || 6 = b or a  || 7 = a -> b  || 8 = b -> a  |")
    print("|9 = a <-> b  || 10 = b <-> a |\n")

    prop = int(raw_input("Choose a proposition: "))

    if prop == 1:
        myTable = TruthTable(['a', 'b'], ['-a'])
        myTable.display()
        print("\n")
        basic()
    if prop == 2:
        myTable = TruthTable(['a', 'b'], ['-b'])
        myTable.display()
        print("\n")
        basic()
    if prop == 3:
        myTable = TruthTable(['a', 'b'], ['a and b'])
        myTable.display()
        print("\n")
        basic()
    if prop == 4:
        myTable = TruthTable(['a', 'b'], ['b and a'])
        myTable.display()
        print("\n")
        basic()
    if prop == 5:
        myTable = TruthTable(['a', 'b'], ['a or b'])
        myTable.display()
        print("\n")
        basic()
    if prop == 6:
        myTable = TruthTable(['a', 'b'], ['b or a'])
        myTable.display()
        print("\n")
        basic()
    if prop == 7:
        myTable = TruthTable(['a', 'b'], ['a -> b'])
        myTable.display()
        print("\n")
        basic()
    if prop == 8:
        myTable = TruthTable(['a', 'b'], ['b -> a'])
        myTable.display()
        print("\n")
        basic()
    if prop == 9:
        myTable = TruthTable(['a', 'b'], ['a <-> b'])
        myTable.display()
        print("\n")
        basic()
    if prop == 10:
        myTable = TruthTable(['a', 'b'], ['b <-> a'])
        myTable.display()
        print("\n")
        basic()

    else:
        print("Not a correct prop!\n")
        basic()
Exemple #13
0
from logic import TruthTable

NextTable = TruthTable(['q -> r' ,'p -> (q -> r)'])
NextTable.display()
NextTable.latex()

TheTable = TruthTable(['p and q','(p and q) -> r'])
TheTable.display()
TheTable.latex()

NoTable = TruthTable(['q -> r', 'p -> (q -> r)'])
NoTable.display()
NoTable.latex()

YesTable = TruthTable(['p -> q', '(p -> q) -> r'])
YesTable.display()
YesTable.latex()
Exemple #14
0
from logic import TruthTable

FourTable = TruthTable(['p', 'q'], ['p and q', 'p or -q'])
FourTable.display()

print ""

FourTable.latex()

print ""

FiveTable = TruthTable(['p', 'q'], ['p or q', '-p or -q'])
FiveTable.display()

print ""

FiveTable.latex()

print ""

SixTable = TruthTable(['p', 'q'], ['p -> q', '-q -> -p'])
SixTable.display()

print ""

SixTable.latex()

print ""

SevenTable = TruthTable(['p', 'q'], ['p -> q', '-p or q'])
SevenTable.display()