logo

Expression of type Conditional

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, 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 = 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\{\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..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 25
operand: 5
2Operationoperator: 118
operands: 4
3ExprTuple5
4ExprTuple216, 6
5Lambdaparameters: 7
body: 8
6Operationoperator: 9
operands: 60
7ExprTuple220, 191
8Conditionalvalue: 10
condition: 11
9Literal
10Operationoperator: 25
operand: 14
11Operationoperator: 99
operands: 13
12ExprTuple14
13ExprTuple15, 16, 17
14Lambdaparameters: 18
body: 19
15Operationoperator: 118
operands: 20
16Operationoperator: 118
operands: 21
17Operationoperator: 120
operands: 22
18ExprTuple217, 196, 215
19Conditionalvalue: 23
condition: 24
20ExprTuple220, 83
21ExprTuple191, 83
22ExprTuple223, 191
23Operationoperator: 25
operand: 28
24Operationoperator: 99
operands: 27
25Literal
26ExprTuple28
27ExprTuple29, 30, 31, 32, 33, 34
28Lambdaparameter: 224
body: 36
29Operationoperator: 118
operands: 37
30Operationoperator: 118
operands: 38
31Operationoperator: 118
operands: 39
32Operationoperator: 118
operands: 40
33Operationoperator: 42
operands: 41
34Operationoperator: 42
operands: 43
35ExprTuple224
36Conditionalvalue: 44
condition: 45
37ExprTuple217, 46
38ExprTuple196, 47
39ExprTuple215, 48
40ExprTuple215, 49
41ExprTuple50, 219
42Literal
43ExprTuple51, 52
44Operationoperator: 120
operands: 53
45Operationoperator: 99
operands: 54
46Operationoperator: 55
operand: 72
47Operationoperator: 57
operands: 58
48Literal
49Operationoperator: 59
operands: 60
50Operationoperator: 61
operand: 196
51Operationoperator: 63
operands: 64
52Operationoperator: 65
operands: 66
53ExprTuple67, 68
54ExprTuple69, 70
55Literal
56ExprTuple72
57Literal
58ExprTuple71, 72
59Literal
60ExprTuple157, 219
61Literal
62ExprTuple196
63Literal
64ExprTuple217, 196
65Literal
66ExprTuple73, 196
67Operationoperator: 212
operands: 74
68Operationoperator: 75
operand: 82
69Operationoperator: 118
operands: 77
70Operationoperator: 120
operands: 78
71Literal
72Operationoperator: 221
operands: 79
73Operationoperator: 221
operands: 80
74ExprTuple219, 81
75Literal
76ExprTuple82
77ExprTuple224, 83
78ExprTuple84, 224
79ExprTuple223, 220
80ExprTuple85, 86
81Operationoperator: 203
operand: 216
82Lambdaparameter: 218
body: 89
83Literal
84Operationoperator: 212
operands: 90
85Literal
86Operationoperator: 205
operands: 91
87ExprTuple216
88ExprTuple218
89Conditionalvalue: 92
condition: 93
90ExprTuple191, 94
91ExprTuple223, 95, 96, 215
92Operationoperator: 97
operands: 98
93Operationoperator: 99
operands: 100
94Operationoperator: 101
operand: 109
95Literal
96Literal
97Literal
98ExprTuple103, 104, 105, 106
99Literal
100ExprTuple107, 108
101Literal
102ExprTuple109
103ExprTuple110, 111
104ExprTuple112, 113
105ExprTuple114, 115
106ExprTuple116, 117
107Operationoperator: 118
operands: 119
108Operationoperator: 120
operands: 121
109Operationoperator: 122
operands: 123
110ExprRangelambda_map: 124
start_index: 219
end_index: 224
111ExprRangelambda_map: 125
start_index: 219
end_index: 220
112ExprRangelambda_map: 126
start_index: 219
end_index: 224
113ExprRangelambda_map: 126
start_index: 198
end_index: 199
114ExprRangelambda_map: 127
start_index: 219
end_index: 224
115ExprRangelambda_map: 128
start_index: 219
end_index: 220
116ExprRangelambda_map: 129
start_index: 219
end_index: 224
117ExprRangelambda_map: 130
start_index: 219
end_index: 220
118Literal
119ExprTuple218, 131
120Literal
121ExprTuple132, 133
122Literal
123ExprTuple223, 134
124Lambdaparameter: 197
body: 135
125Lambdaparameter: 197
body: 136
126Lambdaparameter: 197
body: 137
127Lambdaparameter: 197
body: 138
128Lambdaparameter: 197
body: 139
129Lambdaparameter: 197
body: 140
130Lambdaparameter: 197
body: 142
131Operationoperator: 186
operands: 143
132Operationoperator: 144
operands: 145
133Operationoperator: 221
operands: 146
134Operationoperator: 212
operands: 147
135Operationoperator: 178
operands: 148
136Operationoperator: 155
operands: 149
137Operationoperator: 155
operands: 150
138Operationoperator: 151
operands: 152
139Operationoperator: 179
operands: 153
140Operationoperator: 155
operands: 154
141ExprTuple197
142Operationoperator: 155
operands: 156
143ExprTuple157, 158
144Literal
145ExprTuple159, 219
146ExprTuple223, 160
147ExprTuple223, 161
148NamedExprsstate: 162
149NamedExprselement: 163
targets: 171
150NamedExprselement: 164
targets: 165
151Literal
152NamedExprsbasis: 166
153NamedExprsoperation: 167
154NamedExprselement: 168
targets: 169
155Literal
156NamedExprselement: 170
targets: 171
157Literal
158Operationoperator: 212
operands: 172
159Operationoperator: 212
operands: 173
160Operationoperator: 203
operand: 191
161Operationoperator: 201
operands: 175
162Operationoperator: 176
operand: 193
163Operationoperator: 178
operands: 185
164Operationoperator: 179
operands: 180
165Operationoperator: 186
operands: 181
166Literal
167Literal
168Operationoperator: 184
operands: 182
169Operationoperator: 186
operands: 183
170Operationoperator: 184
operands: 185
171Operationoperator: 186
operands: 187
172ExprTuple214, 188
173ExprTuple189, 190
174ExprTuple191
175ExprTuple219, 192
176Literal
177ExprTuple193
178Literal
179Literal
180NamedExprsoperation: 194
part: 197
181ExprTuple219, 199
182NamedExprsstate: 195
part: 197
183ExprTuple219, 224
184Literal
185NamedExprsstate: 196
part: 197
186Literal
187ExprTuple198, 199
188Operationoperator: 203
operand: 219
189Operationoperator: 201
operands: 202
190Operationoperator: 203
operand: 215
191Variable
192Operationoperator: 205
operands: 206
193Literal
194Operationoperator: 207
operands: 208
195Operationoperator: 209
operands: 210
196Variable
197Variable
198Operationoperator: 212
operands: 211
199Operationoperator: 212
operands: 213
200ExprTuple219
201Literal
202ExprTuple218, 214
203Literal
204ExprTuple215
205Literal
206ExprTuple223, 216
207Literal
208ExprTuple217, 224
209Literal
210ExprTuple218, 224
211ExprTuple224, 219
212Literal
213ExprTuple224, 220
214Operationoperator: 221
operands: 222
215Variable
216Variable
217Variable
218Variable
219Literal
220Variable
221Literal
222ExprTuple223, 224
223Literal
224Variable