Beispiel #1
0
def diagrammatic_to_sentential(context, F, named_states,
                               attribute_interpretation, variable_assignment,
                               *formulae):
    """
    Verify that on the basis of the present diagram :math:`(\sigma;\\rho)` of
    the Context object :math:`(\\beta;(\sigma;\\rho))` in the ``context``
    parameter and some set of Formula objects
    :math:`F_{1}, \ldots, F_{k}, k \ge 0` provided as optional positional
    arguments in the ``formulae`` parameter, that for each NamedState object
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n}), n > 0`,
    contained in the ``named_states`` parameter, a Formula object :math:`F`
    provided in the ``F`` parameter can be derived in every one of these
    :math:`n` cases.

    This is rule :math:`[C_{3}]`.

    This function works as follows:

    1. If :math:`k > 0` (i.e., if at least one Formula object is provided as an
    optional positional argument to the ``formulae`` parameter),  compute the
    basis :math:`\mathcal{B}(F_{1}, \\rho, \chi) ~ \cup ~ \cdots ~ \cup ~ \
    \mathcal{B}(F_{k}, \\rho, \chi)` of :math:`F_{1}, \ldots, F_{k}` and
    determine if the NamedState objects
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})`
    provided in the ``named_states`` parameter form an exhuastive set of
    possibilities on this basis.

    2. Determine if the proviso
    :math:`(\sigma;\\rho) \\Vvdash_{\{F_{1}, \ldots, F_{k}\}} \
    \{(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})\}` (where
    :math:`k \ge 0`) holds.

    3. Return the evaluation of
    :math:`(\\beta \cup \{F_{1}, \ldots, F_{k}\};(\sigma;\\rho)) \models F`.

    :param context: The Context object :math:`(\\beta;(\sigma;\\rho))` from \
    which the present diagram :math:`(\sigma;\\rho)` comes from.
    :type  context: Context
    :param F: The Formula object :math:`F` derivable in the :math:`n > 0` \
    cases provided by the NamedState objects \
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})` in the \
    ``named_state`` parameter.
    :type  F: Formula
    :param named_states: The NamedState objects \
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n}), n > 0` \
    functioning as the set of :math:`n` exhaustive cases from which :math:`F` \
    can be derived.
    :type  named_states: ``list``
    :param attribute_interpretation: The AttributeInterpretation object \
    :math:`I` to use for the interpretation of truth values and the \
    computation of the basis of :math:`F_{1}, \ldots, F_{k}`.
    :type  attribute_interpretation: AttributeInterpretation
    :param variable_assignment: The VariableAssignment object :math:`\chi` to \
    consider when computing the basis \
    :math:`\mathcal{B}(F_{1}, \\rho, \chi) ~ \cup ~ \cdots ~ \cup ~ \
    \mathcal{B}(F_{k}, \\rho, \chi)` of :math:`F_{1}, \ldots, F_{k}` or \
    ``None`` if all terms of the :math:`F_{1}, \ldots, F_{k}` are in \
    :math:`\\rho`.
    :type  variable_assignment: VariableAssignment | ``None``
    :param formulae: The :math:`{k \ge 0}` Formula objects \
    :math:`F_{1}, \ldots, F_{k}` to use in the computation of the basis, \
    computation of the proviso and the evaluation of \
    :math:`{(\\beta \cup \{F_{1}, \ldots, F_{k}\};(\sigma;\\rho)) \models F}`.
    :type  formulae: Formula

    :return: The result of the evaluation of \
    :math:`(\\beta \cup \{F_{1}, \ldots, F_{k}\};(\sigma;\\rho)) \models F`.
    :rtype: ``bool``

    :raises ValueError: If :math:`{k > 0}`, the NamedState objects \
    :math:`{(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n}), n > 0}` \
    are not exhaustive on the basis of the Formula objects \
    :math:`F_{1}, \ldots, F_{k}` or the proviso \
    :math:`{(\sigma;\\rho) \\Vvdash_{\{F_{1}, \ldots, F_{k}\}} \
    \{(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})\}}` (where \
    :math:`k \ge 0`) does not hold.
    """

    if formulae:
        constant_assignment = context._named_state._p
        basis = Formula.get_basis(constant_assignment, variable_assignment,
                                  attribute_interpretation, *formulae)

        if not context._named_state.is_exhaustive(basis, *named_states):
            raise ValueError(
                "named states are not exahustive on basis of formulae.")

        assumption_base = AssumptionBase(*formulae)
    else:
        assumption_base = AssumptionBase(context._assumption_base._vocabulary)

    proviso = context._named_state.is_named_entailment(
        assumption_base, attribute_interpretation, *named_states)

    if not proviso:
        raise ValueError("[C3] proviso does not hold")

    formulae_union = context._assumption_base._formulae + list(formulae)
    if formulae_union:
        assumption_base_union = AssumptionBase(*formulae_union)
    else:
        assumption_base_union = AssumptionBase(
            context._assumption_base._vocabulary)

    # Determine if (β ∪ {F1,...,Fk}; (σ; ρ)) |= F; proviso holds at this point
    extended_context = Context(assumption_base_union, context._named_state)
    if extended_context.entails_formula(F, attribute_interpretation):
        return True
    else:
        return False
Beispiel #2
0
def diagrammatic_to_sentential(context, F, named_states, attribute_interpretation, variable_assignment, *formulae):
    """
    Verify that on the basis of the present diagram :math:`(\sigma;\\rho)` of
    the Context object :math:`(\\beta;(\sigma;\\rho))` in the ``context``
    parameter and some set of Formula objects
    :math:`F_{1}, \ldots, F_{k}, k \ge 0` provided as optional positional
    arguments in the ``formulae`` parameter, that for each NamedState object
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n}), n > 0`,
    contained in the ``named_states`` parameter, a Formula object :math:`F`
    provided in the ``F`` parameter can be derived in every one of these
    :math:`n` cases.

    This is rule :math:`[C_{3}]`.

    This function works as follows:

    1. If :math:`k > 0` (i.e., if at least one Formula object is provided as an
    optional positional argument to the ``formulae`` parameter),  compute the
    basis :math:`\mathcal{B}(F_{1}, \\rho, \chi) ~ \cup ~ \cdots ~ \cup ~ \
    \mathcal{B}(F_{k}, \\rho, \chi)` of :math:`F_{1}, \ldots, F_{k}` and
    determine if the NamedState objects
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})`
    provided in the ``named_states`` parameter form an exhuastive set of
    possibilities on this basis.

    2. Determine if the proviso
    :math:`(\sigma;\\rho) \\Vvdash_{\{F_{1}, \ldots, F_{k}\}} \
    \{(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})\}` (where
    :math:`k \ge 0`) holds.

    3. Return the evaluation of
    :math:`(\\beta \cup \{F_{1}, \ldots, F_{k}\};(\sigma;\\rho)) \models F`.

    :param context: The Context object :math:`(\\beta;(\sigma;\\rho))` from \
    which the present diagram :math:`(\sigma;\\rho)` comes from.
    :type  context: Context
    :param F: The Formula object :math:`F` derivable in the :math:`n > 0` \
    cases provided by the NamedState objects \
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})` in the \
    ``named_state`` parameter.
    :type  F: Formula
    :param named_states: The NamedState objects \
    :math:`(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n}), n > 0` \
    functioning as the set of :math:`n` exhaustive cases from which :math:`F` \
    can be derived.
    :type  named_states: ``list``
    :param attribute_interpretation: The AttributeInterpretation object \
    :math:`I` to use for the interpretation of truth values and the \
    computation of the basis of :math:`F_{1}, \ldots, F_{k}`.
    :type  attribute_interpretation: AttributeInterpretation
    :param variable_assignment: The VariableAssignment object :math:`\chi` to \
    consider when computing the basis \
    :math:`\mathcal{B}(F_{1}, \\rho, \chi) ~ \cup ~ \cdots ~ \cup ~ \
    \mathcal{B}(F_{k}, \\rho, \chi)` of :math:`F_{1}, \ldots, F_{k}` or \
    ``None`` if all terms of the :math:`F_{1}, \ldots, F_{k}` are in \
    :math:`\\rho`.
    :type  variable_assignment: VariableAssignment | ``None``
    :param formulae: The :math:`{k \ge 0}` Formula objects \
    :math:`F_{1}, \ldots, F_{k}` to use in the computation of the basis, \
    computation of the proviso and the evaluation of \
    :math:`{(\\beta \cup \{F_{1}, \ldots, F_{k}\};(\sigma;\\rho)) \models F}`.
    :type  formulae: Formula

    :return: The result of the evaluation of \
    :math:`(\\beta \cup \{F_{1}, \ldots, F_{k}\};(\sigma;\\rho)) \models F`.
    :rtype: ``bool``

    :raises ValueError: If :math:`{k > 0}`, the NamedState objects \
    :math:`{(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n}), n > 0}` \
    are not exhaustive on the basis of the Formula objects \
    :math:`F_{1}, \ldots, F_{k}` or the proviso \
    :math:`{(\sigma;\\rho) \\Vvdash_{\{F_{1}, \ldots, F_{k}\}} \
    \{(\sigma_{1}; \\rho_{1}), \ldots,(\sigma_{n}; \\rho_{n})\}}` (where \
    :math:`k \ge 0`) does not hold.
    """

    if formulae:
        constant_assignment = context._named_state._p
        basis = Formula.get_basis(constant_assignment, variable_assignment, attribute_interpretation, *formulae)

        if not context._named_state.is_exhaustive(basis, *named_states):
            raise ValueError("named states are not exahustive on basis of formulae.")

        assumption_base = AssumptionBase(*formulae)
    else:
        assumption_base = AssumptionBase(context._assumption_base._vocabulary)

    proviso = context._named_state.is_named_entailment(assumption_base, attribute_interpretation, *named_states)

    if not proviso:
        raise ValueError("[C3] proviso does not hold")

    formulae_union = context._assumption_base._formulae + list(formulae)
    if formulae_union:
        assumption_base_union = AssumptionBase(*formulae_union)
    else:
        assumption_base_union = AssumptionBase(context._assumption_base._vocabulary)

    # Determine if (β ∪ {F1,...,Fk}; (σ; ρ)) |= F; proviso holds at this point
    extended_context = Context(assumption_base_union, context._named_state)
    if extended_context.entails_formula(F, attribute_interpretation):
        return True
    else:
        return False