logo

Expression of type Lambda

from the theory of proveit.physics.quantum.QPE

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, Lambda, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import MatrixMult, ScalarMult, Unitary
from proveit.logic import And, Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, Mult, NaturalPos, Real, e, i, one, pi, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, normalized_var_ket_u, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, s_ket_domain, two_pow_s, two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import Prob
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
sub_expr3 = Add(t, s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = Mult(two_pow_t, phase)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Lambda([s, t], Conditional(Forall(instance_param_or_params = [U], instance_expr = Forall(instance_param_or_params = [var_ket_u], instance_expr = Forall(instance_param_or_params = [phase], instance_expr = Equals(Prob(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)], [ExprRange(sub_expr1, sub_expr6, one, t), ExprRange(sub_expr1, sub_expr6, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(sub_expr5, t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)]))), one), domain = Real, conditions = [InSet(sub_expr5, Interval(zero, subtract(two_pow_t, one))), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), var_ket_u))]).with_wrapping(), domain = s_ket_domain, condition = normalized_var_ket_u).with_wrapping(), domain = Unitary(two_pow_s)).with_wrapping(), And(InSet(s, 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(s, t\right) \mapsto \left\{\begin{array}{l}\forall_{U \in \textrm{U}\left(2^{s}\right)}~\\
\left[\begin{array}{l}\forall_{\lvert u \rangle \in \mathbb{C}^{2^{s}}~|~\left \|\lvert u \rangle\right \| = 1}~\\
\left[\begin{array}{l}\forall_{\varphi \in \mathbb{R}~|~\left(2^{t} \cdot \varphi\right) \in \{0~\ldotp \ldotp~2^{t} - 1\}, \left(U \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert u \rangle\right)}~\\
\left(\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) = 1\right)\end{array}\right]\end{array}\right]\end{array} \textrm{ if } s \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
1ExprTuple161, 169
2Conditionalvalue: 3
condition: 4
3Operationoperator: 26
operand: 7
4Operationoperator: 41
operands: 6
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameter: 158
body: 11
8Operationoperator: 56
operands: 12
9Operationoperator: 56
operands: 13
10ExprTuple158
11Conditionalvalue: 14
condition: 15
12ExprTuple161, 16
13ExprTuple169, 16
14Operationoperator: 26
operand: 19
15Operationoperator: 56
operands: 18
16Literal
17ExprTuple19
18ExprTuple158, 20
19Lambdaparameter: 147
body: 21
20Operationoperator: 22
operand: 52
21Conditionalvalue: 24
condition: 25
22Literal
23ExprTuple52
24Operationoperator: 26
operand: 29
25Operationoperator: 41
operands: 28
26Literal
27ExprTuple29
28ExprTuple30, 31
29Lambdaparameter: 165
body: 33
30Operationoperator: 56
operands: 34
31Operationoperator: 58
operands: 35
32ExprTuple165
33Conditionalvalue: 36
condition: 37
34ExprTuple147, 38
35ExprTuple39, 160
36Operationoperator: 58
operands: 40
37Operationoperator: 41
operands: 42
38Operationoperator: 43
operands: 44
39Operationoperator: 45
operand: 147
40ExprTuple47, 160
41Literal
42ExprTuple48, 49, 50
43Literal
44ExprTuple51, 52
45Literal
46ExprTuple147
47Operationoperator: 53
operand: 61
48Operationoperator: 56
operands: 55
49Operationoperator: 56
operands: 57
50Operationoperator: 58
operands: 59
51Literal
52Operationoperator: 166
operands: 60
53Literal
54ExprTuple61
55ExprTuple165, 62
56Literal
57ExprTuple159, 63
58Literal
59ExprTuple64, 65
60ExprTuple168, 161
61Operationoperator: 66
operands: 67
62Literal
63Operationoperator: 142
operands: 68
64Operationoperator: 69
operands: 70
65Operationoperator: 71
operands: 72
66Literal
67ExprTuple73, 74, 75, 76
68ExprTuple77, 78
69Literal
70ExprTuple158, 147
71Literal
72ExprTuple79, 147
73ExprTuple80, 81
74ExprTuple82, 83
75ExprTuple84, 85
76ExprTuple86, 87
77Literal
78Operationoperator: 156
operands: 88
79Operationoperator: 166
operands: 89
80ExprRangelambda_map: 90
start_index: 160
end_index: 169
81ExprRangelambda_map: 91
start_index: 160
end_index: 161
82ExprRangelambda_map: 92
start_index: 160
end_index: 169
83ExprRangelambda_map: 92
start_index: 149
end_index: 150
84ExprRangelambda_map: 93
start_index: 160
end_index: 169
85ExprRangelambda_map: 94
start_index: 160
end_index: 161
86ExprRangelambda_map: 95
start_index: 160
end_index: 169
87ExprRangelambda_map: 96
start_index: 160
end_index: 161
88ExprTuple164, 97
89ExprTuple98, 99
90Lambdaparameter: 148
body: 100
91Lambdaparameter: 148
body: 101
92Lambdaparameter: 148
body: 102
93Lambdaparameter: 148
body: 103
94Lambdaparameter: 148
body: 104
95Lambdaparameter: 148
body: 105
96Lambdaparameter: 148
body: 107
97Operationoperator: 108
operand: 160
98Literal
99Operationoperator: 162
operands: 110
100Operationoperator: 134
operands: 111
101Operationoperator: 118
operands: 112
102Operationoperator: 118
operands: 113
103Operationoperator: 114
operands: 115
104Operationoperator: 135
operands: 116
105Operationoperator: 118
operands: 117
106ExprTuple148
107Operationoperator: 118
operands: 119
108Literal
109ExprTuple160
110ExprTuple168, 120, 121, 165
111NamedExprsstate: 122
112NamedExprselement: 123
targets: 131
113NamedExprselement: 124
targets: 125
114Literal
115NamedExprsbasis: 126
116NamedExprsoperation: 127
117NamedExprselement: 128
targets: 129
118Literal
119NamedExprselement: 130
targets: 131
120Literal
121Literal
122Operationoperator: 132
operand: 144
123Operationoperator: 134
operands: 141
124Operationoperator: 135
operands: 136
125Operationoperator: 142
operands: 137
126Literal
127Literal
128Operationoperator: 140
operands: 138
129Operationoperator: 142
operands: 139
130Operationoperator: 140
operands: 141
131Operationoperator: 142
operands: 143
132Literal
133ExprTuple144
134Literal
135Literal
136NamedExprsoperation: 145
part: 148
137ExprTuple160, 150
138NamedExprsstate: 146
part: 148
139ExprTuple160, 169
140Literal
141NamedExprsstate: 147
part: 148
142Literal
143ExprTuple149, 150
144Literal
145Operationoperator: 151
operands: 152
146Operationoperator: 153
operands: 154
147Variable
148Variable
149Operationoperator: 156
operands: 155
150Operationoperator: 156
operands: 157
151Literal
152ExprTuple158, 169
153Literal
154ExprTuple159, 169
155ExprTuple169, 160
156Literal
157ExprTuple169, 161
158Variable
159Operationoperator: 162
operands: 163
160Literal
161Variable
162Literal
163ExprTuple164, 165
164Operationoperator: 166
operands: 167
165Variable
166Literal
167ExprTuple168, 169
168Literal
169Variable