import itertools as it
print_details = True
# task format:
# [name, vars_tuple, two_expressions_tuple]
tasks = [
['c', ('p', 'q'), ('p and q', 'p or q')],
['c\'', ('p', 'q'), ('implies(p, q)', 'p or q')],
['d', ('p', 'q'), ('implies(p, q)', 'implies(q, p)')],
['e', ('p', 'q'), ('p', 'implies(q, not p)')],
['f', ('p', 'q'), ('p or q', 'implies(not p, not q)')],
['g', ('p', 'q', 'r'), ('implies(p, q or (not r))', 'p and (not q) and r')],
['h', ('p', 'q', 'r'), ('implies(not (p and q), not r)', '(not implies(r, p)) and (not implies(r, q))')],
['i', ('p', 'q', 'r'), ('not (p or (not implies(q, r)))', 'implies(not p, q) and (p or (not r))')],
['j', ('p', 'q'), ('p or (not p)', 'q or (not q)')],
['k', ('p', 'q'), ('p or (not p)', 'not implies(q, q)')],
['l', ('p', 'q'), ('p and (not p)', 'not (q or (not q))')],
['ł', ('p', 'q'), ('p', 'implies(q, q)')],
['m', ('p', 'q'), ('p', 'not implies(not q, not q)')],
]
def implies(x, y):
return not(x) or y
for task in tasks:
name, variables, expressions = task
print(name + ')')
if print_details:
print(' '.join(variables), expressions)
relations = {
'leftToRightImplication': True,
'rightToLeftImplication': True,
'equivalence': True,
'exclusion': True,
'completion': True,
'contradiction': True,
}
for vars_values in it.product(range(2), repeat=len(variables)):
vars_string = ','.join(variables)
exec(vars_string + '=' + ','.join(map(str,vars_values)))
v0, v1 = int(eval(expressions[0]) == True), int(eval(expressions[1]) == True)
if not implies(v0, v1):
relations['leftToRightImplication'] = False
relations['equivalence'] = False
if not implies(v1, v0):
relations['rightToLeftImplication'] = False
relations['equivalence'] = False
if v0 and v1:
relations['exclusion'] = False
relations['contradiction'] = False
if (not v0) and (not v1):
relations['completion'] = False
relations['contradiction'] = False
if print_details:
exec('print(' + vars_string + ', v0, v1)')
for relations_key, relations_value in relations.items():
if relations_value:
print(relations_key + ':', relations_value)
print()
aW1wb3J0IGl0ZXJ0b29scyBhcyBpdAoKCnByaW50X2RldGFpbHMgPSBUcnVlCgojIHRhc2sgZm9ybWF0OgojIFtuYW1lLCB2YXJzX3R1cGxlLCB0d29fZXhwcmVzc2lvbnNfdHVwbGVdCnRhc2tzID0gWwogICAgWydjJywgKCdwJywgJ3EnKSwgKCdwIGFuZCBxJywgJ3Agb3IgcScpXSwKICAgIFsnY1wnJywgKCdwJywgJ3EnKSwgKCdpbXBsaWVzKHAsIHEpJywgJ3Agb3IgcScpXSwKICAgIFsnZCcsICgncCcsICdxJyksICgnaW1wbGllcyhwLCBxKScsICdpbXBsaWVzKHEsIHApJyldLAogICAgWydlJywgKCdwJywgJ3EnKSwgKCdwJywgJ2ltcGxpZXMocSwgbm90IHApJyldLAogICAgWydmJywgKCdwJywgJ3EnKSwgKCdwIG9yIHEnLCAnaW1wbGllcyhub3QgcCwgbm90IHEpJyldLAogICAgWydnJywgKCdwJywgJ3EnLCAncicpLCAoJ2ltcGxpZXMocCwgcSBvciAobm90IHIpKScsICdwIGFuZCAobm90IHEpIGFuZCByJyldLAogICAgWydoJywgKCdwJywgJ3EnLCAncicpLCAoJ2ltcGxpZXMobm90IChwIGFuZCBxKSwgbm90IHIpJywgJyhub3QgaW1wbGllcyhyLCBwKSkgYW5kIChub3QgaW1wbGllcyhyLCBxKSknKV0sCiAgICBbJ2knLCAoJ3AnLCAncScsICdyJyksICgnbm90IChwIG9yIChub3QgaW1wbGllcyhxLCByKSkpJywgJ2ltcGxpZXMobm90IHAsIHEpIGFuZCAocCBvciAobm90IHIpKScpXSwKICAgIFsnaicsICgncCcsICdxJyksICgncCBvciAobm90IHApJywgJ3Egb3IgKG5vdCBxKScpXSwKICAgIFsnaycsICgncCcsICdxJyksICgncCBvciAobm90IHApJywgJ25vdCBpbXBsaWVzKHEsIHEpJyldLAogICAgWydsJywgKCdwJywgJ3EnKSwgKCdwIGFuZCAobm90IHApJywgJ25vdCAocSBvciAobm90IHEpKScpXSwKICAgIFsnxYInLCAoJ3AnLCAncScpLCAoJ3AnLCAnaW1wbGllcyhxLCBxKScpXSwKICAgIFsnbScsICgncCcsICdxJyksICgncCcsICdub3QgaW1wbGllcyhub3QgcSwgbm90IHEpJyldLAogICAgXQoKCmRlZiBpbXBsaWVzKHgsIHkpOgogICAgcmV0dXJuIG5vdCh4KSBvciB5Cgpmb3IgdGFzayBpbiB0YXNrczoKICAgIG5hbWUsIHZhcmlhYmxlcywgZXhwcmVzc2lvbnMgPSB0YXNrCiAgICBwcmludChuYW1lICsgJyknKQogICAgaWYgcHJpbnRfZGV0YWlsczoKICAgICAgICBwcmludCgnICcuam9pbih2YXJpYWJsZXMpLCBleHByZXNzaW9ucykKICAgIAogICAgcmVsYXRpb25zID0gewogICAgICAgICdsZWZ0VG9SaWdodEltcGxpY2F0aW9uJzogVHJ1ZSwKICAgICAgICAncmlnaHRUb0xlZnRJbXBsaWNhdGlvbic6IFRydWUsCiAgICAgICAgJ2VxdWl2YWxlbmNlJzogVHJ1ZSwKICAgICAgICAnZXhjbHVzaW9uJzogVHJ1ZSwKICAgICAgICAnY29tcGxldGlvbic6IFRydWUsCiAgICAgICAgJ2NvbnRyYWRpY3Rpb24nOiBUcnVlLAogICAgICAgIH0KCiAgICBmb3IgdmFyc192YWx1ZXMgaW4gaXQucHJvZHVjdChyYW5nZSgyKSwgcmVwZWF0PWxlbih2YXJpYWJsZXMpKToKICAgICAgICB2YXJzX3N0cmluZyA9ICcsJy5qb2luKHZhcmlhYmxlcykKICAgICAgICBleGVjKHZhcnNfc3RyaW5nICsgJz0nICsgJywnLmpvaW4obWFwKHN0cix2YXJzX3ZhbHVlcykpKQogICAgICAgIHYwLCB2MSA9IGludChldmFsKGV4cHJlc3Npb25zWzBdKSA9PSBUcnVlKSwgaW50KGV2YWwoZXhwcmVzc2lvbnNbMV0pID09IFRydWUpCiAgICAgICAgaWYgbm90IGltcGxpZXModjAsIHYxKToKICAgICAgICAgICAgcmVsYXRpb25zWydsZWZ0VG9SaWdodEltcGxpY2F0aW9uJ10gPSBGYWxzZQogICAgICAgICAgICByZWxhdGlvbnNbJ2VxdWl2YWxlbmNlJ10gPSBGYWxzZQogICAgICAgIGlmIG5vdCBpbXBsaWVzKHYxLCB2MCk6CiAgICAgICAgICAgIHJlbGF0aW9uc1sncmlnaHRUb0xlZnRJbXBsaWNhdGlvbiddID0gRmFsc2UKICAgICAgICAgICAgcmVsYXRpb25zWydlcXVpdmFsZW5jZSddID0gRmFsc2UKICAgICAgICBpZiB2MCBhbmQgdjE6CiAgICAgICAgICAgIHJlbGF0aW9uc1snZXhjbHVzaW9uJ10gPSBGYWxzZQogICAgICAgICAgICByZWxhdGlvbnNbJ2NvbnRyYWRpY3Rpb24nXSA9IEZhbHNlCiAgICAgICAgaWYgKG5vdCB2MCkgYW5kIChub3QgdjEpOgogICAgICAgICAgICByZWxhdGlvbnNbJ2NvbXBsZXRpb24nXSA9IEZhbHNlCiAgICAgICAgICAgIHJlbGF0aW9uc1snY29udHJhZGljdGlvbiddID0gRmFsc2UKICAgICAgICBpZiBwcmludF9kZXRhaWxzOgogICAgICAgICAgICBleGVjKCdwcmludCgnICsgdmFyc19zdHJpbmcgKyAnLCB2MCwgdjEpJykgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAKICAgIGZvciByZWxhdGlvbnNfa2V5LCByZWxhdGlvbnNfdmFsdWUgaW4gcmVsYXRpb25zLml0ZW1zKCk6CiAgICAgICAgaWYgcmVsYXRpb25zX3ZhbHVlOgogICAgICAgICAgICBwcmludChyZWxhdGlvbnNfa2V5ICsgJzonLCByZWxhdGlvbnNfdmFsdWUpCiAgICBwcmludCgpCg==