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, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, IntervalCO, Mod, Mult, NaturalPos, Real, Round, e, four, frac, greater, i, one, pi, 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 Prob
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([s, t], Conditional(Forall(instance_param_or_params = [U], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [phase], instance_expr = greater(Prob(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(Mod(Round(Mult(two_pow_t, phase)), two_pow_t), 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)]))), frac(four, Exp(pi, two))), domain = Real, conditions = [InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), var_ket_u))]).with_wrapping(), domain = s_ket_domain, condition = normalized_var_ket_u).with_wrapping(), domain = Unitary(two_pow_s)).with_wrapping(), And(InSet(s, NaturalPos), InSet(t, NaturalPos)))))
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(s, t\right) \mapsto \left\{\begin{array}{l}\forall_{U \in \textrm{U}\left(2^{s}\right)}~\\
\left[\begin{array}{l}\forall_{\lvert u \rangle \in \mathbb{C}^{2^{s}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\left[\begin{array}{l}\forall_{\varphi \in \mathbb{R}~|~\varphi \in \left[0,1\right), \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \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 round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) > \frac{4}{\pi^{2}}\right)\end{array}\right]\end{array}\right]\end{array} \textrm{ if } s \in \mathbb{N}^+ ,  t \in \mathbb{N}^+\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
2ExprTuple165, 179
3Conditionalvalue: 4
condition: 5
4Operationoperator: 27
operand: 8
5Operationoperator: 43
operands: 7
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameter: 162
body: 12
9Operationoperator: 61
operands: 13
10Operationoperator: 61
operands: 14
11ExprTuple162
12Conditionalvalue: 15
condition: 16
13ExprTuple165, 17
14ExprTuple179, 17
15Operationoperator: 27
operand: 20
16Operationoperator: 61
operands: 19
17Literal
18ExprTuple20
19ExprTuple162, 21
20Lambdaparameter: 151
body: 22
21Operationoperator: 23
operand: 55
22Conditionalvalue: 25
condition: 26
23Literal
24ExprTuple55
25Operationoperator: 27
operand: 30
26Operationoperator: 43
operands: 29
27Literal
28ExprTuple30
29ExprTuple31, 32
30Lambdaparameter: 175
body: 34
31Operationoperator: 61
operands: 35
32Operationoperator: 63
operands: 36
33ExprTuple175
34Conditionalvalue: 37
condition: 38
35ExprTuple151, 39
36ExprTuple40, 164
37Operationoperator: 41
operands: 42
38Operationoperator: 43
operands: 44
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operand: 151
41Literal
42ExprTuple49, 50
43Literal
44ExprTuple51, 52, 53
45Literal
46ExprTuple54, 55
47Literal
48ExprTuple151
49Operationoperator: 56
operands: 57
50Operationoperator: 58
operand: 68
51Operationoperator: 61
operands: 60
52Operationoperator: 61
operands: 62
53Operationoperator: 63
operands: 64
54Literal
55Operationoperator: 176
operands: 65
56Literal
57ExprTuple66, 67
58Literal
59ExprTuple68
60ExprTuple175, 69
61Literal
62ExprTuple175, 70
63Literal
64ExprTuple71, 72
65ExprTuple178, 165
66Literal
67Operationoperator: 176
operands: 73
68Operationoperator: 74
operands: 75
69Literal
70Operationoperator: 76
operands: 77
71Operationoperator: 78
operands: 79
72Operationoperator: 80
operands: 81
73ExprTuple124, 178
74Literal
75ExprTuple82, 83, 84, 85
76Literal
77ExprTuple86, 164
78Literal
79ExprTuple162, 151
80Literal
81ExprTuple87, 151
82ExprTuple88, 89
83ExprTuple90, 91
84ExprTuple92, 93
85ExprTuple94, 95
86Literal
87Operationoperator: 176
operands: 96
88ExprRangelambda_map: 97
start_index: 164
end_index: 179
89ExprRangelambda_map: 98
start_index: 164
end_index: 165
90ExprRangelambda_map: 99
start_index: 164
end_index: 179
91ExprRangelambda_map: 99
start_index: 153
end_index: 154
92ExprRangelambda_map: 100
start_index: 164
end_index: 179
93ExprRangelambda_map: 101
start_index: 164
end_index: 165
94ExprRangelambda_map: 102
start_index: 164
end_index: 179
95ExprRangelambda_map: 103
start_index: 164
end_index: 165
96ExprTuple104, 105
97Lambdaparameter: 152
body: 106
98Lambdaparameter: 152
body: 107
99Lambdaparameter: 152
body: 108
100Lambdaparameter: 152
body: 109
101Lambdaparameter: 152
body: 110
102Lambdaparameter: 152
body: 111
103Lambdaparameter: 152
body: 113
104Literal
105Operationoperator: 172
operands: 114
106Operationoperator: 138
operands: 115
107Operationoperator: 122
operands: 116
108Operationoperator: 122
operands: 117
109Operationoperator: 118
operands: 119
110Operationoperator: 139
operands: 120
111Operationoperator: 122
operands: 121
112ExprTuple152
113Operationoperator: 122
operands: 123
114ExprTuple178, 124, 125, 175
115NamedExprsstate: 126
116NamedExprselement: 127
targets: 135
117NamedExprselement: 128
targets: 129
118Literal
119NamedExprsbasis: 130
120NamedExprsoperation: 131
121NamedExprselement: 132
targets: 133
122Literal
123NamedExprselement: 134
targets: 135
124Literal
125Literal
126Operationoperator: 136
operand: 148
127Operationoperator: 138
operands: 145
128Operationoperator: 139
operands: 140
129Operationoperator: 146
operands: 141
130Literal
131Literal
132Operationoperator: 144
operands: 142
133Operationoperator: 146
operands: 143
134Operationoperator: 144
operands: 145
135Operationoperator: 146
operands: 147
136Literal
137ExprTuple148
138Literal
139Literal
140NamedExprsoperation: 149
part: 152
141ExprTuple164, 154
142NamedExprsstate: 150
part: 152
143ExprTuple164, 179
144Literal
145NamedExprsstate: 151
part: 152
146Literal
147ExprTuple153, 154
148Literal
149Operationoperator: 155
operands: 156
150Operationoperator: 157
operands: 158
151Variable
152Variable
153Operationoperator: 160
operands: 159
154Operationoperator: 160
operands: 161
155Literal
156ExprTuple162, 179
157Literal
158ExprTuple163, 179
159ExprTuple179, 164
160Literal
161ExprTuple179, 165
162Variable
163Operationoperator: 166
operands: 167
164Literal
165Variable
166Literal
167ExprTuple168, 174
168Operationoperator: 169
operand: 171
169Literal
170ExprTuple171
171Operationoperator: 172
operands: 173
172Literal
173ExprTuple174, 175
174Operationoperator: 176
operands: 177
175Variable
176Literal
177ExprTuple178, 179
178Literal
179Variable