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, IntervalCO, Mod, Mult, NaturalPos, Real, Round, e, four, frac, greater, i, one, pi, 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 = 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 = greater(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_expr5, one, t), ExprRange(sub_expr1, sub_expr5, 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(Mod(Round(Mult(two_pow_t, phase)), two_pow_t), 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)]))), frac(four, Exp(pi, two))), domain = Real, conditions = [InSet(phase, IntervalCO(zero, 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}~|~\varphi \in \left[0,1\right), \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 round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \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 round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert round\left(2^{t} \cdot \varphi\right) ~\textup{mod}~ 2^{t} \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right) > \frac{4}{\pi^{2}}\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
1ExprTuple164, 178
2Conditionalvalue: 3
condition: 4
3Operationoperator: 26
operand: 7
4Operationoperator: 42
operands: 6
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameter: 161
body: 11
8Operationoperator: 60
operands: 12
9Operationoperator: 60
operands: 13
10ExprTuple161
11Conditionalvalue: 14
condition: 15
12ExprTuple164, 16
13ExprTuple178, 16
14Operationoperator: 26
operand: 19
15Operationoperator: 60
operands: 18
16Literal
17ExprTuple19
18ExprTuple161, 20
19Lambdaparameter: 150
body: 21
20Operationoperator: 22
operand: 54
21Conditionalvalue: 24
condition: 25
22Literal
23ExprTuple54
24Operationoperator: 26
operand: 29
25Operationoperator: 42
operands: 28
26Literal
27ExprTuple29
28ExprTuple30, 31
29Lambdaparameter: 174
body: 33
30Operationoperator: 60
operands: 34
31Operationoperator: 62
operands: 35
32ExprTuple174
33Conditionalvalue: 36
condition: 37
34ExprTuple150, 38
35ExprTuple39, 163
36Operationoperator: 40
operands: 41
37Operationoperator: 42
operands: 43
38Operationoperator: 44
operands: 45
39Operationoperator: 46
operand: 150
40Literal
41ExprTuple48, 49
42Literal
43ExprTuple50, 51, 52
44Literal
45ExprTuple53, 54
46Literal
47ExprTuple150
48Operationoperator: 55
operands: 56
49Operationoperator: 57
operand: 67
50Operationoperator: 60
operands: 59
51Operationoperator: 60
operands: 61
52Operationoperator: 62
operands: 63
53Literal
54Operationoperator: 175
operands: 64
55Literal
56ExprTuple65, 66
57Literal
58ExprTuple67
59ExprTuple174, 68
60Literal
61ExprTuple174, 69
62Literal
63ExprTuple70, 71
64ExprTuple177, 164
65Literal
66Operationoperator: 175
operands: 72
67Operationoperator: 73
operands: 74
68Literal
69Operationoperator: 75
operands: 76
70Operationoperator: 77
operands: 78
71Operationoperator: 79
operands: 80
72ExprTuple123, 177
73Literal
74ExprTuple81, 82, 83, 84
75Literal
76ExprTuple85, 163
77Literal
78ExprTuple161, 150
79Literal
80ExprTuple86, 150
81ExprTuple87, 88
82ExprTuple89, 90
83ExprTuple91, 92
84ExprTuple93, 94
85Literal
86Operationoperator: 175
operands: 95
87ExprRangelambda_map: 96
start_index: 163
end_index: 178
88ExprRangelambda_map: 97
start_index: 163
end_index: 164
89ExprRangelambda_map: 98
start_index: 163
end_index: 178
90ExprRangelambda_map: 98
start_index: 152
end_index: 153
91ExprRangelambda_map: 99
start_index: 163
end_index: 178
92ExprRangelambda_map: 100
start_index: 163
end_index: 164
93ExprRangelambda_map: 101
start_index: 163
end_index: 178
94ExprRangelambda_map: 102
start_index: 163
end_index: 164
95ExprTuple103, 104
96Lambdaparameter: 151
body: 105
97Lambdaparameter: 151
body: 106
98Lambdaparameter: 151
body: 107
99Lambdaparameter: 151
body: 108
100Lambdaparameter: 151
body: 109
101Lambdaparameter: 151
body: 110
102Lambdaparameter: 151
body: 112
103Literal
104Operationoperator: 171
operands: 113
105Operationoperator: 137
operands: 114
106Operationoperator: 121
operands: 115
107Operationoperator: 121
operands: 116
108Operationoperator: 117
operands: 118
109Operationoperator: 138
operands: 119
110Operationoperator: 121
operands: 120
111ExprTuple151
112Operationoperator: 121
operands: 122
113ExprTuple177, 123, 124, 174
114NamedExprsstate: 125
115NamedExprselement: 126
targets: 134
116NamedExprselement: 127
targets: 128
117Literal
118NamedExprsbasis: 129
119NamedExprsoperation: 130
120NamedExprselement: 131
targets: 132
121Literal
122NamedExprselement: 133
targets: 134
123Literal
124Literal
125Operationoperator: 135
operand: 147
126Operationoperator: 137
operands: 144
127Operationoperator: 138
operands: 139
128Operationoperator: 145
operands: 140
129Literal
130Literal
131Operationoperator: 143
operands: 141
132Operationoperator: 145
operands: 142
133Operationoperator: 143
operands: 144
134Operationoperator: 145
operands: 146
135Literal
136ExprTuple147
137Literal
138Literal
139NamedExprsoperation: 148
part: 151
140ExprTuple163, 153
141NamedExprsstate: 149
part: 151
142ExprTuple163, 178
143Literal
144NamedExprsstate: 150
part: 151
145Literal
146ExprTuple152, 153
147Literal
148Operationoperator: 154
operands: 155
149Operationoperator: 156
operands: 157
150Variable
151Variable
152Operationoperator: 159
operands: 158
153Operationoperator: 159
operands: 160
154Literal
155ExprTuple161, 178
156Literal
157ExprTuple162, 178
158ExprTuple178, 163
159Literal
160ExprTuple178, 164
161Variable
162Operationoperator: 165
operands: 166
163Literal
164Variable
165Literal
166ExprTuple167, 173
167Operationoperator: 168
operand: 170
168Literal
169ExprTuple170
170Operationoperator: 171
operands: 172
171Literal
172ExprTuple173, 174
173Operationoperator: 175
operands: 176
174Variable
175Literal
176ExprTuple177, 178
177Literal
178Variable