from the theory of proveit.physics.quantum.QPE¶

In [1]:
import proveit
# Automation is not needed when building an expression:
proveit.defaults.automation = False # This will speed things up.
proveit.defaults.inline_pngs = False # Makes files smaller.
# import Expression classes needed to build the expression
from proveit import Function, Variable, l
from proveit.logic import Equals
from proveit.numbers import Abs, Add, Exp, Sum, two
from proveit.physics.quantum.QPE import _neg_domain, _pos_domain, _rel_indexed_alpha
from proveit.statistics import ProbOfAll

In [2]:
# build up the expression from sub-expressions
sub_expr1 = [l]
sub_expr2 = Exp(Abs(_rel_indexed_alpha), two)
expr = Equals(ProbOfAll(instance_param_or_params = sub_expr1, instance_element = Function(Variable("_b", latex_format = r"{_{-}b}"), sub_expr1)), Add(Sum(index_or_indices = sub_expr1, summand = sub_expr2, domain = _neg_domain), Sum(index_or_indices = sub_expr1, summand = sub_expr2, domain = _pos_domain))).with_wrapping_at(2)

expr:
In [3]:
# check that the built expression is the same as the stored expression
assert expr == stored_expr
assert expr._style_id == stored_expr._style_id
print("Passed sanity check: expr matches stored_expr")

Passed sanity check: expr matches stored_expr

In [4]:
# Show the LaTeX representation of the expression for convenience if you need it.
print(stored_expr.latex())

\begin{array}{c} \begin{array}{l} \left[\textrm{Prob}_{l}~{_{-}b}\left(l\right)\right] =  \\ \left(\left(\sum_{l = -2^{t - 1} + 1}^{-\left(e + 1\right)} \left|\alpha_{b_{\textit{f}} \oplus l}\right|^{2}\right) + \left(\sum_{l = e + 1}^{2^{t - 1}} \left|\alpha_{b_{\textit{f}} \oplus l}\right|^{2}\right)\right) \end{array} \end{array}

In [5]:
stored_expr.style_options()

namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()(2)('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()

core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 5
operand: 8
4Operationoperator: 58
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameter: 53
body: 11
9Operationoperator: 13
operand: 16
10Operationoperator: 13
operand: 17
11Operationoperator: 15
operand: 53
12ExprTuple16
13Literal
14ExprTuple17
15Variable
16Lambdaparameter: 53
body: 18
17Lambdaparameter: 53
body: 20
18Conditionalvalue: 22
condition: 21
19ExprTuple53
20Conditionalvalue: 22
condition: 23
21Operationoperator: 26
operands: 24
22Operationoperator: 54
operands: 25
23Operationoperator: 26
operands: 27
24ExprTuple53, 28
25ExprTuple29, 56
26Literal
27ExprTuple53, 30
28Operationoperator: 34
operands: 31
29Operationoperator: 32
operand: 38
30Operationoperator: 34
operands: 35
31ExprTuple36, 37
32Literal
33ExprTuple38
34Literal
35ExprTuple44, 50
36Operationoperator: 58
operands: 39
37Operationoperator: 62
operand: 44
38Operationoperator: 41
operand: 45
39ExprTuple43, 64
40ExprTuple44
41Literal
42ExprTuple45
43Operationoperator: 62
operand: 50
44Operationoperator: 58
operands: 47
45Operationoperator: 48
operands: 49
46ExprTuple50
47ExprTuple51, 64
48Literal
49ExprTuple52, 53
50Operationoperator: 54
operands: 55
51Variable
52Literal
53Variable
54Literal
55ExprTuple56, 57
56Literal
57Operationoperator: 58
operands: 59
58Literal
59ExprTuple60, 61
60Literal
61Operationoperator: 62
operand: 64
62Literal
63ExprTuple64
64Literal