def test_variables_all_operators(debug=False): for infix,variables in [['(x|(y70&~(p?y70:z)))', {'p', 'x', 'y70', 'z'}], ['(((x1->x11)-|x111)-&(x1?x11:(x111<->x1111)))', {'x1', 'x11', 'x111', 'x1111'}]]: formula = Formula.from_infix(infix) if debug: print ("Testing variables of", formula) assert formula.variables() == variables
def test_from_infix_all_operators(debug=False): for infix in ['T', 'F', 'p', '~p', '(p&q)', '(p|q)', '(p->q)', '(p<->q)', '(p-&q)', '(p-|q)', '(p?q:r)', '(F?F:F)', '(T->T)', '(~(x->y)->z)', '~(T?T:T)', '((x<->x)?x:x)', '(F?(y123-&F):(y123-|F))']: if debug: print("Testing infix parsing of formula", infix) assert Formula.from_infix(infix).infix() == infix
def test_variables(debug=False): for infix,variables in [['(x|(y70&~x))', {'x', 'y70'}], ['((x|y)|z)', {'x', 'y', 'z'}], ['~~(p11&~q11)', {'p11', 'q11'}], ['(T|p)', {'p'}], ['F', set()], ['~(T|F)', set()]]: formula = Formula.from_infix(infix) if debug: print ("Testing variables of", formula) assert formula.variables() == variables
def test_from_infix(debug=False): for infix in ['p', '~x12', '(x&y)', '~~(x|~T)', '((x1&~x2)|F)']: if debug: print("Testing infix parsing of formula", infix) assert Formula.from_infix(infix).infix() == infix
# DESCRIPTION : # ################################################## from propositions.syntax import Formula if __name__ == '__main__': q = Formula('q') z = Formula('z') nz = Formula('~', z) f = Formula('&', q, z) t = Formula('~', f) s = '(((~(y10|F)|T)&(F|T))|s2)' prefixString = '~|~~&pq2&pq5' q = Formula('|', t, f) infixTest = Formula.from_infix(s) print(infixTest) # h = Formula(t,q,f) q.from_infix('~(~~(q&r4)|(q&r6))') # if q.from_prefix(prefixString ).prefix() == prefixString : # print(q.from_prefix(prefixString )) # print(q.from_prefix(prefixString ).prefix()) # print("variables of prefix:", q.from_prefix(prefixString ).variables()) # # print('variables of q: ', q.variables()) # # exit(0) if q.from_infix(s).infix() == s: print(s) print(q)