logo

Expression of type Forall

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 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, 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 = 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()
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())
\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}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
with_wrappingIf 'True', wrap the Expression after the parametersNoneTrue('with_wrapping',)
condition_wrappingWrap 'before' or 'after' the condition (or None).NoneNone/False('with_wrap_after_condition', 'with_wrap_before_condition')
wrap_paramsIf 'True', wraps every two parameters AND wraps the Expression after the parametersNoneNone/False('with_params',)
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 20
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple215, 186
4Conditionalvalue: 5
condition: 6
5Operationoperator: 20
operand: 9
6Operationoperator: 94
operands: 8
7ExprTuple9
8ExprTuple10, 11, 12
9Lambdaparameters: 13
body: 14
10Operationoperator: 113
operands: 15
11Operationoperator: 113
operands: 16
12Operationoperator: 115
operands: 17
13ExprTuple212, 191, 210
14Conditionalvalue: 18
condition: 19
15ExprTuple215, 78
16ExprTuple186, 78
17ExprTuple218, 186
18Operationoperator: 20
operand: 23
19Operationoperator: 94
operands: 22
20Literal
21ExprTuple23
22ExprTuple24, 25, 26, 27, 28, 29
23Lambdaparameter: 219
body: 31
24Operationoperator: 113
operands: 32
25Operationoperator: 113
operands: 33
26Operationoperator: 113
operands: 34
27Operationoperator: 113
operands: 35
28Operationoperator: 37
operands: 36
29Operationoperator: 37
operands: 38
30ExprTuple219
31Conditionalvalue: 39
condition: 40
32ExprTuple212, 41
33ExprTuple191, 42
34ExprTuple210, 43
35ExprTuple210, 44
36ExprTuple45, 214
37Literal
38ExprTuple46, 47
39Operationoperator: 115
operands: 48
40Operationoperator: 94
operands: 49
41Operationoperator: 50
operand: 67
42Operationoperator: 52
operands: 53
43Literal
44Operationoperator: 54
operands: 55
45Operationoperator: 56
operand: 191
46Operationoperator: 58
operands: 59
47Operationoperator: 60
operands: 61
48ExprTuple62, 63
49ExprTuple64, 65
50Literal
51ExprTuple67
52Literal
53ExprTuple66, 67
54Literal
55ExprTuple152, 214
56Literal
57ExprTuple191
58Literal
59ExprTuple212, 191
60Literal
61ExprTuple68, 191
62Operationoperator: 207
operands: 69
63Operationoperator: 70
operand: 77
64Operationoperator: 113
operands: 72
65Operationoperator: 115
operands: 73
66Literal
67Operationoperator: 216
operands: 74
68Operationoperator: 216
operands: 75
69ExprTuple214, 76
70Literal
71ExprTuple77
72ExprTuple219, 78
73ExprTuple79, 219
74ExprTuple218, 215
75ExprTuple80, 81
76Operationoperator: 198
operand: 211
77Lambdaparameter: 213
body: 84
78Literal
79Operationoperator: 207
operands: 85
80Literal
81Operationoperator: 200
operands: 86
82ExprTuple211
83ExprTuple213
84Conditionalvalue: 87
condition: 88
85ExprTuple186, 89
86ExprTuple218, 90, 91, 210
87Operationoperator: 92
operands: 93
88Operationoperator: 94
operands: 95
89Operationoperator: 96
operand: 104
90Literal
91Literal
92Literal
93ExprTuple98, 99, 100, 101
94Literal
95ExprTuple102, 103
96Literal
97ExprTuple104
98ExprTuple105, 106
99ExprTuple107, 108
100ExprTuple109, 110
101ExprTuple111, 112
102Operationoperator: 113
operands: 114
103Operationoperator: 115
operands: 116
104Operationoperator: 117
operands: 118
105ExprRangelambda_map: 119
start_index: 214
end_index: 219
106ExprRangelambda_map: 120
start_index: 214
end_index: 215
107ExprRangelambda_map: 121
start_index: 214
end_index: 219
108ExprRangelambda_map: 121
start_index: 193
end_index: 194
109ExprRangelambda_map: 122
start_index: 214
end_index: 219
110ExprRangelambda_map: 123
start_index: 214
end_index: 215
111ExprRangelambda_map: 124
start_index: 214
end_index: 219
112ExprRangelambda_map: 125
start_index: 214
end_index: 215
113Literal
114ExprTuple213, 126
115Literal
116ExprTuple127, 128
117Literal
118ExprTuple218, 129
119Lambdaparameter: 192
body: 130
120Lambdaparameter: 192
body: 131
121Lambdaparameter: 192
body: 132
122Lambdaparameter: 192
body: 133
123Lambdaparameter: 192
body: 134
124Lambdaparameter: 192
body: 135
125Lambdaparameter: 192
body: 137
126Operationoperator: 181
operands: 138
127Operationoperator: 139
operands: 140
128Operationoperator: 216
operands: 141
129Operationoperator: 207
operands: 142
130Operationoperator: 173
operands: 143
131Operationoperator: 150
operands: 144
132Operationoperator: 150
operands: 145
133Operationoperator: 146
operands: 147
134Operationoperator: 174
operands: 148
135Operationoperator: 150
operands: 149
136ExprTuple192
137Operationoperator: 150
operands: 151
138ExprTuple152, 153
139Literal
140ExprTuple154, 214
141ExprTuple218, 155
142ExprTuple218, 156
143NamedExprsstate: 157
144NamedExprselement: 158
targets: 166
145NamedExprselement: 159
targets: 160
146Literal
147NamedExprsbasis: 161
148NamedExprsoperation: 162
149NamedExprselement: 163
targets: 164
150Literal
151NamedExprselement: 165
targets: 166
152Literal
153Operationoperator: 207
operands: 167
154Operationoperator: 207
operands: 168
155Operationoperator: 198
operand: 186
156Operationoperator: 196
operands: 170
157Operationoperator: 171
operand: 188
158Operationoperator: 173
operands: 180
159Operationoperator: 174
operands: 175
160Operationoperator: 181
operands: 176
161Literal
162Literal
163Operationoperator: 179
operands: 177
164Operationoperator: 181
operands: 178
165Operationoperator: 179
operands: 180
166Operationoperator: 181
operands: 182
167ExprTuple209, 183
168ExprTuple184, 185
169ExprTuple186
170ExprTuple214, 187
171Literal
172ExprTuple188
173Literal
174Literal
175NamedExprsoperation: 189
part: 192
176ExprTuple214, 194
177NamedExprsstate: 190
part: 192
178ExprTuple214, 219
179Literal
180NamedExprsstate: 191
part: 192
181Literal
182ExprTuple193, 194
183Operationoperator: 198
operand: 214
184Operationoperator: 196
operands: 197
185Operationoperator: 198
operand: 210
186Variable
187Operationoperator: 200
operands: 201
188Literal
189Operationoperator: 202
operands: 203
190Operationoperator: 204
operands: 205
191Variable
192Variable
193Operationoperator: 207
operands: 206
194Operationoperator: 207
operands: 208
195ExprTuple214
196Literal
197ExprTuple213, 209
198Literal
199ExprTuple210
200Literal
201ExprTuple218, 211
202Literal
203ExprTuple212, 219
204Literal
205ExprTuple213, 219
206ExprTuple219, 214
207Literal
208ExprTuple219, 215
209Operationoperator: 216
operands: 217
210Variable
211Variable
212Variable
213Variable
214Literal
215Variable
216Literal
217ExprTuple218, 219
218Literal
219Variable