Ejemplo n.º 1
0
def prove_from_skeleton_proof(formula: Formula,
                              skeleton_proof: PropositionalProof,
                              substitution_map: Mapping[str, Formula]) -> \
        Proof:
    """Converts the given proof of a propositional skeleton of the given
    predicate-logic formula into a proof of that predicate-logic formula.

    Parameters:
        formula: predicate-logic formula to prove.
        skeleton_proof: valid propositional-logic proof of a propositional
            skeleton of the given formula, from no assumptions and via
            `~propositions.axiomatic_systems.AXIOMATIC_SYSTEM`.
        substitution_map: map from each atomic propositional subformula of the
            skeleton of the given formula that is proven in the given proof to
            the respective predicate-logic subformula of the given formula.

    Returns:
        A valid predicate-logic proof of the given formula from the axioms
        `PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS` via only assumption lines and
        MP lines.
    """
    assert len(skeleton_proof.statement.assumptions) == 0 and \
           skeleton_proof.rules.issubset(PROPOSITIONAL_AXIOMATIC_SYSTEM) and \
           skeleton_proof.is_valid()
    assert Formula.from_propositional_skeleton(
        skeleton_proof.statement.conclusion, substitution_map) == formula
    # Task 9.11.2
    # create the proof, translate lines, assumption and conclusion

    # creating lines:
    predicate_line_formulas = [
        Formula.from_propositional_skeleton(line.formula, substitution_map)
        for line in skeleton_proof.lines
    ]
    real_predicate_lines = []
    for predicate_formula, skeleton_line in zip(predicate_line_formulas,
                                                skeleton_proof.lines):
        # if line was proven using MP
        if skeleton_line.rule == MP:
            # if the line is MP create a predicate MP line
            real_predicate_lines.append(
                Proof.MPLine(predicate_formula, skeleton_line.assumptions[0],
                             skeleton_line.assumptions[1]))

        else:  # line must be from an axiom
            line_to_specialization_map = PropositionalInferenceRule.formula_specialization_map(
                skeleton_line.rule.conclusion, skeleton_line.formula)
            instantiation_map = axiom_specialization_map_to_schema_instantiation_map(
                line_to_specialization_map, substitution_map)
            real_predicate_lines.append(
                Proof.AssumptionLine(
                    predicate_formula,
                    PROPOSITIONAL_AXIOM_TO_SCHEMA[skeleton_line.rule],
                    instantiation_map))
    # create the final proof
    return Proof(PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS, formula,
                 real_predicate_lines)
Ejemplo n.º 2
0
def prove_from_skeleton_proof(formula: Formula,
                              skeleton_proof: PropositionalProof,
                              substitution_map: Mapping[str, Formula]) -> \
        Proof:
    """Converts the given proof of a propositional skeleton of the given
    predicate-logic formula into a proof of that predicate-logic formula.

    Parameters:
        formula: predicate-logic formula to prove.
        skeleton_proof: valid propositional-logic proof of a propositional
            skeleton of the given formula, from no assumptions and via
            `~propositions.axiomatic_systems.AXIOMATIC_SYSTEM`.
        substitution_map: map from each atomic propositional subformula of the
            skeleton of the given formula that is proven in the given proof to
            the respective predicate-logic subformula of the given formula.

    Returns:
        A valid predicate-logic proof of the given formula from the axioms
        `PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS` via only assumption lines and
        MP lines.
    """
    assert len(skeleton_proof.statement.assumptions) == 0 and \
           skeleton_proof.rules.issubset(PROPOSITIONAL_AXIOMATIC_SYSTEM) and \
           skeleton_proof.is_valid()
    assert Formula.from_propositional_skeleton(
        skeleton_proof.statement.conclusion, substitution_map) == formula
    # Task 9.11.2

    assumptions = PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS
    conclusion = formula
    lines = []

    for skeleton_line in skeleton_proof.lines:
        line_formula = Formula.from_propositional_skeleton(
            skeleton_line.formula, substitution_map)
        if PropositionalProof.Line.is_assumption(skeleton_line):
            assumption_schema = Schema(line_formula, set())
            line = Proof.AssumptionLine(line_formula, assumption_schema,
                                        dict())
        else:
            if skeleton_line.rule == MP:
                ante_line_num, cond_line_num = [
                    skeleton_line.assumptions[i] for i in [0, 1]
                ]
                line = Proof.MPLine(line_formula, ante_line_num, cond_line_num)
            else:
                schema_rule = PROPOSITIONAL_AXIOM_TO_SCHEMA[skeleton_line.rule]
                prop_spec_map = PropositionalInferenceRule.formula_specialization_map(
                    skeleton_line.rule.conclusion, skeleton_line.formula)
                inst_map = axiom_specialization_map_to_schema_instantiation_map(
                    prop_spec_map, substitution_map)
                line = Proof.AssumptionLine(line_formula, schema_rule,
                                            inst_map)
        lines.append(line)

    return Proof(assumptions, conclusion, lines)
Ejemplo n.º 3
0
def prove_from_skeleton_proof(formula: Formula,
                              skeleton_proof: PropositionalProof,
                              substitution_map: Mapping[str, Formula]) -> \
        Proof:
    """Converts the given proof of a propositional skeleton of the given
    predicate-logic formula into a proof of that predicate-logic formula.

    Parameters:
        formula: predicate-logic formula to prove.
        skeleton_proof: valid propositional-logic proof of a propositional
            skeleton of the given formula, from no assumptions and via
            `~propositions.axiomatic_systems.AXIOMATIC_SYSTEM`.
        substitution_map: map from each atomic propositional subformula of the
            skeleton of the given formula that is proven in the given proof to
            the respective predicate-logic subformula of the given formula.

    Returns:
        A valid predicate-logic proof of the given formula from the axioms
        `PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS` via only assumption lines and
        MP lines.
    """
    assert len(skeleton_proof.statement.assumptions) == 0 and \
           skeleton_proof.rules.issubset(PROPOSITIONAL_AXIOMATIC_SYSTEM) and \
           skeleton_proof.is_valid()
    assert Formula.from_propositional_skeleton(
        skeleton_proof.statement.conclusion, substitution_map) == formula
    # Task 9.11.2

    lines = list()

    for line in skeleton_proof.lines:
        if len(line.assumptions) == 0:
            new_line = Proof.AssumptionLine(
                Formula.from_propositional_skeleton(line.formula,
                                                    substitution_map),
                PROPOSITIONAL_AXIOM_TO_SCHEMA[line.rule],
                axiom_specialization_map_to_schema_instantiation_map(
                    PropositionalInferenceRule.formula_specialization_map(
                        line.rule.conclusion, line.formula), substitution_map))

        else:
            new_line = Proof.MPLine(
                Formula.from_propositional_skeleton(line.formula,
                                                    substitution_map),
                line.assumptions[0], line.assumptions[1])
        lines.append(new_line)

    return Proof(PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS, formula, lines)
Ejemplo n.º 4
0
def prove_from_skeleton_proof(formula: Formula,
                              skeleton_proof: PropositionalProof,
                              substitution_map: Mapping[str, Formula]) -> \
        Proof:
    """Converts the given proof of a propositional skeleton of the given
    predicate-logic formula into a proof of that predicate-logic formula.

    Parameters:
        formula: predicate-logic formula to prove.
        skeleton_proof: valid propositional-logic proof of a propositional
            skeleton of the given formula, from no assumptions and via
            `~propositions.axiomatic_systems.AXIOMATIC_SYSTEM`.
        substitution_map: map from each atomic propositional subformula of the
            skeleton of the given formula that is proven in the given proof to
            the respective predicate-logic subformula of the given formula.

    Returns:
        A valid predicate-logic proof of the given formula from the axioms
        `PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS` via only assumption lines and
        MP lines.
    """
    assert len(skeleton_proof.statement.assumptions) == 0 and \
           skeleton_proof.rules.issubset(PROPOSITIONAL_AXIOMATIC_SYSTEM) and \
           skeleton_proof.is_valid()
    assert Formula.from_propositional_skeleton(
        skeleton_proof.statement.conclusion, substitution_map) == formula

    # Setup the proof builder
    builder = Proof.ProofBuilder() \
        .with_assumptions(PROPOSITIONAL_AXIOMATIC_SYSTEM_SCHEMAS) \
        .with_conclusion(Formula.from_propositional_skeleton(skeleton_proof.statement.conclusion, substitution_map))

    for line in skeleton_proof.lines:
        # Which rule type do we got
        if line.rule == MP:
            builder.add_mp_line(Formula.from_propositional_skeleton(line.formula, substitution_map),
                                line.assumptions[0], line.assumptions[1])
        else:
            builder.add_claim_line(Formula.from_propositional_skeleton(line.formula, substitution_map),
                                   PROPOSITIONAL_AXIOM_TO_SCHEMA[line.rule],
                                   axiom_specialization_map_to_schema_instantiation_map(
                                       PropositionalInferenceRule.formula_specialization_map(line.rule.conclusion,
                                                                                             line.formula),
                                       substitution_map))

    return builder.build()