コード例 #1
0
ファイル: deci.py プロジェクト: rmmilewi/Prove-It
def num(x):
    from proveit.number import Neg
    if x < 0:
        return Neg(num(abs(x)))
    if isinstance(x, int):
        if x < 10:
            if x == 0:
                return zero
            elif x == 1:
                return one
            elif x == 2:
                return two
            elif x == 3:
                return three
            elif x == 4:
                return four
            elif x == 5:
                return five
            elif x == 6:
                return six
            elif x == 7:
                return seven
            elif x == 8:
                return eight
            elif x == 9:
                return nine
        else:
            return DecimalSequence(*[num(int(digit)) for digit in str(x)])
    else:
        assert False, 'num not implemented for anything except integers currently. plans to take in strings or floats with specified precision'
コード例 #2
0
greaterThanAddRight

greaterThanAddLeft = Forall([a, b, c],
                            GreaterThan(Add(c, a), Add(c, b)),
                            domain=Reals,
                            conditions=[GreaterThan(a, b)])
greaterThanAddLeft

greaterThanSubtract = Forall([a, b, c],
                             GreaterThan(Sub(a, c), Sub(b, c)),
                             domain=Reals,
                             conditions=[GreaterThan(a, b)])
greaterThanSubtract

negatedLessThan = Forall([a, b],
                         GreaterThan(Neg(a), Neg(b)),
                         domain=Reals,
                         conditions=[LessThan(a, b)])
negatedLessThan

negatedLessThanEquals = Forall([a, b],
                               GreaterThanEquals(Neg(a), Neg(b)),
                               domain=Reals,
                               conditions=[LessThanEquals(a, b)])
negatedLessThanEquals

negatedGreaterThan = Forall([a, b],
                            LessThan(Neg(a), Neg(b)),
                            domain=Reals,
                            conditions=[GreaterThan(a, b)])
negatedGreaterThan
コード例 #3
0
ファイル: theorems.py プロジェクト: rmmilewi/Prove-It
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
コード例 #4
0
greaterThanAddRight

greaterThanAddLeft = Forall([a, b, c],
                            Greater(Add(c, a), Add(c, b)),
                            domain=Reals,
                            conditions=[Greater(a, b)])
greaterThanAddLeft

greaterThanSubtract = Forall([a, b, c],
                             Greater(Sub(a, c), Sub(b, c)),
                             domain=Reals,
                             conditions=[Greater(a, b)])
greaterThanSubtract

negatedLessThan = Forall([a, b],
                         Greater(Neg(a), Neg(b)),
                         domain=Reals,
                         conditions=[Less(a, b)])
negatedLessThan

negatedLessThanEquals = Forall([a, b],
                               GreaterEq(Neg(a), Neg(b)),
                               domain=Reals,
                               conditions=[LessEq(a, b)])
negatedLessThanEquals

negatedGreaterThan = Forall([a, b],
                            Less(Neg(a), Neg(b)),
                            domain=Reals,
                            conditions=[Greater(a, b)])
negatedGreaterThan
コード例 #5
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))
コード例 #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
from proveit.logic import Equals
from proveit.number import Mod, ModAbs, Min, Neg
from proveit.common import a, b
from proveit import beginAxioms, endAxioms

beginAxioms(locals())

modAbsDef = Equals(ModAbs(a, b), Min(Mod(a, b), Mod(Neg(a), b)))
modAbsDef

endAxioms(locals(), __package__)


コード例 #8
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)])
diffFracInExp
コード例 #9
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__)
コード例 #10
0
ファイル: abs.py プロジェクト: shoelbling/Prove-It
    def doReducedSimplification(self, assumptions=USE_DEFAULTS):
        '''
        For the case Abs(x) where the operand x is already known to
        be or assumed to be a non-negative real, derive and return 
        this Abs expression equated with the operand itself:
        |- Abs(x) = x. For the case where x is already known or assumed
        to be a negative real, return the Abs expression equated with
        the negative of the operand: |- Abs(x) = -x.
        Assumptions may be necessary to deduce necessary conditions for
        the simplification.
        '''
        from proveit.number import Greater, GreaterEq, Mult, Neg
        from proveit.number import (zero, Naturals, NaturalsPos, RealsNeg,
                                    RealsNonNeg, RealsPos)
        # among other things, convert any assumptions=None
        # to assumptions=() (thus averting len(None) errors)
        assumptions = defaults.checkedAssumptions(assumptions)

        #-- -------------------------------------------------------- --#
        #-- Case (1): Abs(x) where entire operand x is known or      --#
        #--           assumed to be non-negative Real.               --#
        #-- -------------------------------------------------------- --#
        if InSet(self.operand, RealsNonNeg).proven(assumptions=assumptions):
            # Entire operand is known to be or assumed to be a
            # non-negative real, so we can return Abs(x) = x
            return self.absElimination(operand_type='non-negative',
                                       assumptions=assumptions)

        #-- -------------------------------------------------------- --#
        #-- Case (2): Abs(x) where entire operand x is known or      --#
        #--           assumed to be a negative Real.                 --#
        #-- -------------------------------------------------------- --#
        if InSet(self.operand, RealsNeg).proven(assumptions=assumptions):
            # Entire operand is known to be or assumed to be a
            # negative real, so we can return Abs(x) = -x
            return self.absElimination(operand_type='negative',
                                       assumptions=assumptions)

        #-- -------------------------------------------------------- --#
        #-- Case (3): Abs(x) where entire operand x is not yet known --*
        #--           to be a non-negative Real, but can easily be   --#
        #--           proven to be a non-negative Real because it is --#
        #--           (a) known or assumed to be ≥ 0 or
        #--           (b) known or assumed to be in a subset of the  --#
        #--               non-negative Reals, or                     --#
        #--           (c) the addition or product of operands, all   --#
        #--               of which are known or assumed to be non-   --#
        #--               negative reals. TBA!
        #-- -------------------------------------------------------- --#
        if (Greater(self.operand, zero).proven(assumptions=assumptions)
                and not GreaterEq(self.operand,
                                  zero).proven(assumptions=assumptions)):
            GreaterEq(self.operand, zero).prove(assumptions=assumptions)
            # and then it will get picked up in the next if() below

        if GreaterEq(self.operand, zero).proven(assumptions=assumptions):
            from proveit.number.sets.real._theorems_ import (
                inRealsNonNegIfGreaterEqZero)
            inRealsNonNegIfGreaterEqZero.specialize({a: self.operand},
                                                    assumptions=assumptions)
            return self.absElimination(operand_type='non-negative',
                                       assumptions=assumptions)

        if self.operand in InSet.knownMemberships.keys():
            for kt in InSet.knownMemberships[self.operand]:
                if kt.isSufficient(assumptions):
                    if isEqualToOrSubsetEqOf(
                            kt.expr.operands[1],
                            equal_sets=[RealsNonNeg, RealsPos],
                            subset_eq_sets=[Naturals, NaturalsPos, RealsPos],
                            assumptions=assumptions):

                        InSet(self.operand,
                              RealsNonNeg).prove(assumptions=assumptions)
                        return self.absElimination(operand_type='non-negative',
                                                   assumptions=assumptions)

        if isinstance(self.operand, Add) or isinstance(self.operand, Mult):
            count_of_known_memberships = 0
            count_of_known_relevant_memberships = 0
            for op in self.operand.operands:
                if op in InSet.knownMemberships.keys():
                    count_of_known_memberships += 1
            if count_of_known_memberships == len(self.operand.operands):
                for op in self.operand.operands:
                    op_temp_known_memberships = InSet.knownMemberships[op]
                    for kt in op_temp_known_memberships:
                        if (kt.isSufficient(assumptions)
                                and isEqualToOrSubsetEqOf(
                                    kt.expr.operands[1],
                                    equal_sets=[RealsNonNeg, RealsPos],
                                    subset_eq_sets=[
                                        Naturals, NaturalsPos, RealsPos,
                                        RealsNonNeg
                                    ],
                                    assumptions=assumptions)):

                            count_of_known_relevant_memberships += 1
                            break

                if (count_of_known_relevant_memberships == len(
                        self.operand.operands)):
                    # Prove that the sum or product is in
                    # RealsNonNeg and then instantiate absElimination.
                    for op in self.operand.operands:
                        InSet(op, RealsNonNeg).prove(assumptions=assumptions)
                    return self.absElimination(assumptions=assumptions)

        #-- -------------------------------------------------------- --#
        #-- Case (4): Abs(x) where operand x can easily be proven    --#
        #--           to be a negative Real because -x is known to   --#
        #--           be in a subset of the positive Reals           --#
        #-- -------------------------------------------------------- --#
        negated_op = None
        if isinstance(self.operand, Neg):
            negated_op = self.operand.operand
        else:
            negated_op = Neg(self.operand)
        negated_op_simp = negated_op.simplification(
            assumptions=assumptions).rhs

        if negated_op_simp in InSet.knownMemberships.keys():
            from proveit.number.sets.real._theorems_ import (
                negInRealsNegIfPosInRealsPos)
            for kt in InSet.knownMemberships[negated_op_simp]:
                if kt.isSufficient(assumptions):
                    if isEqualToOrSubsetEqOf(
                            kt.expr.operands[1],
                            equal_sets=[RealsNonNeg, RealsPos],
                            subset_sets=[NaturalsPos, RealsPos],
                            subset_eq_sets=[NaturalsPos, RealsPos],
                            assumptions=assumptions):

                        InSet(negated_op_simp,
                              RealsPos).prove(assumptions=assumptions)
                        negInRealsNegIfPosInRealsPos.specialize(
                            {a: negated_op_simp}, assumptions=assumptions)
                        return self.absElimination(operand_type='negative',
                                                   assumptions=assumptions)

        # for updating our equivalence claim(s) for the
        # remaining possibilities
        from proveit import TransRelUpdater
        eq = TransRelUpdater(self, assumptions)
        return eq.relation
コード例 #11
0
ファイル: theorems.py プロジェクト: wdcraft01/Prove-It
from proveit import Etcetera
from proveit.logic import Forall, InSet, Equals, NotEquals
from proveit.number import Neg, Integers, Reals, Complexes, Add, Sub, Mult, LessThan, GreaterThan
from proveit.common import a, b, x, y, xEtc, xMulti
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,
コード例 #12
0
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), 
                                         Add(x, Neg(y))), 
                          domain=Complexes)
subtractAsAddNeg

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


absorbTermsIntoSubtraction = Forall([wEtc, x, y, zEtc],
                                    Equals(Add(wEtc, Sub(x, y), zEtc),
                                           Sub(Add(wEtc, x, zEtc), y)), domain=Complexes)
absorbTermsIntoSubtraction

コード例 #13
0
greaterThanEqualsAddRight

greaterThanEqualsAddLeft = Forall([a, b, c], GreaterThanEquals(Add(c, a), Add(c, b)), domain=Reals, conditions=[GreaterThanEquals(a, b)])
greaterThanEqualsAddLeft

greaterThanEqualsSubtract = Forall([a, b, c], GreaterThanEquals(Sub(a, c), Sub(b, c)), domain=Reals, conditions=[GreaterThanEquals(a, b)])
greaterThanEqualsSubtract

greaterThanAddRight = Forall([a, b, c], GreaterThan(Add(a, c), Add(b, c)), domain=Reals, conditions=[GreaterThan(a, b)])
greaterThanAddRight

greaterThanAddLeft = Forall([a, b, c], GreaterThan(Add(c, a), Add(c, b)), domain=Reals, conditions=[GreaterThan(a, b)])
greaterThanAddLeft

greaterThanSubtract = Forall([a, b, c], GreaterThan(Sub(a, c), Sub(b, c)), domain=Reals, conditions=[GreaterThan(a, b)])
greaterThanSubtract

negatedLessThan = Forall([a, b], GreaterThan(Neg(a), Neg(b)), domain=Reals, conditions=[LessThan(a, b)])
negatedLessThan

negatedLessThanEquals = Forall([a, b], GreaterThanEquals(Neg(a), Neg(b)), domain=Reals, conditions=[LessThanEquals(a, b)])
negatedLessThanEquals

negatedGreaterThan = Forall([a, b], LessThan(Neg(a), Neg(b)), domain=Reals, conditions=[GreaterThan(a, b)])
negatedGreaterThan

negatedGreaterThanEquals = Forall([a, b], LessThanEquals(Neg(a), Neg(b)), domain=Reals, conditions=[GreaterThanEquals(a, b)])
negatedGreaterThanEquals

endTheorems(locals(), __package__)