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, t
from proveit.logic import Equals, InSet
from proveit.numbers import Add, Interval, NaturalPos, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE1, _U, _ket_u, _psi_t_ket, _s
from proveit.physics.quantum.circuits import Gate, Input, 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 = QPE1(_U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Lambda(t, Conditional(Equals(Prob(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, MultiQubitElem(element = Output(state = _psi_t_ket, 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)]))), one), InSet(t, NaturalPos)))
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\{\textrm{Pr}\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}_1\left(U, t\right)} & \multiqout{3}{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \ghostqout{\lvert \psi_{t} \rangle} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}_1\left(U, t\right)} & \qout{\lvert u \rangle}
} \end{array}\right) = 1 \textrm{ if } t \in \mathbb{N}^+\right..
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 77
body: 1
1Conditionalvalue: 2
condition: 3
2Operationoperator: 4
operands: 5
3Operationoperator: 6
operands: 7
4Literal
5ExprTuple8, 76
6Literal
7ExprTuple77, 9
8Operationoperator: 10
operand: 12
9Literal
10Literal
11ExprTuple12
12Operationoperator: 13
operands: 14
13Literal
14ExprTuple15, 16, 17
15ExprTuple18, 19
16ExprTuple20, 21
17ExprTuple22, 23
18ExprRangelambda_map: 24
start_index: 76
end_index: 77
19ExprRangelambda_map: 25
start_index: 76
end_index: 78
20ExprRangelambda_map: 26
start_index: 76
end_index: 77
21ExprRangelambda_map: 26
start_index: 66
end_index: 67
22ExprRangelambda_map: 27
start_index: 76
end_index: 77
23ExprRangelambda_map: 28
start_index: 76
end_index: 78
24Lambdaparameter: 65
body: 29
25Lambdaparameter: 65
body: 30
26Lambdaparameter: 65
body: 31
27Lambdaparameter: 65
body: 32
28Lambdaparameter: 65
body: 34
29Operationoperator: 51
operands: 35
30Operationoperator: 39
operands: 36
31Operationoperator: 39
operands: 37
32Operationoperator: 39
operands: 38
33ExprTuple65
34Operationoperator: 39
operands: 40
35NamedExprsstate: 41
36NamedExprselement: 42
targets: 48
37NamedExprselement: 43
targets: 44
38NamedExprselement: 45
targets: 46
39Literal
40NamedExprselement: 47
targets: 48
41Operationoperator: 49
operand: 61
42Operationoperator: 51
operands: 58
43Operationoperator: 52
operands: 53
44Operationoperator: 59
operands: 54
45Operationoperator: 57
operands: 55
46Operationoperator: 59
operands: 56
47Operationoperator: 57
operands: 58
48Operationoperator: 59
operands: 60
49Literal
50ExprTuple61
51Literal
52Literal
53NamedExprsoperation: 62
part: 65
54ExprTuple76, 67
55NamedExprsstate: 63
part: 65
56ExprTuple76, 77
57Literal
58NamedExprsstate: 64
part: 65
59Literal
60ExprTuple66, 67
61Literal
62Operationoperator: 68
operands: 69
63Operationoperator: 70
operand: 77
64Literal
65Variable
66Operationoperator: 73
operands: 72
67Operationoperator: 73
operands: 74
68Literal
69ExprTuple75, 77
70Literal
71ExprTuple77
72ExprTuple77, 76
73Literal
74ExprTuple77, 78
75Literal
76Literal
77Variable
78Literal