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 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 = ExprTuple(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(\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..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Lambdaparameters: 2
body: 3
2ExprTuple198, 177, 196
3Conditionalvalue: 4
condition: 5
4Operationoperator: 6
operand: 9
5Operationoperator: 80
operands: 8
6Literal
7ExprTuple9
8ExprTuple10, 11, 12, 13, 14, 15
9Lambdaparameter: 205
body: 17
10Operationoperator: 99
operands: 18
11Operationoperator: 99
operands: 19
12Operationoperator: 99
operands: 20
13Operationoperator: 99
operands: 21
14Operationoperator: 23
operands: 22
15Operationoperator: 23
operands: 24
16ExprTuple205
17Conditionalvalue: 25
condition: 26
18ExprTuple198, 27
19ExprTuple177, 28
20ExprTuple196, 29
21ExprTuple196, 30
22ExprTuple31, 200
23Literal
24ExprTuple32, 33
25Operationoperator: 101
operands: 34
26Operationoperator: 80
operands: 35
27Operationoperator: 36
operand: 53
28Operationoperator: 38
operands: 39
29Literal
30Operationoperator: 40
operands: 41
31Operationoperator: 42
operand: 177
32Operationoperator: 44
operands: 45
33Operationoperator: 46
operands: 47
34ExprTuple48, 49
35ExprTuple50, 51
36Literal
37ExprTuple53
38Literal
39ExprTuple52, 53
40Literal
41ExprTuple138, 200
42Literal
43ExprTuple177
44Literal
45ExprTuple198, 177
46Literal
47ExprTuple54, 177
48Operationoperator: 193
operands: 55
49Operationoperator: 56
operand: 63
50Operationoperator: 99
operands: 58
51Operationoperator: 101
operands: 59
52Literal
53Operationoperator: 202
operands: 60
54Operationoperator: 202
operands: 61
55ExprTuple200, 62
56Literal
57ExprTuple63
58ExprTuple205, 64
59ExprTuple65, 205
60ExprTuple204, 201
61ExprTuple66, 67
62Operationoperator: 184
operand: 197
63Lambdaparameter: 199
body: 70
64Literal
65Operationoperator: 193
operands: 71
66Literal
67Operationoperator: 186
operands: 72
68ExprTuple197
69ExprTuple199
70Conditionalvalue: 73
condition: 74
71ExprTuple172, 75
72ExprTuple204, 76, 77, 196
73Operationoperator: 78
operands: 79
74Operationoperator: 80
operands: 81
75Operationoperator: 82
operand: 90
76Literal
77Literal
78Literal
79ExprTuple84, 85, 86, 87
80Literal
81ExprTuple88, 89
82Literal
83ExprTuple90
84ExprTuple91, 92
85ExprTuple93, 94
86ExprTuple95, 96
87ExprTuple97, 98
88Operationoperator: 99
operands: 100
89Operationoperator: 101
operands: 102
90Operationoperator: 103
operands: 104
91ExprRangelambda_map: 105
start_index: 200
end_index: 205
92ExprRangelambda_map: 106
start_index: 200
end_index: 201
93ExprRangelambda_map: 107
start_index: 200
end_index: 205
94ExprRangelambda_map: 107
start_index: 179
end_index: 180
95ExprRangelambda_map: 108
start_index: 200
end_index: 205
96ExprRangelambda_map: 109
start_index: 200
end_index: 201
97ExprRangelambda_map: 110
start_index: 200
end_index: 205
98ExprRangelambda_map: 111
start_index: 200
end_index: 201
99Literal
100ExprTuple199, 112
101Literal
102ExprTuple113, 114
103Literal
104ExprTuple204, 115
105Lambdaparameter: 178
body: 116
106Lambdaparameter: 178
body: 117
107Lambdaparameter: 178
body: 118
108Lambdaparameter: 178
body: 119
109Lambdaparameter: 178
body: 120
110Lambdaparameter: 178
body: 121
111Lambdaparameter: 178
body: 123
112Operationoperator: 167
operands: 124
113Operationoperator: 125
operands: 126
114Operationoperator: 202
operands: 127
115Operationoperator: 193
operands: 128
116Operationoperator: 159
operands: 129
117Operationoperator: 136
operands: 130
118Operationoperator: 136
operands: 131
119Operationoperator: 132
operands: 133
120Operationoperator: 160
operands: 134
121Operationoperator: 136
operands: 135
122ExprTuple178
123Operationoperator: 136
operands: 137
124ExprTuple138, 139
125Literal
126ExprTuple140, 200
127ExprTuple204, 141
128ExprTuple204, 142
129NamedExprsstate: 143
130NamedExprselement: 144
targets: 152
131NamedExprselement: 145
targets: 146
132Literal
133NamedExprsbasis: 147
134NamedExprsoperation: 148
135NamedExprselement: 149
targets: 150
136Literal
137NamedExprselement: 151
targets: 152
138Literal
139Operationoperator: 193
operands: 153
140Operationoperator: 193
operands: 154
141Operationoperator: 184
operand: 172
142Operationoperator: 182
operands: 156
143Operationoperator: 157
operand: 174
144Operationoperator: 159
operands: 166
145Operationoperator: 160
operands: 161
146Operationoperator: 167
operands: 162
147Literal
148Literal
149Operationoperator: 165
operands: 163
150Operationoperator: 167
operands: 164
151Operationoperator: 165
operands: 166
152Operationoperator: 167
operands: 168
153ExprTuple195, 169
154ExprTuple170, 171
155ExprTuple172
156ExprTuple200, 173
157Literal
158ExprTuple174
159Literal
160Literal
161NamedExprsoperation: 175
part: 178
162ExprTuple200, 180
163NamedExprsstate: 176
part: 178
164ExprTuple200, 205
165Literal
166NamedExprsstate: 177
part: 178
167Literal
168ExprTuple179, 180
169Operationoperator: 184
operand: 200
170Operationoperator: 182
operands: 183
171Operationoperator: 184
operand: 196
172Variable
173Operationoperator: 186
operands: 187
174Literal
175Operationoperator: 188
operands: 189
176Operationoperator: 190
operands: 191
177Variable
178Variable
179Operationoperator: 193
operands: 192
180Operationoperator: 193
operands: 194
181ExprTuple200
182Literal
183ExprTuple199, 195
184Literal
185ExprTuple196
186Literal
187ExprTuple204, 197
188Literal
189ExprTuple198, 205
190Literal
191ExprTuple199, 205
192ExprTuple205, 200
193Literal
194ExprTuple205, 201
195Operationoperator: 202
operands: 203
196Variable
197Variable
198Variable
199Variable
200Literal
201Variable
202Literal
203ExprTuple204, 205
204Literal
205Variable