コード例 #1
0
def test_replace_constant(debug=False):
    from predicates.prover_test import syllogism_proof,\
                                       syllogism_proof_with_universal_instantiation
    from predicates.some_proofs import unique_zero_proof, GROUP_AXIOMS

    # Replace in assumptions formulae, constant instantiation maps, mp
    if debug:
        print('Testing replace_constant for replacing aristotle with z in '
              'syllogism proof')
    for proof in [
            syllogism_proof(),
            syllogism_proof_with_universal_instantiation()
    ]:
        replaced = replace_constant(proof, 'aristotle', 'z')
        assert replaced.assumptions == \
               Prover.AXIOMS + [Schema('Ax[(Man(x)->Mortal(x))]'),
                                Schema('Man(z)')]
        assert str(replaced.conclusion) == 'Mortal(z)'
        if debug:
            print(
                'Verifying returned proof (' +
                '{:,}'.format(len(replaced.lines)), 'lines) of',
                replaced.conclusion)
        # Will be tested with the course staff's implementation of is_valid
        assert replaced.is_valid()

    # Replace in ug, tautology, relation instantiation maps
    proof = unique_zero_proof()
    if debug:
        print('Testing replace_constant for replacing a with zz in '
              'unique-zero proof')
    replaced = replace_constant(proof, 'a')
    assert replaced.assumptions == \
           Prover.AXIOMS + [Schema(a) for a in GROUP_AXIOMS] + \
           [Schema('plus(zz,c)=zz')]
    assert str(replaced.conclusion) == 'c=0'
    if debug:
        print(
            'Verifying returned proof (' + '{:,}'.format(len(replaced.lines)),
            'lines) of', replaced.conclusion)
    # Will be tested with the course staff's implementation of is_valid
    assert replaced.is_valid()
コード例 #2
0
ファイル: deduction_test.py プロジェクト: noamRoditi/Logic
def test_remove_assumption(debug=False):
    from predicates.some_proofs import \
         GROUP_AXIOMS,unique_zero_proof,lovers_proof,homework_proof
    from predicates.some_proofs_test import \
         test_unique_zero_proof,test_lovers_proof,test_homework_proof
    from predicates.prover_test import \
         syllogism_proof,syllogism_proof_with_universal_instantiation,\
         syllogism_all_all_proof,\
         syllogism_all_all_proof_with_tautological_inference,\
         syllogism_all_exists_proof,\
         syllogism_all_exists_proof_with_existential_derivation

    # Test one invocation
    test_unique_zero_proof()
    proof = unique_zero_proof()
    if (debug):
        print(
            "Testing remove_assumption with assumption 'plus(a,c)=a' for the "
            'following proof:\n' + str(proof))
    result = remove_assumption(proof, Formula.parse('plus(a,c)=a'), debug)
    assert result.assumptions == \
           Prover.AXIOMS.union({Schema(Formula.parse(a)) for a in GROUP_AXIOMS})
    assert str(result.conclusion) == '(plus(a,c)=a->c=0)'
    # Will be tested with the course staff's implementation of is_valid
    assert result.is_valid()

    # Test two concurrent invocations
    test_lovers_proof()
    test_homework_proof()
    for proof, assumption1, assumption2 in [
        (syllogism_proof(), 'Ax[(Man(x)->Mortal(x))]', 'Man(aristotle)'),
        (syllogism_proof(), 'Man(aristotle)', 'Ax[(Man(x)->Mortal(x))]'),
        (syllogism_proof_with_universal_instantiation(),
         'Ax[(Man(x)->Mortal(x))]', 'Man(aristotle)'),
        (syllogism_proof_with_universal_instantiation(), 'Man(aristotle)',
         'Ax[(Man(x)->Mortal(x))]'),
        (syllogism_all_all_proof(), 'Ax[(Greek(x)->Human(x))]',
         'Ax[(Human(x)->Mortal(x))]'),
        (syllogism_all_all_proof(), 'Ax[(Human(x)->Mortal(x))]',
         'Ax[(Greek(x)->Human(x))]'),
        (syllogism_all_all_proof_with_tautological_inference(),
         'Ax[(Greek(x)->Human(x))]', 'Ax[(Human(x)->Mortal(x))]'),
        (syllogism_all_all_proof_with_tautological_inference(),
         'Ax[(Human(x)->Mortal(x))]', 'Ax[(Greek(x)->Human(x))]'),
        (syllogism_all_exists_proof(), 'Ax[(Man(x)->Mortal(x))]',
         'Ex[Man(x)]'),
        (syllogism_all_exists_proof(), 'Ex[Man(x)]',
         'Ax[(Man(x)->Mortal(x))]'),
        (syllogism_all_exists_proof_with_existential_derivation(),
         'Ax[(Man(x)->Mortal(x))]', 'Ex[Man(x)]'),
        (syllogism_all_exists_proof_with_existential_derivation(),
         'Ex[Man(x)]', 'Ax[(Man(x)->Mortal(x))]'),
        (lovers_proof(), 'Ax[Ey[Loves(x,y)]]',
         'Ax[Az[Ay[(Loves(x,y)->Loves(z,x))]]]'),
        (lovers_proof(), 'Ax[Az[Ay[(Loves(x,y)->Loves(z,x))]]]',
         'Ax[Ey[Loves(x,y)]]'),
        (homework_proof(), '~Ex[(Homework(x)&Fun(x))]',
         'Ex[(Homework(x)&Reading(x))]'),
        (homework_proof(), 'Ex[(Homework(x)&Reading(x))]',
         '~Ex[(Homework(x)&Fun(x))]')
    ]:
        if (debug):
            print("Testing remove_assumption with assumption '" + assumption1 +
                  "' for the following proof:\n" + str(proof))
        assumption1 = Formula.parse(assumption1)
        assumption2 = Formula.parse(assumption2)
        result1 = remove_assumption(proof, assumption1)
        assert result1.assumptions == Prover.AXIOMS.union(
            {Schema(assumption2)})
        assert result1.conclusion == Formula('->', assumption1,
                                             proof.conclusion)
        # Will be tested with the course staff's implementation of is_valid
        assert result1.is_valid()

        if (debug):
            print("Testing remove_assumption with assumption '" +
                  str(assumption2) + "'for the following proof:\n" +
                  str(result1))
        result2 = remove_assumption(result1, assumption2)
        assert result2.assumptions == Prover.AXIOMS
        assert result2.conclusion == Formula(
            '->', assumption2, Formula('->', assumption1, proof.conclusion))
        # Will be tested with the course staff's implementation of is_valid
        assert result2.is_valid()