def test_prove_from_skeleton_proof(debug=False): from propositions.tautology import prove_tautology for formula,skeleton,substitution_map in [ ('(R(c)->R(c))', '(z23->z23)', {'z23':Formula.parse('R(c)')}), ('(x=0->x=0)', '(z24->z24)', {'z24':Formula.parse('x=0')}), ('(Ex[x=0]->Ex[x=0])', '(z25->z25)', {'z25':Formula.parse('Ex[x=0]')}), ('((~y=1->~x=1)->(x=1->y=1))', '((~z26->~z27)->(z27->z26))', {'z26':Formula.parse('y=1'), 'z27':Formula.parse('x=1')}), ('(~~Ex[y=2]->Ex[y=2])', '(~~z28->z28)', {'z28':Formula.parse('Ex[y=2]')}), ('(Ex[Ey[x=y]]->~~Ex[Ey[x=y]])', '(z29->~~z29)', {'z29':Formula.parse('Ex[Ey[x=y]]')}), ('((~Ex[(x=2->x=3)]->~R(y,4))->((Ex[(x=2->x=3)]->~R(y,4))->~R(y,4)))', '((~z30->~z31)->((z30->~z31)->~z31))', {'z30':Formula.parse('Ex[(x=2->x=3)]'), 'z31':Formula.parse('R(y,4)')}), ('((Ey[~x=y]->(y=3->y=74))->(y=3->(Ey[~x=y]->y=74)))', '((z32->(z33->z34))->(z33->(z32->z34)))', {'z32':Formula.parse('Ey[~x=y]'), 'z33':Formula.parse('y=3'), 'z34':Formula.parse('y=74')}), ('(~~~~Q()->~~Q())', '(~~~~z35->~~z35)', {'z35':Formula.parse('Q()')})]: if debug: print('Testing proving', formula, 'from proof of', skeleton) formula = Formula.parse(formula) skeleton = PropositionalFormula.parse(skeleton) skeleton_proof = prove_tautology(skeleton) assert skeleton_proof.is_valid(), 'Bug in prove_tautology!' proof = prove_from_skeleton_proof(formula, skeleton_proof, frozendict(substitution_map)) assert proof.assumptions == PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS assert proof.conclusion == formula assert proof.is_valid()
def test_prove_tautology(debug=False): for tautology in [ '(R(c)->R(c))', '(x=0->x=0)', '(Ex[x=0]->Ex[x=0])', '((~y=1->~x=1)->(x=1->y=1))', '(~~Ex[y=2]->Ex[y=2])', '(Ex[Ey[x=y]]->~~Ex[Ey[x=y]])', '((~Ex[(x=2->x=3)]->~R(y,4))->' + '((Ex[(x=2->x=3)]->~R(y,4))->~R(y,4)))', '((Ey[~x=y]->(y=3->y=74))->(y=3->(Ey[~x=y]->y=74)))', '(~~~~Q()->~~Q())']: if debug: print('Testing proving the tautology', tautology) tautology = Formula.parse(tautology) proof = prove_tautology(tautology) assert proof.assumptions == PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS assert proof.conclusion == tautology for line in proof.lines: assert type(line) in {Proof.AssumptionLine, Proof.MPLine} assert proof.is_valid()