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, 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([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(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..
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
1ExprTuple3
2Conditionalvalue: 4
condition: 5
3ExprRangelambda_map: 6
start_index: 162
end_index: 161
4Operationoperator: 16
operand: 9
5Operationoperator: 38
operands: 8
6Lambdaparameter: 171
body: 75
7ExprTuple9
8ExprTuple10
9Lambdaparameter: 109
body: 11
10ExprRangelambda_map: 12
start_index: 162
end_index: 161
11Conditionalvalue: 13
condition: 14
12Lambdaparameter: 171
body: 15
13Operationoperator: 16
operand: 20
14Operationoperator: 38
operands: 18
15Operationoperator: 26
operands: 19
16Literal
17ExprTuple20
18ExprTuple21, 22
19ExprTuple75, 23
20Lambdaparameters: 24
body: 25
21Operationoperator: 26
operands: 27
22Operationoperator: 122
operands: 28
23Operationoperator: 29
operand: 47
24ExprTuple31
25Conditionalvalue: 32
condition: 33
26Literal
27ExprTuple109, 34
28ExprTuple35, 162
29Literal
30ExprTuple47
31ExprRangelambda_map: 36
start_index: 162
end_index: 161
32Operationoperator: 122
operands: 37
33Operationoperator: 38
operands: 39
34Operationoperator: 40
operands: 41
35Operationoperator: 42
operand: 109
36Lambdaparameter: 171
body: 168
37ExprTuple44, 162
38Literal
39ExprTuple45
40Literal
41ExprTuple46, 47
42Literal
43ExprTuple109
44Operationoperator: 48
operand: 52
45ExprRangelambda_map: 50
start_index: 162
end_index: 161
46Literal
47Operationoperator: 153
operands: 51
48Literal
49ExprTuple52
50Lambdaparameter: 171
body: 53
51ExprTuple165, 145
52Operationoperator: 54
operands: 55
53Operationoperator: 122
operands: 56
54Literal
55ExprTuple57, 58, 59
56ExprTuple60, 61
57ExprTuple62, 63
58ExprRangelambda_map: 64
start_index: 162
end_index: 161
59ExprTuple65, 66
60Operationoperator: 67
operands: 68
61Operationoperator: 140
operands: 69
62ExprRangelambda_map: 70
start_index: 162
end_index: 161
63ExprRangelambda_map: 71
start_index: 162
end_index: 145
64Lambdaparameter: 144
body: 72
65ExprRangelambda_map: 73
start_index: 162
end_index: 161
66ExprRangelambda_map: 74
start_index: 162
end_index: 145
67Literal
68ExprTuple75, 109
69ExprTuple148, 109
70Lambdaparameter: 171
body: 76
71Lambdaparameter: 171
body: 77
72ExprTuple78, 79
73Lambdaparameter: 171
body: 80
74Lambdaparameter: 171
body: 81
75IndexedVarvariable: 135
index: 171
76Operationoperator: 95
operands: 82
77Operationoperator: 120
operands: 83
78ExprRangelambda_map: 84
start_index: 162
end_index: 161
79ExprRangelambda_map: 85
start_index: 162
end_index: 145
80Operationoperator: 100
operands: 86
81Operationoperator: 120
operands: 87
82NamedExprsstate: 88
83NamedExprselement: 89
targets: 106
84Lambdaparameter: 171
body: 90
85Lambdaparameter: 171
body: 91
86NamedExprsstate: 92
87NamedExprselement: 93
targets: 106
88Operationoperator: 155
operand: 102
89Operationoperator: 95
operands: 101
90Operationoperator: 96
operands: 97
91Operationoperator: 120
operands: 98
92Operationoperator: 140
operands: 99
93Operationoperator: 100
operands: 101
94ExprTuple102
95Literal
96Literal
97ExprTuple103, 104
98NamedExprselement: 105
targets: 106
99ExprTuple107, 108
100Literal
101NamedExprsstate: 109
part: 171
102Literal
103Conditionalvalue: 110
condition: 111
104Conditionalvalue: 112
condition: 113
105Operationoperator: 123
operands: 114
106Operationoperator: 115
operands: 116
107Operationoperator: 151
operands: 117
108Operationoperator: 118
operands: 119
109Variable
110Operationoperator: 120
operands: 121
111Operationoperator: 122
operands: 126
112Operationoperator: 123
operands: 124
113Operationoperator: 125
operands: 126
114NamedExprsoperation: 127
part: 171
115Literal
116ExprTuple150, 128
117ExprTuple162, 129
118Literal
119ExprTuple130, 131
120Literal
121NamedExprselement: 132
targets: 133
122Literal
123Literal
124NamedExprsoperation: 134
125Literal
126ExprTuple144, 171
127IndexedVarvariable: 135
index: 144
128Operationoperator: 157
operands: 137
129Operationoperator: 153
operands: 138
130Operationoperator: 155
operand: 147
131Operationoperator: 140
operands: 141
132Literal
133Operationoperator: 142
operand: 150
134Literal
135Variable
136ExprTuple144
137ExprTuple161, 145
138ExprTuple165, 146
139ExprTuple147
140Literal
141ExprTuple148, 149
142Literal
143ExprTuple150
144Variable
145Variable
146Operationoperator: 151
operands: 152
147Literal
148Operationoperator: 153
operands: 154
149Operationoperator: 155
operand: 162
150Operationoperator: 157
operands: 158
151Literal
152ExprTuple162, 165
153Literal
154ExprTuple159, 160
155Literal
156ExprTuple162
157Literal
158ExprTuple161, 162
159Literal
160Operationoperator: 163
operands: 164
161Variable
162Literal
163Literal
164ExprTuple165, 166, 167, 168
165Literal
166Literal
167Literal
168IndexedVarvariable: 169
index: 171
169Variable
170ExprTuple171
171Variable