logo

Expression of type ExprTuple

from the theory of proveit.physics.quantum.circuits

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, IndexedVar, Lambda, U, Variable, m, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Exp, Mult, NaturalPos, e, i, one, pi, two
from proveit.physics.quantum import m_ket_domain, normalized_var_ket_u, var_ket_u, varphi
from proveit.physics.quantum.circuits import phase_kickback_on_register_circuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = IndexedVar(U, sub_expr1)
sub_expr3 = IndexedVar(varphi, sub_expr1)
expr = ExprTuple(Lambda([m, t], Conditional(Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr2, one, t)], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr3, one, t)], instance_expr = Equals(Prob(phase_kickback_on_register_circuit), one), condition = ExprRange(sub_expr1, Equals(MatrixMult(sub_expr2, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, sub_expr3)), var_ket_u)), one, t)).with_wrapping(), domain = m_ket_domain, condition = normalized_var_ket_u).with_wrapping(), domain = Unitary(Exp(two, m))).with_wrapping(), And(InSet(m, 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(m, t\right) \mapsto \left\{\begin{array}{l}\forall_{U_{1}, U_{2}, \ldots, U_{t} \in \textrm{U}\left(2^{m}\right)}~\\
\left[\begin{array}{l}\forall_{\lvert u \rangle \in \mathbb{C}^{2^{m}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\left[\begin{array}{l}\forall_{\varphi_{1}, \varphi_{2}, \ldots, \varphi_{t}~|~\left(\left(U_{1} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert u \rangle\right)\right), \left(\left(U_{2} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert u \rangle\right)\right), \ldots, \left(\left(U_{t} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert u \rangle\right)\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qout{\vdots} \\
\qin{\lvert + \rangle} & \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{t}} \cdot \lvert 1 \rangle\right)\right)} \\
\qin{\lvert u \rangle} & \gate{U_{1}} & \gate{U_{2}} & \gate{\cdots} & \gate{U_{t}} & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\end{array}\right]\end{array}\right]\end{array} \textrm{ if } m \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
2ExprTuple158, 174
3Conditionalvalue: 4
condition: 5
4Operationoperator: 29
operand: 8
5Operationoperator: 51
operands: 7
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameters: 11
body: 12
9Operationoperator: 39
operands: 13
10Operationoperator: 39
operands: 14
11ExprTuple15
12Conditionalvalue: 16
condition: 17
13ExprTuple158, 18
14ExprTuple174, 18
15ExprRangelambda_map: 19
start_index: 175
end_index: 174
16Operationoperator: 29
operand: 22
17Operationoperator: 51
operands: 21
18Literal
19Lambdaparameter: 184
body: 88
20ExprTuple22
21ExprTuple23
22Lambdaparameter: 122
body: 24
23ExprRangelambda_map: 25
start_index: 175
end_index: 174
24Conditionalvalue: 26
condition: 27
25Lambdaparameter: 184
body: 28
26Operationoperator: 29
operand: 33
27Operationoperator: 51
operands: 31
28Operationoperator: 39
operands: 32
29Literal
30ExprTuple33
31ExprTuple34, 35
32ExprTuple88, 36
33Lambdaparameters: 37
body: 38
34Operationoperator: 39
operands: 40
35Operationoperator: 135
operands: 41
36Operationoperator: 42
operand: 60
37ExprTuple44
38Conditionalvalue: 45
condition: 46
39Literal
40ExprTuple122, 47
41ExprTuple48, 175
42Literal
43ExprTuple60
44ExprRangelambda_map: 49
start_index: 175
end_index: 174
45Operationoperator: 135
operands: 50
46Operationoperator: 51
operands: 52
47Operationoperator: 53
operands: 54
48Operationoperator: 55
operand: 122
49Lambdaparameter: 184
body: 181
50ExprTuple57, 175
51Literal
52ExprTuple58
53Literal
54ExprTuple59, 60
55Literal
56ExprTuple122
57Operationoperator: 61
operand: 65
58ExprRangelambda_map: 63
start_index: 175
end_index: 174
59Literal
60Operationoperator: 166
operands: 64
61Literal
62ExprTuple65
63Lambdaparameter: 184
body: 66
64ExprTuple178, 158
65Operationoperator: 67
operands: 68
66Operationoperator: 135
operands: 69
67Literal
68ExprTuple70, 71, 72
69ExprTuple73, 74
70ExprTuple75, 76
71ExprRangelambda_map: 77
start_index: 175
end_index: 174
72ExprTuple78, 79
73Operationoperator: 80
operands: 81
74Operationoperator: 153
operands: 82
75ExprRangelambda_map: 83
start_index: 175
end_index: 174
76ExprRangelambda_map: 84
start_index: 175
end_index: 158
77Lambdaparameter: 157
body: 85
78ExprRangelambda_map: 86
start_index: 175
end_index: 174
79ExprRangelambda_map: 87
start_index: 175
end_index: 158
80Literal
81ExprTuple88, 122
82ExprTuple161, 122
83Lambdaparameter: 184
body: 89
84Lambdaparameter: 184
body: 90
85ExprTuple91, 92
86Lambdaparameter: 184
body: 93
87Lambdaparameter: 184
body: 94
88IndexedVarvariable: 148
index: 184
89Operationoperator: 108
operands: 95
90Operationoperator: 133
operands: 96
91ExprRangelambda_map: 97
start_index: 175
end_index: 174
92ExprRangelambda_map: 98
start_index: 175
end_index: 158
93Operationoperator: 113
operands: 99
94Operationoperator: 133
operands: 100
95NamedExprsstate: 101
96NamedExprselement: 102
targets: 119
97Lambdaparameter: 184
body: 103
98Lambdaparameter: 184
body: 104
99NamedExprsstate: 105
100NamedExprselement: 106
targets: 119
101Operationoperator: 168
operand: 115
102Operationoperator: 108
operands: 114
103Operationoperator: 109
operands: 110
104Operationoperator: 133
operands: 111
105Operationoperator: 153
operands: 112
106Operationoperator: 113
operands: 114
107ExprTuple115
108Literal
109Literal
110ExprTuple116, 117
111NamedExprselement: 118
targets: 119
112ExprTuple120, 121
113Literal
114NamedExprsstate: 122
part: 184
115Literal
116Conditionalvalue: 123
condition: 124
117Conditionalvalue: 125
condition: 126
118Operationoperator: 136
operands: 127
119Operationoperator: 128
operands: 129
120Operationoperator: 164
operands: 130
121Operationoperator: 131
operands: 132
122Variable
123Operationoperator: 133
operands: 134
124Operationoperator: 135
operands: 139
125Operationoperator: 136
operands: 137
126Operationoperator: 138
operands: 139
127NamedExprsoperation: 140
part: 184
128Literal
129ExprTuple163, 141
130ExprTuple175, 142
131Literal
132ExprTuple143, 144
133Literal
134NamedExprselement: 145
targets: 146
135Literal
136Literal
137NamedExprsoperation: 147
138Literal
139ExprTuple157, 184
140IndexedVarvariable: 148
index: 157
141Operationoperator: 170
operands: 150
142Operationoperator: 166
operands: 151
143Operationoperator: 168
operand: 160
144Operationoperator: 153
operands: 154
145Literal
146Operationoperator: 155
operand: 163
147Literal
148Variable
149ExprTuple157
150ExprTuple174, 158
151ExprTuple178, 159
152ExprTuple160
153Literal
154ExprTuple161, 162
155Literal
156ExprTuple163
157Variable
158Variable
159Operationoperator: 164
operands: 165
160Literal
161Operationoperator: 166
operands: 167
162Operationoperator: 168
operand: 175
163Operationoperator: 170
operands: 171
164Literal
165ExprTuple175, 178
166Literal
167ExprTuple172, 173
168Literal
169ExprTuple175
170Literal
171ExprTuple174, 175
172Literal
173Operationoperator: 176
operands: 177
174Variable
175Literal
176Literal
177ExprTuple178, 179, 180, 181
178Literal
179Literal
180Literal
181IndexedVarvariable: 182
index: 184
182Variable
183ExprTuple184
184Variable