fork download
  1. import itertools as it
  2.  
  3.  
  4. print_details = True
  5.  
  6. # task format:
  7. # [name, vars_tuple, two_expressions_tuple]
  8. tasks = [
  9. ['c', ('p', 'q'), ('p and q', 'p or q')],
  10. ['c\'', ('p', 'q'), ('implies(p, q)', 'p or q')],
  11. ['d', ('p', 'q'), ('implies(p, q)', 'implies(q, p)')],
  12. ['e', ('p', 'q'), ('p', 'implies(q, not p)')],
  13. ['f', ('p', 'q'), ('p or q', 'implies(not p, not q)')],
  14. ['g', ('p', 'q', 'r'), ('implies(p, q or (not r))', 'p and (not q) and r')],
  15. ['h', ('p', 'q', 'r'), ('implies(not (p and q), not r)', '(not implies(r, p)) and (not implies(r, q))')],
  16. ['i', ('p', 'q', 'r'), ('not (p or (not implies(q, r)))', 'implies(not p, q) and (p or (not r))')],
  17. ['j', ('p', 'q'), ('p or (not p)', 'q or (not q)')],
  18. ['k', ('p', 'q'), ('p or (not p)', 'not implies(q, q)')],
  19. ['l', ('p', 'q'), ('p and (not p)', 'not (q or (not q))')],
  20. ['ł', ('p', 'q'), ('p', 'implies(q, q)')],
  21. ['m', ('p', 'q'), ('p', 'not implies(not q, not q)')],
  22. ]
  23.  
  24.  
  25. def implies(x, y):
  26. return not(x) or y
  27.  
  28. for task in tasks:
  29. name, variables, expressions = task
  30. print(name + ')')
  31. if print_details:
  32. print(' '.join(variables), expressions)
  33.  
  34. relations = {
  35. 'leftToRightImplication': True,
  36. 'rightToLeftImplication': True,
  37. 'equivalence': True,
  38. 'exclusion': True,
  39. 'completion': True,
  40. 'contradiction': True,
  41. }
  42.  
  43. for vars_values in it.product(range(2), repeat=len(variables)):
  44. vars_string = ','.join(variables)
  45. exec(vars_string + '=' + ','.join(map(str,vars_values)))
  46. v0, v1 = int(eval(expressions[0]) == True), int(eval(expressions[1]) == True)
  47. if not implies(v0, v1):
  48. relations['leftToRightImplication'] = False
  49. relations['equivalence'] = False
  50. if not implies(v1, v0):
  51. relations['rightToLeftImplication'] = False
  52. relations['equivalence'] = False
  53. if v0 and v1:
  54. relations['exclusion'] = False
  55. relations['contradiction'] = False
  56. if (not v0) and (not v1):
  57. relations['completion'] = False
  58. relations['contradiction'] = False
  59. if print_details:
  60. exec('print(' + vars_string + ', v0, v1)')
  61.  
  62. for relations_key, relations_value in relations.items():
  63. if relations_value:
  64. print(relations_key + ':', relations_value)
  65. print()
  66.  
Success #stdin #stdout 0.05s 9492KB
stdin
Standard input is empty
stdout
c)
p q ('p and q', 'p or q')
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
leftToRightImplication: True

c')
p q ('implies(p, q)', 'p or q')
0 0 1 0
0 1 1 1
1 0 0 1
1 1 1 1
completion: True

d)
p q ('implies(p, q)', 'implies(q, p)')
0 0 1 1
0 1 1 0
1 0 0 1
1 1 1 1
completion: True

e)
p q ('p', 'implies(q, not p)')
0 0 0 1
0 1 0 1
1 0 1 1
1 1 1 0
completion: True

f)
p q ('p or q', 'implies(not p, not q)')
0 0 0 1
0 1 1 0
1 0 1 1
1 1 1 1
completion: True

g)
p q r ('implies(p, q or (not r))', 'p and (not q) and r')
0 0 0 1 0
0 0 1 1 0
0 1 0 1 0
0 1 1 1 0
1 0 0 1 0
1 0 1 0 1
1 1 0 1 0
1 1 1 1 0
completion: True
contradiction: True
exclusion: True

h)
p q r ('implies(not (p and q), not r)', '(not implies(r, p)) and (not implies(r, q))')
0 0 0 1 0
0 0 1 0 1
0 1 0 1 0
0 1 1 0 0
1 0 0 1 0
1 0 1 0 0
1 1 0 1 0
1 1 1 1 0
exclusion: True

i)
p q r ('not (p or (not implies(q, r)))', 'implies(not p, q) and (p or (not r))')
0 0 0 1 0
0 0 1 1 0
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 0 1
1 1 0 0 1
1 1 1 0 1
completion: True
contradiction: True
exclusion: True

j)
p q ('p or (not p)', 'q or (not q)')
0 0 1 1
0 1 1 1
1 0 1 1
1 1 1 1
rightToLeftImplication: True
completion: True
leftToRightImplication: True
equivalence: True

k)
p q ('p or (not p)', 'not implies(q, q)')
0 0 1 0
0 1 1 0
1 0 1 0
1 1 1 0
rightToLeftImplication: True
completion: True
contradiction: True
exclusion: True

l)
p q ('p and (not p)', 'not (q or (not q))')
0 0 0 0
0 1 0 0
1 0 0 0
1 1 0 0
rightToLeftImplication: True
leftToRightImplication: True
exclusion: True
equivalence: True

ł)
p q ('p', 'implies(q, q)')
0 0 0 1
0 1 0 1
1 0 1 1
1 1 1 1
completion: True
leftToRightImplication: True

m)
p q ('p', 'not implies(not q, not q)')
0 0 0 0
0 1 0 0
1 0 1 0
1 1 1 0
rightToLeftImplication: True
exclusion: True