logo

Expression of type Forall

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.
%load_expr # Load the stored expression as 'stored_expr'
# import Expression classes needed to build the expression
from proveit import ExprRange, U, Variable, VertExprArray, eps, m, n, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import Equals, Forall, InSet
from proveit.numbers import Add, Ceil, Exp, Interval, IntervalCO, IntervalOC, LessEq, Log, ModAbs, Mult, NaturalPos, Neg, Real, e, frac, greater_eq, i, one, pi, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, normalized_var_ket_u, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, s_ket_domain, two_pow_s, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import ProbOfAll
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
sub_expr3 = Add(t, s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Forall(instance_param_or_params = [eps], instance_expr = Forall(instance_param_or_params = [s, n], instance_expr = Forall(instance_param_or_params = [U, var_ket_u, phase], instance_expr = Forall(instance_param_or_params = [t], instance_expr = greater_eq(ProbOfAll(instance_param_or_params = [m], instance_element = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)], [ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)])), domain = Interval(zero, subtract(two_pow_t, one)), condition = LessEq(ModAbs(subtract(frac(m, two_pow_t), phase), one), Exp(two, Neg(n)))).with_wrapping(), subtract(one, eps)), domain = NaturalPos, condition = greater_eq(t, Add(n, Ceil(Log(two, Add(two, frac(one, Mult(two, eps)))))))).with_wrapping(), domains = [Unitary(two_pow_s), s_ket_domain, Real], conditions = [InSet(phase, IntervalCO(zero, one)), normalized_var_ket_u, Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), var_ket_u))]).with_wrapping(), domain = NaturalPos, condition = greater_eq(n, two)).with_wrapping(), domain = IntervalOC(zero, one)).with_wrapping()
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}{l}\forall_{\epsilon \in \left(0,1\right]}~\\
\left[\begin{array}{l}\forall_{s, n \in \mathbb{N}^+~|~n \geq 2}~\\
\left[\begin{array}{l}\forall_{U \in \textrm{U}\left(2^{s}\right), \lvert u \rangle \in \mathbb{C}^{2^{s}}, \varphi \in \mathbb{R}~|~\varphi \in \left[0,1\right), \left \|\lvert u \rangle\right \| = 1, \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\\
\left[\begin{array}{l}\forall_{t \in \mathbb{N}^+~|~t \geq \left(n + \left\lceil \textrm{log}_2\left(2 + \frac{1}{2 \cdot \epsilon}\right)\right\rceil\right)}~\\
\left(\left[\begin{array}{l}\textrm{Prob}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}~|~\left|\frac{m}{2^{t}} - \varphi\right|_{\textup{mod}\thinspace 1} \leq 2^{-n}}~\\
\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)\end{array}\right] \geq \left(1 - \epsilon\right)\right)\end{array}\right]\end{array}\right]\end{array}\right]\end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('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: 28
operand: 2
1ExprTuple2
2Lambdaparameter: 219
body: 3
3Conditionalvalue: 4
condition: 5
4Operationoperator: 28
operand: 8
5Operationoperator: 121
operands: 7
6ExprTuple8
7ExprTuple219, 9
8Lambdaparameters: 10
body: 11
9Operationoperator: 12
operands: 63
10ExprTuple223, 194
11Conditionalvalue: 13
condition: 14
12Literal
13Operationoperator: 28
operand: 17
14Operationoperator: 102
operands: 16
15ExprTuple17
16ExprTuple18, 19, 20
17Lambdaparameters: 21
body: 22
18Operationoperator: 121
operands: 23
19Operationoperator: 121
operands: 24
20Operationoperator: 123
operands: 25
21ExprTuple220, 199, 218
22Conditionalvalue: 26
condition: 27
23ExprTuple223, 86
24ExprTuple194, 86
25ExprTuple226, 194
26Operationoperator: 28
operand: 31
27Operationoperator: 102
operands: 30
28Literal
29ExprTuple31
30ExprTuple32, 33, 34, 35, 36, 37
31Lambdaparameter: 227
body: 39
32Operationoperator: 121
operands: 40
33Operationoperator: 121
operands: 41
34Operationoperator: 121
operands: 42
35Operationoperator: 121
operands: 43
36Operationoperator: 45
operands: 44
37Operationoperator: 45
operands: 46
38ExprTuple227
39Conditionalvalue: 47
condition: 48
40ExprTuple220, 49
41ExprTuple199, 50
42ExprTuple218, 51
43ExprTuple218, 52
44ExprTuple53, 222
45Literal
46ExprTuple54, 55
47Operationoperator: 123
operands: 56
48Operationoperator: 102
operands: 57
49Operationoperator: 58
operand: 75
50Operationoperator: 60
operands: 61
51Literal
52Operationoperator: 62
operands: 63
53Operationoperator: 64
operand: 199
54Operationoperator: 66
operands: 67
55Operationoperator: 68
operands: 69
56ExprTuple70, 71
57ExprTuple72, 73
58Literal
59ExprTuple75
60Literal
61ExprTuple74, 75
62Literal
63ExprTuple160, 222
64Literal
65ExprTuple199
66Literal
67ExprTuple220, 199
68Literal
69ExprTuple76, 199
70Operationoperator: 215
operands: 77
71Operationoperator: 78
operand: 85
72Operationoperator: 121
operands: 80
73Operationoperator: 123
operands: 81
74Literal
75Operationoperator: 224
operands: 82
76Operationoperator: 224
operands: 83
77ExprTuple222, 84
78Literal
79ExprTuple85
80ExprTuple227, 86
81ExprTuple87, 227
82ExprTuple226, 223
83ExprTuple88, 89
84Operationoperator: 206
operand: 219
85Lambdaparameter: 221
body: 92
86Literal
87Operationoperator: 215
operands: 93
88Literal
89Operationoperator: 208
operands: 94
90ExprTuple219
91ExprTuple221
92Conditionalvalue: 95
condition: 96
93ExprTuple194, 97
94ExprTuple226, 98, 99, 218
95Operationoperator: 100
operands: 101
96Operationoperator: 102
operands: 103
97Operationoperator: 104
operand: 112
98Literal
99Literal
100Literal
101ExprTuple106, 107, 108, 109
102Literal
103ExprTuple110, 111
104Literal
105ExprTuple112
106ExprTuple113, 114
107ExprTuple115, 116
108ExprTuple117, 118
109ExprTuple119, 120
110Operationoperator: 121
operands: 122
111Operationoperator: 123
operands: 124
112Operationoperator: 125
operands: 126
113ExprRangelambda_map: 127
start_index: 222
end_index: 227
114ExprRangelambda_map: 128
start_index: 222
end_index: 223
115ExprRangelambda_map: 129
start_index: 222
end_index: 227
116ExprRangelambda_map: 129
start_index: 201
end_index: 202
117ExprRangelambda_map: 130
start_index: 222
end_index: 227
118ExprRangelambda_map: 131
start_index: 222
end_index: 223
119ExprRangelambda_map: 132
start_index: 222
end_index: 227
120ExprRangelambda_map: 133
start_index: 222
end_index: 223
121Literal
122ExprTuple221, 134
123Literal
124ExprTuple135, 136
125Literal
126ExprTuple226, 137
127Lambdaparameter: 200
body: 138
128Lambdaparameter: 200
body: 139
129Lambdaparameter: 200
body: 140
130Lambdaparameter: 200
body: 141
131Lambdaparameter: 200
body: 142
132Lambdaparameter: 200
body: 143
133Lambdaparameter: 200
body: 145
134Operationoperator: 189
operands: 146
135Operationoperator: 147
operands: 148
136Operationoperator: 224
operands: 149
137Operationoperator: 215
operands: 150
138Operationoperator: 181
operands: 151
139Operationoperator: 158
operands: 152
140Operationoperator: 158
operands: 153
141Operationoperator: 154
operands: 155
142Operationoperator: 182
operands: 156
143Operationoperator: 158
operands: 157
144ExprTuple200
145Operationoperator: 158
operands: 159
146ExprTuple160, 161
147Literal
148ExprTuple162, 222
149ExprTuple226, 163
150ExprTuple226, 164
151NamedExprsstate: 165
152NamedExprselement: 166
targets: 174
153NamedExprselement: 167
targets: 168
154Literal
155NamedExprsbasis: 169
156NamedExprsoperation: 170
157NamedExprselement: 171
targets: 172
158Literal
159NamedExprselement: 173
targets: 174
160Literal
161Operationoperator: 215
operands: 175
162Operationoperator: 215
operands: 176
163Operationoperator: 206
operand: 194
164Operationoperator: 204
operands: 178
165Operationoperator: 179
operand: 196
166Operationoperator: 181
operands: 188
167Operationoperator: 182
operands: 183
168Operationoperator: 189
operands: 184
169Literal
170Literal
171Operationoperator: 187
operands: 185
172Operationoperator: 189
operands: 186
173Operationoperator: 187
operands: 188
174Operationoperator: 189
operands: 190
175ExprTuple217, 191
176ExprTuple192, 193
177ExprTuple194
178ExprTuple222, 195
179Literal
180ExprTuple196
181Literal
182Literal
183NamedExprsoperation: 197
part: 200
184ExprTuple222, 202
185NamedExprsstate: 198
part: 200
186ExprTuple222, 227
187Literal
188NamedExprsstate: 199
part: 200
189Literal
190ExprTuple201, 202
191Operationoperator: 206
operand: 222
192Operationoperator: 204
operands: 205
193Operationoperator: 206
operand: 218
194Variable
195Operationoperator: 208
operands: 209
196Literal
197Operationoperator: 210
operands: 211
198Operationoperator: 212
operands: 213
199Variable
200Variable
201Operationoperator: 215
operands: 214
202Operationoperator: 215
operands: 216
203ExprTuple222
204Literal
205ExprTuple221, 217
206Literal
207ExprTuple218
208Literal
209ExprTuple226, 219
210Literal
211ExprTuple220, 227
212Literal
213ExprTuple221, 227
214ExprTuple227, 222
215Literal
216ExprTuple227, 223
217Operationoperator: 224
operands: 225
218Variable
219Variable
220Variable
221Variable
222Literal
223Variable
224Literal
225ExprTuple226, 227
226Literal
227Variable