Skip to content

Instantly share code, notes, and snippets.

@manu354
Created May 10, 2020 05:59
Show Gist options
  • Select an option

  • Save manu354/8a5420ecc1677e81b619cc7cb0958b7c to your computer and use it in GitHub Desktop.

Select an option

Save manu354/8a5420ecc1677e81b619cc7cb0958b7c to your computer and use it in GitHub Desktop.
Three valued logic truth table generator
# Manu Masson
def or_f( a, b, ):
if a > b:
return a
else:
return b
def and_f( a, b):
if a < b:
return a
else:
return b
def if_f(a,b):
if a <= b:
return 1
elif a ==1 and b == 0:
return 0
else:
return 1/2
def not_f(a):
return 1-a
def print_table(rows):
for a in [0, 1 / 2, 1]:
if(rows> 1):
for b in [0, 1 / 2, 1]:
if(rows >2 ):
for c in [0, 1 / 2, 1]:
print(" %.1f | %.1f | %.1f || %.1f" %
(a, b, c,
output_f(a,b,c),
))
else:
print(" %.1f | %.1f || %.1f" %
(a, b,
output_f(a,b),
))
else:
print(" %.1f || %.1f" %
(a,
output_f(a)
))
def output_f(*args, **kwargs):
p = args[0]
if len(args) > 1: q = args[1]
if len(args) > 2: r = args[2]
# ENTER THE LOGICAL FORMULA HERE
# e.g not_f(if_f(and_f(p,or_f(q,r)), or_f(and_f(p,q), r)))
# equals the formula ∼((p&(q∨r))⊃((p&q)∨r))
return not_f(and_f(p,not_f(p)))
def main():
# ENTER THE NUMBER OF ATOMS HERE, 1-3
print_table(1)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment