logo

Expression of type Conditional

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, 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 = 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\{\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()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operand: 6
2Operationoperator: 77
operands: 5
3Literal
4ExprTuple6
5ExprTuple7, 8, 9, 10, 11, 12
6Lambdaparameter: 202
body: 14
7Operationoperator: 96
operands: 15
8Operationoperator: 96
operands: 16
9Operationoperator: 96
operands: 17
10Operationoperator: 96
operands: 18
11Operationoperator: 20
operands: 19
12Operationoperator: 20
operands: 21
13ExprTuple202
14Conditionalvalue: 22
condition: 23
15ExprTuple195, 24
16ExprTuple174, 25
17ExprTuple193, 26
18ExprTuple193, 27
19ExprTuple28, 197
20Literal
21ExprTuple29, 30
22Operationoperator: 98
operands: 31
23Operationoperator: 77
operands: 32
24Operationoperator: 33
operand: 50
25Operationoperator: 35
operands: 36
26Literal
27Operationoperator: 37
operands: 38
28Operationoperator: 39
operand: 174
29Operationoperator: 41
operands: 42
30Operationoperator: 43
operands: 44
31ExprTuple45, 46
32ExprTuple47, 48
33Literal
34ExprTuple50
35Literal
36ExprTuple49, 50
37Literal
38ExprTuple135, 197
39Literal
40ExprTuple174
41Literal
42ExprTuple195, 174
43Literal
44ExprTuple51, 174
45Operationoperator: 190
operands: 52
46Operationoperator: 53
operand: 60
47Operationoperator: 96
operands: 55
48Operationoperator: 98
operands: 56
49Literal
50Operationoperator: 199
operands: 57
51Operationoperator: 199
operands: 58
52ExprTuple197, 59
53Literal
54ExprTuple60
55ExprTuple202, 61
56ExprTuple62, 202
57ExprTuple201, 198
58ExprTuple63, 64
59Operationoperator: 181
operand: 194
60Lambdaparameter: 196
body: 67
61Literal
62Operationoperator: 190
operands: 68
63Literal
64Operationoperator: 183
operands: 69
65ExprTuple194
66ExprTuple196
67Conditionalvalue: 70
condition: 71
68ExprTuple169, 72
69ExprTuple201, 73, 74, 193
70Operationoperator: 75
operands: 76
71Operationoperator: 77
operands: 78
72Operationoperator: 79
operand: 87
73Literal
74Literal
75Literal
76ExprTuple81, 82, 83, 84
77Literal
78ExprTuple85, 86
79Literal
80ExprTuple87
81ExprTuple88, 89
82ExprTuple90, 91
83ExprTuple92, 93
84ExprTuple94, 95
85Operationoperator: 96
operands: 97
86Operationoperator: 98
operands: 99
87Operationoperator: 100
operands: 101
88ExprRangelambda_map: 102
start_index: 197
end_index: 202
89ExprRangelambda_map: 103
start_index: 197
end_index: 198
90ExprRangelambda_map: 104
start_index: 197
end_index: 202
91ExprRangelambda_map: 104
start_index: 176
end_index: 177
92ExprRangelambda_map: 105
start_index: 197
end_index: 202
93ExprRangelambda_map: 106
start_index: 197
end_index: 198
94ExprRangelambda_map: 107
start_index: 197
end_index: 202
95ExprRangelambda_map: 108
start_index: 197
end_index: 198
96Literal
97ExprTuple196, 109
98Literal
99ExprTuple110, 111
100Literal
101ExprTuple201, 112
102Lambdaparameter: 175
body: 113
103Lambdaparameter: 175
body: 114
104Lambdaparameter: 175
body: 115
105Lambdaparameter: 175
body: 116
106Lambdaparameter: 175
body: 117
107Lambdaparameter: 175
body: 118
108Lambdaparameter: 175
body: 120
109Operationoperator: 164
operands: 121
110Operationoperator: 122
operands: 123
111Operationoperator: 199
operands: 124
112Operationoperator: 190
operands: 125
113Operationoperator: 156
operands: 126
114Operationoperator: 133
operands: 127
115Operationoperator: 133
operands: 128
116Operationoperator: 129
operands: 130
117Operationoperator: 157
operands: 131
118Operationoperator: 133
operands: 132
119ExprTuple175
120Operationoperator: 133
operands: 134
121ExprTuple135, 136
122Literal
123ExprTuple137, 197
124ExprTuple201, 138
125ExprTuple201, 139
126NamedExprsstate: 140
127NamedExprselement: 141
targets: 149
128NamedExprselement: 142
targets: 143
129Literal
130NamedExprsbasis: 144
131NamedExprsoperation: 145
132NamedExprselement: 146
targets: 147
133Literal
134NamedExprselement: 148
targets: 149
135Literal
136Operationoperator: 190
operands: 150
137Operationoperator: 190
operands: 151
138Operationoperator: 181
operand: 169
139Operationoperator: 179
operands: 153
140Operationoperator: 154
operand: 171
141Operationoperator: 156
operands: 163
142Operationoperator: 157
operands: 158
143Operationoperator: 164
operands: 159
144Literal
145Literal
146Operationoperator: 162
operands: 160
147Operationoperator: 164
operands: 161
148Operationoperator: 162
operands: 163
149Operationoperator: 164
operands: 165
150ExprTuple192, 166
151ExprTuple167, 168
152ExprTuple169
153ExprTuple197, 170
154Literal
155ExprTuple171
156Literal
157Literal
158NamedExprsoperation: 172
part: 175
159ExprTuple197, 177
160NamedExprsstate: 173
part: 175
161ExprTuple197, 202
162Literal
163NamedExprsstate: 174
part: 175
164Literal
165ExprTuple176, 177
166Operationoperator: 181
operand: 197
167Operationoperator: 179
operands: 180
168Operationoperator: 181
operand: 193
169Variable
170Operationoperator: 183
operands: 184
171Literal
172Operationoperator: 185
operands: 186
173Operationoperator: 187
operands: 188
174Variable
175Variable
176Operationoperator: 190
operands: 189
177Operationoperator: 190
operands: 191
178ExprTuple197
179Literal
180ExprTuple196, 192
181Literal
182ExprTuple193
183Literal
184ExprTuple201, 194
185Literal
186ExprTuple195, 202
187Literal
188ExprTuple196, 202
189ExprTuple202, 197
190Literal
191ExprTuple202, 198
192Operationoperator: 199
operands: 200
193Variable
194Variable
195Variable
196Variable
197Literal
198Variable
199Literal
200ExprTuple201, 202
201Literal
202Variable