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, Literal, Variable, VertExprArray, m
from proveit.logic import InSet
from proveit.numbers import Add, Exp, Interval, one, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import QPE
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(Literal("t", theory = "proveit.physics.quantum.QPE"), one)
sub_expr3 = Add(Literal("t", theory = "proveit.physics.quantum.QPE"), Literal("s", theory = "proveit.physics.quantum.QPE"))
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(Literal("U", theory = "proveit.physics.quantum.QPE"), Literal("t", theory = "proveit.physics.quantum.QPE")), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Lambda(m, Conditional(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, sub_expr5, one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, Literal("s", theory = "proveit.physics.quantum.QPE"))], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, Literal("t", theory = "proveit.physics.quantum.QPE")), part = sub_expr1), targets = Interval(one, Literal("t", theory = "proveit.physics.quantum.QPE"))), one, Literal("t", theory = "proveit.physics.quantum.QPE")), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = Literal("|u>", latex_format = r"\lvert u \rangle", theory = "proveit.physics.quantum.QPE"), part = sub_expr1), targets = sub_expr4), one, Literal("s", theory = "proveit.physics.quantum.QPE"))])), InSet(m, Interval(zero, subtract(Exp(two, Literal("t", theory = "proveit.physics.quantum.QPE")), one)))))
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())
m \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 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} \textrm{ if } m \in \{0~\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: 94
body: 2
1ExprTuple94
2Conditionalvalue: 3
condition: 4
3Operationoperator: 5
operands: 6
4Operationoperator: 7
operands: 8
5Literal
6ExprTuple9, 10, 11, 12
7Literal
8ExprTuple94, 13
9ExprTuple14, 15
10ExprTuple16, 17
11ExprTuple18, 19
12ExprTuple20, 21
13Operationoperator: 76
operands: 22
14ExprRangelambda_map: 23
start_index: 95
end_index: 96
15ExprRangelambda_map: 24
start_index: 95
end_index: 97
16ExprRangelambda_map: 25
start_index: 95
end_index: 96
17ExprRangelambda_map: 25
start_index: 84
end_index: 85
18ExprRangelambda_map: 26
start_index: 95
end_index: 96
19ExprRangelambda_map: 27
start_index: 95
end_index: 97
20ExprRangelambda_map: 28
start_index: 95
end_index: 96
21ExprRangelambda_map: 29
start_index: 95
end_index: 97
22ExprTuple30, 31
23Lambdaparameter: 83
body: 32
24Lambdaparameter: 83
body: 33
25Lambdaparameter: 83
body: 34
26Lambdaparameter: 83
body: 35
27Lambdaparameter: 83
body: 36
28Lambdaparameter: 83
body: 37
29Lambdaparameter: 83
body: 39
30Literal
31Operationoperator: 91
operands: 40
32Operationoperator: 68
operands: 41
33Operationoperator: 48
operands: 42
34Operationoperator: 48
operands: 43
35Operationoperator: 44
operands: 45
36Operationoperator: 69
operands: 46
37Operationoperator: 48
operands: 47
38ExprTuple83
39Operationoperator: 48
operands: 49
40ExprTuple50, 51
41NamedExprsstate: 52
42NamedExprselement: 53
targets: 61
43NamedExprselement: 54
targets: 55
44Literal
45NamedExprsbasis: 56
46NamedExprsoperation: 57
47NamedExprselement: 58
targets: 59
48Literal
49NamedExprselement: 60
targets: 61
50Operationoperator: 62
operands: 63
51Operationoperator: 64
operand: 95
52Operationoperator: 66
operand: 79
53Operationoperator: 68
operands: 75
54Operationoperator: 69
operands: 70
55Operationoperator: 76
operands: 71
56Literal
57Literal
58Operationoperator: 74
operands: 72
59Operationoperator: 76
operands: 73
60Operationoperator: 74
operands: 75
61Operationoperator: 76
operands: 77
62Literal
63ExprTuple78, 96
64Literal
65ExprTuple95
66Literal
67ExprTuple79
68Literal
69Literal
70NamedExprsoperation: 80
part: 83
71ExprTuple95, 85
72NamedExprsstate: 81
part: 83
73ExprTuple95, 96
74Literal
75NamedExprsstate: 82
part: 83
76Literal
77ExprTuple84, 85
78Literal
79Literal
80Operationoperator: 86
operands: 87
81Operationoperator: 88
operands: 89
82Literal
83Variable
84Operationoperator: 91
operands: 90
85Operationoperator: 91
operands: 92
86Literal
87ExprTuple93, 96
88Literal
89ExprTuple94, 96
90ExprTuple96, 95
91Literal
92ExprTuple96, 97
93Literal
94Variable
95Literal
96Literal
97Literal