logo

Expression of type ExprTuple

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 ExprRange, ExprTuple, Variable, VertExprArray, t
from proveit.numbers import Add, Interval, 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
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 = ExprTuple(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)])))
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())
\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)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Operationoperator: 2
operands: 3
2Literal
3ExprTuple4, 5, 6
4ExprTuple7, 8
5ExprTuple9, 10
6ExprTuple11, 12
7ExprRangelambda_map: 13
start_index: 65
end_index: 66
8ExprRangelambda_map: 14
start_index: 65
end_index: 67
9ExprRangelambda_map: 15
start_index: 65
end_index: 66
10ExprRangelambda_map: 15
start_index: 55
end_index: 56
11ExprRangelambda_map: 16
start_index: 65
end_index: 66
12ExprRangelambda_map: 17
start_index: 65
end_index: 67
13Lambdaparameter: 54
body: 18
14Lambdaparameter: 54
body: 19
15Lambdaparameter: 54
body: 20
16Lambdaparameter: 54
body: 21
17Lambdaparameter: 54
body: 23
18Operationoperator: 40
operands: 24
19Operationoperator: 28
operands: 25
20Operationoperator: 28
operands: 26
21Operationoperator: 28
operands: 27
22ExprTuple54
23Operationoperator: 28
operands: 29
24NamedExprsstate: 30
25NamedExprselement: 31
targets: 37
26NamedExprselement: 32
targets: 33
27NamedExprselement: 34
targets: 35
28Literal
29NamedExprselement: 36
targets: 37
30Operationoperator: 38
operand: 50
31Operationoperator: 40
operands: 47
32Operationoperator: 41
operands: 42
33Operationoperator: 48
operands: 43
34Operationoperator: 46
operands: 44
35Operationoperator: 48
operands: 45
36Operationoperator: 46
operands: 47
37Operationoperator: 48
operands: 49
38Literal
39ExprTuple50
40Literal
41Literal
42NamedExprsoperation: 51
part: 54
43ExprTuple65, 56
44NamedExprsstate: 52
part: 54
45ExprTuple65, 66
46Literal
47NamedExprsstate: 53
part: 54
48Literal
49ExprTuple55, 56
50Literal
51Operationoperator: 57
operands: 58
52Operationoperator: 59
operand: 66
53Literal
54Variable
55Operationoperator: 62
operands: 61
56Operationoperator: 62
operands: 63
57Literal
58ExprTuple64, 66
59Literal
60ExprTuple66
61ExprTuple66, 65
62Literal
63ExprTuple66, 67
64Literal
65Literal
66Variable
67Literal