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, 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, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, 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(phase, Conditional(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))), And(InSet(phase, Real), InSet(phase, IntervalCO(zero, one)), Equals(MatrixMult(U, var_ket_u), ScalarMult(Exp(e, Mult(two, pi, i, phase)), 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())
\varphi \mapsto \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}} \textrm{ if } \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)\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 132
body: 2
1ExprTuple132
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10
7Literal
8ExprTuple11, 12, 13
9Operationoperator: 14
operands: 15
10Operationoperator: 16
operand: 25
11Operationoperator: 19
operands: 18
12Operationoperator: 19
operands: 20
13Operationoperator: 21
operands: 22
14Literal
15ExprTuple23, 24
16Literal
17ExprTuple25
18ExprTuple132, 26
19Literal
20ExprTuple132, 27
21Literal
22ExprTuple28, 29
23Literal
24Operationoperator: 133
operands: 30
25Operationoperator: 31
operands: 32
26Literal
27Operationoperator: 33
operands: 34
28Operationoperator: 35
operands: 36
29Operationoperator: 37
operands: 38
30ExprTuple81, 135
31Literal
32ExprTuple39, 40, 41, 42
33Literal
34ExprTuple43, 121
35Literal
36ExprTuple119, 108
37Literal
38ExprTuple44, 108
39ExprTuple45, 46
40ExprTuple47, 48
41ExprTuple49, 50
42ExprTuple51, 52
43Literal
44Operationoperator: 133
operands: 53
45ExprRangelambda_map: 54
start_index: 121
end_index: 136
46ExprRangelambda_map: 55
start_index: 121
end_index: 122
47ExprRangelambda_map: 56
start_index: 121
end_index: 136
48ExprRangelambda_map: 56
start_index: 110
end_index: 111
49ExprRangelambda_map: 57
start_index: 121
end_index: 136
50ExprRangelambda_map: 58
start_index: 121
end_index: 122
51ExprRangelambda_map: 59
start_index: 121
end_index: 136
52ExprRangelambda_map: 60
start_index: 121
end_index: 122
53ExprTuple61, 62
54Lambdaparameter: 109
body: 63
55Lambdaparameter: 109
body: 64
56Lambdaparameter: 109
body: 65
57Lambdaparameter: 109
body: 66
58Lambdaparameter: 109
body: 67
59Lambdaparameter: 109
body: 68
60Lambdaparameter: 109
body: 70
61Literal
62Operationoperator: 129
operands: 71
63Operationoperator: 95
operands: 72
64Operationoperator: 79
operands: 73
65Operationoperator: 79
operands: 74
66Operationoperator: 75
operands: 76
67Operationoperator: 96
operands: 77
68Operationoperator: 79
operands: 78
69ExprTuple109
70Operationoperator: 79
operands: 80
71ExprTuple135, 81, 82, 132
72NamedExprsstate: 83
73NamedExprselement: 84
targets: 92
74NamedExprselement: 85
targets: 86
75Literal
76NamedExprsbasis: 87
77NamedExprsoperation: 88
78NamedExprselement: 89
targets: 90
79Literal
80NamedExprselement: 91
targets: 92
81Literal
82Literal
83Operationoperator: 93
operand: 105
84Operationoperator: 95
operands: 102
85Operationoperator: 96
operands: 97
86Operationoperator: 103
operands: 98
87Literal
88Literal
89Operationoperator: 101
operands: 99
90Operationoperator: 103
operands: 100
91Operationoperator: 101
operands: 102
92Operationoperator: 103
operands: 104
93Literal
94ExprTuple105
95Literal
96Literal
97NamedExprsoperation: 106
part: 109
98ExprTuple121, 111
99NamedExprsstate: 107
part: 109
100ExprTuple121, 136
101Literal
102NamedExprsstate: 108
part: 109
103Literal
104ExprTuple110, 111
105Literal
106Operationoperator: 112
operands: 113
107Operationoperator: 114
operands: 115
108Variable
109Variable
110Operationoperator: 117
operands: 116
111Operationoperator: 117
operands: 118
112Literal
113ExprTuple119, 136
114Literal
115ExprTuple120, 136
116ExprTuple136, 121
117Literal
118ExprTuple136, 122
119Variable
120Operationoperator: 123
operands: 124
121Literal
122Variable
123Literal
124ExprTuple125, 131
125Operationoperator: 126
operand: 128
126Literal
127ExprTuple128
128Operationoperator: 129
operands: 130
129Literal
130ExprTuple131, 132
131Operationoperator: 133
operands: 134
132Variable
133Literal
134ExprTuple135, 136
135Literal
136Variable