logo

Expression of type Lambda

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, 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 = 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(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..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameters: 1
body: 2
1ExprTuple157, 173
2Conditionalvalue: 3
condition: 4
3Operationoperator: 28
operand: 7
4Operationoperator: 50
operands: 6
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameters: 10
body: 11
8Operationoperator: 38
operands: 12
9Operationoperator: 38
operands: 13
10ExprTuple14
11Conditionalvalue: 15
condition: 16
12ExprTuple157, 17
13ExprTuple173, 17
14ExprRangelambda_map: 18
start_index: 174
end_index: 173
15Operationoperator: 28
operand: 21
16Operationoperator: 50
operands: 20
17Literal
18Lambdaparameter: 183
body: 87
19ExprTuple21
20ExprTuple22
21Lambdaparameter: 121
body: 23
22ExprRangelambda_map: 24
start_index: 174
end_index: 173
23Conditionalvalue: 25
condition: 26
24Lambdaparameter: 183
body: 27
25Operationoperator: 28
operand: 32
26Operationoperator: 50
operands: 30
27Operationoperator: 38
operands: 31
28Literal
29ExprTuple32
30ExprTuple33, 34
31ExprTuple87, 35
32Lambdaparameters: 36
body: 37
33Operationoperator: 38
operands: 39
34Operationoperator: 134
operands: 40
35Operationoperator: 41
operand: 59
36ExprTuple43
37Conditionalvalue: 44
condition: 45
38Literal
39ExprTuple121, 46
40ExprTuple47, 174
41Literal
42ExprTuple59
43ExprRangelambda_map: 48
start_index: 174
end_index: 173
44Operationoperator: 134
operands: 49
45Operationoperator: 50
operands: 51
46Operationoperator: 52
operands: 53
47Operationoperator: 54
operand: 121
48Lambdaparameter: 183
body: 180
49ExprTuple56, 174
50Literal
51ExprTuple57
52Literal
53ExprTuple58, 59
54Literal
55ExprTuple121
56Operationoperator: 60
operand: 64
57ExprRangelambda_map: 62
start_index: 174
end_index: 173
58Literal
59Operationoperator: 165
operands: 63
60Literal
61ExprTuple64
62Lambdaparameter: 183
body: 65
63ExprTuple177, 157
64Operationoperator: 66
operands: 67
65Operationoperator: 134
operands: 68
66Literal
67ExprTuple69, 70, 71
68ExprTuple72, 73
69ExprTuple74, 75
70ExprRangelambda_map: 76
start_index: 174
end_index: 173
71ExprTuple77, 78
72Operationoperator: 79
operands: 80
73Operationoperator: 152
operands: 81
74ExprRangelambda_map: 82
start_index: 174
end_index: 173
75ExprRangelambda_map: 83
start_index: 174
end_index: 157
76Lambdaparameter: 156
body: 84
77ExprRangelambda_map: 85
start_index: 174
end_index: 173
78ExprRangelambda_map: 86
start_index: 174
end_index: 157
79Literal
80ExprTuple87, 121
81ExprTuple160, 121
82Lambdaparameter: 183
body: 88
83Lambdaparameter: 183
body: 89
84ExprTuple90, 91
85Lambdaparameter: 183
body: 92
86Lambdaparameter: 183
body: 93
87IndexedVarvariable: 147
index: 183
88Operationoperator: 107
operands: 94
89Operationoperator: 132
operands: 95
90ExprRangelambda_map: 96
start_index: 174
end_index: 173
91ExprRangelambda_map: 97
start_index: 174
end_index: 157
92Operationoperator: 112
operands: 98
93Operationoperator: 132
operands: 99
94NamedExprsstate: 100
95NamedExprselement: 101
targets: 118
96Lambdaparameter: 183
body: 102
97Lambdaparameter: 183
body: 103
98NamedExprsstate: 104
99NamedExprselement: 105
targets: 118
100Operationoperator: 167
operand: 114
101Operationoperator: 107
operands: 113
102Operationoperator: 108
operands: 109
103Operationoperator: 132
operands: 110
104Operationoperator: 152
operands: 111
105Operationoperator: 112
operands: 113
106ExprTuple114
107Literal
108Literal
109ExprTuple115, 116
110NamedExprselement: 117
targets: 118
111ExprTuple119, 120
112Literal
113NamedExprsstate: 121
part: 183
114Literal
115Conditionalvalue: 122
condition: 123
116Conditionalvalue: 124
condition: 125
117Operationoperator: 135
operands: 126
118Operationoperator: 127
operands: 128
119Operationoperator: 163
operands: 129
120Operationoperator: 130
operands: 131
121Variable
122Operationoperator: 132
operands: 133
123Operationoperator: 134
operands: 138
124Operationoperator: 135
operands: 136
125Operationoperator: 137
operands: 138
126NamedExprsoperation: 139
part: 183
127Literal
128ExprTuple162, 140
129ExprTuple174, 141
130Literal
131ExprTuple142, 143
132Literal
133NamedExprselement: 144
targets: 145
134Literal
135Literal
136NamedExprsoperation: 146
137Literal
138ExprTuple156, 183
139IndexedVarvariable: 147
index: 156
140Operationoperator: 169
operands: 149
141Operationoperator: 165
operands: 150
142Operationoperator: 167
operand: 159
143Operationoperator: 152
operands: 153
144Literal
145Operationoperator: 154
operand: 162
146Literal
147Variable
148ExprTuple156
149ExprTuple173, 157
150ExprTuple177, 158
151ExprTuple159
152Literal
153ExprTuple160, 161
154Literal
155ExprTuple162
156Variable
157Variable
158Operationoperator: 163
operands: 164
159Literal
160Operationoperator: 165
operands: 166
161Operationoperator: 167
operand: 174
162Operationoperator: 169
operands: 170
163Literal
164ExprTuple174, 177
165Literal
166ExprTuple171, 172
167Literal
168ExprTuple174
169Literal
170ExprTuple173, 174
171Literal
172Operationoperator: 175
operands: 176
173Variable
174Literal
175Literal
176ExprTuple177, 178, 179, 180
177Literal
178Literal
179Literal
180IndexedVarvariable: 181
index: 183
181Variable
182ExprTuple183
183Variable