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 Equals, Forall, InSet
from proveit.numbers import Add, Exp, Interval, IntervalCO, Mod, Mult, 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(U, Conditional(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(), InSet(U, Unitary(two_pow_s))))
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())
U \mapsto \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} \textrm{ if } U \in \textrm{U}\left(2^{s}\right)\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 149
body: 2
1ExprTuple149
2Conditionalvalue: 3
condition: 4
3Operationoperator: 14
operand: 7
4Operationoperator: 48
operands: 6
5ExprTuple7
6ExprTuple149, 8
7Lambdaparameter: 138
body: 9
8Operationoperator: 10
operand: 42
9Conditionalvalue: 12
condition: 13
10Literal
11ExprTuple42
12Operationoperator: 14
operand: 17
13Operationoperator: 30
operands: 16
14Literal
15ExprTuple17
16ExprTuple18, 19
17Lambdaparameter: 162
body: 21
18Operationoperator: 48
operands: 22
19Operationoperator: 50
operands: 23
20ExprTuple162
21Conditionalvalue: 24
condition: 25
22ExprTuple138, 26
23ExprTuple27, 151
24Operationoperator: 28
operands: 29
25Operationoperator: 30
operands: 31
26Operationoperator: 32
operands: 33
27Operationoperator: 34
operand: 138
28Literal
29ExprTuple36, 37
30Literal
31ExprTuple38, 39, 40
32Literal
33ExprTuple41, 42
34Literal
35ExprTuple138
36Operationoperator: 43
operands: 44
37Operationoperator: 45
operand: 55
38Operationoperator: 48
operands: 47
39Operationoperator: 48
operands: 49
40Operationoperator: 50
operands: 51
41Literal
42Operationoperator: 163
operands: 52
43Literal
44ExprTuple53, 54
45Literal
46ExprTuple55
47ExprTuple162, 56
48Literal
49ExprTuple162, 57
50Literal
51ExprTuple58, 59
52ExprTuple165, 152
53Literal
54Operationoperator: 163
operands: 60
55Operationoperator: 61
operands: 62
56Literal
57Operationoperator: 63
operands: 64
58Operationoperator: 65
operands: 66
59Operationoperator: 67
operands: 68
60ExprTuple111, 165
61Literal
62ExprTuple69, 70, 71, 72
63Literal
64ExprTuple73, 151
65Literal
66ExprTuple149, 138
67Literal
68ExprTuple74, 138
69ExprTuple75, 76
70ExprTuple77, 78
71ExprTuple79, 80
72ExprTuple81, 82
73Literal
74Operationoperator: 163
operands: 83
75ExprRangelambda_map: 84
start_index: 151
end_index: 166
76ExprRangelambda_map: 85
start_index: 151
end_index: 152
77ExprRangelambda_map: 86
start_index: 151
end_index: 166
78ExprRangelambda_map: 86
start_index: 140
end_index: 141
79ExprRangelambda_map: 87
start_index: 151
end_index: 166
80ExprRangelambda_map: 88
start_index: 151
end_index: 152
81ExprRangelambda_map: 89
start_index: 151
end_index: 166
82ExprRangelambda_map: 90
start_index: 151
end_index: 152
83ExprTuple91, 92
84Lambdaparameter: 139
body: 93
85Lambdaparameter: 139
body: 94
86Lambdaparameter: 139
body: 95
87Lambdaparameter: 139
body: 96
88Lambdaparameter: 139
body: 97
89Lambdaparameter: 139
body: 98
90Lambdaparameter: 139
body: 100
91Literal
92Operationoperator: 159
operands: 101
93Operationoperator: 125
operands: 102
94Operationoperator: 109
operands: 103
95Operationoperator: 109
operands: 104
96Operationoperator: 105
operands: 106
97Operationoperator: 126
operands: 107
98Operationoperator: 109
operands: 108
99ExprTuple139
100Operationoperator: 109
operands: 110
101ExprTuple165, 111, 112, 162
102NamedExprsstate: 113
103NamedExprselement: 114
targets: 122
104NamedExprselement: 115
targets: 116
105Literal
106NamedExprsbasis: 117
107NamedExprsoperation: 118
108NamedExprselement: 119
targets: 120
109Literal
110NamedExprselement: 121
targets: 122
111Literal
112Literal
113Operationoperator: 123
operand: 135
114Operationoperator: 125
operands: 132
115Operationoperator: 126
operands: 127
116Operationoperator: 133
operands: 128
117Literal
118Literal
119Operationoperator: 131
operands: 129
120Operationoperator: 133
operands: 130
121Operationoperator: 131
operands: 132
122Operationoperator: 133
operands: 134
123Literal
124ExprTuple135
125Literal
126Literal
127NamedExprsoperation: 136
part: 139
128ExprTuple151, 141
129NamedExprsstate: 137
part: 139
130ExprTuple151, 166
131Literal
132NamedExprsstate: 138
part: 139
133Literal
134ExprTuple140, 141
135Literal
136Operationoperator: 142
operands: 143
137Operationoperator: 144
operands: 145
138Variable
139Variable
140Operationoperator: 147
operands: 146
141Operationoperator: 147
operands: 148
142Literal
143ExprTuple149, 166
144Literal
145ExprTuple150, 166
146ExprTuple166, 151
147Literal
148ExprTuple166, 152
149Variable
150Operationoperator: 153
operands: 154
151Literal
152Variable
153Literal
154ExprTuple155, 161
155Operationoperator: 156
operand: 158
156Literal
157ExprTuple158
158Operationoperator: 159
operands: 160
159Literal
160ExprTuple161, 162
161Operationoperator: 163
operands: 164
162Variable
163Literal
164ExprTuple165, 166
165Literal
166Variable