Пример #1
0
 def join(self, secondSummation, assumptions=frozenset()):
     '''
     Join the "second summation" with "this" summation, deducing and returning
     the equivalence of these summations added with the joined summation.
     Both summation must be over Intervals.
     The relation between the first summation upper bound, UB1, and the second
     summation lower bound, LB2 must be explicitly either UB1 = LB2-1 or LB2=UB1+1.
     '''
     from theorems import sumSplitAfter, sumSplitBefore
     from proveit.number.common import one
     from proveit.number import Sub, Add
     if not isinstance(self.domain, Interval) or not isinstance(secondSummation.domain, Interval):
         raise Exception('Sum joining only implemented for Interval domains')
     if self.summand != secondSummation.summand:
         raise Exception('Sum joining only allowed when the summands are the same')            
     if self.domain.upperBound == Sub(secondSummation.domain.lowerBound, one):
         sumSplit = sumSplitBefore 
         splitIndex = secondSummation.domain.lowerBound
     elif secondSummation.domain.lowerBound == Add(self.domain.upperBound, one):
         sumSplit = sumSplitAfter
         splitIndex = self.domain.upperBound
     else:
         raise Exception('Sum joining only implemented when there is an explicit increment of one from the upper bound and the second summations lower bound')
     lowerBound, upperBound = self.domain.lowerBound, secondSummation.domain.upperBound
     deduceInIntegers(lowerBound, assumptions)
     deduceInIntegers(upperBound, assumptions)
     deduceInIntegers(splitIndex, assumptions)
     return sumSplit.specialize({Operation(f, self.instanceVars):self.summand}).specialize({a:lowerBound, b:splitIndex, c:upperBound, x:self.indices[0]}).deriveReversed()
Пример #2
0
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)])
notEqualsIsLessThanOrGreaterThan

shiftLessThanToLessThanEquals = Forall((a, b),
                                       LessThanEquals(a, b),
                                       domain=Integers,
                                       conditions=[LessThan(Sub(a, one), b)])
shiftLessThanToLessThanEquals

lessThanEqualsAddRight = Forall([a, b, c],
                                LessThanEquals(Add(a, c), Add(b, c)),
                                domain=Reals,
                                conditions=[LessThanEquals(a, b)])
lessThanEqualsAddRight

lessThanEqualsAddLeft = Forall([a, b, c],
                               LessThanEquals(Add(c, a), Add(c, b)),
                               domain=Reals,
                               conditions=[LessThanEquals(a, b)])
lessThanEqualsAddLeft

lessThanEqualsSubtract = Forall([a, b, c],
Пример #3
0
from proveit import Etcetera
from proveit.logic import Forall, InSet, Equals, NotEquals, Iff, And, SetOfAll
from proveit.number import Integers, Interval, Reals, RealsPos, Complexes
from proveit.number import Abs, Mod, ModAbs, GreaterThanEquals, LessThanEquals, Add, Sub, Neg, Mult, Fraction, IntervalCO
from proveit.common import a, b, c, x, y, N, xEtc, xMulti
from proveit.number.common import zero, one
from proveit import beginTheorems, endTheorems

beginTheorems(locals())

modIntClosure = Forall((a, b), InSet(Mod(a, b), Integers), domain=Integers)
modIntClosure

modInInterval = Forall((a, b),
                       InSet(Mod(a, b), Interval(zero, Sub(b, one))),
                       domain=Integers)
modInInterval

modRealClosure = Forall((a, b), InSet(Mod(a, b), Reals), domain=Reals)
modRealClosure

modAbsRealClosure = Forall((a, b), InSet(ModAbs(a, b), Reals), domain=Reals)
modAbsRealClosure

absComplexClosure = Forall([a], InSet(Abs(a), Reals), domain=Complexes)
absComplexClosure

absNonzeroClosure = Forall([a],
                           InSet(Abs(a), RealsPos),
                           domain=Complexes,
                           conditions=[NotEquals(a, zero)])
Пример #4
0
# m: Random variable for the measurement of Psi as an integer from the register's binary representation.
m_ = Literal(pkg, 'm')

# phase_m: Random variable for the phase result of the quantum phase estimation.
#          phase_m = m / 2^t
phase_m_ = Literal(pkg, 'phase_m', {LATEX: r'\varphi_m'})

# b: The "best" outcome of m such that phase_m is as close as possible to phase.
b_ = Literal(pkg, 'b')

# 2^t
two_pow_t = Exp(two, t_)

# 2^{t-1}
two_pow_t_minus_one = Exp(two, Sub(t_, one))

# amplitude of output register as indexted
alpha_ = Literal(pkg, 'alpha', {STRING: 'alpha', LATEX: r'\alpha'})
alpha_l = SubIndexed(alpha_, l)
abs_alpha_l = Abs(alpha_l)
alpha_l_sqrd = Exp(Abs(alpha_l), two)

# delta: difference between the phase and the best phase_m
delta_ = Literal(pkg, 'delta', {LATEX: r'\delta'})

fullDomain = Interval(Add(Neg(Exp(two, Sub(t_, one))), one),
                      Exp(two, Sub(t_, one)))
negDomain = Interval(Add(Neg(two_pow_t_minus_one), one), Neg(Add(eps, one)))
posDomain = Interval(Add(eps, one), two_pow_t_minus_one)
epsDomain = Interval(one, Sub(two_pow_t_minus_one, two))
Пример #5
0
greaterThanEqualsInBools = Forall([a, b],
                                  InSet(GreaterEq(a, b), Booleans),
                                  domain=Reals)
greaterThanEqualsInBools

notEqualsIsLessThanOrGreaterThan = Forall((a, x),
                                          Or(Less(x, a), Greater(x, a)),
                                          domain=Reals,
                                          conditions=[NotEquals(x, a)])
notEqualsIsLessThanOrGreaterThan

shiftLessThanToLessThanEquals = Forall((a, b),
                                       LessEq(a, b),
                                       domain=Integers,
                                       conditions=[Less(Sub(a, one), b)])
shiftLessThanToLessThanEquals

lessThanEqualsAddRight = Forall([a, b, c],
                                LessEq(Add(a, c), Add(b, c)),
                                domain=Reals,
                                conditions=[LessEq(a, b)])
lessThanEqualsAddRight

lessThanEqualsAddLeft = Forall([a, b, c],
                               LessEq(Add(c, a), Add(c, b)),
                               domain=Reals,
                               conditions=[LessEq(a, b)])
lessThanEqualsAddLeft

lessThanEqualsSubtract = Forall([a, b, c],
Пример #6
0
addOneRightInExpRev

addOneLeftInExp = Forall([a, b],
                         Equals(Exp(a, Add(one, b)), Mult(a, Exp(a, b))),
                         domain=Complexes,
                         conditions=[NotEquals(a, zero)])
addOneLeftInExp

addOneLeftInExpRev = Forall([a, b],
                            Equals(Mult(a, Exp(a, b)), Exp(a, Add(one, b))),
                            domain=Complexes,
                            conditions=[NotEquals(a, zero)])
addOneLeftInExpRev

diffInExp = Forall([a, b, c],
                   Equals(Exp(a, Sub(b, c)), Mult(Exp(a, b), Exp(a, Neg(c)))),
                   domain=Complexes,
                   conditions=[NotEquals(a, zero)])
diffInExp

diffInExpRev = Forall([a, b, c],
                      Equals(Mult(Exp(a, b), Exp(a, Neg(c))),
                             Exp(a, Sub(b, c))),
                      domain=Complexes,
                      conditions=[NotEquals(a, zero)])
diffInExpRev

diffFracInExp = Forall([a, b, c, d],
                       Equals(Exp(a, Sub(b, frac(c, d))),
                              Mult(Exp(a, b), Exp(a, frac(Neg(c), d)))),
                       domain=Complexes,
Пример #7
0
                                      domain=Complexes,
                                      conditions=[NotEquals(y, zero)])
distributeFractionThroughSum

distributeFractionThroughSumRev = Forall([xEtc, y],
                                         Equals(
                                             Add(Etcetera(Fraction(xMulti,
                                                                   y))),
                                             Fraction(Add(xEtc), y)),
                                         domain=Complexes,
                                         conditions=[NotEquals(y, zero)])
distributeFractionThroughSumRev

distributeFractionThroughSubtract = Forall([x, y, z],
                                           Equals(
                                               Fraction(Sub(x, y), z),
                                               Sub(Fraction(x, z),
                                                   Fraction(y, z))),
                                           domain=Complexes,
                                           conditions=[NotEquals(z, zero)])
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
Пример #8
0
    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,
    Forall([a, b],
           Equals(Sum(x, fx, Interval(a, b)),
                  Add(fa, Sum(x, fx, Interval(Add(a, one), b)))),
           domain=Integers,
           conditions=[LessThan(a, b)]))
sumSplitFirst

sumZeroAndOne = Forall(
Пример #9
0
distributeThroughSum = Forall([xEtc, yEtc, zEtc],
                              Equals(Mult(xEtc, Add(yEtc), zEtc),
                                     Add(Etcetera(Mult(xEtc, yMulti, zEtc)))),
                              domain=Complexes)
distributeThroughSum

distributeThroughSumRev = Forall([xEtc, yEtc, zEtc],
                                 Equals(
                                     Add(Etcetera(Mult(xEtc, yMulti, zEtc))),
                                     Mult(xEtc, Add(yEtc), zEtc)),
                                 domain=Complexes)
distributeThroughSumRev

distributeThroughSubtract = Forall([wEtc, x, y, zEtc],
                                   Equals(
                                       Mult(wEtc, Sub(x, y), zEtc),
                                       Sub(Mult(wEtc, x, zEtc),
                                           Mult(wEtc, 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],
Пример #10
0
addOneLeftInExp = Forall([a,b],
                Equals(Exp(a,Add(one, b)),
                       Mult(a, Exp(a,b))),
                domain = Complexes, conditions=[NotEquals(a, zero)])
addOneLeftInExp

addOneLeftInExpRev = Forall([a,b],
                Equals(Mult(a, Exp(a,b)),
                       Exp(a,Add(one, b))),
                domain = Complexes, conditions=[NotEquals(a, zero)])
addOneLeftInExpRev


diffInExp = Forall([a,b,c],
                Equals(Exp(a,Sub(b,c)),
                       Mult(Exp(a,b),Exp(a,Neg(c)))),
                domain = Complexes, conditions=[NotEquals(a, zero)])
diffInExp


diffInExpRev = Forall([a,b,c],
                Equals(Mult(Exp(a,b),Exp(a,Neg(c))),
                       Exp(a,Sub(b,c))),
                domain = Complexes, conditions=[NotEquals(a, zero)])
diffInExpRev

diffFracInExp = Forall([a,b,c,d],
                Equals(Exp(a,Sub(b,Fraction(c, d))),
                       Mult(Exp(a,b),Exp(a,Fraction(Neg(c), d)))),
                domain = Complexes, conditions=[NotEquals(a, zero), NotEquals(d, zero)])
Пример #11
0
from proveit.logic import Forall, Equals, And, InSet
from proveit.number import Floor, Sub, IntervalCO, Integers, Reals
from proveit.common import x
from proveit.number.common import zero, one
from proveit import beginAxioms, endAxioms

beginAxioms(locals())

floorDef = Forall(x,
                  And(InSet(Floor(x), Integers),
                      InSet(Sub(x, Floor(x)), IntervalCO(zero, one))),
                  domain=Reals)
floorDef

endAxioms(locals(), __package__)
Пример #12
0
negNotEqZero

distributeNegThroughSum = Forall([xEtc],
                                 Equals(Neg(Add(xEtc)),
                                        Add(Etcetera(Neg(xMulti)))),
                                 domain=Complexes)
distributeNegThroughSum

distributeNegThroughSumRev = Forall([xEtc],
                                    Equals(Add(Etcetera(Neg(xMulti))),
                                           Neg(Add(xEtc))),
                                    domain=Complexes)
distributeNegThroughSumRev

distributeNegThroughSubtract = Forall([x, y],
                                      Equals(Neg(Sub(x, y)), Add(Neg(x), y)),
                                      domain=Complexes)
distributeNegThroughSubtract

negTimesPos = Forall([x, y],
                     Equals(Mult(Neg(x), y), Neg(Mult(x, y))),
                     domain=Complexes)
negTimesPos

negTimesPosRev = Forall([x, y],
                        Equals(Neg(Mult(x, y)), Mult(Neg(x), y)),
                        domain=Complexes)
negTimesPosRev

posTimesNeg = Forall([x, y],
                     Equals(Mult(x, Neg(y)), Neg(Mult(x, y))),
Пример #13
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), 
Пример #14
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__)
Пример #15
0
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)])
notEqualsIsLessThanOrGreaterThan

shiftLessThanToLessThanEquals = Forall((a, b), LessThanEquals(a, b), domain=Integers, conditions=[LessThan(Sub(a, one), b)])
shiftLessThanToLessThanEquals

lessThanEqualsAddRight = Forall([a, b, c], LessThanEquals(Add(a, c), Add(b, c)), domain=Reals, conditions=[LessThanEquals(a, b)])
lessThanEqualsAddRight

lessThanEqualsAddLeft = Forall([a, b, c], LessThanEquals(Add(c, a), Add(c, b)), domain=Reals, conditions=[LessThanEquals(a, b)])
lessThanEqualsAddLeft

lessThanEqualsSubtract = Forall([a, b, c], LessThanEquals(Sub(a, c), Sub(b, c)), domain=Reals, conditions=[LessThanEquals(a, b)])
lessThanEqualsSubtract

lessThanAddRight = Forall([a, b, c], LessThan(Add(a, c), Add(b, c)), domain=Reals, conditions=[LessThan(a, b)])
lessThanAddRight

lessThanAddLeft = Forall([a, b, c], LessThan(Add(c, a), Add(c, b)), domain=Reals, conditions=[LessThan(a, b)])
Пример #16
0
distributefracThroughSum = Forall([xEtc, y],
                                  Equals(frac(Add(xEtc), y),
                                         Add(Etcetera(frac(xMulti, y)))),
                                  domain=Complexes,
                                  conditions=[NotEquals(y, zero)])
distributefracThroughSum

distributefracThroughSumRev = Forall([xEtc, y],
                                     Equals(Add(Etcetera(frac(xMulti, y))),
                                            frac(Add(xEtc), y)),
                                     domain=Complexes,
                                     conditions=[NotEquals(y, zero)])
distributefracThroughSumRev

distributefracThroughSubtract = Forall([x, y, z],
                                       Equals(frac(Sub(x, y), z),
                                              Sub(frac(x, z), frac(y, z))),
                                       domain=Complexes,
                                       conditions=[NotEquals(z, zero)])
distributefracThroughSubtract

distributefracThroughSubtractRev = Forall([x, y, z],
                                          Equals(Sub(frac(x, z), frac(y, z)),
                                                 frac(Sub(x, y), z)),
                                          domain=Complexes,
                                          conditions=[NotEquals(z, zero)])
distributefracThroughSubtractRev

distributefracThroughSummation = Forall(
    [P, S],
    Implies(