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, U, Variable, VertExprArray, s, t
from proveit.numbers import Add, Interval, Mult, one
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
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 = ExprTuple(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(Mult(two_pow_t, phase), 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)])))
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}\left(U, t\right)} & \meter & \multiqout{3}{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \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 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert 2^{t} \cdot \varphi \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \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, 7
4ExprTuple8, 9
5ExprTuple10, 11
6ExprTuple12, 13
7ExprTuple14, 15
8ExprRangelambda_map: 16
start_index: 78
end_index: 87
9ExprRangelambda_map: 17
start_index: 78
end_index: 79
10ExprRangelambda_map: 18
start_index: 78
end_index: 87
11ExprRangelambda_map: 18
start_index: 67
end_index: 68
12ExprRangelambda_map: 19
start_index: 78
end_index: 87
13ExprRangelambda_map: 20
start_index: 78
end_index: 79
14ExprRangelambda_map: 21
start_index: 78
end_index: 87
15ExprRangelambda_map: 22
start_index: 78
end_index: 79
16Lambdaparameter: 66
body: 23
17Lambdaparameter: 66
body: 24
18Lambdaparameter: 66
body: 25
19Lambdaparameter: 66
body: 26
20Lambdaparameter: 66
body: 27
21Lambdaparameter: 66
body: 28
22Lambdaparameter: 66
body: 30
23Operationoperator: 52
operands: 31
24Operationoperator: 38
operands: 32
25Operationoperator: 38
operands: 33
26Operationoperator: 34
operands: 35
27Operationoperator: 53
operands: 36
28Operationoperator: 38
operands: 37
29ExprTuple66
30Operationoperator: 38
operands: 39
31NamedExprsstate: 40
32NamedExprselement: 41
targets: 49
33NamedExprselement: 42
targets: 43
34Literal
35NamedExprsbasis: 44
36NamedExprsoperation: 45
37NamedExprselement: 46
targets: 47
38Literal
39NamedExprselement: 48
targets: 49
40Operationoperator: 50
operand: 62
41Operationoperator: 52
operands: 59
42Operationoperator: 53
operands: 54
43Operationoperator: 60
operands: 55
44Literal
45Literal
46Operationoperator: 58
operands: 56
47Operationoperator: 60
operands: 57
48Operationoperator: 58
operands: 59
49Operationoperator: 60
operands: 61
50Literal
51ExprTuple62
52Literal
53Literal
54NamedExprsoperation: 63
part: 66
55ExprTuple78, 68
56NamedExprsstate: 64
part: 66
57ExprTuple78, 87
58Literal
59NamedExprsstate: 65
part: 66
60Literal
61ExprTuple67, 68
62Literal
63Operationoperator: 69
operands: 70
64Operationoperator: 71
operands: 72
65Variable
66Variable
67Operationoperator: 74
operands: 73
68Operationoperator: 74
operands: 75
69Literal
70ExprTuple76, 87
71Literal
72ExprTuple77, 87
73ExprTuple87, 78
74Literal
75ExprTuple87, 79
76Variable
77Operationoperator: 80
operands: 81
78Literal
79Variable
80Literal
81ExprTuple82, 83
82Operationoperator: 84
operands: 85
83Variable
84Literal
85ExprTuple86, 87
86Literal
87Variable