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, eps, m, n, s, t
from proveit.logic import And, InSet
from proveit.numbers import Add, Ceil, Exp, Interval, LessEq, Log, ModAbs, Mult, NaturalPos, Neg, frac, greater_eq, one, subtract, 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 ProbOfAll
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(t, Conditional(greater_eq(ProbOfAll(instance_param_or_params = [m], instance_element = 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(m, 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)])), domain = Interval(zero, subtract(two_pow_t, one)), condition = LessEq(ModAbs(subtract(frac(m, two_pow_t), phase), one), Exp(two, Neg(n)))).with_wrapping(), subtract(one, eps)), And(InSet(t, NaturalPos), greater_eq(t, Add(n, Ceil(Log(two, Add(two, frac(one, Mult(two, eps))))))))))
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())
t \mapsto \left\{\left[\begin{array}{l}\textrm{Prob}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}~|~\left|\frac{m}{2^{t}} - \varphi\right|_{\textup{mod}\thinspace 1} \leq 2^{-n}}~\\
\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \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 m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)\end{array}\right] \geq \left(1 - \epsilon\right) \textrm{ if } t \in \mathbb{N}^+ ,  t \geq \left(n + \left\lceil \textrm{log}_2\left(2 + \frac{1}{2 \cdot \epsilon}\right)\right\rceil\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: 154
body: 2
1ExprTuple154
2Conditionalvalue: 3
condition: 4
3Operationoperator: 50
operands: 5
4Operationoperator: 29
operands: 6
5ExprTuple7, 8
6ExprTuple9, 10
7Operationoperator: 142
operands: 11
8Operationoperator: 12
operand: 17
9Operationoperator: 48
operands: 14
10Operationoperator: 50
operands: 15
11ExprTuple149, 16
12Literal
13ExprTuple17
14ExprTuple154, 18
15ExprTuple19, 154
16Operationoperator: 133
operand: 146
17Lambdaparameter: 148
body: 22
18Literal
19Operationoperator: 142
operands: 23
20ExprTuple146
21ExprTuple148
22Conditionalvalue: 24
condition: 25
23ExprTuple121, 26
24Operationoperator: 27
operands: 28
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operand: 39
27Literal
28ExprTuple33, 34, 35, 36
29Literal
30ExprTuple37, 38
31Literal
32ExprTuple39
33ExprTuple40, 41
34ExprTuple42, 43
35ExprTuple44, 45
36ExprTuple46, 47
37Operationoperator: 48
operands: 49
38Operationoperator: 50
operands: 51
39Operationoperator: 52
operands: 53
40ExprRangelambda_map: 54
start_index: 149
end_index: 154
41ExprRangelambda_map: 55
start_index: 149
end_index: 150
42ExprRangelambda_map: 56
start_index: 149
end_index: 154
43ExprRangelambda_map: 56
start_index: 128
end_index: 129
44ExprRangelambda_map: 57
start_index: 149
end_index: 154
45ExprRangelambda_map: 58
start_index: 149
end_index: 150
46ExprRangelambda_map: 59
start_index: 149
end_index: 154
47ExprRangelambda_map: 60
start_index: 149
end_index: 150
48Literal
49ExprTuple148, 61
50Literal
51ExprTuple62, 63
52Literal
53ExprTuple153, 64
54Lambdaparameter: 127
body: 65
55Lambdaparameter: 127
body: 66
56Lambdaparameter: 127
body: 67
57Lambdaparameter: 127
body: 68
58Lambdaparameter: 127
body: 69
59Lambdaparameter: 127
body: 70
60Lambdaparameter: 127
body: 72
61Operationoperator: 116
operands: 73
62Operationoperator: 74
operands: 75
63Operationoperator: 151
operands: 76
64Operationoperator: 142
operands: 77
65Operationoperator: 108
operands: 78
66Operationoperator: 85
operands: 79
67Operationoperator: 85
operands: 80
68Operationoperator: 81
operands: 82
69Operationoperator: 109
operands: 83
70Operationoperator: 85
operands: 84
71ExprTuple127
72Operationoperator: 85
operands: 86
73ExprTuple87, 88
74Literal
75ExprTuple89, 149
76ExprTuple153, 90
77ExprTuple153, 91
78NamedExprsstate: 92
79NamedExprselement: 93
targets: 101
80NamedExprselement: 94
targets: 95
81Literal
82NamedExprsbasis: 96
83NamedExprsoperation: 97
84NamedExprselement: 98
targets: 99
85Literal
86NamedExprselement: 100
targets: 101
87Literal
88Operationoperator: 142
operands: 102
89Operationoperator: 142
operands: 103
90Operationoperator: 133
operand: 121
91Operationoperator: 131
operands: 105
92Operationoperator: 106
operand: 123
93Operationoperator: 108
operands: 115
94Operationoperator: 109
operands: 110
95Operationoperator: 116
operands: 111
96Literal
97Literal
98Operationoperator: 114
operands: 112
99Operationoperator: 116
operands: 113
100Operationoperator: 114
operands: 115
101Operationoperator: 116
operands: 117
102ExprTuple144, 118
103ExprTuple119, 120
104ExprTuple121
105ExprTuple149, 122
106Literal
107ExprTuple123
108Literal
109Literal
110NamedExprsoperation: 124
part: 127
111ExprTuple149, 129
112NamedExprsstate: 125
part: 127
113ExprTuple149, 154
114Literal
115NamedExprsstate: 126
part: 127
116Literal
117ExprTuple128, 129
118Operationoperator: 133
operand: 149
119Operationoperator: 131
operands: 132
120Operationoperator: 133
operand: 145
121Variable
122Operationoperator: 135
operands: 136
123Literal
124Operationoperator: 137
operands: 138
125Operationoperator: 139
operands: 140
126Variable
127Variable
128Operationoperator: 142
operands: 141
129Operationoperator: 142
operands: 143
130ExprTuple149
131Literal
132ExprTuple148, 144
133Literal
134ExprTuple145
135Literal
136ExprTuple153, 146
137Literal
138ExprTuple147, 154
139Literal
140ExprTuple148, 154
141ExprTuple154, 149
142Literal
143ExprTuple154, 150
144Operationoperator: 151
operands: 152
145Variable
146Variable
147Variable
148Variable
149Literal
150Variable
151Literal
152ExprTuple153, 154
153Literal
154Variable