logo

Expression of type VertExprArray

from the theory of proveit.physics.quantum.circuits

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 A, ExprRange, IndexedVar, Variable, VertExprArray, k, l, m
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import I, var_ket_psi, var_ket_u, var_ket_v
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr3 = Interval(one, l)
sub_expr4 = Interval(Add(l, one), Add(l, m))
expr = VertExprArray([ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr3), one, l), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_psi, part = sub_expr1), targets = sub_expr4), one, m)], ExprRange(sub_expr2, [ExprRange(sub_expr1, IndexedVar(A, [sub_expr2, sub_expr1]), one, l), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, m)], one, k), [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_v, part = sub_expr1), targets = sub_expr3), one, l), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_psi, part = sub_expr1), targets = sub_expr4), one, m)])
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())
\begin{array}{cccccc} 
 \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~l\}} & \qw 
} \end{array} & A_{1, 1} & A_{2, 1} & \cdots & A_{k, 1} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert v \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~l\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~l\}} & \qw 
} \end{array} & A_{1, 2} & A_{2, 2} & \cdots & A_{k, 2} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert v \rangle~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~l\}} 
} \end{array} \\
\vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~l~\mbox{on}~\{1~\ldotp \ldotp~l\}} & \qw 
} \end{array} & A_{1, l} & A_{2, l} & \cdots & A_{k, l} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert v \rangle~\mbox{part}~l~\mbox{on}~\{1~\ldotp \ldotp~l\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi \rangle~\mbox{part}~1~\mbox{on}~\{l + 1~\ldotp \ldotp~l + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi \rangle~\mbox{part}~1~\mbox{on}~\{l + 1~\ldotp \ldotp~l + m\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi \rangle~\mbox{part}~2~\mbox{on}~\{l + 1~\ldotp \ldotp~l + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi \rangle~\mbox{part}~2~\mbox{on}~\{l + 1~\ldotp \ldotp~l + m\}} 
} \end{array} \\
\vdots & \begin{array}{c}:\\ \left(m - 3\right) \times \\:\end{array} & \begin{array}{c}:\\ \left(m - 3\right) \times \\:\end{array} & \ddots & \begin{array}{c}:\\ \left(m - 3\right) \times \\:\end{array} & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi \rangle~\mbox{part}~m~\mbox{on}~\{l + 1~\ldotp \ldotp~l + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi \rangle~\mbox{part}~m~\mbox{on}~\{l + 1~\ldotp \ldotp~l + m\}} 
} \end{array} \\
\end{array}

In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
justificationjustify to the 'left', 'center', or 'right' in the array cellscentercenterwith_justification
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2, 3
1ExprTuple4, 5
2ExprRangelambda_map: 6
start_index: 61
end_index: 7
3ExprTuple8, 9
4ExprRangelambda_map: 10
start_index: 61
end_index: 62
5ExprRangelambda_map: 11
start_index: 61
end_index: 63
6Lambdaparameter: 51
body: 13
7Variable
8ExprRangelambda_map: 14
start_index: 61
end_index: 62
9ExprRangelambda_map: 15
start_index: 61
end_index: 63
10Lambdaparameter: 55
body: 16
11Lambdaparameter: 55
body: 17
12ExprTuple51
13ExprTuple18, 19
14Lambdaparameter: 55
body: 20
15Lambdaparameter: 55
body: 21
16Operationoperator: 27
operands: 22
17Operationoperator: 27
operands: 23
18ExprRangelambda_map: 24
start_index: 61
end_index: 62
19ExprRangelambda_map: 25
start_index: 61
end_index: 63
20Operationoperator: 27
operands: 26
21Operationoperator: 27
operands: 28
22NamedExprselement: 29
targets: 35
23NamedExprselement: 30
targets: 37
24Lambdaparameter: 55
body: 31
25Lambdaparameter: 55
body: 33
26NamedExprselement: 34
targets: 35
27Literal
28NamedExprselement: 36
targets: 37
29Operationoperator: 39
operands: 38
30Operationoperator: 39
operands: 47
31IndexedVarvariable: 40
indices: 41
32ExprTuple55
33Operationoperator: 42
operands: 43
34Operationoperator: 46
operands: 44
35Operationoperator: 48
operands: 45
36Operationoperator: 46
operands: 47
37Operationoperator: 48
operands: 49
38NamedExprsstate: 50
part: 55
39Literal
40Variable
41ExprTuple51, 55
42Literal
43NamedExprsoperation: 52
44NamedExprsstate: 53
part: 55
45ExprTuple61, 62
46Literal
47NamedExprsstate: 54
part: 55
48Literal
49ExprTuple56, 57
50Variable
51Variable
52Literal
53Variable
54Variable
55Variable
56Operationoperator: 59
operands: 58
57Operationoperator: 59
operands: 60
58ExprTuple62, 61
59Literal
60ExprTuple62, 63
61Literal
62Variable
63Variable