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 = [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()
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_{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}
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: 7
operand: 2
1ExprTuple2
2Lambdaparameters: 3
body: 4
3ExprTuple199, 178, 197
4Conditionalvalue: 5
condition: 6
5Operationoperator: 7
operand: 10
6Operationoperator: 81
operands: 9
7Literal
8ExprTuple10
9ExprTuple11, 12, 13, 14, 15, 16
10Lambdaparameter: 206
body: 18
11Operationoperator: 100
operands: 19
12Operationoperator: 100
operands: 20
13Operationoperator: 100
operands: 21
14Operationoperator: 100
operands: 22
15Operationoperator: 24
operands: 23
16Operationoperator: 24
operands: 25
17ExprTuple206
18Conditionalvalue: 26
condition: 27
19ExprTuple199, 28
20ExprTuple178, 29
21ExprTuple197, 30
22ExprTuple197, 31
23ExprTuple32, 201
24Literal
25ExprTuple33, 34
26Operationoperator: 102
operands: 35
27Operationoperator: 81
operands: 36
28Operationoperator: 37
operand: 54
29Operationoperator: 39
operands: 40
30Literal
31Operationoperator: 41
operands: 42
32Operationoperator: 43
operand: 178
33Operationoperator: 45
operands: 46
34Operationoperator: 47
operands: 48
35ExprTuple49, 50
36ExprTuple51, 52
37Literal
38ExprTuple54
39Literal
40ExprTuple53, 54
41Literal
42ExprTuple139, 201
43Literal
44ExprTuple178
45Literal
46ExprTuple199, 178
47Literal
48ExprTuple55, 178
49Operationoperator: 194
operands: 56
50Operationoperator: 57
operand: 64
51Operationoperator: 100
operands: 59
52Operationoperator: 102
operands: 60
53Literal
54Operationoperator: 203
operands: 61
55Operationoperator: 203
operands: 62
56ExprTuple201, 63
57Literal
58ExprTuple64
59ExprTuple206, 65
60ExprTuple66, 206
61ExprTuple205, 202
62ExprTuple67, 68
63Operationoperator: 185
operand: 198
64Lambdaparameter: 200
body: 71
65Literal
66Operationoperator: 194
operands: 72
67Literal
68Operationoperator: 187
operands: 73
69ExprTuple198
70ExprTuple200
71Conditionalvalue: 74
condition: 75
72ExprTuple173, 76
73ExprTuple205, 77, 78, 197
74Operationoperator: 79
operands: 80
75Operationoperator: 81
operands: 82
76Operationoperator: 83
operand: 91
77Literal
78Literal
79Literal
80ExprTuple85, 86, 87, 88
81Literal
82ExprTuple89, 90
83Literal
84ExprTuple91
85ExprTuple92, 93
86ExprTuple94, 95
87ExprTuple96, 97
88ExprTuple98, 99
89Operationoperator: 100
operands: 101
90Operationoperator: 102
operands: 103
91Operationoperator: 104
operands: 105
92ExprRangelambda_map: 106
start_index: 201
end_index: 206
93ExprRangelambda_map: 107
start_index: 201
end_index: 202
94ExprRangelambda_map: 108
start_index: 201
end_index: 206
95ExprRangelambda_map: 108
start_index: 180
end_index: 181
96ExprRangelambda_map: 109
start_index: 201
end_index: 206
97ExprRangelambda_map: 110
start_index: 201
end_index: 202
98ExprRangelambda_map: 111
start_index: 201
end_index: 206
99ExprRangelambda_map: 112
start_index: 201
end_index: 202
100Literal
101ExprTuple200, 113
102Literal
103ExprTuple114, 115
104Literal
105ExprTuple205, 116
106Lambdaparameter: 179
body: 117
107Lambdaparameter: 179
body: 118
108Lambdaparameter: 179
body: 119
109Lambdaparameter: 179
body: 120
110Lambdaparameter: 179
body: 121
111Lambdaparameter: 179
body: 122
112Lambdaparameter: 179
body: 124
113Operationoperator: 168
operands: 125
114Operationoperator: 126
operands: 127
115Operationoperator: 203
operands: 128
116Operationoperator: 194
operands: 129
117Operationoperator: 160
operands: 130
118Operationoperator: 137
operands: 131
119Operationoperator: 137
operands: 132
120Operationoperator: 133
operands: 134
121Operationoperator: 161
operands: 135
122Operationoperator: 137
operands: 136
123ExprTuple179
124Operationoperator: 137
operands: 138
125ExprTuple139, 140
126Literal
127ExprTuple141, 201
128ExprTuple205, 142
129ExprTuple205, 143
130NamedExprsstate: 144
131NamedExprselement: 145
targets: 153
132NamedExprselement: 146
targets: 147
133Literal
134NamedExprsbasis: 148
135NamedExprsoperation: 149
136NamedExprselement: 150
targets: 151
137Literal
138NamedExprselement: 152
targets: 153
139Literal
140Operationoperator: 194
operands: 154
141Operationoperator: 194
operands: 155
142Operationoperator: 185
operand: 173
143Operationoperator: 183
operands: 157
144Operationoperator: 158
operand: 175
145Operationoperator: 160
operands: 167
146Operationoperator: 161
operands: 162
147Operationoperator: 168
operands: 163
148Literal
149Literal
150Operationoperator: 166
operands: 164
151Operationoperator: 168
operands: 165
152Operationoperator: 166
operands: 167
153Operationoperator: 168
operands: 169
154ExprTuple196, 170
155ExprTuple171, 172
156ExprTuple173
157ExprTuple201, 174
158Literal
159ExprTuple175
160Literal
161Literal
162NamedExprsoperation: 176
part: 179
163ExprTuple201, 181
164NamedExprsstate: 177
part: 179
165ExprTuple201, 206
166Literal
167NamedExprsstate: 178
part: 179
168Literal
169ExprTuple180, 181
170Operationoperator: 185
operand: 201
171Operationoperator: 183
operands: 184
172Operationoperator: 185
operand: 197
173Variable
174Operationoperator: 187
operands: 188
175Literal
176Operationoperator: 189
operands: 190
177Operationoperator: 191
operands: 192
178Variable
179Variable
180Operationoperator: 194
operands: 193
181Operationoperator: 194
operands: 195
182ExprTuple201
183Literal
184ExprTuple200, 196
185Literal
186ExprTuple197
187Literal
188ExprTuple205, 198
189Literal
190ExprTuple199, 206
191Literal
192ExprTuple200, 206
193ExprTuple206, 201
194Literal
195ExprTuple206, 202
196Operationoperator: 203
operands: 204
197Variable
198Variable
199Variable
200Variable
201Literal
202Variable
203Literal
204ExprTuple205, 206
205Literal
206Variable