logo

Expression of type Lambda

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, Lambda, 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 = Lambda([s, n], 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(s, n\right) \mapsto \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()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple213, 184
2Conditionalvalue: 3
condition: 4
3Operationoperator: 18
operand: 7
4Operationoperator: 92
operands: 6
5ExprTuple7
6ExprTuple8, 9, 10
7Lambdaparameters: 11
body: 12
8Operationoperator: 111
operands: 13
9Operationoperator: 111
operands: 14
10Operationoperator: 113
operands: 15
11ExprTuple210, 189, 208
12Conditionalvalue: 16
condition: 17
13ExprTuple213, 76
14ExprTuple184, 76
15ExprTuple216, 184
16Operationoperator: 18
operand: 21
17Operationoperator: 92
operands: 20
18Literal
19ExprTuple21
20ExprTuple22, 23, 24, 25, 26, 27
21Lambdaparameter: 217
body: 29
22Operationoperator: 111
operands: 30
23Operationoperator: 111
operands: 31
24Operationoperator: 111
operands: 32
25Operationoperator: 111
operands: 33
26Operationoperator: 35
operands: 34
27Operationoperator: 35
operands: 36
28ExprTuple217
29Conditionalvalue: 37
condition: 38
30ExprTuple210, 39
31ExprTuple189, 40
32ExprTuple208, 41
33ExprTuple208, 42
34ExprTuple43, 212
35Literal
36ExprTuple44, 45
37Operationoperator: 113
operands: 46
38Operationoperator: 92
operands: 47
39Operationoperator: 48
operand: 65
40Operationoperator: 50
operands: 51
41Literal
42Operationoperator: 52
operands: 53
43Operationoperator: 54
operand: 189
44Operationoperator: 56
operands: 57
45Operationoperator: 58
operands: 59
46ExprTuple60, 61
47ExprTuple62, 63
48Literal
49ExprTuple65
50Literal
51ExprTuple64, 65
52Literal
53ExprTuple150, 212
54Literal
55ExprTuple189
56Literal
57ExprTuple210, 189
58Literal
59ExprTuple66, 189
60Operationoperator: 205
operands: 67
61Operationoperator: 68
operand: 75
62Operationoperator: 111
operands: 70
63Operationoperator: 113
operands: 71
64Literal
65Operationoperator: 214
operands: 72
66Operationoperator: 214
operands: 73
67ExprTuple212, 74
68Literal
69ExprTuple75
70ExprTuple217, 76
71ExprTuple77, 217
72ExprTuple216, 213
73ExprTuple78, 79
74Operationoperator: 196
operand: 209
75Lambdaparameter: 211
body: 82
76Literal
77Operationoperator: 205
operands: 83
78Literal
79Operationoperator: 198
operands: 84
80ExprTuple209
81ExprTuple211
82Conditionalvalue: 85
condition: 86
83ExprTuple184, 87
84ExprTuple216, 88, 89, 208
85Operationoperator: 90
operands: 91
86Operationoperator: 92
operands: 93
87Operationoperator: 94
operand: 102
88Literal
89Literal
90Literal
91ExprTuple96, 97, 98, 99
92Literal
93ExprTuple100, 101
94Literal
95ExprTuple102
96ExprTuple103, 104
97ExprTuple105, 106
98ExprTuple107, 108
99ExprTuple109, 110
100Operationoperator: 111
operands: 112
101Operationoperator: 113
operands: 114
102Operationoperator: 115
operands: 116
103ExprRangelambda_map: 117
start_index: 212
end_index: 217
104ExprRangelambda_map: 118
start_index: 212
end_index: 213
105ExprRangelambda_map: 119
start_index: 212
end_index: 217
106ExprRangelambda_map: 119
start_index: 191
end_index: 192
107ExprRangelambda_map: 120
start_index: 212
end_index: 217
108ExprRangelambda_map: 121
start_index: 212
end_index: 213
109ExprRangelambda_map: 122
start_index: 212
end_index: 217
110ExprRangelambda_map: 123
start_index: 212
end_index: 213
111Literal
112ExprTuple211, 124
113Literal
114ExprTuple125, 126
115Literal
116ExprTuple216, 127
117Lambdaparameter: 190
body: 128
118Lambdaparameter: 190
body: 129
119Lambdaparameter: 190
body: 130
120Lambdaparameter: 190
body: 131
121Lambdaparameter: 190
body: 132
122Lambdaparameter: 190
body: 133
123Lambdaparameter: 190
body: 135
124Operationoperator: 179
operands: 136
125Operationoperator: 137
operands: 138
126Operationoperator: 214
operands: 139
127Operationoperator: 205
operands: 140
128Operationoperator: 171
operands: 141
129Operationoperator: 148
operands: 142
130Operationoperator: 148
operands: 143
131Operationoperator: 144
operands: 145
132Operationoperator: 172
operands: 146
133Operationoperator: 148
operands: 147
134ExprTuple190
135Operationoperator: 148
operands: 149
136ExprTuple150, 151
137Literal
138ExprTuple152, 212
139ExprTuple216, 153
140ExprTuple216, 154
141NamedExprsstate: 155
142NamedExprselement: 156
targets: 164
143NamedExprselement: 157
targets: 158
144Literal
145NamedExprsbasis: 159
146NamedExprsoperation: 160
147NamedExprselement: 161
targets: 162
148Literal
149NamedExprselement: 163
targets: 164
150Literal
151Operationoperator: 205
operands: 165
152Operationoperator: 205
operands: 166
153Operationoperator: 196
operand: 184
154Operationoperator: 194
operands: 168
155Operationoperator: 169
operand: 186
156Operationoperator: 171
operands: 178
157Operationoperator: 172
operands: 173
158Operationoperator: 179
operands: 174
159Literal
160Literal
161Operationoperator: 177
operands: 175
162Operationoperator: 179
operands: 176
163Operationoperator: 177
operands: 178
164Operationoperator: 179
operands: 180
165ExprTuple207, 181
166ExprTuple182, 183
167ExprTuple184
168ExprTuple212, 185
169Literal
170ExprTuple186
171Literal
172Literal
173NamedExprsoperation: 187
part: 190
174ExprTuple212, 192
175NamedExprsstate: 188
part: 190
176ExprTuple212, 217
177Literal
178NamedExprsstate: 189
part: 190
179Literal
180ExprTuple191, 192
181Operationoperator: 196
operand: 212
182Operationoperator: 194
operands: 195
183Operationoperator: 196
operand: 208
184Variable
185Operationoperator: 198
operands: 199
186Literal
187Operationoperator: 200
operands: 201
188Operationoperator: 202
operands: 203
189Variable
190Variable
191Operationoperator: 205
operands: 204
192Operationoperator: 205
operands: 206
193ExprTuple212
194Literal
195ExprTuple211, 207
196Literal
197ExprTuple208
198Literal
199ExprTuple216, 209
200Literal
201ExprTuple210, 217
202Literal
203ExprTuple211, 217
204ExprTuple217, 212
205Literal
206ExprTuple217, 213
207Operationoperator: 214
operands: 215
208Variable
209Variable
210Variable
211Variable
212Literal
213Variable
214Literal
215ExprTuple216, 217
216Literal
217Variable