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
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 = QPE(U, t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = ExprTuple(Prob(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)]))), 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())
\left(\textrm{Pr}\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), 1\right)
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 81
1Operationoperator: 2
operand: 4
2Literal
3ExprTuple4
4Operationoperator: 5
operands: 6
5Literal
6ExprTuple7, 8, 9, 10
7ExprTuple11, 12
8ExprTuple13, 14
9ExprTuple15, 16
10ExprTuple17, 18
11ExprRangelambda_map: 19
start_index: 81
end_index: 90
12ExprRangelambda_map: 20
start_index: 81
end_index: 82
13ExprRangelambda_map: 21
start_index: 81
end_index: 90
14ExprRangelambda_map: 21
start_index: 70
end_index: 71
15ExprRangelambda_map: 22
start_index: 81
end_index: 90
16ExprRangelambda_map: 23
start_index: 81
end_index: 82
17ExprRangelambda_map: 24
start_index: 81
end_index: 90
18ExprRangelambda_map: 25
start_index: 81
end_index: 82
19Lambdaparameter: 69
body: 26
20Lambdaparameter: 69
body: 27
21Lambdaparameter: 69
body: 28
22Lambdaparameter: 69
body: 29
23Lambdaparameter: 69
body: 30
24Lambdaparameter: 69
body: 31
25Lambdaparameter: 69
body: 33
26Operationoperator: 55
operands: 34
27Operationoperator: 41
operands: 35
28Operationoperator: 41
operands: 36
29Operationoperator: 37
operands: 38
30Operationoperator: 56
operands: 39
31Operationoperator: 41
operands: 40
32ExprTuple69
33Operationoperator: 41
operands: 42
34NamedExprsstate: 43
35NamedExprselement: 44
targets: 52
36NamedExprselement: 45
targets: 46
37Literal
38NamedExprsbasis: 47
39NamedExprsoperation: 48
40NamedExprselement: 49
targets: 50
41Literal
42NamedExprselement: 51
targets: 52
43Operationoperator: 53
operand: 65
44Operationoperator: 55
operands: 62
45Operationoperator: 56
operands: 57
46Operationoperator: 63
operands: 58
47Literal
48Literal
49Operationoperator: 61
operands: 59
50Operationoperator: 63
operands: 60
51Operationoperator: 61
operands: 62
52Operationoperator: 63
operands: 64
53Literal
54ExprTuple65
55Literal
56Literal
57NamedExprsoperation: 66
part: 69
58ExprTuple81, 71
59NamedExprsstate: 67
part: 69
60ExprTuple81, 90
61Literal
62NamedExprsstate: 68
part: 69
63Literal
64ExprTuple70, 71
65Literal
66Operationoperator: 72
operands: 73
67Operationoperator: 74
operands: 75
68Variable
69Variable
70Operationoperator: 77
operands: 76
71Operationoperator: 77
operands: 78
72Literal
73ExprTuple79, 90
74Literal
75ExprTuple80, 90
76ExprTuple90, 81
77Literal
78ExprTuple90, 82
79Variable
80Operationoperator: 83
operands: 84
81Literal
82Variable
83Literal
84ExprTuple85, 86
85Operationoperator: 87
operands: 88
86Variable
87Literal
88ExprTuple89, 90
89Literal
90Variable