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, m, n
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import QPE, _U, _ket_u, _s, _s_wire, _t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output
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(one, _t)
sub_expr5 = Interval(sub_expr2, sub_expr3)
sub_expr6 = [ExprRange(sub_expr1, Measure(basis = Z), one, _t), _s_wire]
sub_expr7 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = Interval(one, sub_expr3))
sub_expr8 = ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr5), one, _s)
sub_expr9 = [ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr5), one, _s)]
sub_expr10 = [ExprRange(sub_expr1, sub_expr7, one, _t), ExprRange(sub_expr1, sub_expr7, sub_expr2, sub_expr3)]
expr = ExprTuple(VertExprArray(sub_expr9, sub_expr10, sub_expr6, [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, _t), part = sub_expr1), targets = sub_expr4), one, _t), sub_expr8]), VertExprArray(sub_expr9, sub_expr10, sub_expr6, [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(n, _t), part = sub_expr1), targets = sub_expr4), one, _t), sub_expr8]))
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(\left(\begin{array}{cccc} 
 \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert m \rangle_{t}~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert m \rangle_{t}~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array} & \vdots & \begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array} & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert m \rangle_{t}~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\vdots & \vdots & \begin{array}{c}:\\ \left(s - 3\right) \times \\:\end{array} & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\end{array}
\right), \left(\begin{array}{cccc} 
 \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert n \rangle_{t}~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert n \rangle_{t}~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array} & \vdots & \begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array} & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \meter 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert n \rangle_{t}~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\vdots & \vdots & \begin{array}{c}:\\ \left(s - 3\right) \times \\:\end{array} & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array} \\
\end{array}
\right)\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, 2
1ExprTuple4, 5, 6, 3
2ExprTuple4, 5, 6, 7
3ExprTuple8, 16
4ExprTuple9, 10
5ExprTuple11, 12
6ExprTuple13, 14
7ExprTuple15, 16
8ExprRangelambda_map: 17
start_index: 87
end_index: 88
9ExprRangelambda_map: 18
start_index: 87
end_index: 88
10ExprRangelambda_map: 19
start_index: 87
end_index: 89
11ExprRangelambda_map: 20
start_index: 87
end_index: 88
12ExprRangelambda_map: 20
start_index: 74
end_index: 75
13ExprRangelambda_map: 21
start_index: 87
end_index: 88
14ExprRangelambda_map: 22
start_index: 87
end_index: 89
15ExprRangelambda_map: 23
start_index: 87
end_index: 88
16ExprRangelambda_map: 24
start_index: 87
end_index: 89
17Lambdaparameter: 73
body: 25
18Lambdaparameter: 73
body: 26
19Lambdaparameter: 73
body: 27
20Lambdaparameter: 73
body: 28
21Lambdaparameter: 73
body: 29
22Lambdaparameter: 73
body: 30
23Lambdaparameter: 73
body: 31
24Lambdaparameter: 73
body: 33
25Operationoperator: 42
operands: 34
26Operationoperator: 58
operands: 35
27Operationoperator: 42
operands: 36
28Operationoperator: 42
operands: 37
29Operationoperator: 38
operands: 39
30Operationoperator: 59
operands: 40
31Operationoperator: 42
operands: 41
32ExprTuple73
33Operationoperator: 42
operands: 43
34NamedExprselement: 44
targets: 52
35NamedExprsstate: 45
36NamedExprselement: 46
targets: 54
37NamedExprselement: 47
targets: 48
38Literal
39NamedExprsbasis: 49
40NamedExprsoperation: 50
41NamedExprselement: 51
targets: 52
42Literal
43NamedExprselement: 53
targets: 54
44Operationoperator: 64
operands: 55
45Operationoperator: 56
operand: 69
46Operationoperator: 58
operands: 65
47Operationoperator: 59
operands: 60
48Operationoperator: 66
operands: 61
49Literal
50Literal
51Operationoperator: 64
operands: 62
52Operationoperator: 66
operands: 63
53Operationoperator: 64
operands: 65
54Operationoperator: 66
operands: 67
55NamedExprsstate: 68
part: 73
56Literal
57ExprTuple69
58Literal
59Literal
60NamedExprsoperation: 70
part: 73
61ExprTuple87, 75
62NamedExprsstate: 71
part: 73
63ExprTuple87, 88
64Literal
65NamedExprsstate: 72
part: 73
66Literal
67ExprTuple74, 75
68Operationoperator: 79
operands: 76
69Literal
70Operationoperator: 77
operands: 78
71Operationoperator: 79
operands: 80
72Literal
73Variable
74Operationoperator: 82
operands: 81
75Operationoperator: 82
operands: 83
76ExprTuple84, 88
77Literal
78ExprTuple85, 88
79Literal
80ExprTuple86, 88
81ExprTuple88, 87
82Literal
83ExprTuple88, 89
84Variable
85Literal
86Variable
87Literal
88Literal
89Literal