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 And, Equals, Forall, InSet
from proveit.numbers import Add, Ceil, Exp, Interval, IntervalCO, 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 = [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(), And(InSet(s, NaturalPos), InSet(n, NaturalPos), greater_eq(n, two)))
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_{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} \textrm{ if } s \in \mathbb{N}^+ ,  n \in \mathbb{N}^+ ,  n \geq 2\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: 16
operand: 5
2Operationoperator: 90
operands: 4
3ExprTuple5
4ExprTuple6, 7, 8
5Lambdaparameters: 9
body: 10
6Operationoperator: 109
operands: 11
7Operationoperator: 109
operands: 12
8Operationoperator: 111
operands: 13
9ExprTuple208, 187, 206
10Conditionalvalue: 14
condition: 15
11ExprTuple211, 74
12ExprTuple182, 74
13ExprTuple214, 182
14Operationoperator: 16
operand: 19
15Operationoperator: 90
operands: 18
16Literal
17ExprTuple19
18ExprTuple20, 21, 22, 23, 24, 25
19Lambdaparameter: 215
body: 27
20Operationoperator: 109
operands: 28
21Operationoperator: 109
operands: 29
22Operationoperator: 109
operands: 30
23Operationoperator: 109
operands: 31
24Operationoperator: 33
operands: 32
25Operationoperator: 33
operands: 34
26ExprTuple215
27Conditionalvalue: 35
condition: 36
28ExprTuple208, 37
29ExprTuple187, 38
30ExprTuple206, 39
31ExprTuple206, 40
32ExprTuple41, 210
33Literal
34ExprTuple42, 43
35Operationoperator: 111
operands: 44
36Operationoperator: 90
operands: 45
37Operationoperator: 46
operand: 63
38Operationoperator: 48
operands: 49
39Literal
40Operationoperator: 50
operands: 51
41Operationoperator: 52
operand: 187
42Operationoperator: 54
operands: 55
43Operationoperator: 56
operands: 57
44ExprTuple58, 59
45ExprTuple60, 61
46Literal
47ExprTuple63
48Literal
49ExprTuple62, 63
50Literal
51ExprTuple148, 210
52Literal
53ExprTuple187
54Literal
55ExprTuple208, 187
56Literal
57ExprTuple64, 187
58Operationoperator: 203
operands: 65
59Operationoperator: 66
operand: 73
60Operationoperator: 109
operands: 68
61Operationoperator: 111
operands: 69
62Literal
63Operationoperator: 212
operands: 70
64Operationoperator: 212
operands: 71
65ExprTuple210, 72
66Literal
67ExprTuple73
68ExprTuple215, 74
69ExprTuple75, 215
70ExprTuple214, 211
71ExprTuple76, 77
72Operationoperator: 194
operand: 207
73Lambdaparameter: 209
body: 80
74Literal
75Operationoperator: 203
operands: 81
76Literal
77Operationoperator: 196
operands: 82
78ExprTuple207
79ExprTuple209
80Conditionalvalue: 83
condition: 84
81ExprTuple182, 85
82ExprTuple214, 86, 87, 206
83Operationoperator: 88
operands: 89
84Operationoperator: 90
operands: 91
85Operationoperator: 92
operand: 100
86Literal
87Literal
88Literal
89ExprTuple94, 95, 96, 97
90Literal
91ExprTuple98, 99
92Literal
93ExprTuple100
94ExprTuple101, 102
95ExprTuple103, 104
96ExprTuple105, 106
97ExprTuple107, 108
98Operationoperator: 109
operands: 110
99Operationoperator: 111
operands: 112
100Operationoperator: 113
operands: 114
101ExprRangelambda_map: 115
start_index: 210
end_index: 215
102ExprRangelambda_map: 116
start_index: 210
end_index: 211
103ExprRangelambda_map: 117
start_index: 210
end_index: 215
104ExprRangelambda_map: 117
start_index: 189
end_index: 190
105ExprRangelambda_map: 118
start_index: 210
end_index: 215
106ExprRangelambda_map: 119
start_index: 210
end_index: 211
107ExprRangelambda_map: 120
start_index: 210
end_index: 215
108ExprRangelambda_map: 121
start_index: 210
end_index: 211
109Literal
110ExprTuple209, 122
111Literal
112ExprTuple123, 124
113Literal
114ExprTuple214, 125
115Lambdaparameter: 188
body: 126
116Lambdaparameter: 188
body: 127
117Lambdaparameter: 188
body: 128
118Lambdaparameter: 188
body: 129
119Lambdaparameter: 188
body: 130
120Lambdaparameter: 188
body: 131
121Lambdaparameter: 188
body: 133
122Operationoperator: 177
operands: 134
123Operationoperator: 135
operands: 136
124Operationoperator: 212
operands: 137
125Operationoperator: 203
operands: 138
126Operationoperator: 169
operands: 139
127Operationoperator: 146
operands: 140
128Operationoperator: 146
operands: 141
129Operationoperator: 142
operands: 143
130Operationoperator: 170
operands: 144
131Operationoperator: 146
operands: 145
132ExprTuple188
133Operationoperator: 146
operands: 147
134ExprTuple148, 149
135Literal
136ExprTuple150, 210
137ExprTuple214, 151
138ExprTuple214, 152
139NamedExprsstate: 153
140NamedExprselement: 154
targets: 162
141NamedExprselement: 155
targets: 156
142Literal
143NamedExprsbasis: 157
144NamedExprsoperation: 158
145NamedExprselement: 159
targets: 160
146Literal
147NamedExprselement: 161
targets: 162
148Literal
149Operationoperator: 203
operands: 163
150Operationoperator: 203
operands: 164
151Operationoperator: 194
operand: 182
152Operationoperator: 192
operands: 166
153Operationoperator: 167
operand: 184
154Operationoperator: 169
operands: 176
155Operationoperator: 170
operands: 171
156Operationoperator: 177
operands: 172
157Literal
158Literal
159Operationoperator: 175
operands: 173
160Operationoperator: 177
operands: 174
161Operationoperator: 175
operands: 176
162Operationoperator: 177
operands: 178
163ExprTuple205, 179
164ExprTuple180, 181
165ExprTuple182
166ExprTuple210, 183
167Literal
168ExprTuple184
169Literal
170Literal
171NamedExprsoperation: 185
part: 188
172ExprTuple210, 190
173NamedExprsstate: 186
part: 188
174ExprTuple210, 215
175Literal
176NamedExprsstate: 187
part: 188
177Literal
178ExprTuple189, 190
179Operationoperator: 194
operand: 210
180Operationoperator: 192
operands: 193
181Operationoperator: 194
operand: 206
182Variable
183Operationoperator: 196
operands: 197
184Literal
185Operationoperator: 198
operands: 199
186Operationoperator: 200
operands: 201
187Variable
188Variable
189Operationoperator: 203
operands: 202
190Operationoperator: 203
operands: 204
191ExprTuple210
192Literal
193ExprTuple209, 205
194Literal
195ExprTuple206
196Literal
197ExprTuple214, 207
198Literal
199ExprTuple208, 215
200Literal
201ExprTuple209, 215
202ExprTuple215, 210
203Literal
204ExprTuple215, 211
205Operationoperator: 212
operands: 213
206Variable
207Variable
208Variable
209Variable
210Literal
211Variable
212Literal
213ExprTuple214, 215
214Literal
215Variable