Beispiel #1
0
def deduceNegative(exprOrList, assumptions=frozenset(), dontTryRealsNeg=False):
    '''
    For each given expression, attempt to derive that it is negative
    under the given assumptions.  If successful, returns the deduced statement,
    otherwise raises an Exception.  
    '''
    from proveit.number import LessThan, 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 [
            deduceNegative(expr, assumptions=assumptions)
            for expr in exprOrList
        ]
    # A single Expression:
    expr = exprOrList
    try:
        # may be done before we started
        return LessThan(expr, num(0)).checked(assumptions)
    except:
        pass  # not so simple

    if not dontTryRealsNeg:
        try:
            # see if we can deduce in RealsNeg first
            deduceInNumberSet(expr, RealsNeg, assumptions, dontTryNeg=True)
            inRealsNeg = True
        except:
            inRealsNeg = False  # not so simple
        if inRealsNeg:
            deduceInReals(expr, assumptions)
            return real.theorems.inRealsNeg_iff_negative.specialize({
                a: expr
            }).deriveRight().checked(assumptions)

    # Try using negativeTheorem
    if not isinstance(expr, NumberOp):
        # See of the Expression class has deduceNotZero method (as a last resort):
        if hasattr(expr, 'deduceNegative'):
            return expr.deduceNegative()
        raise DeduceNegativeException(expr, assumptions)
    negativeThm = expr._negativeTheorem()
    if negativeThm is None:
        raise DeduceNegativeException(expr, assumptions)
    assert isinstance(
        negativeThm,
        Forall), 'Expecting deduce negative theorem to be a Forall expression'
    iVars = negativeThm.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 negative theorem of an AssociativeOperation'
        assert isinstance(
            iVars[0], Etcetera
        ), 'Expecting the instance variable for the negative theorem of an AssociativeOperation to be an Etcetera Variable'
        negativeSpec = negativeThm.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'
            )
        negativeSpec = negativeThm.specialize(
            {iVar: operand
             for iVar, operand in zip(iVars, expr.operands)})
    # deduce any of the requirements for the notEqZeroThm application
    _deduceRequirements(negativeThm, negativeSpec, assumptions)
    try:
        return LessThan(expr, num(0)).checked(assumptions)
    except:
        raise DeduceNegativeException(expr, assumptions)
Beispiel #2
0
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)
allInIntervalCO_InReals 

allInIntervalOC_InReals = Forall((a, b), Forall(x, InSet(x, Reals), domain=IntervalOC(a, b)), domain=Reals)
Beispiel #3
0
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)
greaterThanInBools
Beispiel #4
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 #5
0
                                            InSet(PxEtc, Complexes),
                                            domain=S),
                                     InSet(Sum(xMulti, PxEtc, domain=S),
                                           Complexes)))
summationComplexClosure

sumSplitAfter = Forall(
    f,
    Forall([a, b, c],
           Equals(
               Sum(x, fx, Interval(a, c)),
               Add(Sum(x, fx, Interval(a, b)),
                   Sum(x, fx, Interval(Add(b, one), c)))),
           domain=Integers,
           conditions=[LessThanEquals(a, b),
                       LessThan(b, c)]))
sumSplitAfter

sumSplitBefore = Forall(
    f,
    Forall([a, b, c],
           Equals(
               Sum(x, fx, Interval(a, c)),
               Add(Sum(x, fx, Interval(a, Sub(b, one))),
                   Sum(x, fx, Interval(b, c)))),
           domain=Integers,
           conditions=[LessThan(a, b), LessThanEquals(b, c)]))
sumSplitBefore

sumSplitFirst = Forall(
    f,
Beispiel #6
0
                        Add(
                                xEtc,Add(yEtc),zEtc),
                        Add(
                                xEtc,yEtc,zEtc)
                        )
                  )
addAssocRev

# One issue with this is that it only applies when |aEtc|+|bEtc| > 0.  This isn't an issue
# for applying the theorem because there will be an error if b is left alone with Add, but
# it will be an issue when deriving this.  Probably need to include |aEtc|+|bEtc| > 0 as a condition.
strictlyIncreasingAdditions = Forall((aEtc, cEtc), Forall(b, GreaterThan(Add(aEtc, b, cEtc), b),
                                                          domain=Reals),
                                     domain=RealsPos)
strictlyIncreasingAdditions


# In[80]:

# One issue with this is that it only applies when |aEtc|+|bEtc| > 0.  This isn't an issue
# for applying the theorem because there will be an error if b is left alone with Add, but
# it will be an issue when deriving this.  Probably need to include |aEtc|+|bEtc| > 0 as a condition.
strictlyDecreasingAdditions = Forall((aEtc, cEtc), Forall(b, LessThan(Add(aEtc, b, cEtc), b),
                                                          domain=Reals),
                                     domain=RealsNeg)
strictlyDecreasingAdditions



endTheorems(locals(), __package__)
Beispiel #7
0
from proveit.number.common import zero
from proveit import beginTheorems, endTheorems

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
Beispiel #8
0
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)])
allInPositiveIntervalArePositive

intervalLowerBound = Forall((a, b), Forall(n, LessThanEquals(a, n), domain=Interval(a, b)), domain=Integers)
intervalLowerBound

intervalUpperBound = Forall((a, b), Forall(n, LessThanEquals(n, b), domain=Interval(a, b)), domain=Integers)
intervalUpperBound

inInterval = Forall((a, b, n), InSet(n, Interval(a, b)), domain=Integers, conditions=[LessThanEquals(a, n), LessThanEquals(n, b)])
inInterval

natsInInts = Forall(a,InSet(a,Integers),domain = Naturals)
Beispiel #9
0
from proveit.logic import Forall, Equals
from proveit.number import Sum, Integers, Interval, LessThan, Add, Sub
from proveit.common import a, b, f, x, fa, fb, fx
from proveit.number.common import one
from proveit import beginAxioms, endAxioms

beginAxioms(locals())

sumSingle = Forall(f, Forall(a,
                              Equals(Sum(x,fx,Interval(a,a)),
                                     fa),
                              domain=Integers))
sumSingle

sumSplitLast = Forall(f, 
                      Forall([a,b],
                             Equals(Sum(x,fx,Interval(a,b)),
                                    Add(Sum(x,fx,Interval(a,Sub(b, one))),
                                       fb)),
                             domain=Integers, conditions=[LessThan(a, b)]))
sumSplitLast


endAxioms(locals(), __package__)
Beispiel #10
0
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)
greaterThanInBools

greaterThanEqualsInBools = Forall([a, b], InSet(GreaterThanEquals(a, b), Booleans), domain=Reals)
greaterThanEqualsInBools

notEqualsIsLessThanOrGreaterThan = Forall((a, x), Or(LessThan(x, a), GreaterThan(x, a)), domain=Reals, conditions=[NotEquals(x, a)])