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, 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_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(U, Conditional(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(), 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}~|~\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} \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: 146
body: 2
1ExprTuple146
2Conditionalvalue: 3
condition: 4
3Operationoperator: 14
operand: 7
4Operationoperator: 44
operands: 6
5ExprTuple7
6ExprTuple146, 8
7Lambdaparameter: 135
body: 9
8Operationoperator: 10
operand: 40
9Conditionalvalue: 12
condition: 13
10Literal
11ExprTuple40
12Operationoperator: 14
operand: 17
13Operationoperator: 29
operands: 16
14Literal
15ExprTuple17
16ExprTuple18, 19
17Lambdaparameter: 153
body: 21
18Operationoperator: 44
operands: 22
19Operationoperator: 46
operands: 23
20ExprTuple153
21Conditionalvalue: 24
condition: 25
22ExprTuple135, 26
23ExprTuple27, 148
24Operationoperator: 46
operands: 28
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operands: 32
27Operationoperator: 33
operand: 135
28ExprTuple35, 148
29Literal
30ExprTuple36, 37, 38
31Literal
32ExprTuple39, 40
33Literal
34ExprTuple135
35Operationoperator: 41
operand: 49
36Operationoperator: 44
operands: 43
37Operationoperator: 44
operands: 45
38Operationoperator: 46
operands: 47
39Literal
40Operationoperator: 154
operands: 48
41Literal
42ExprTuple49
43ExprTuple153, 50
44Literal
45ExprTuple147, 51
46Literal
47ExprTuple52, 53
48ExprTuple156, 149
49Operationoperator: 54
operands: 55
50Literal
51Operationoperator: 130
operands: 56
52Operationoperator: 57
operands: 58
53Operationoperator: 59
operands: 60
54Literal
55ExprTuple61, 62, 63, 64
56ExprTuple65, 66
57Literal
58ExprTuple146, 135
59Literal
60ExprTuple67, 135
61ExprTuple68, 69
62ExprTuple70, 71
63ExprTuple72, 73
64ExprTuple74, 75
65Literal
66Operationoperator: 144
operands: 76
67Operationoperator: 154
operands: 77
68ExprRangelambda_map: 78
start_index: 148
end_index: 157
69ExprRangelambda_map: 79
start_index: 148
end_index: 149
70ExprRangelambda_map: 80
start_index: 148
end_index: 157
71ExprRangelambda_map: 80
start_index: 137
end_index: 138
72ExprRangelambda_map: 81
start_index: 148
end_index: 157
73ExprRangelambda_map: 82
start_index: 148
end_index: 149
74ExprRangelambda_map: 83
start_index: 148
end_index: 157
75ExprRangelambda_map: 84
start_index: 148
end_index: 149
76ExprTuple152, 85
77ExprTuple86, 87
78Lambdaparameter: 136
body: 88
79Lambdaparameter: 136
body: 89
80Lambdaparameter: 136
body: 90
81Lambdaparameter: 136
body: 91
82Lambdaparameter: 136
body: 92
83Lambdaparameter: 136
body: 93
84Lambdaparameter: 136
body: 95
85Operationoperator: 96
operand: 148
86Literal
87Operationoperator: 150
operands: 98
88Operationoperator: 122
operands: 99
89Operationoperator: 106
operands: 100
90Operationoperator: 106
operands: 101
91Operationoperator: 102
operands: 103
92Operationoperator: 123
operands: 104
93Operationoperator: 106
operands: 105
94ExprTuple136
95Operationoperator: 106
operands: 107
96Literal
97ExprTuple148
98ExprTuple156, 108, 109, 153
99NamedExprsstate: 110
100NamedExprselement: 111
targets: 119
101NamedExprselement: 112
targets: 113
102Literal
103NamedExprsbasis: 114
104NamedExprsoperation: 115
105NamedExprselement: 116
targets: 117
106Literal
107NamedExprselement: 118
targets: 119
108Literal
109Literal
110Operationoperator: 120
operand: 132
111Operationoperator: 122
operands: 129
112Operationoperator: 123
operands: 124
113Operationoperator: 130
operands: 125
114Literal
115Literal
116Operationoperator: 128
operands: 126
117Operationoperator: 130
operands: 127
118Operationoperator: 128
operands: 129
119Operationoperator: 130
operands: 131
120Literal
121ExprTuple132
122Literal
123Literal
124NamedExprsoperation: 133
part: 136
125ExprTuple148, 138
126NamedExprsstate: 134
part: 136
127ExprTuple148, 157
128Literal
129NamedExprsstate: 135
part: 136
130Literal
131ExprTuple137, 138
132Literal
133Operationoperator: 139
operands: 140
134Operationoperator: 141
operands: 142
135Variable
136Variable
137Operationoperator: 144
operands: 143
138Operationoperator: 144
operands: 145
139Literal
140ExprTuple146, 157
141Literal
142ExprTuple147, 157
143ExprTuple157, 148
144Literal
145ExprTuple157, 149
146Variable
147Operationoperator: 150
operands: 151
148Literal
149Variable
150Literal
151ExprTuple152, 153
152Operationoperator: 154
operands: 155
153Variable
154Literal
155ExprTuple156, 157
156Literal
157Variable