Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pull_out_quantifications_across_binary_operator(formula: Formula) -> \
- Tuple[Formula, Proof]:
- """Converts the given formula with uniquely named variables of the form
- ``'(``\ `Q1`\ `x1`\ ``[``\ `Q2`\ `x2`\ ``[``...\ `Qn`\ `xn`\ ``[``\ `inner_first`\ ``]``...\ ``]]``\ `*`\ `P1`\ `y1`\ ``[``\ `P2`\ `y2`\ ``[``...\ `Pm`\ `ym`\ ``[``\ `inner_second`\ ``]``...\ ``]])'``
- to an equivalent formula of the form
- ``'``\ `Q'1`\ `x1`\ ``[``\ `Q'2`\ `x2`\ ``[``...\ `Q'n`\ `xn`\ ``[``\ `P'1`\ `y1`\ ``[``\ `P'2`\ `y2`\ ``[``...\ `P'm`\ `ym`\ ``[(``\ `inner_first`\ `*`\ `inner_second`\ ``)]``...\ ``]]]``...\ ``]]'``
- and proves the equivalence of these two formulas.
- Parameters:
- formula: formula with uniquely named variables to convert, whose root
- is a binary operator, i.e., which is of the form
- ``'(``\ `Q1`\ `x1`\ ``[``\ `Q2`\ `x2`\ ``[``...\ `Qn`\ `xn`\ ``[``\ `inner_first`\ ``]``...\ ``]]``\ `*`\ `P1`\ `y1`\ ``[``\ `P2`\ `y2`\ ``[``...\ `Pm`\ `ym`\ ``[``\ `inner_second`\ ``]``...\ ``]])'``
- where `*` is a binary operator, `n`>=0, `m`>=0, each `Qi` and `Pi`
- is a quantifier, each `xi` and `yi` is a variable name, and neither
- `inner_first` nor `inner_second` starts with a quantifier.
- Returns:
- A pair. The first element of the pair is a formula equivalent to the
- given formula, but of the form
- ``'``\ `Q'1`\ `x1`\ ``[``\ `Q'2`\ `x2`\ ``[``...\ `Q'n`\ `xn`\ ``[``\ `P'1`\ `y1`\ ``[``\ `P'2`\ `y2`\ ``[``...\ `P'm`\ `ym`\ ``[(``\ `inner_first`\ `*`\ `inner_second`\ ``)]``...\ ``]]]``...\ ``]]'``
- where each `Q'i` and `P'i` is a quantifier, and where the operator `*`,
- the `xi` and `yi` variable names, `inner_first`, and `inner_second` are
- the same as in the given formula. The second element of the pair is a
- proof of the equivalence of the given formula and the returned formula
- (i.e., a proof of
- `equivalence_of`\ ``(``\ `formula`\ ``,``\ `returned_formula`\ ``)``)
- via `~predicates.prover.Prover.AXIOMS` and
- `ADDITIONAL_QUANTIFICATION_AXIOMS`.
- Examples:
- >>> formula = Formula.parse('(Ax[Ey[R(x,y)]]->Ez[P(1,z)])')
- >>> returned_formula, proof = pull_out_quantifications_across_binary_operator(
- ... formula)
- >>> returned_formula
- Ex[Ay[Ez[(R(x,y)->P(1,z))]]]
- >>> proof.is_valid()
- True
- >>> proof.conclusion == equivalence_of(formula, returned_formula)
- True
- >>> proof.assumptions == Prover.AXIOMS.union(
- ... ADDITIONAL_QUANTIFICATION_AXIOMS)
- True
- """
- assert has_uniquely_named_variables(formula)
- assert is_binary(formula.root)
- prover = Prover(ADDITIONAL_QUANTIFICATION_AXIOMS)
- f1, p1 = pull_out_quantifications_from_left_across_binary_operator(formula)
- curr = f1
- lst_of_tuples = []
- while is_quantifier(curr.root):
- lst_of_tuples.append((curr.root, curr.variable))
- curr = curr.predicate
- f2, p2 = pull_out_quantifications_from_right_across_binary_operator(curr)
- step1 = prover.add_proof(p1.conclusion, p1)
- step2 = prover.add_proof(p2.conclusion, p2)
- dct = {'A': ADDITIONAL_QUANTIFICATION_AXIOMS[14], 'E': ADDITIONAL_QUANTIFICATION_AXIOMS[15]}
- inst = p2.conclusion
- for quantifier, variable in reversed(lst_of_tuples):
- map1 = {'R': inst.first.first, 'Q': inst.first.second, 'x': variable, 'y': variable}
- axiom = dct[quantifier]
- inst = axiom.instantiate(map1)
- step3 = prover.add_instantiated_assumption(inst, axiom, map1)
- inst = inst.second
- step2 = prover.add_mp(inst, step2, step3)
- prover.add_tautological_implication(equivalence_of(p1.conclusion.second.second,
- inst.first.second),
- {step1, step2})
- f = inst.first.second
- return f, prover.qed()
- # Task 11.8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement