def test(): substitution.specialize({fx:Not(x), x:a, y:b}, assumptions=[Equals(a, b)]) expr = Equals(a, Add(b, Frac(c, d), Exp(c, d))) gRepl = Lambda.globalRepl(expr, d) d_eq_y = Equals(d, y) d_eq_y.substitution(gRepl, assumptions=[d_eq_y]) d_eq_y.substitution(expr, assumptions=[d_eq_y]) d_eq_y.substitution(expr, assumptions=[d_eq_y]).proof() innerExpr = expr.innerExpr() innerExpr = innerExpr.rhs innerExpr = innerExpr.operands[1] innerExpr = innerExpr.denominator d_eq_y.substitution(innerExpr, assumptions=[d_eq_y]) d_eq_y.substitution(expr.innerExpr().rhs.operands[2].exponent, assumptions=[d_eq_y]) d_eq_y.subRightSideInto(gRepl, assumptions=[d_eq_y,expr]) d_eq_y.subRightSideInto(expr, assumptions=[d_eq_y,expr]) y_eq_d = Equals(y, d) y_eq_d.subLeftSideInto(gRepl, assumptions=[y_eq_d,expr]) y_eq_d.subLeftSideInto(expr, assumptions=[y_eq_d,expr]) y_eq_d.subLeftSideInto(expr, assumptions=[y_eq_d,expr]).proof()
def conclude(self, assumptions): ''' Attempt to conclude that the element is in the domain. First, see if it is known to be contained in a known subset of the domain. Next, check if the element has a known simplification; if so, try to derive membership via this simplification. If there isn't a known simplification, next try to call the 'self.domain.membershipObject.conclude(..)' method to prove the membership. If that fails, try simplifying the element again, this time using automation to push the simplification through if possible. ''' from proveit.logic import Equals, SubsetEq from proveit import ProofFailure from proveit.logic import SimplificationError # See if the membership is already known. if self.element in InSet.knownMemberships: for knownMembership in InSet.knownMemberships[self.element]: if knownMembership.isSufficient(assumptions): # x in R is a known truth; if we know that R subseteq S, # or R = S we are done. eqRel = Equals(knownMembership.domain, self.domain) if eqRel.proven(assumptions): return eqRel.subRightSideInto( knownMembership.innerExpr().domain) subRel = SubsetEq(knownMembership.domain, self.domain) if subRel.proven(assumptions): # S is a superset of R, so now we can prove x in S. return subRel.deriveSupersetMembership( 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=False) if elem_simplification.lhs == elem_simplification.rhs: elem_simplification = None # reflection doesn't count except SimplificationError: elem_simplification = None if elem_simplification is None: # Let's try harder to simplify the element. try: elem_simplification = self.element.simplification(assumptions) if elem_simplification.lhs == elem_simplification.rhs: elem_simplification = None # reflection doesn't count except SimplificationError: pass # 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_membership = InSet(simple_elem, self.domain).prove(assumptions) inner_expr = simple_membership.innerExpr().element return elem_simplification.subLeftSideInto(inner_expr, assumptions) else: # Unable to simplify the element. Try to conclude via # the 'membershipObject' if there is one. if hasattr(self, 'membershipObject'): return self.membershipObject.conclude(assumptions) raise ProofFailure( self, assumptions, "Unable to conclude automatically; " "the domain, %s, has no 'membershipObject' " "method with a strategy for proving " "membership." % self.domain)