コード例 #1
0
 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)
コード例 #2
0
ファイル: equals.py プロジェクト: gustavomonente/Prove-It
    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'.")
コード例 #3
0
 def deriveIff(self, assumptions=USE_DEFAULTS):
     r'''
     From A => B derive and return A <=> B assuming B => A.
     '''
     from proveit.logic import Iff
     return Iff(self.A, self.B).concludeViaDefinition()
コード例 #4
0
ファイル: theorems.py プロジェクト: rmmilewi/Prove-It
modInIntervalCO

absIsNonNeg = Forall(a, GreaterThanEquals(Abs(a), zero), domain=Complexes)
absIsNonNeg

absNotEqZero = Forall([a],
                      NotEquals(Abs(a), zero),
                      domain=Complexes,
                      conditions=[NotEquals(a, zero)])
absNotEqZero

absElim = Forall(x, Equals(Abs(x), x), domain=RealsPos)
absElim

absIneq = Forall((x, y),
                 Iff(LessThanEquals(Abs(x), y),
                     And(LessThanEquals(Neg(y), x), LessThanEquals(x, y))),
                 domain=Reals,
                 conditions=[GreaterThanEquals(y, zero)])
absIneq

triangleInequality = Forall([a, b],
                            LessThanEquals(Abs(Add(a, b)), Add(Abs(a),
                                                               Abs(b))),
                            domain=Complexes)
triangleInequality

absProd = Forall(xEtc,
                 Equals(Abs(Mult(xEtc)), Mult(Etcetera(Abs(xMulti)))),
                 domain=Complexes)
absProd
コード例 #5
0
ファイル: theorems.py プロジェクト: gustavomonente/Prove-It
    conditions=[
        NotEquals(
            a,
            zero)])
abs_not_eq_zero

# transferred by wdc 3/11/2020
abs_elim = Forall(x, Equals(Abs(x), x),
                  domain=RealPos)
abs_elim

# transferred by wdc 3/11/2020
abs_ineq = Forall(
    (x, y), Iff(
        LessThanEquals(
            Abs(x), y), And(
                LessThanEquals(
                    Neg(y), x), LessThanEquals(
                        x, y))), domain=Real, conditions=[
                            GreaterThanEquals(
                                y, zero)])
abs_ineq

# transferred by wdc 3/11/2020
triangle_inequality = Forall([a, b], LessThanEquals(
    Abs(Add(a, b)), Add(Abs(a), Abs(b))), domain=Complex)
triangle_inequality

# transferred by wdc 3/11/2020
abs_prod = Forall(x_etc,
                  Equals(Abs(Mult(x_etc)),
                         Mult(Etcetera(Abs(x_multi)))),
コード例 #6
0
                    domain = Reals)
inComplexes

inRealsPos_inReals = Forall(a, InSet(a,Reals), domain = RealsPos)
inRealsPos_inReals

inRealsNeg_inReals = Forall(a, InSet(a,Reals), domain = RealsNeg)
inRealsNeg_inReals

inRealsPos_inComplexes = Forall(a, InSet(a,Complexes), domain = RealsPos)
inRealsPos_inComplexes

inRealsNeg_inComplexes = Forall(a, InSet(a,Complexes), domain = RealsNeg)
inRealsNeg_inComplexes

inRealsPos_iff_positive = Forall(a, Iff(InSet(a, RealsPos), GreaterThan(a, zero)), domain=Reals)
inRealsPos_iff_positive

inRealsNeg_iff_negative = Forall(a, Iff(InSet(a, RealsNeg), LessThan(a, zero)), domain=Reals)
inRealsNeg_iff_negative

positive_implies_notZero = Forall(a, NotEquals(a, zero), domain=Reals, conditions=[GreaterThan(a, zero)])
positive_implies_notZero

negative_implies_notZero = Forall(a, NotEquals(a, zero), domain=Reals, conditions=[LessThan(a, zero)])
negative_implies_notZero

allInIntervalOO_InReals = Forall((a, b), Forall(x, InSet(x, Reals), domain=IntervalOO(a, b)), domain=Reals)
allInIntervalOO_InReals 

allInIntervalCO_InReals = Forall((a, b), Forall(x, InSet(x, Reals), domain=IntervalCO(a, b)), domain=Reals)
コード例 #7
0
 def derive_iff(self, **defaults_config):
     r'''
     From A => B derive and return A <=> B assuming B => A.
     '''
     from proveit.logic import Iff
     return Iff(self.A, self.B).conclude_via_definition()
コード例 #8
0
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)))

endAxioms(locals(), __package__)