def b(x,y): return Logic(x > y)
def o(n): return Logic(int(n)%2==1)
def e(n): return Logic(int(n)%2==0)
def l(x,y): return Logic(len(prep(x)) > len(prep(y)))
def s(x,y): return Logic(False) if not x else (Logic(True) if x[0] in y else s(x[1:], y))
def f(s): return Logic(len(prep(s)) == 5)
def t(s): return Logic(prep(s)[0] == "t")
def r(s): return Logic(prep(s)[0] == "r")
def int2bintup(i,cuanto): s = bin(int(i))[2:] while len(s) < cuanto: s = "0" + s return tuple([Logic(char) for char in s])
def draw(lam,n,funs): t = (Logic(False),Logic(True)) the_set = set() valid = set() vars = n n = len(vars) headers = vars + funs lens = tuple([len(h) for h in headers]) first_line = "+" each_line_s = "|" for l in [*lens]: first_line += "-"*(l+2) + "+" each_line_s += " {:^" + str(l) + "} |" each_line = lambda v: each_line_s.format(*v) print(first_line) headers = list(headers) for i,h in enumerate(headers): h = h.replace("|","∨") h = h.replace("&","∧") h = h.replace("^","⊕") h = h.replace("~","¬") h = h.replace("=","↔") h = h.replace(">","→") headers[i] = h print(each_line(headers)) def int2bintup(i,cuanto): s = bin(int(i))[2:] while len(s) < cuanto: s = "0" + s return tuple([Logic(char) for char in s]) def validity(vals): return (not ands(vals[:-1])) or vals[-1] for i in range(2**n): cur = int2bintup(i,n) vals = list(cur) + [l(*cur) for l in lam] the_set |= {bool(vals[-1])} es_valid = bool(validity(vals[n:])) valid |= {es_valid} print(first_line) printme = each_line(vals) if not es_valid: printme = printme[:-1] + "+-invalid" print(printme) vals = { 'Validity': len(lam)<2 or {True}==valid, 'Satisfiable': {True} <= the_set, 'Contradiction': {False} == the_set, 'Tautology': {True} == the_set, 'Contingency': {True,False} == the_set } new_line = '+---------------+---+' if len(first_line) > len(new_line): first_line, new_line = new_line, first_line to_draw = '' for i in range(len(first_line)): if first_line[i] == "+" or new_line[i] == "+": to_draw += "+" else: to_draw += "-" to_draw += new_line[len(first_line):] print(to_draw) for k,v in vals.items(): print('| {:>13} | {} |'.format(k,Logic(v))) print('+---------------+---+')