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
from proveit.logic import And, 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_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(var_ket_u, Conditional(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(), And(InSet(var_ket_u, s_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 \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} \textrm{ if } \lvert u \rangle \in \mathbb{C}^{2^{s}} ,  \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: 128
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 20
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameter: 152
body: 11
8Operationoperator: 38
operands: 12
9Operationoperator: 40
operands: 13
10ExprTuple152
11Conditionalvalue: 14
condition: 15
12ExprTuple128, 16
13ExprTuple17, 141
14Operationoperator: 18
operands: 19
15Operationoperator: 20
operands: 21
16Operationoperator: 22
operands: 23
17Operationoperator: 24
operand: 128
18Literal
19ExprTuple26, 27
20Literal
21ExprTuple28, 29, 30
22Literal
23ExprTuple31, 32
24Literal
25ExprTuple128
26Operationoperator: 33
operands: 34
27Operationoperator: 35
operand: 45
28Operationoperator: 38
operands: 37
29Operationoperator: 38
operands: 39
30Operationoperator: 40
operands: 41
31Literal
32Operationoperator: 153
operands: 42
33Literal
34ExprTuple43, 44
35Literal
36ExprTuple45
37ExprTuple152, 46
38Literal
39ExprTuple152, 47
40Literal
41ExprTuple48, 49
42ExprTuple155, 142
43Literal
44Operationoperator: 153
operands: 50
45Operationoperator: 51
operands: 52
46Literal
47Operationoperator: 53
operands: 54
48Operationoperator: 55
operands: 56
49Operationoperator: 57
operands: 58
50ExprTuple101, 155
51Literal
52ExprTuple59, 60, 61, 62
53Literal
54ExprTuple63, 141
55Literal
56ExprTuple139, 128
57Literal
58ExprTuple64, 128
59ExprTuple65, 66
60ExprTuple67, 68
61ExprTuple69, 70
62ExprTuple71, 72
63Literal
64Operationoperator: 153
operands: 73
65ExprRangelambda_map: 74
start_index: 141
end_index: 156
66ExprRangelambda_map: 75
start_index: 141
end_index: 142
67ExprRangelambda_map: 76
start_index: 141
end_index: 156
68ExprRangelambda_map: 76
start_index: 130
end_index: 131
69ExprRangelambda_map: 77
start_index: 141
end_index: 156
70ExprRangelambda_map: 78
start_index: 141
end_index: 142
71ExprRangelambda_map: 79
start_index: 141
end_index: 156
72ExprRangelambda_map: 80
start_index: 141
end_index: 142
73ExprTuple81, 82
74Lambdaparameter: 129
body: 83
75Lambdaparameter: 129
body: 84
76Lambdaparameter: 129
body: 85
77Lambdaparameter: 129
body: 86
78Lambdaparameter: 129
body: 87
79Lambdaparameter: 129
body: 88
80Lambdaparameter: 129
body: 90
81Literal
82Operationoperator: 149
operands: 91
83Operationoperator: 115
operands: 92
84Operationoperator: 99
operands: 93
85Operationoperator: 99
operands: 94
86Operationoperator: 95
operands: 96
87Operationoperator: 116
operands: 97
88Operationoperator: 99
operands: 98
89ExprTuple129
90Operationoperator: 99
operands: 100
91ExprTuple155, 101, 102, 152
92NamedExprsstate: 103
93NamedExprselement: 104
targets: 112
94NamedExprselement: 105
targets: 106
95Literal
96NamedExprsbasis: 107
97NamedExprsoperation: 108
98NamedExprselement: 109
targets: 110
99Literal
100NamedExprselement: 111
targets: 112
101Literal
102Literal
103Operationoperator: 113
operand: 125
104Operationoperator: 115
operands: 122
105Operationoperator: 116
operands: 117
106Operationoperator: 123
operands: 118
107Literal
108Literal
109Operationoperator: 121
operands: 119
110Operationoperator: 123
operands: 120
111Operationoperator: 121
operands: 122
112Operationoperator: 123
operands: 124
113Literal
114ExprTuple125
115Literal
116Literal
117NamedExprsoperation: 126
part: 129
118ExprTuple141, 131
119NamedExprsstate: 127
part: 129
120ExprTuple141, 156
121Literal
122NamedExprsstate: 128
part: 129
123Literal
124ExprTuple130, 131
125Literal
126Operationoperator: 132
operands: 133
127Operationoperator: 134
operands: 135
128Variable
129Variable
130Operationoperator: 137
operands: 136
131Operationoperator: 137
operands: 138
132Literal
133ExprTuple139, 156
134Literal
135ExprTuple140, 156
136ExprTuple156, 141
137Literal
138ExprTuple156, 142
139Variable
140Operationoperator: 143
operands: 144
141Literal
142Variable
143Literal
144ExprTuple145, 151
145Operationoperator: 146
operand: 148
146Literal
147ExprTuple148
148Operationoperator: 149
operands: 150
149Literal
150ExprTuple151, 152
151Operationoperator: 153
operands: 154
152Variable
153Literal
154ExprTuple155, 156
155Literal
156Variable