logo

Expression of type ExprTuple

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 Conditional, ExprRange, ExprTuple, Lambda, 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 = ExprTuple(Lambda(eps, Conditional(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(), InSet(eps, IntervalOC(zero, one)))))
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())
\left(\epsilon \mapsto \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} \textrm{ if } \epsilon \in \left(0,1\right]\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameter: 218
body: 2
2Conditionalvalue: 3
condition: 4
3Operationoperator: 27
operand: 7
4Operationoperator: 120
operands: 6
5ExprTuple7
6ExprTuple218, 8
7Lambdaparameters: 9
body: 10
8Operationoperator: 11
operands: 62
9ExprTuple222, 193
10Conditionalvalue: 12
condition: 13
11Literal
12Operationoperator: 27
operand: 16
13Operationoperator: 101
operands: 15
14ExprTuple16
15ExprTuple17, 18, 19
16Lambdaparameters: 20
body: 21
17Operationoperator: 120
operands: 22
18Operationoperator: 120
operands: 23
19Operationoperator: 122
operands: 24
20ExprTuple219, 198, 217
21Conditionalvalue: 25
condition: 26
22ExprTuple222, 85
23ExprTuple193, 85
24ExprTuple225, 193
25Operationoperator: 27
operand: 30
26Operationoperator: 101
operands: 29
27Literal
28ExprTuple30
29ExprTuple31, 32, 33, 34, 35, 36
30Lambdaparameter: 226
body: 38
31Operationoperator: 120
operands: 39
32Operationoperator: 120
operands: 40
33Operationoperator: 120
operands: 41
34Operationoperator: 120
operands: 42
35Operationoperator: 44
operands: 43
36Operationoperator: 44
operands: 45
37ExprTuple226
38Conditionalvalue: 46
condition: 47
39ExprTuple219, 48
40ExprTuple198, 49
41ExprTuple217, 50
42ExprTuple217, 51
43ExprTuple52, 221
44Literal
45ExprTuple53, 54
46Operationoperator: 122
operands: 55
47Operationoperator: 101
operands: 56
48Operationoperator: 57
operand: 74
49Operationoperator: 59
operands: 60
50Literal
51Operationoperator: 61
operands: 62
52Operationoperator: 63
operand: 198
53Operationoperator: 65
operands: 66
54Operationoperator: 67
operands: 68
55ExprTuple69, 70
56ExprTuple71, 72
57Literal
58ExprTuple74
59Literal
60ExprTuple73, 74
61Literal
62ExprTuple159, 221
63Literal
64ExprTuple198
65Literal
66ExprTuple219, 198
67Literal
68ExprTuple75, 198
69Operationoperator: 214
operands: 76
70Operationoperator: 77
operand: 84
71Operationoperator: 120
operands: 79
72Operationoperator: 122
operands: 80
73Literal
74Operationoperator: 223
operands: 81
75Operationoperator: 223
operands: 82
76ExprTuple221, 83
77Literal
78ExprTuple84
79ExprTuple226, 85
80ExprTuple86, 226
81ExprTuple225, 222
82ExprTuple87, 88
83Operationoperator: 205
operand: 218
84Lambdaparameter: 220
body: 91
85Literal
86Operationoperator: 214
operands: 92
87Literal
88Operationoperator: 207
operands: 93
89ExprTuple218
90ExprTuple220
91Conditionalvalue: 94
condition: 95
92ExprTuple193, 96
93ExprTuple225, 97, 98, 217
94Operationoperator: 99
operands: 100
95Operationoperator: 101
operands: 102
96Operationoperator: 103
operand: 111
97Literal
98Literal
99Literal
100ExprTuple105, 106, 107, 108
101Literal
102ExprTuple109, 110
103Literal
104ExprTuple111
105ExprTuple112, 113
106ExprTuple114, 115
107ExprTuple116, 117
108ExprTuple118, 119
109Operationoperator: 120
operands: 121
110Operationoperator: 122
operands: 123
111Operationoperator: 124
operands: 125
112ExprRangelambda_map: 126
start_index: 221
end_index: 226
113ExprRangelambda_map: 127
start_index: 221
end_index: 222
114ExprRangelambda_map: 128
start_index: 221
end_index: 226
115ExprRangelambda_map: 128
start_index: 200
end_index: 201
116ExprRangelambda_map: 129
start_index: 221
end_index: 226
117ExprRangelambda_map: 130
start_index: 221
end_index: 222
118ExprRangelambda_map: 131
start_index: 221
end_index: 226
119ExprRangelambda_map: 132
start_index: 221
end_index: 222
120Literal
121ExprTuple220, 133
122Literal
123ExprTuple134, 135
124Literal
125ExprTuple225, 136
126Lambdaparameter: 199
body: 137
127Lambdaparameter: 199
body: 138
128Lambdaparameter: 199
body: 139
129Lambdaparameter: 199
body: 140
130Lambdaparameter: 199
body: 141
131Lambdaparameter: 199
body: 142
132Lambdaparameter: 199
body: 144
133Operationoperator: 188
operands: 145
134Operationoperator: 146
operands: 147
135Operationoperator: 223
operands: 148
136Operationoperator: 214
operands: 149
137Operationoperator: 180
operands: 150
138Operationoperator: 157
operands: 151
139Operationoperator: 157
operands: 152
140Operationoperator: 153
operands: 154
141Operationoperator: 181
operands: 155
142Operationoperator: 157
operands: 156
143ExprTuple199
144Operationoperator: 157
operands: 158
145ExprTuple159, 160
146Literal
147ExprTuple161, 221
148ExprTuple225, 162
149ExprTuple225, 163
150NamedExprsstate: 164
151NamedExprselement: 165
targets: 173
152NamedExprselement: 166
targets: 167
153Literal
154NamedExprsbasis: 168
155NamedExprsoperation: 169
156NamedExprselement: 170
targets: 171
157Literal
158NamedExprselement: 172
targets: 173
159Literal
160Operationoperator: 214
operands: 174
161Operationoperator: 214
operands: 175
162Operationoperator: 205
operand: 193
163Operationoperator: 203
operands: 177
164Operationoperator: 178
operand: 195
165Operationoperator: 180
operands: 187
166Operationoperator: 181
operands: 182
167Operationoperator: 188
operands: 183
168Literal
169Literal
170Operationoperator: 186
operands: 184
171Operationoperator: 188
operands: 185
172Operationoperator: 186
operands: 187
173Operationoperator: 188
operands: 189
174ExprTuple216, 190
175ExprTuple191, 192
176ExprTuple193
177ExprTuple221, 194
178Literal
179ExprTuple195
180Literal
181Literal
182NamedExprsoperation: 196
part: 199
183ExprTuple221, 201
184NamedExprsstate: 197
part: 199
185ExprTuple221, 226
186Literal
187NamedExprsstate: 198
part: 199
188Literal
189ExprTuple200, 201
190Operationoperator: 205
operand: 221
191Operationoperator: 203
operands: 204
192Operationoperator: 205
operand: 217
193Variable
194Operationoperator: 207
operands: 208
195Literal
196Operationoperator: 209
operands: 210
197Operationoperator: 211
operands: 212
198Variable
199Variable
200Operationoperator: 214
operands: 213
201Operationoperator: 214
operands: 215
202ExprTuple221
203Literal
204ExprTuple220, 216
205Literal
206ExprTuple217
207Literal
208ExprTuple225, 218
209Literal
210ExprTuple219, 226
211Literal
212ExprTuple220, 226
213ExprTuple226, 221
214Literal
215ExprTuple226, 222
216Operationoperator: 223
operands: 224
217Variable
218Variable
219Variable
220Variable
221Literal
222Variable
223Literal
224ExprTuple225, 226
225Literal
226Variable