def conclude(self, assumptions): ''' Attempt to conclude the equality various ways: simple reflexivity (x=x), via an evaluation (if one side is an irreducible), or via transitivity. ''' from proveit.logic import TRUE, FALSE, Implies, Iff if self.lhs == self.rhs: # Trivial x=x return self.concludeViaReflexivity() if self.lhs or self.rhs in (TRUE, FALSE): try: # Try to conclude as TRUE or FALSE. return self.concludeBooleanEquality(assumptions) except ProofFailure: pass if isIrreducibleValue(self.rhs): return self.lhs.evaluation() elif isIrreducibleValue(self.lhs): return self.rhs.evaluation().deriveReversed() try: Implies(self.lhs, self.rhs).prove(assumptions, automation=False) Implies(self.rhs, self.lhs).prove(assumptions, automation=False) # lhs => rhs and rhs => lhs, so attempt to prove lhs = rhs via lhs <=> rhs # which works when they can both be proven to be Booleans. try: return Iff(self.lhs, self.rhs).deriveEquality(assumptions) except: from proveit.logic.boolean.implication._theorems_ import eqFromMutualImpl return eqFromMutualImpl.specialize({ A: self.lhs, B: self.rhs }, assumptions=assumptions) except ProofFailure: pass """ # Use concludeEquality if available if hasattr(self.lhs, 'concludeEquality'): return self.lhs.concludeEquality(assumptions) if hasattr(self.rhs, 'concludeEquality'): return self.rhs.concludeEquality(assumptions) """ # Use a breadth-first search approach to find the shortest # path to get from one end-point to the other. return TransitiveRelation.conclude(self, assumptions)
def deriveCommonConclusion(self, conclusion, assumptions=USE_DEFAULTS): ''' From (A or B) derive and return the provided conclusion C assuming A=>C, B=>C, A,B,C in BOOLEANS. ''' from ._theorems_ import hypotheticalDisjunction from proveit.logic import Implies, compose # forall_{A in Bool, B in Bool, C in Bool} (A=>C and B=>C) => ((A or B) => C) assert len(self.operands) == 2 leftOperand, rightOperand = self.operands leftImplConclusion = Implies(leftOperand, conclusion) rightImplConclusion = Implies(rightOperand, conclusion) # (A=>C and B=>C) assuming A=>C, B=>C compose([leftImplConclusion, rightImplConclusion], assumptions) return hypotheticalDisjunction.specialize( { A: leftOperand, B: rightOperand, C: conclusion }, assumptions=assumptions).deriveConclusion( assumptions).deriveConclusion(assumptions)
def derive_common_conclusion(self, conclusion, assumptions=USE_DEFAULTS): ''' From (A or B) derive and return the provided conclusion C assuming A=>C, B=>C, A,B,C in BOOLEANS. ''' from . import hypothetical_disjunction from proveit.logic import Implies, compose # forall_{A in Bool, B in Bool, C in Bool} (A=>C and B=>C) => ((A or B) # => C) assert self.operands.is_double() left_operand, right_operand = self.operands left_impl_conclusion = Implies(left_operand, conclusion) right_impl_conclusion = Implies(right_operand, conclusion) # (A=>C and B=>C) assuming A=>C, B=>C compose([left_impl_conclusion, right_impl_conclusion], assumptions) return hypothetical_disjunction.instantiate( { A: left_operand, B: right_operand, C: conclusion }, assumptions=assumptions).derive_conclusion( assumptions).derive_conclusion(assumptions)
def __init__(self, consequentTruth, antecedentExpr): from proveit.logic import Implies assumptions = [assumption for assumption in consequentTruth.assumptions if assumption != antecedentExpr] prev_default_assumptions = defaults.assumptions defaults.assumptions = assumptions # these assumptions will be used for deriving any side-effects try: implicationExpr = Implies(antecedentExpr, consequentTruth.expr) implicationTruth = KnownTruth(implicationExpr, assumptions, self) self.consequentTruth = consequentTruth Proof.__init__(self, implicationTruth, [self.consequentTruth]) finally: # restore the original default assumptions defaults.assumptions = prev_default_assumptions
def conclude(self, assumptions): ''' Attempt to conclude the equality various ways: simple reflexivity (x=x), via an evaluation (if one side is an irreducible). Use conclude_via_transitivity for transitivity cases. ''' from proveit.logic import TRUE, FALSE, Implies, Iff, in_bool if self.lhs == self.rhs: # Trivial x=x return self.conclude_via_reflexivity() if (self.lhs in (TRUE, FALSE)) or (self.rhs in (TRUE, FALSE)): try: # Try to conclude as TRUE or FALSE. return self.conclude_boolean_equality(assumptions) except ProofFailure: pass if is_irreducible_value(self.rhs): try: evaluation = self.lhs.evaluation(assumptions) if evaluation.rhs != self.rhs: raise ProofFailure( self, assumptions, "Does not match with evaluation: %s" % str(evaluation)) return evaluation except EvaluationError as e: raise ProofFailure(self, assumptions, "Evaluation error: %s" % e.message) elif is_irreducible_value(self.lhs): try: evaluation = self.rhs.evaluation(assumptions) if evaluation.rhs != self.lhs: raise ProofFailure( self, assumptions, "Does not match with evaluation: %s" % str(evaluation)) return evaluation.derive_reversed() except EvaluationError as e: raise ProofFailure(self, assumptions, "Evaluation error: %s" % e.message) if (Implies(self.lhs, self.rhs).proven(assumptions) and Implies(self.rhs, self.lhs).proven(assumptions) and in_bool(self.lhs).proven(assumptions) and in_bool(self.rhs).proven(assumptions)): # There is mutual implication both sides are known to be # boolean. Conclude equality via mutual implication. return Iff(self.lhs, self.rhs).derive_equality(assumptions) if hasattr(self.lhs, 'deduce_equality'): # If there is a 'deduce_equality' method, use that. # The responsibility then shifts to that method for # determining what strategies should be attempted # (with the recommendation that it should not attempt # multiple non-trivial automation strategies). eq = self.lhs.deduce_equality(self, assumptions) if eq.expr != self: raise ValueError("'deduce_equality' not implemented " "correctly; must deduce the 'equality' " "that it is given if it can: " "'%s' != '%s'" % (eq.expr, self)) return eq else: ''' If there is no 'deduce_equality' method, we'll try simplifying each side to see if they are equal. ''' # Try to prove equality via simplifying both sides. lhs_simplification = self.lhs.simplification(assumptions) rhs_simplification = self.rhs.simplification(assumptions) simplified_lhs = lhs_simplification.rhs simplified_rhs = rhs_simplification.rhs try: if simplified_lhs != self.lhs or simplified_rhs != self.rhs: simplified_eq = Equals(simplified_lhs, simplified_rhs).prove(assumptions) return Equals.apply_transitivities([ lhs_simplification, simplified_eq, rhs_simplification ], assumptions) except ProofFailure: pass raise ProofFailure( self, assumptions, "Unable to automatically conclude by " "standard means. To try to prove this via " "transitive relations, try " "'conclude_via_transitivity'.")
conditions=[NotEquals(z, zero)]) distributefrac_through_subtract distributefrac_through_subtract_rev = Forall([x, y, z], Equals( Sub(frac(x, z), frac(y, z)), frac(Sub(x, y), z)), domain=Complex, conditions=[NotEquals(z, zero)]) distributefrac_through_subtract_rev distributefrac_through_summation = Forall( [P, S], Implies( Forall(y_etc, InSet(Py_etc, Complex), domain=S), Forall(z, Equals(frac(Sum(y_etc, Py_etc, domain=S), z), Sum(y_etc, frac(Py_etc, z), domain=S)), domain=Complex))) distributefrac_through_summation distributefrac_through_summation_rev = Forall( [P, S], Implies( Forall(y_etc, InSet(Py_etc, Complex), domain=S), Forall(z, Equals(Sum(y_etc, frac(Py_etc, z), domain=S), frac(Sum(y_etc, Py_etc, domain=S), z)), domain=Complex))) distributefrac_through_summation_rev frac_in_prod = Forall([w_etc, x, y, z_etc],
distributeFractionThroughSubtract distributeFractionThroughSubtractRev = Forall([x, y, z], Equals( Sub(Fraction(x, z), Fraction(y, z)), Fraction(Sub(x, y), z)), domain=Complexes, conditions=[NotEquals(z, zero)]) distributeFractionThroughSubtractRev distributeFractionThroughSummation = Forall( [P, S], Implies( Forall(yEtc, InSet(PyEtc, Complexes), domain=S), Forall(z, Equals(Fraction(Sum(yEtc, PyEtc, domain=S), z), Sum(yEtc, Fraction(PyEtc, z), domain=S)), domain=Complexes))) distributeFractionThroughSummation distributeFractionThroughSummationRev = Forall( [P, S], Implies( Forall(yEtc, InSet(PyEtc, Complexes), domain=S), Forall(z, Equals(Sum(yEtc, Fraction(PyEtc, z), domain=S), Fraction(Sum(yEtc, PyEtc, domain=S), z)), domain=Complexes))) distributeFractionThroughSummationRev fracInProd = Forall([wEtc, x, y, zEtc],
domain=Complexes) distributeThroughSubtract distributeThroughSubtractRev = Forall([wEtc, x, y, zEtc], Equals( Sub(Mult(wEtc, x, zEtc), Mult(wEtc, y, zEtc)), Mult(wEtc, Sub(x, y), zEtc)), domain=Complexes) distributeThroughSubtractRev distributeThroughSummation = Forall( [P, S], Implies( Forall(yEtc, InSet(PyEtc, Complexes), domain=S), Forall([xEtc, zEtc], Equals(Mult(xEtc, Sum(yEtc, PyEtc, domain=S), zEtc), Sum(yEtc, Mult(xEtc, PyEtc, zEtc), domain=S)), domain=Complexes))) distributeThroughSummation distributeThroughSummationRev = Forall( [P, S], Implies( Forall(yEtc, InSet(PyEtc, Complexes), domain=S), Forall([xEtc, zEtc], Equals(Sum(yEtc, Mult(xEtc, PyEtc, zEtc), domain=S), Mult(xEtc, Sum(yEtc, PyEtc, domain=S), zEtc)), domain=Complexes))) distributeThroughSummationRev endTheorems(locals(), __package__)
from proveit.logic import Forall, InSet, NotInSet, NotEquals, And, Implies, Equals, Booleans from proveit.number import Integers, Naturals, NaturalsPos, Interval, Reals, RealsPos, Complexes from proveit.number import Add, GreaterThan, GreaterThanEquals, LessThan, LessThanEquals from proveit.number import Len from proveit.common import a, b, n, m, x, y, P, S, xMulti, xEtc, PxEtc from proveit.number import zero, one, two, three, four, five, six, seven, eight, nine from proveit.number.common import Pzero, Pm, P_mAddOne, Pn from proveit import beginTheorems, endTheorems beginTheorems(locals()) zeroInNats = InSet(zero, Naturals) successiveNats = Forall(n, InSet(Add(n, one), Naturals), domain=Naturals) inductionLemma = Forall(n, Forall(S, Implies(And(InSet(zero, S), Forall(x, InSet(Add(x,one), S), domain=S)), InSet(n, S))), domain=Naturals) induction = Forall(P, Implies(And(Pzero, Forall(m, P_mAddOne, domain=Naturals, conditions=[Pm])), Forall(n, Pn, Naturals))) zeroLenExprList = Equals(Len(), zero) multiVarInduction = Forall(P, Implies(Forall((xMulti, y), Implies(PxEtc, Operation(P, [xEtc, y]))), Forall(xMulti, PxEtc))) inIntsIsBool = Forall(a, InSet(InSet(a, Integers), Booleans)) inIntsIsBool notInIntsIsBool = Forall(a, InSet(NotInSet(a, Integers), Booleans)) notInIntsIsBool intsInReals = Forall(a, InSet(a, Reals), domain=Integers) intsInReals
from proveit.logic import Forall, Implies, InSet from proveit.numbers import Real from proveit.numbers import Integrate from proveit.common import P, S, x_etc, Px_etc from proveit import begin_theorems, end_theorems begin_theorems(locals()) integration_closure = Forall([P, S], Implies( Forall(x_etc, InSet(Px_etc, Real), domain=S), InSet(Integrate(x_etc, Px_etc, domain=S), Real))) integration_closure end_theorems(locals(), __package__)
domain=Complex) distribute_through_subtract distribute_through_subtract_rev = Forall([w_etc, x, y, z_etc], Equals( Sub(Mult(w_etc, x, z_etc), Mult(w_etc, y, z_etc)), Mult(w_etc, Sub(x, y), z_etc)), domain=Complex) distribute_through_subtract_rev distribute_through_summation = Forall( [P, S], Implies( Forall(y_etc, InSet(Py_etc, Complex), domain=S), Forall([x_etc, z_etc], Equals(Mult(x_etc, Sum(y_etc, Py_etc, domain=S), z_etc), Sum(y_etc, Mult(x_etc, Py_etc, z_etc), domain=S)), domain=Complex))) distribute_through_summation distribute_through_summation_rev = Forall( [P, S], Implies( Forall(y_etc, InSet(Py_etc, Complex), domain=S), Forall([x_etc, z_etc], Equals(Sum(y_etc, Mult(x_etc, Py_etc, z_etc), domain=S), Mult(x_etc, Sum(y_etc, Py_etc, domain=S), z_etc)), domain=Complex))) distribute_through_summation_rev end_theorems(locals(), __package__)
true_eq_true_eval = Equals(Equals(TRUE, TRUE), TRUE) false_eq_false = Equals(FALSE, FALSE) false_eq_false_eval = Equals(Equals(FALSE, FALSE), TRUE) true_not_false = NotEquals(TRUE, FALSE) not_equals_false = Forall(A, NotEquals(A, FALSE), conditions=[A]) true_eq_false_eval = Equals(Equals(TRUE, FALSE), FALSE) false_eq_true_eval = Equals(Equals(FALSE, TRUE), FALSE) true_conclusion = Forall(A, Implies(A, TRUE)) in_bool_equiv = Forall( A, Equals(in_bool(A), Or(Equals(A, TRUE), Equals(A, FALSE)))) true_is_bool = in_bool(TRUE) false_is_bool = in_bool(FALSE) unfold_forall_over_bool = Forall( P, Implies(Forall(A, PofA, domain=Boolean), And(PofTrue, PofFalse))) in_bool_if_true = Forall(A, in_bool(A), conditions=[A]) in_bool_if_false = Forall(A, in_bool(A), conditions=[Not(A)])
begin_axioms(locals()) less_than_equals_def = Forall([x, y], Or(LessThan(x, y), Equals(x, y)), domain=Real, conditions=LessThanEquals(x, y)) less_than_equals_def greater_than_equals_def = Forall([x, y], Or(GreaterThan(x, y), Equals(x, y)), domain=Real, conditions=GreaterThanEquals(x, y)) greater_than_equals_def reverse_greater_than_equals = Forall((x, y), Implies(GreaterThanEquals(x, y), LessThanEquals(y, x))) reverse_greater_than_equals reverse_less_than_equals = Forall((x, y), Implies(LessThanEquals(x, y), GreaterThanEquals(y, x))) reverse_less_than_equals reverse_greater_than = Forall((x, y), Implies(GreaterThan(x, y), LessThan(y, x))) reverse_greater_than reverse_less_than = Forall((x, y), Implies(LessThan(x, y), GreaterThan(y, x))) reverse_less_than greater_than_equals_def = Forall((x, y),
from proveit.common import n, xMulti, xEtc, x, y, S from common import zero, one, two from proveit import beginAxioms, endAxioms beginAxioms(locals()) # Define the set of Naturals as, essentially, the minimum set that contains zero and all of its successors; # that is, n is in Naturals iff n is in all sets that contain zero and all successors. naturalsDef = Forall( n, Equals( InSet(n, Naturals), Forall( S, Implies( And(InSet(zero, S), Forall(x, InSet(Add(x, one), S), domain=S)), InSet(n, S))))) # Define the length of an ExpressionList inductively. exprListLengthDef = And( Equals(Len(), zero), Forall((xMulti, y), Equals(Len(xEtc, y), Add(Len(xEtc), one)))) naturalsPosDef = Forall(n, Iff(InSet(n, NaturalsPos), GreaterThanEquals(n, one)), domain=Naturals) naturalsPosDef integersDef = Equals(Integers, Union(Naturals, SetOfAll(n, Neg(n), domain=Naturals)))
from proveit.logic import Forall, Implies, InSet from proveit.number import Reals from proveit.number import Integrate from proveit.common import P, S, xEtc, PxEtc from proveit import beginTheorems, endTheorems beginTheorems(locals()) integrationClosure = Forall([P, S], Implies( Forall(xEtc, InSet(PxEtc, Reals), domain=S), InSet(Integrate(xEtc, PxEtc, domain=S), Reals))) integrationClosure endTheorems(locals(), __package__)
from proveit.numbers import zero, one, two, three, four, five, six, seven, eight, nine from proveit.numbers.common import Pzero, Pm, P_mAddOne, Pn from proveit import begin_theorems, end_theorems begin_theorems(locals()) zero_in_nats = InSet(zero, Natural) successive_nats = Forall(n, InSet(Add(n, one), Natural), domain=Natural) induction_lemma = Forall(n, Forall( S, Implies( And( InSet(zero, S), Forall(x, InSet(Add(x, one), S), domain=S)), InSet(n, S))), domain=Natural) induction = Forall( P, Implies(And(Pzero, Forall(m, P_mAddOne, domain=Natural, conditions=[Pm])), Forall(n, Pn, Natural))) zero_len_expr_tuple = Equals(Len(), zero) multi_var_induction = Forall( P, Implies(Forall((x_multi, y), Implies(Px_etc, Operation(P, [x_etc, y]))), Forall(x_multi, Px_etc)))
beginAxioms(locals()) lessThanEqualsDef = Forall([x, y], Or(Less(x, y), Equals(x, y)), domain=Reals, conditions=LessEq(x, y)) lessThanEqualsDef greaterThanEqualsDef = Forall([x, y], Or(Greater(x, y), Equals(x, y)), domain=Reals, conditions=GreaterEq(x, y)) greaterThanEqualsDef reverseGreaterThanEquals = Forall((x, y), Implies(GreaterEq(x, y), LessEq(y, x))) reverseGreaterThanEquals reverseLessThanEquals = Forall((x, y), Implies(LessEq(x, y), GreaterEq(y, x))) reverseLessThanEquals reverseGreaterThan = Forall((x, y), Implies(Greater(x, y), Less(y, x))) reverseGreaterThan reverseLessThan = Forall((x, y), Implies(Less(x, y), Greater(y, x))) reverseLessThan greaterThanEqualsDef = Forall((x, y), Implies(GreaterEq(x, y), Or(Greater(x, y), Equals(x, y)))) greaterThanEqualsDef
from proveit import Operation from proveit.logic import Forall, Implies, InSet, Equals, SetOfAll from proveit.number import Integers, Reals, Complexes from proveit.number import Sum, Interval, Exp, Fraction, Sub, Add, LessThan, LessThanEquals from proveit.common import a, b, c, f, g, k, l, m, n, x, y, fa, fx, gx, gy, xMulti, xEtc, P, R, S, PxEtc from proveit.number.common import zero, one, infinity from proveit import beginTheorems, endTheorems beginTheorems(locals()) summationRealClosure = Forall([P, S], Implies( Forall(xMulti, InSet(PxEtc, Reals), domain=S), InSet(Sum(xMulti, PxEtc, domain=S), Reals))) summationRealClosure summationComplexClosure = Forall([P, S], Implies( Forall(xMulti, InSet(PxEtc, Complexes), domain=S), InSet(Sum(xMulti, PxEtc, domain=S), Complexes))) summationComplexClosure sumSplitAfter = Forall( f, Forall([a, b, c], Equals(