예제 #1
0
def _axiom_specialization_map_to_schema_instantiation_map(
        propositional_specialization_map: PropositionalSpecializationMap,
        substitution_map: Mapping[str, Formula]) -> Mapping[str, Formula]:
    """Converts the given propositional-logic specialization map from a
    propositional-logic axiom to its specialization, to an instantiation map
    from the schema equivalent of that axiom to a predicate-logic formula whose
    skeleton is that specialization.

    Parameters:
        propositional_specialization_map: mapping specifying how some
            propositional-logic axiom `axiom` (which is not specified) from
            `~propositions.axiomatic_systems.AXIOMATIC_SYSTEM` specializes into
            some specialization `specialization` (which is also not specified),
            and containing no constants or operators beyond ``'~'``, ``'->'``,
            ``'|'``, and ``'&'``.
        substitution_map: mapping from each atomic propositional subformula of
            `specialization` to a predicate-logic formula.

    Returns:
        An instantiation map for instantiating the schema equivalent of `axiom`
        into the predicate-logic formula obtained from its propositional
        skeleton `specialization` by the given substitution map.

    Examples:
        >>> _axiom_specialization_map_to_schema_instantiation_map(
        ...     {'p': PropositionalFormula.parse('(z1->z2)'),
        ...      'q': PropositionalFormula.parse('~z1')},
        ...     {'z1': Formula.parse('Ax[(x=5&M())]'),
        ...      'z2': Formula.parse('R(f(8,9))')})
        {'P': (Ax[(x=5&M())]->R(f(8,9))), 'Q': ~Ax[(x=5&M())]}
    """
    for variable in propositional_specialization_map:
        assert is_propositional_variable(variable)
        for operator in propositional_specialization_map[variable].operators():
            assert is_unary(operator) or is_binary(operator)
    for key in substitution_map:
        assert is_propositional_variable(key)
    relation_to_formula = dict()
    for key, formula in propositional_specialization_map.items():
        relation_key = key.upper()
        real_formula = Formula.from_propositional_skeleton(
            formula, substitution_map)
        relation_to_formula[relation_key] = real_formula
    return relation_to_formula
예제 #2
0
def axiom_specialization_map_to_schema_instantiation_map(
        propositional_specialization_map: PropositionalSpecializationMap,
        substitution_map: Mapping[str, Formula]) -> Mapping[str, Formula]:
    """Converts the given propositional-logic specialization map from a
    propositional axiom to its specialization, to an instantiation map from
    the schema equivalent of that axiom to a predicate-logic formula whose
    skeleton is that specialization.

    Parameters:
        propositional_specialization_map: map specifying how some propositional
            axiom `axiom` (which is not specified) from
            `~propositions.axiomatic_systems.AXIOMATIC_SYSTEM` specializes into
            some specialization `specialization` (which is also not specified).
        substitution_map: map from each atomic propositional subformula of
            `specialization` to a predicate-logic formula.

    Returns:
        An instantiation map for instantiating the schema equivalent of `axiom`
        into the predicate-logic formula obtained from its propositional
        skeleton `specialization` by the given substitution map.

    Examples:
        >>> axiom_specialization_map_to_schema_instantiation_map(
        ...     {'p': PropositionalFormula.parse('(z1->z2)'),
        ...      'q': PropositionalFormula.parse('~z1')},
        ...     {'z1': Formula.parse('Ax[(x=5&M())]'),
        ...      'z2': Formula.parse('R(f(8,9))')})
        {'P': (Ax[(x=5&M())]->R(f(8,9))), 'Q': ~Ax[(x=5&M())]}
    """
    for variable in propositional_specialization_map:
        assert is_propositional_variable(variable)
    for key in substitution_map:
        assert is_propositional_variable(key)
    # Task 9.11.1
    new_spec = {}
    for key, val in propositional_specialization_map.items():
        new_key = str.upper(key[0]) + key[1:]
        new_val = Formula.from_propositional_skeleton(val, substitution_map)
        new_spec[new_key] = new_val
    return new_spec