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()
