# 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 m
from proveit.logic import Equals, Forall
from proveit.physics.quantum.QPE import _alpha_m_sqrd, _m_domain, _phase_est_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
expr = Forall(instance_param_or_params = [m], instance_expr = Equals(Prob(_phase_est_circuit), _alpha_m_sqrd), domain = _m_domain)
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())
\forall_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}}~\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = \left|\alpha_{m}\right|^{2}\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneNone/False('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3Lambdaparameter: 110
body: 4
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operands: 8
6Operationoperator: 9
operands: 10
7Literal
8ExprTuple11, 12
9Literal
10ExprTuple110, 13
11Operationoperator: 14
operand: 18
12Operationoperator: 44
operands: 16
13Operationoperator: 93
operands: 17
14Literal
15ExprTuple18
16ExprTuple19, 55
17ExprTuple20, 21
18Operationoperator: 22
operands: 23
19Operationoperator: 24
operand: 31
20Literal
21Operationoperator: 107
operands: 26
22Literal
23ExprTuple27, 28, 29, 30
24Literal
25ExprTuple31
26ExprTuple32, 33
27ExprTuple34, 35
28ExprTuple36, 37
29ExprTuple38, 39
30ExprTuple40, 41
31Operationoperator: 42
operand: 110
32Operationoperator: 44
operands: 45
33Operationoperator: 46
operand: 111
34ExprRangelambda_map: 48
start_index: 111
end_index: 112
35ExprRangelambda_map: 49
start_index: 111
end_index: 113
36ExprRangelambda_map: 50
start_index: 111
end_index: 112
37ExprRangelambda_map: 50
start_index: 100
end_index: 101
38ExprRangelambda_map: 51
start_index: 111
end_index: 112
39ExprRangelambda_map: 52
start_index: 111
end_index: 113
40ExprRangelambda_map: 53
start_index: 111
end_index: 112
41ExprRangelambda_map: 54
start_index: 111
end_index: 113
42Literal
43ExprTuple110
44Literal
45ExprTuple55, 112
46Literal
47ExprTuple111
48Lambdaparameter: 99
body: 56
49Lambdaparameter: 99
body: 57
50Lambdaparameter: 99
body: 58
51Lambdaparameter: 99
body: 59
52Lambdaparameter: 99
body: 60
53Lambdaparameter: 99
body: 61
54Lambdaparameter: 99
body: 63
55Literal
56Operationoperator: 85
operands: 64
57Operationoperator: 71
operands: 65
58Operationoperator: 71
operands: 66
59Operationoperator: 67
operands: 68
60Operationoperator: 86
operands: 69
61Operationoperator: 71
operands: 70
62ExprTuple99
63Operationoperator: 71
operands: 72
65NamedExprselement: 74
targets: 82
66NamedExprselement: 75
targets: 76
67Literal
68NamedExprsbasis: 77
69NamedExprsoperation: 78
70NamedExprselement: 79
targets: 80
71Literal
72NamedExprselement: 81
targets: 82
73Operationoperator: 83
operand: 95
74Operationoperator: 85
operands: 92
75Operationoperator: 86
operands: 87
76Operationoperator: 93
operands: 88
77Literal
78Literal
79Operationoperator: 91
operands: 89
80Operationoperator: 93
operands: 90
81Operationoperator: 91
operands: 92
82Operationoperator: 93
operands: 94
83Literal
84ExprTuple95
85Literal
86Literal
87NamedExprsoperation: 96
part: 99
88ExprTuple111, 101
part: 99
90ExprTuple111, 112
91Literal
part: 99
93Literal
94ExprTuple100, 101
95Literal
96Operationoperator: 102
operands: 103
97Operationoperator: 104
operands: 105
98Literal
99Variable
100Operationoperator: 107
operands: 106
101Operationoperator: 107
operands: 108
102Literal
103ExprTuple109, 112
104Literal
105ExprTuple110, 112
106ExprTuple112, 111
107Literal
108ExprTuple112, 113
109Literal
110Variable
111Literal
112Literal
113Literal