Exemple #1
0
 def proving_dfs(expression):
     if not isinstance(expression.left, Variable):
         proving_dfs(expression.left)
     if expression.right is not None and not isinstance(expression.right, Variable):
         proving_dfs(expression.right)
     if isinstance(expression, Negation):
         if var_mapping[expression.left]:
             key = 'A|-!!A'
         else:
             key = '!A|-!A'
         proof_pattern = simpleProves[key]
         proof.extend([eval_by_mapping(expr, {'A': expression.left}) for expr in proof_pattern])
         i = 0
         neg = proof[-1]
         while isinstance(neg, Negation):
             i += 1
             neg = neg.left
         i = i % 2 == 0
         var_mapping[proof[-1]] = var_mapping[neg] if i else not var_mapping[neg]
         var_mapping[proof[-1].left] = not var_mapping[proof[-1]]
     else:
         asmp_a = expression.left if expression.left in var_mapping else Negation(expression.left)
         asmp_b = expression.right if expression.right in var_mapping else Negation(expression.right)
         truth_table = {'A': var_mapping[asmp_a], 'B': var_mapping[asmp_b]}
         asmp_a = 'A' if truth_table['A'] else '!A'
         asmp_b = 'B' if truth_table['B'] else '!B'
         statement = ('' if expression.op_eval(truth_table) else '!') + '(A{}B)'.format(expression.op())
         key = asmp_a + ',' + asmp_b + '|-' + statement
         proof_pattern = simpleProves[key]
         proof.extend([eval_by_mapping(expr, {'A': expression.left, 'B': expression.right}) for expr in proof_pattern])
         var_mapping[expression] = expression.op_eval(truth_table)
         if isinstance(proof[-1], Negation):
             var_mapping[proof[-1]] = not var_mapping[expression]
     pass
Exemple #2
0
def assumption_pop(assumptions, alpha, formula, old_proof_negated, old_proof):
    proof = deduction(assumptions, alpha, old_proof)  # Вывод Г |- alpha -> formula - (1)
    proof.extend(deduction(assumptions, Negation(alpha), old_proof_negated))  # Вывод Г |- !alpha -> formula - (2)
    proof.extend(
        [eval_by_mapping(line, {'A': alpha}) for line in simpleProves['|-A|!A']]
    )  # док-во alpha|!alpha - (3)
    mapping = {'A': alpha, 'B': formula, 'C': Negation(alpha)}
    proof.append(eval_by_mapping(parsed_axioms[7][0], mapping))  # сх. аксиом 8 - (4)
    proof.append(eval_by_mapping(parsed_axioms[7][0].right, mapping))  # M.P. последнее выражение в (1), (4)  - (5)
    proof.append(eval_by_mapping(parsed_axioms[7][0].right.right, mapping))  # M.P. последнее выражение в (2), (5) - (6)
    proof.append(eval_by_mapping(parsed_axioms[7][0].right.right.right, mapping))  # M.P. последнее выражение в (3), (6)
    return proof
Exemple #3
0
def deduction(assump, alpha, old_proof):
    cache = {}
    self_consequence = ['A->A->A',
                       '(A->A->A)->(A->(A->A)->A)->(A->A)',
                                  '(A->(A->A)->A)->(A->A)',
                                   'A->(A->A)->A',
                                                   'A->A']
    self_consequence = [p.parse(i) for i in self_consequence]
    res = []
    proof = []
    j = 0
    for line in old_proof:
        if j == 34:
            pass
        for exp in assump + parsed_axioms:
            if (isinstance(exp, tuple) and exp[0] == line) or \
                    ((isinstance(exp, Expression) or isinstance(exp, Variable)) and exp == line):
                res.append(Consequence(line, Consequence(alpha, line)))
                res.append(line)
                res.append(Consequence(alpha, line))
                break
        else:
            if line == alpha:
                for i in self_consequence:
                    res.append(eval_by_mapping(i, {'A': alpha}))
            else:
                for cons, i in reversed(proof):
                    if isinstance(cons, Consequence) and cons.right == line and cons.left in cache:
                        q = {'A': alpha, 'B': cons.left, 'C': line}
                        res.append(eval_by_mapping(parsed_axioms[1][0], q))
                        res.append(eval_by_mapping(parsed_axioms[1][0].right, q))
                        res.append(Consequence(alpha, line))
                        break
        proof.append((line, len(proof) + 1))
        cache[line] = len(proof)
        j += 1
    return res