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, t
from proveit.linear_algebra import MatrixMult, ScalarMult
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(varphi, sub_expr1)
expr = Lambda(var_ket_u, Conditional(Forall(instance_param_or_params = [ExprRange(sub_expr1, sub_expr2, one, t)], instance_expr = Equals(Prob(phase_kickback_on_register_circuit), one), condition = ExprRange(sub_expr1, Equals(MatrixMult(IndexedVar(U, sub_expr1), var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, sub_expr2)), var_ket_u)), one, t)).with_wrapping(), And(InSet(var_ket_u, m_ket_domain), normalized_var_ket_u)))
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())
\lvert u \rangle \mapsto \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} \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{m}} ,  \left \|\lvert u \rangle\right \| = 1\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 93
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 22
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameters: 10
body: 11
8Operationoperator: 12
operands: 13
9Operationoperator: 106
operands: 14
10ExprTuple15
11Conditionalvalue: 16
condition: 17
12Literal
13ExprTuple93, 18
14ExprTuple19, 146
15ExprRangelambda_map: 20
start_index: 146
end_index: 145
16Operationoperator: 106
operands: 21
17Operationoperator: 22
operands: 23
18Operationoperator: 24
operands: 25
19Operationoperator: 26
operand: 93
20Lambdaparameter: 155
body: 152
21ExprTuple28, 146
22Literal
23ExprTuple29
24Literal
25ExprTuple30, 31
26Literal
27ExprTuple93
28Operationoperator: 32
operand: 36
29ExprRangelambda_map: 34
start_index: 146
end_index: 145
30Literal
31Operationoperator: 137
operands: 35
32Literal
33ExprTuple36
34Lambdaparameter: 155
body: 37
35ExprTuple149, 129
36Operationoperator: 38
operands: 39
37Operationoperator: 106
operands: 40
38Literal
39ExprTuple41, 42, 43
40ExprTuple44, 45
41ExprTuple46, 47
42ExprRangelambda_map: 48
start_index: 146
end_index: 145
43ExprTuple49, 50
44Operationoperator: 51
operands: 52
45Operationoperator: 124
operands: 53
46ExprRangelambda_map: 54
start_index: 146
end_index: 145
47ExprRangelambda_map: 55
start_index: 146
end_index: 129
48Lambdaparameter: 128
body: 56
49ExprRangelambda_map: 57
start_index: 146
end_index: 145
50ExprRangelambda_map: 58
start_index: 146
end_index: 129
51Literal
52ExprTuple59, 93
53ExprTuple132, 93
54Lambdaparameter: 155
body: 60
55Lambdaparameter: 155
body: 61
56ExprTuple62, 63
57Lambdaparameter: 155
body: 64
58Lambdaparameter: 155
body: 65
59IndexedVarvariable: 119
index: 155
60Operationoperator: 79
operands: 66
61Operationoperator: 104
operands: 67
62ExprRangelambda_map: 68
start_index: 146
end_index: 145
63ExprRangelambda_map: 69
start_index: 146
end_index: 129
64Operationoperator: 84
operands: 70
65Operationoperator: 104
operands: 71
66NamedExprsstate: 72
67NamedExprselement: 73
targets: 90
68Lambdaparameter: 155
body: 74
69Lambdaparameter: 155
body: 75
70NamedExprsstate: 76
71NamedExprselement: 77
targets: 90
72Operationoperator: 139
operand: 86
73Operationoperator: 79
operands: 85
74Operationoperator: 80
operands: 81
75Operationoperator: 104
operands: 82
76Operationoperator: 124
operands: 83
77Operationoperator: 84
operands: 85
78ExprTuple86
79Literal
80Literal
81ExprTuple87, 88
82NamedExprselement: 89
targets: 90
83ExprTuple91, 92
84Literal
85NamedExprsstate: 93
part: 155
86Literal
87Conditionalvalue: 94
condition: 95
88Conditionalvalue: 96
condition: 97
89Operationoperator: 107
operands: 98
90Operationoperator: 99
operands: 100
91Operationoperator: 135
operands: 101
92Operationoperator: 102
operands: 103
93Variable
94Operationoperator: 104
operands: 105
95Operationoperator: 106
operands: 110
96Operationoperator: 107
operands: 108
97Operationoperator: 109
operands: 110
98NamedExprsoperation: 111
part: 155
99Literal
100ExprTuple134, 112
101ExprTuple146, 113
102Literal
103ExprTuple114, 115
104Literal
105NamedExprselement: 116
targets: 117
106Literal
107Literal
108NamedExprsoperation: 118
109Literal
110ExprTuple128, 155
111IndexedVarvariable: 119
index: 128
112Operationoperator: 141
operands: 121
113Operationoperator: 137
operands: 122
114Operationoperator: 139
operand: 131
115Operationoperator: 124
operands: 125
116Literal
117Operationoperator: 126
operand: 134
118Literal
119Variable
120ExprTuple128
121ExprTuple145, 129
122ExprTuple149, 130
123ExprTuple131
124Literal
125ExprTuple132, 133
126Literal
127ExprTuple134
128Variable
129Variable
130Operationoperator: 135
operands: 136
131Literal
132Operationoperator: 137
operands: 138
133Operationoperator: 139
operand: 146
134Operationoperator: 141
operands: 142
135Literal
136ExprTuple146, 149
137Literal
138ExprTuple143, 144
139Literal
140ExprTuple146
141Literal
142ExprTuple145, 146
143Literal
144Operationoperator: 147
operands: 148
145Variable
146Literal
147Literal
148ExprTuple149, 150, 151, 152
149Literal
150Literal
151Literal
152IndexedVarvariable: 153
index: 155
153Variable
154ExprTuple155
155Variable