Exemplo n.º 1
0
    def conclude(self, assumptions):
        '''
        Attempt to conclude that the element is in the domain.
        First, see if it is not contained in a superset of the domain.
        Next, check if the element has a known simplification; if so,
        try to derive non-membership via this simplification.
        If there isn't a known simplification, next try to call
        the 'self.domain.nonmembership_object.conclude(..)' method to prove
        the non-membership.  If that fails, try simplifying the element
        again, this time using automation to push the simplification through
        if possible.
        As a last resort, try 'conclude_as_folded'.
        '''
        from proveit.logic import SubsetEq, InSet
        from proveit import ProofFailure
        from proveit.logic import SimplificationError

        # See if the membership is already known.
        if self.element in NotInSet.known_nonmemberships:
            for known_nonmembership in NotInSet.known_nonmemberships[
                    self.element]:
                if known_nonmembership.is_sufficient(assumptions):
                    # x not in R is known to be true; if we know that
                    # S subset_eq R, we are done.
                    rel = SubsetEq(self.domain, known_nonmembership.domain)
                    if rel.proven(assumptions):
                        # S is a subset of R, so now we can prove
                        # x not in S.
                        return rel.derive_subset_nonmembership(
                            self.element, assumptions)
        # No known membership works.  Let's see if there is a known
        # simplification of the element before trying anything else.
        try:
            elem_simplification = self.element.simplification(assumptions,
                                                              automation=True)
            if elem_simplification.lhs == elem_simplification.rhs:
                elem_simplification = None  # reflection doesn't count
        except SimplificationError:
            elem_simplification = None

        # If the element simplification succeeded, prove the membership
        # via the simplified form of the element.
        if elem_simplification is not None:
            simple_elem = elem_simplification.rhs
            simple_nonmembership = NotInSet(simple_elem,
                                            self.domain).prove(assumptions)
            inner_expr = simple_nonmembership.inner_expr().element
            return elem_simplification.sub_left_side_into(
                inner_expr, assumptions)
        else:
            # If it has a 'nonmembership_object', try to conclude
            # nonmembership using that.
            if hasattr(self, 'nonmembership_object'):
                return self.nonmembership_object.conclude(assumptions)
            else:
                # Otherwise, attempt to conclude via Not(x in S)
                return self.conclude_as_folded(assumptions=assumptions)
Exemplo n.º 2
0
    def conclude(self, **defaults_config):
        '''
        Attempt to conclude that the the NotInSet object is true ---
        i.e. that the element is not in the domain.
        First, see if it is not contained in a superset of the domain.
        Next, check if the element has a known simplification; if so,
        try to derive non-membership via this simplification.
        If there isn't a known simplification, next try to call
        the 'self.domain.nonmembership_object.conclude(..)' method to
        prove the non-membership.  If that fails, try simplifying the
        element again, this time using automation to push the
        simplification through if possible.
        As a last resort, try 'conclude_as_folded'.
        '''
        from proveit import ProofFailure
        from proveit.logic import SubsetEq, evaluation_or_simplification

        if self.negated().disproven():
            return self.conclude_as_folded()

        # See if the element, or something known to be equal to
        # the element, is known to be a nonmember of the domain or a
        # superset of the domain.
        if self.element in NotInClass.known_nonmemberships:
            for known_nonmembership in \
                    NotInClass.known_nonmemberships[self.element]:
                if known_nonmembership.is_applicable():
                    # x not in R is known to be true; if we know that
                    # S subset_eq R, we are done.
                    rel = SubsetEq(self.domain, known_nonmembership.domain)
                    if rel.proven():
                        # S is a subset of R, so now we can prove
                        # x not in S.
                        return rel.derive_subset_nonmembership(self.element)

        # Try the standard Relation strategies -- evaluate or
        # simplify both sides.
        try:
            return Relation.conclude(self)
        except ProofFailure:
            # Both sides are already irreducible or simplified
            # or we were unable to simplify either side.
            pass

        # If it has a 'nonmembership_object', try to conclude
        # nonmembership using that.
        if hasattr(self, 'nonmembership_object'):
            return self.nonmembership_object.conclude()
        else:
            # Otherwise, attempt to conclude via Not(x in S)
            return self.conclude_as_folded()