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([U, var_ket_u, phase], Conditional(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(), And(InSet(U, Unitary(two_pow_s)), InSet(var_ket_u, s_ket_domain), InSet(phase, Real), 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)))))
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(U, \lvert u \rangle, \varphi\right) \mapsto \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} \textrm{ if } 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)\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
1ExprTuple197, 176, 195
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operand: 8
4Operationoperator: 79
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10, 11, 12, 13, 14
8Lambdaparameter: 204
body: 16
9Operationoperator: 98
operands: 17
10Operationoperator: 98
operands: 18
11Operationoperator: 98
operands: 19
12Operationoperator: 98
operands: 20
13Operationoperator: 22
operands: 21
14Operationoperator: 22
operands: 23
15ExprTuple204
16Conditionalvalue: 24
condition: 25
17ExprTuple197, 26
18ExprTuple176, 27
19ExprTuple195, 28
20ExprTuple195, 29
21ExprTuple30, 199
22Literal
23ExprTuple31, 32
24Operationoperator: 100
operands: 33
25Operationoperator: 79
operands: 34
26Operationoperator: 35
operand: 52
27Operationoperator: 37
operands: 38
28Literal
29Operationoperator: 39
operands: 40
30Operationoperator: 41
operand: 176
31Operationoperator: 43
operands: 44
32Operationoperator: 45
operands: 46
33ExprTuple47, 48
34ExprTuple49, 50
35Literal
36ExprTuple52
37Literal
38ExprTuple51, 52
39Literal
40ExprTuple137, 199
41Literal
42ExprTuple176
43Literal
44ExprTuple197, 176
45Literal
46ExprTuple53, 176
47Operationoperator: 192
operands: 54
48Operationoperator: 55
operand: 62
49Operationoperator: 98
operands: 57
50Operationoperator: 100
operands: 58
51Literal
52Operationoperator: 201
operands: 59
53Operationoperator: 201
operands: 60
54ExprTuple199, 61
55Literal
56ExprTuple62
57ExprTuple204, 63
58ExprTuple64, 204
59ExprTuple203, 200
60ExprTuple65, 66
61Operationoperator: 183
operand: 196
62Lambdaparameter: 198
body: 69
63Literal
64Operationoperator: 192
operands: 70
65Literal
66Operationoperator: 185
operands: 71
67ExprTuple196
68ExprTuple198
69Conditionalvalue: 72
condition: 73
70ExprTuple171, 74
71ExprTuple203, 75, 76, 195
72Operationoperator: 77
operands: 78
73Operationoperator: 79
operands: 80
74Operationoperator: 81
operand: 89
75Literal
76Literal
77Literal
78ExprTuple83, 84, 85, 86
79Literal
80ExprTuple87, 88
81Literal
82ExprTuple89
83ExprTuple90, 91
84ExprTuple92, 93
85ExprTuple94, 95
86ExprTuple96, 97
87Operationoperator: 98
operands: 99
88Operationoperator: 100
operands: 101
89Operationoperator: 102
operands: 103
90ExprRangelambda_map: 104
start_index: 199
end_index: 204
91ExprRangelambda_map: 105
start_index: 199
end_index: 200
92ExprRangelambda_map: 106
start_index: 199
end_index: 204
93ExprRangelambda_map: 106
start_index: 178
end_index: 179
94ExprRangelambda_map: 107
start_index: 199
end_index: 204
95ExprRangelambda_map: 108
start_index: 199
end_index: 200
96ExprRangelambda_map: 109
start_index: 199
end_index: 204
97ExprRangelambda_map: 110
start_index: 199
end_index: 200
98Literal
99ExprTuple198, 111
100Literal
101ExprTuple112, 113
102Literal
103ExprTuple203, 114
104Lambdaparameter: 177
body: 115
105Lambdaparameter: 177
body: 116
106Lambdaparameter: 177
body: 117
107Lambdaparameter: 177
body: 118
108Lambdaparameter: 177
body: 119
109Lambdaparameter: 177
body: 120
110Lambdaparameter: 177
body: 122
111Operationoperator: 166
operands: 123
112Operationoperator: 124
operands: 125
113Operationoperator: 201
operands: 126
114Operationoperator: 192
operands: 127
115Operationoperator: 158
operands: 128
116Operationoperator: 135
operands: 129
117Operationoperator: 135
operands: 130
118Operationoperator: 131
operands: 132
119Operationoperator: 159
operands: 133
120Operationoperator: 135
operands: 134
121ExprTuple177
122Operationoperator: 135
operands: 136
123ExprTuple137, 138
124Literal
125ExprTuple139, 199
126ExprTuple203, 140
127ExprTuple203, 141
128NamedExprsstate: 142
129NamedExprselement: 143
targets: 151
130NamedExprselement: 144
targets: 145
131Literal
132NamedExprsbasis: 146
133NamedExprsoperation: 147
134NamedExprselement: 148
targets: 149
135Literal
136NamedExprselement: 150
targets: 151
137Literal
138Operationoperator: 192
operands: 152
139Operationoperator: 192
operands: 153
140Operationoperator: 183
operand: 171
141Operationoperator: 181
operands: 155
142Operationoperator: 156
operand: 173
143Operationoperator: 158
operands: 165
144Operationoperator: 159
operands: 160
145Operationoperator: 166
operands: 161
146Literal
147Literal
148Operationoperator: 164
operands: 162
149Operationoperator: 166
operands: 163
150Operationoperator: 164
operands: 165
151Operationoperator: 166
operands: 167
152ExprTuple194, 168
153ExprTuple169, 170
154ExprTuple171
155ExprTuple199, 172
156Literal
157ExprTuple173
158Literal
159Literal
160NamedExprsoperation: 174
part: 177
161ExprTuple199, 179
162NamedExprsstate: 175
part: 177
163ExprTuple199, 204
164Literal
165NamedExprsstate: 176
part: 177
166Literal
167ExprTuple178, 179
168Operationoperator: 183
operand: 199
169Operationoperator: 181
operands: 182
170Operationoperator: 183
operand: 195
171Variable
172Operationoperator: 185
operands: 186
173Literal
174Operationoperator: 187
operands: 188
175Operationoperator: 189
operands: 190
176Variable
177Variable
178Operationoperator: 192
operands: 191
179Operationoperator: 192
operands: 193
180ExprTuple199
181Literal
182ExprTuple198, 194
183Literal
184ExprTuple195
185Literal
186ExprTuple203, 196
187Literal
188ExprTuple197, 204
189Literal
190ExprTuple198, 204
191ExprTuple204, 199
192Literal
193ExprTuple204, 200
194Operationoperator: 201
operands: 202
195Variable
196Variable
197Variable
198Variable
199Literal
200Variable
201Literal
202ExprTuple203, 204
203Literal
204Variable