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, Variable, VertExprArray, l
from proveit.logic import InSet
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import ModAdd, QPE, _U, _b_floor, _full_domain, _ket_u, _s, _s_wire, _t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
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(l, Conditional(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _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), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(ModAdd(_b_floor, l), _t), part = sub_expr1), targets = Interval(one, _t)), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)])), InSet(l, _full_domain)))
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())
l \mapsto \left\{\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \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 b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array} \textrm{ if } l \in \{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 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: 101
body: 2
1ExprTuple101
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10, 11, 12
7Literal
8ExprTuple101, 13
9ExprTuple14, 15
10ExprTuple16, 17
11ExprTuple18, 19
12ExprTuple20, 21
13Operationoperator: 71
operands: 22
14ExprRangelambda_map: 23
start_index: 104
end_index: 98
15ExprRangelambda_map: 24
start_index: 104
end_index: 93
16ExprRangelambda_map: 25
start_index: 104
end_index: 98
17ExprRangelambda_map: 25
start_index: 79
end_index: 80
18ExprRangelambda_map: 26
start_index: 104
end_index: 98
19ExprRangelambda_map: 27
start_index: 104
end_index: 93
20ExprRangelambda_map: 28
start_index: 104
end_index: 98
21ExprRangelambda_map: 29
start_index: 104
end_index: 93
22ExprTuple30, 73
23Lambdaparameter: 78
body: 31
24Lambdaparameter: 78
body: 32
25Lambdaparameter: 78
body: 33
26Lambdaparameter: 78
body: 34
27Lambdaparameter: 78
body: 35
28Lambdaparameter: 78
body: 36
29Lambdaparameter: 78
body: 38
30Operationoperator: 94
operands: 39
31Operationoperator: 63
operands: 40
32Operationoperator: 47
operands: 41
33Operationoperator: 47
operands: 42
34Operationoperator: 43
operands: 44
35Operationoperator: 64
operands: 45
36Operationoperator: 47
operands: 46
37ExprTuple78
38Operationoperator: 47
operands: 48
39ExprTuple49, 104
40NamedExprsstate: 50
41NamedExprselement: 51
targets: 59
42NamedExprselement: 52
targets: 53
43Literal
44NamedExprsbasis: 54
45NamedExprsoperation: 55
46NamedExprselement: 56
targets: 57
47Literal
48NamedExprselement: 58
targets: 59
49Operationoperator: 102
operand: 73
50Operationoperator: 61
operand: 74
51Operationoperator: 63
operands: 70
52Operationoperator: 64
operands: 65
53Operationoperator: 71
operands: 66
54Literal
55Literal
56Operationoperator: 69
operands: 67
57Operationoperator: 71
operands: 68
58Operationoperator: 69
operands: 70
59Operationoperator: 71
operands: 72
60ExprTuple73
61Literal
62ExprTuple74
63Literal
64Literal
65NamedExprsoperation: 75
part: 78
66ExprTuple104, 80
67NamedExprsstate: 76
part: 78
68ExprTuple104, 98
69Literal
70NamedExprsstate: 77
part: 78
71Literal
72ExprTuple79, 80
73Operationoperator: 81
operands: 82
74Literal
75Operationoperator: 83
operands: 84
76Operationoperator: 85
operands: 86
77Literal
78Variable
79Operationoperator: 94
operands: 87
80Operationoperator: 94
operands: 88
81Literal
82ExprTuple89, 90
83Literal
84ExprTuple91, 98
85Literal
86ExprTuple92, 98
87ExprTuple98, 104
88ExprTuple98, 93
89Literal
90Operationoperator: 94
operands: 95
91Literal
92Operationoperator: 96
operands: 97
93Literal
94Literal
95ExprTuple98, 99
96Literal
97ExprTuple100, 101
98Literal
99Operationoperator: 102
operand: 104
100Literal
101Variable
102Literal
103ExprTuple104
104Literal