Beispiel #1
0
minRealClosure = Forall((a, b), InSet(Min(a, b), Reals), domain=Reals)
minRealClosure

minRealPosClosure = Forall((a, b), InSet(Min(a, b), RealsPos), domain=RealsPos)
minRealPosClosure

maxRealClosure = Forall((a, b), InSet(Max(a, b), Reals), domain=Reals)
maxRealClosure

maxRealPosClosure = Forall((a, b), InSet(Max(a, b), RealsPos), domain=RealsPos)
maxRealPosClosure

relaxGreaterThan = Forall([a, b],
                          GreaterThanEquals(a, b),
                          domain=Reals,
                          conditions=GreaterThan(a, b))
relaxGreaterThan

relaxLessThan = Forall([a, b],
                       LessThanEquals(a, b),
                       domain=Reals,
                       conditions=LessThan(a, b))
relaxLessThan

lessThanInBools = Forall([a, b], InSet(LessThan(a, b), Booleans), domain=Reals)
lessThanInBools

lessThanEqualsInBools = Forall([a, b],
                               InSet(LessThanEquals(a, b), Booleans),
                               domain=Reals)
lessThanEqualsInBools
Beispiel #2
0
def deducePositive(exprOrList, assumptions=frozenset(), dontTryRealsPos=False):
    '''
    For each given expression, attempt to derive that it is positive
    under the given assumptions.  If successful, returns the deduced statement,
    otherwise raises an Exception.  
    '''
    from proveit.number import GreaterThan, num
    import real.theorems
    if not isinstance(assumptions, set) and not isinstance(
            assumptions, frozenset):
        raise Exception('assumptions should be a set')
    if not isinstance(exprOrList, Expression) or isinstance(
            exprOrList, ExpressionList):
        # If it isn't an Expression, assume it's iterable and deduce each
        return [
            deducePositive(expr, assumptions=assumptions)
            for expr in exprOrList
        ]
    # A single Expression:
    expr = exprOrList
    try:
        # may be done before we started
        return GreaterThan(expr, num(0)).checked(assumptions)
    except:
        pass  # not so simple

    if not dontTryRealsPos:
        try:
            # see if we can deduce in RealsPos first
            deduceInNumberSet(expr, RealsPos, assumptions, dontTryPos=True)
            inRealsPos = True
        except:
            inRealsPos = False  # not so simple
        if inRealsPos:
            deduceInReals(expr, assumptions)
            return real.theorems.inRealsPos_iff_positive.specialize({
                a: expr
            }).deriveRight().checked(assumptions)

    # Try using positiveTheorem
    if not isinstance(expr, NumberOp):
        # See of the Expression class has deduceNotZero method (as a last resort):
        if hasattr(expr, 'deducePositive'):
            return expr.deducePositive()
        raise DeducePositiveException(expr, assumptions)
    positiveThm = expr._positiveTheorem()
    if positiveThm is None:
        raise DeducePositiveException(expr, assumptions)
    assert isinstance(
        positiveThm,
        Forall), 'Expecting deduce positive theorem to be a Forall expression'
    iVars = positiveThm.instanceVars
    # Specialize the closure theorem differently for AccociativeOperation compared with other cases
    if isinstance(expr, AssociativeOperation):
        assert len(
            iVars
        ) == 1, 'Expecting one instance variables for the positive theorem of an AssociativeOperation'
        assert isinstance(
            iVars[0], Etcetera
        ), 'Expecting the instance variable for the positive theorem of an AssociativeOperation to be an Etcetera Variable'
        positiveSpec = positiveThm.specialize({iVars[0]: expr.operands})
    else:
        if len(iVars) != len(expr.operands):
            raise Exception(
                'Expecting the number of instance variables for the closure theorem to be the same as the number of operands of the Expression'
            )
        positiveSpec = positiveThm.specialize(
            {iVar: operand
             for iVar, operand in zip(iVars, expr.operands)})
    # deduce any of the requirements for the notEqZeroThm application
    _deduceRequirements(positiveThm, positiveSpec, assumptions)
    try:
        return GreaterThan(expr, num(0)).checked(assumptions)
    except:
        raise DeducePositiveException(expr, assumptions)
Beispiel #3
0
from proveit import beginTheorems, endTheorems

beginTheorems(locals())

expNatClosure = Forall((a, b),
                       InSet(Exp(a, b), NaturalsPos),
                       domain=Naturals,
                       conditions=[NotEquals(a, zero)])
expNatClosure

expRealClosure = Forall(
    [a, b],
    InSet(Exp(a, b), Reals),
    domain=Reals,
    conditions=[GreaterThanEquals(a, zero),
                GreaterThan(b, zero)])
expRealClosure

expRealPosClosure = Forall([a, b],
                           InSet(Exp(a, b), RealsPos),
                           domain=Reals,
                           conditions=[GreaterThan(a, zero)])
expRealPosClosure

expComplexClosure = Forall([a, b],
                           InSet(Exp(a, b), Complexes),
                           domain=Complexes,
                           conditions=[NotEquals(a, zero)])
expComplexClosure

sqrtRealClosure = Forall([a],
Beispiel #4
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)
Beispiel #5
0
from proveit import Etcetera
from proveit.logic import Forall, InSet, Equals, NotEquals
from proveit.number import Integers, Naturals, NaturalsPos, Reals, RealsPos, Complexes
from proveit.number import Exp, sqrt, Add, Mult, Sub, Neg, frac, Abs, GreaterThan, GreaterThanEquals, LessThan, LessThanEquals
from proveit.common import a, b, c, d, n, x, y, z, xEtc, xMulti
from proveit.number.common import zero, one, two
from proveit import beginTheorems, endTheorems

beginTheorems(locals())

expNatClosure = Forall((a, b), InSet(Exp(a, b), NaturalsPos), domain=Naturals, conditions=[NotEquals(a, zero)])
expNatClosure

expRealClosure = Forall([a, b], InSet(Exp(a, b), Reals), domain=Reals,
                       conditions=[GreaterThanEquals(a, zero), GreaterThan(b, zero)])
expRealClosure

expRealPosClosure = Forall([a, b], InSet(Exp(a, b), RealsPos), domain=Reals,
                       conditions=[GreaterThan(a, zero)])
expRealPosClosure

expComplexClosure = Forall([a, b], InSet(Exp(a, b), Complexes), domain=Complexes, 
                    conditions=[NotEquals(a, zero)])
expComplexClosure

sqrtRealClosure = Forall([a], InSet(sqrt(a), Reals), domain=Reals,
                         conditions=[GreaterThanEquals(a, zero)])
sqrtRealClosure

sqrtRealPosClosure = Forall([a], InSet(sqrt(a), RealsPos), domain=RealsPos)
sqrtRealPosClosure
Beispiel #6
0
from proveit.logic import Forall, Or, Equals, Implies
from proveit.number import Reals
from proveit.number import LessThan, LessThanEquals, GreaterThan, GreaterThanEquals
from proveit.common import x, y, z
from proveit import beginAxioms, endAxioms

beginAxioms(locals())

lessThanEqualsDef = Forall([x, y],
                           Or(LessThan(x, y), Equals(x, y)),
                           domain=Reals,
                           conditions=LessThanEquals(x, y))
lessThanEqualsDef

greaterThanEqualsDef = Forall([x, y],
                              Or(GreaterThan(x, y), Equals(x, y)),
                              domain=Reals,
                              conditions=GreaterThanEquals(x, y))
greaterThanEqualsDef

reverseGreaterThanEquals = Forall((x, y),
                                  Implies(GreaterThanEquals(x, y),
                                          LessThanEquals(y, x)))
reverseGreaterThanEquals

reverseLessThanEquals = Forall((x, y),
                               Implies(LessThanEquals(x, y),
                                       GreaterThanEquals(y, x)))
reverseLessThanEquals

reverseGreaterThan = Forall((x, y), Implies(GreaterThan(x, y), LessThan(y, x)))
Beispiel #7
0
beginTheorems(locals())

addIntClosure = Forall([xEtc], InSet(Add(xEtc),Integers), domain = Integers)
addIntClosure

addNatClosure = Forall((a, b), InSet(Add(a, b), Naturals), domain=Naturals)
addNatClosure

addRealClosure = Forall([xEtc], InSet(Add(xEtc),Reals), domain=Reals)
addRealClosure

addComplexClosure = Forall([xEtc], InSet(Add(xEtc),Complexes), domain = Complexes)
addComplexClosure

addNatPosClosure = Forall((aEtc, b, cEtc), InSet(Add(aEtc, b, cEtc), NaturalsPos), domain=Naturals, conditions=[GreaterThan(b, zero)])
addNatPosClosure

addZero = Forall(x, Equals(Add(zero, x), x), domain=Complexes)
addZero

addComm = Forall([vEtc,wEtc,xEtc,yEtc,zEtc],
                 Equals(
                        Add(vEtc,wEtc,xEtc,yEtc,zEtc),
                        Add(vEtc,yEtc,xEtc,wEtc,zEtc)
                        ),
                 domain = Complexes
                 )
addComm

addAssoc = Forall([xEtc,yEtc,zEtc],
Beispiel #8
0
beginTheorems(locals())

negIntClosure = Forall(a, InSet(Neg(a), Integers), domain=Integers)
negIntClosure

negRealClosure = Forall(a, InSet(Neg(a), Reals), domain=Reals)
negRealClosure

negComplexClosure = Forall(a, InSet(Neg(a), Complexes), domain=Complexes)
negComplexClosure

negatedPositiveIsNegative = Forall(a,
                                   LessThan(Neg(a), zero),
                                   domain=Reals,
                                   conditions=[GreaterThan(a, zero)])
negatedPositiveIsNegative

negatedNegativeIsPositive = Forall(a,
                                   GreaterThan(Neg(a), zero),
                                   domain=Reals,
                                   conditions=[LessThan(a, zero)])
negatedNegativeIsPositive

negNotEqZero = Forall(a,
                      NotEquals(Neg(a), zero),
                      domain=Complexes,
                      conditions=[NotEquals(a, zero)])
negNotEqZero

distributeNegThroughSum = Forall([xEtc],
Beispiel #9
0
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

intsInComplexes = Forall(a, InSet(a, Complexes), domain=Integers)
intsInComplexes

inNaturalsIfNonNeg = Forall(a, InSet(a,Naturals), domain=Integers, conditions=[GreaterThanEquals(a, zero)])
inNaturalsIfNonNeg

inNaturalsPosIfPos = Forall(a, InSet(a,NaturalsPos), domain=Integers, conditions=[GreaterThan(a, zero)])
inNaturalsPosIfPos

intervalInInts = Forall((a, b), Forall(n, InSet(n, Integers), domain=Interval(a, b)), domain=Integers)
intervalInInts          

intervalInNats = Forall((a, b), Forall(n, InSet(n, Naturals), domain=Interval(a, b)), domain=Naturals)
intervalInNats  

intervalInNatsPos = Forall((a, b), Forall(n, InSet(n, NaturalsPos), domain=Interval(a, b)), domain=Integers, conditions=[GreaterThan(a, zero)])
intervalInNatsPos

allInNegativeIntervalAreNegative = Forall((a, b), Forall(n, LessThan(n, zero), domain=Interval(a, b)), domain=Integers, conditions=[LessThan(b, zero)])
allInNegativeIntervalAreNegative

allInPositiveIntervalArePositive = Forall((a, b), Forall(n, GreaterThan(n, zero), domain=Interval(a, b)), domain=Integers, conditions=[GreaterThan(a, zero)])
Beispiel #10
0
from proveit import Etcetera
from proveit.logic import Forall, InSet, NotEquals, Equals
from proveit.number import Sub, Naturals, NaturalsPos, Integers, Reals, Complexes, Add, Neg, GreaterThan, GreaterThanEquals
from proveit.common import a, b, w, x, y, z, xEtc, yEtc, vEtc, wEtc, zEtc, yMulti
from proveit.number.common import zero, one
from proveit import beginTheorems, endTheorems

beginTheorems(locals())

subtractIntClosure = Forall([a, b], InSet(Sub(a, b), Integers), domain=Integers)
subtractIntClosure

subtractClosureNats = Forall([a, b], InSet(Sub(a, b), Naturals), domain=Integers, conditions=[GreaterThanEquals(a, b)])
subtractClosureNats

subtractClosureNatsPos = Forall([a, b], InSet(Sub(a, b), NaturalsPos), domain=Integers, conditions=[GreaterThan(a, b)])
subtractClosureNatsPos

subtractComplexClosure = Forall([a, b], InSet(Sub(a, b), Complexes), domain=Complexes)
subtractComplexClosure

subtractRealClosure = Forall([a, b], InSet(Sub(a, b), Reals), domain=Reals)
subtractRealClosure

subtractOneInNats = Forall(a, InSet(Sub(a, one), Naturals), domain=NaturalsPos)
subtractOneInNats

diffNotEqZero = Forall((a, b), NotEquals(Sub(a, b), zero), domain=Complexes, conditions=[NotEquals(a, b)])
diffNotEqZero

subtractAsAddNeg = Forall([x, y], Equals(Sub(x, y), 
Beispiel #11
0
minRealClosure = Forall((a, b), InSet(Min(a, b), Reals), domain=Reals)
minRealClosure

minRealPosClosure = Forall((a, b), InSet(Min(a, b), RealsPos), domain=RealsPos)
minRealPosClosure

maxRealClosure = Forall((a, b), InSet(Max(a, b), Reals), domain=Reals)
maxRealClosure

maxRealPosClosure = Forall((a, b), InSet(Max(a, b), RealsPos), domain=RealsPos)
maxRealPosClosure

relaxGreaterThan = Forall([a,b],
                         GreaterThanEquals(a,b),
                         domain = Reals,
                         conditions = GreaterThan(a,b))
relaxGreaterThan

relaxLessThan = Forall([a,b],
                         LessThanEquals(a,b),
                         domain = Reals,
                         conditions = LessThan(a,b))
relaxLessThan

lessThanInBools = Forall([a, b], InSet(LessThan(a, b), Booleans), domain=Reals)
lessThanInBools

lessThanEqualsInBools = Forall([a, b], InSet(LessThanEquals(a, b), Booleans), domain=Reals)
lessThanEqualsInBools

greaterThanInBools = Forall([a, b], InSet(GreaterThan(a, b), Booleans), domain=Reals)