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, Mult, 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_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(var_ket_u, Conditional(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(), 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}~|~\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} \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: 125
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operand: 7
3Operationoperator: 19
operands: 6
4Literal
5ExprTuple7
6ExprTuple8, 9
7Lambdaparameter: 143
body: 11
8Operationoperator: 34
operands: 12
9Operationoperator: 36
operands: 13
10ExprTuple143
11Conditionalvalue: 14
condition: 15
12ExprTuple125, 16
13ExprTuple17, 138
14Operationoperator: 36
operands: 18
15Operationoperator: 19
operands: 20
16Operationoperator: 21
operands: 22
17Operationoperator: 23
operand: 125
18ExprTuple25, 138
19Literal
20ExprTuple26, 27, 28
21Literal
22ExprTuple29, 30
23Literal
24ExprTuple125
25Operationoperator: 31
operand: 39
26Operationoperator: 34
operands: 33
27Operationoperator: 34
operands: 35
28Operationoperator: 36
operands: 37
29Literal
30Operationoperator: 144
operands: 38
31Literal
32ExprTuple39
33ExprTuple143, 40
34Literal
35ExprTuple137, 41
36Literal
37ExprTuple42, 43
38ExprTuple146, 139
39Operationoperator: 44
operands: 45
40Literal
41Operationoperator: 120
operands: 46
42Operationoperator: 47
operands: 48
43Operationoperator: 49
operands: 50
44Literal
45ExprTuple51, 52, 53, 54
46ExprTuple55, 56
47Literal
48ExprTuple136, 125
49Literal
50ExprTuple57, 125
51ExprTuple58, 59
52ExprTuple60, 61
53ExprTuple62, 63
54ExprTuple64, 65
55Literal
56Operationoperator: 134
operands: 66
57Operationoperator: 144
operands: 67
58ExprRangelambda_map: 68
start_index: 138
end_index: 147
59ExprRangelambda_map: 69
start_index: 138
end_index: 139
60ExprRangelambda_map: 70
start_index: 138
end_index: 147
61ExprRangelambda_map: 70
start_index: 127
end_index: 128
62ExprRangelambda_map: 71
start_index: 138
end_index: 147
63ExprRangelambda_map: 72
start_index: 138
end_index: 139
64ExprRangelambda_map: 73
start_index: 138
end_index: 147
65ExprRangelambda_map: 74
start_index: 138
end_index: 139
66ExprTuple142, 75
67ExprTuple76, 77
68Lambdaparameter: 126
body: 78
69Lambdaparameter: 126
body: 79
70Lambdaparameter: 126
body: 80
71Lambdaparameter: 126
body: 81
72Lambdaparameter: 126
body: 82
73Lambdaparameter: 126
body: 83
74Lambdaparameter: 126
body: 85
75Operationoperator: 86
operand: 138
76Literal
77Operationoperator: 140
operands: 88
78Operationoperator: 112
operands: 89
79Operationoperator: 96
operands: 90
80Operationoperator: 96
operands: 91
81Operationoperator: 92
operands: 93
82Operationoperator: 113
operands: 94
83Operationoperator: 96
operands: 95
84ExprTuple126
85Operationoperator: 96
operands: 97
86Literal
87ExprTuple138
88ExprTuple146, 98, 99, 143
89NamedExprsstate: 100
90NamedExprselement: 101
targets: 109
91NamedExprselement: 102
targets: 103
92Literal
93NamedExprsbasis: 104
94NamedExprsoperation: 105
95NamedExprselement: 106
targets: 107
96Literal
97NamedExprselement: 108
targets: 109
98Literal
99Literal
100Operationoperator: 110
operand: 122
101Operationoperator: 112
operands: 119
102Operationoperator: 113
operands: 114
103Operationoperator: 120
operands: 115
104Literal
105Literal
106Operationoperator: 118
operands: 116
107Operationoperator: 120
operands: 117
108Operationoperator: 118
operands: 119
109Operationoperator: 120
operands: 121
110Literal
111ExprTuple122
112Literal
113Literal
114NamedExprsoperation: 123
part: 126
115ExprTuple138, 128
116NamedExprsstate: 124
part: 126
117ExprTuple138, 147
118Literal
119NamedExprsstate: 125
part: 126
120Literal
121ExprTuple127, 128
122Literal
123Operationoperator: 129
operands: 130
124Operationoperator: 131
operands: 132
125Variable
126Variable
127Operationoperator: 134
operands: 133
128Operationoperator: 134
operands: 135
129Literal
130ExprTuple136, 147
131Literal
132ExprTuple137, 147
133ExprTuple147, 138
134Literal
135ExprTuple147, 139
136Variable
137Operationoperator: 140
operands: 141
138Literal
139Variable
140Literal
141ExprTuple142, 143
142Operationoperator: 144
operands: 145
143Variable
144Literal
145ExprTuple146, 147
146Literal
147Variable