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, 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([ExprRange(sub_expr1, sub_expr2, one, t)], Conditional(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(), And(ExprRange(sub_expr1, InSet(sub_expr2, Unitary(Exp(two, m))), one, t)))))
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(U_{1}, U_{2}, \ldots, U_{t}\right) \mapsto \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} \textrm{ if } \left(U_{1} \in \textrm{U}\left(2^{m}\right)\right) \land  \left(U_{2} \in \textrm{U}\left(2^{m}\right)\right) \land  \ldots \land  \left(U_{t} \in \textrm{U}\left(2^{m}\right)\right)\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
2ExprTuple4
3Conditionalvalue: 5
condition: 6
4ExprRangelambda_map: 7
start_index: 163
end_index: 162
5Operationoperator: 17
operand: 10
6Operationoperator: 39
operands: 9
7Lambdaparameter: 172
body: 76
8ExprTuple10
9ExprTuple11
10Lambdaparameter: 110
body: 12
11ExprRangelambda_map: 13
start_index: 163
end_index: 162
12Conditionalvalue: 14
condition: 15
13Lambdaparameter: 172
body: 16
14Operationoperator: 17
operand: 21
15Operationoperator: 39
operands: 19
16Operationoperator: 27
operands: 20
17Literal
18ExprTuple21
19ExprTuple22, 23
20ExprTuple76, 24
21Lambdaparameters: 25
body: 26
22Operationoperator: 27
operands: 28
23Operationoperator: 123
operands: 29
24Operationoperator: 30
operand: 48
25ExprTuple32
26Conditionalvalue: 33
condition: 34
27Literal
28ExprTuple110, 35
29ExprTuple36, 163
30Literal
31ExprTuple48
32ExprRangelambda_map: 37
start_index: 163
end_index: 162
33Operationoperator: 123
operands: 38
34Operationoperator: 39
operands: 40
35Operationoperator: 41
operands: 42
36Operationoperator: 43
operand: 110
37Lambdaparameter: 172
body: 169
38ExprTuple45, 163
39Literal
40ExprTuple46
41Literal
42ExprTuple47, 48
43Literal
44ExprTuple110
45Operationoperator: 49
operand: 53
46ExprRangelambda_map: 51
start_index: 163
end_index: 162
47Literal
48Operationoperator: 154
operands: 52
49Literal
50ExprTuple53
51Lambdaparameter: 172
body: 54
52ExprTuple166, 146
53Operationoperator: 55
operands: 56
54Operationoperator: 123
operands: 57
55Literal
56ExprTuple58, 59, 60
57ExprTuple61, 62
58ExprTuple63, 64
59ExprRangelambda_map: 65
start_index: 163
end_index: 162
60ExprTuple66, 67
61Operationoperator: 68
operands: 69
62Operationoperator: 141
operands: 70
63ExprRangelambda_map: 71
start_index: 163
end_index: 162
64ExprRangelambda_map: 72
start_index: 163
end_index: 146
65Lambdaparameter: 145
body: 73
66ExprRangelambda_map: 74
start_index: 163
end_index: 162
67ExprRangelambda_map: 75
start_index: 163
end_index: 146
68Literal
69ExprTuple76, 110
70ExprTuple149, 110
71Lambdaparameter: 172
body: 77
72Lambdaparameter: 172
body: 78
73ExprTuple79, 80
74Lambdaparameter: 172
body: 81
75Lambdaparameter: 172
body: 82
76IndexedVarvariable: 136
index: 172
77Operationoperator: 96
operands: 83
78Operationoperator: 121
operands: 84
79ExprRangelambda_map: 85
start_index: 163
end_index: 162
80ExprRangelambda_map: 86
start_index: 163
end_index: 146
81Operationoperator: 101
operands: 87
82Operationoperator: 121
operands: 88
83NamedExprsstate: 89
84NamedExprselement: 90
targets: 107
85Lambdaparameter: 172
body: 91
86Lambdaparameter: 172
body: 92
87NamedExprsstate: 93
88NamedExprselement: 94
targets: 107
89Operationoperator: 156
operand: 103
90Operationoperator: 96
operands: 102
91Operationoperator: 97
operands: 98
92Operationoperator: 121
operands: 99
93Operationoperator: 141
operands: 100
94Operationoperator: 101
operands: 102
95ExprTuple103
96Literal
97Literal
98ExprTuple104, 105
99NamedExprselement: 106
targets: 107
100ExprTuple108, 109
101Literal
102NamedExprsstate: 110
part: 172
103Literal
104Conditionalvalue: 111
condition: 112
105Conditionalvalue: 113
condition: 114
106Operationoperator: 124
operands: 115
107Operationoperator: 116
operands: 117
108Operationoperator: 152
operands: 118
109Operationoperator: 119
operands: 120
110Variable
111Operationoperator: 121
operands: 122
112Operationoperator: 123
operands: 127
113Operationoperator: 124
operands: 125
114Operationoperator: 126
operands: 127
115NamedExprsoperation: 128
part: 172
116Literal
117ExprTuple151, 129
118ExprTuple163, 130
119Literal
120ExprTuple131, 132
121Literal
122NamedExprselement: 133
targets: 134
123Literal
124Literal
125NamedExprsoperation: 135
126Literal
127ExprTuple145, 172
128IndexedVarvariable: 136
index: 145
129Operationoperator: 158
operands: 138
130Operationoperator: 154
operands: 139
131Operationoperator: 156
operand: 148
132Operationoperator: 141
operands: 142
133Literal
134Operationoperator: 143
operand: 151
135Literal
136Variable
137ExprTuple145
138ExprTuple162, 146
139ExprTuple166, 147
140ExprTuple148
141Literal
142ExprTuple149, 150
143Literal
144ExprTuple151
145Variable
146Variable
147Operationoperator: 152
operands: 153
148Literal
149Operationoperator: 154
operands: 155
150Operationoperator: 156
operand: 163
151Operationoperator: 158
operands: 159
152Literal
153ExprTuple163, 166
154Literal
155ExprTuple160, 161
156Literal
157ExprTuple163
158Literal
159ExprTuple162, 163
160Literal
161Operationoperator: 164
operands: 165
162Variable
163Literal
164Literal
165ExprTuple166, 167, 168, 169
166Literal
167Literal
168Literal
169IndexedVarvariable: 170
index: 172
170Variable
171ExprTuple172
172Variable