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 ExprRange, U, Variable, VertExprArray, m
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.logic import Set
from proveit.numbers import Add, Exp, Interval, Mult, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import CONTROL, ket0, ket1, ket_plus, var_ket_u, varphi
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 = Add(m, one)
sub_expr3 = Interval(two, Add(m, two))
expr = VertExprArray([Input(state = ket_plus), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_ket_u, part = sub_expr1), targets = sub_expr3), one, sub_expr2)], [MultiQubitElem(element = CONTROL, targets = Set(two)), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = U, part = sub_expr1), targets = sub_expr3), one, sub_expr2)], [Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, varphi)), ket1)))), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr3), one, sub_expr2)])
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}{ccc} 
 \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{2\right\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U~\mbox{part}~1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U~\mbox{part}~2~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} 
} \end{array} \\
\vdots & \vdots & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~m + 1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U~\mbox{part}~m + 1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~m + 1~\mbox{on}~\{2~\ldotp \ldotp~m + 2\}} 
} \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
2ExprTuple6, 7
3ExprTuple8, 9
4Operationoperator: 41
operands: 10
5ExprRangelambda_map: 11
start_index: 77
end_index: 16
6Operationoperator: 32
operands: 12
7ExprRangelambda_map: 13
start_index: 77
end_index: 16
8Operationoperator: 47
operands: 14
9ExprRangelambda_map: 15
start_index: 77
end_index: 16
10NamedExprsstate: 17
11Lambdaparameter: 56
body: 18
12NamedExprselement: 19
targets: 20
13Lambdaparameter: 56
body: 21
14NamedExprsstate: 22
15Lambdaparameter: 56
body: 24
16Operationoperator: 62
operands: 25
17Operationoperator: 73
operand: 34
18Operationoperator: 32
operands: 27
19Literal
20Operationoperator: 28
operand: 80
21Operationoperator: 32
operands: 30
22Operationoperator: 60
operands: 31
23ExprTuple56
24Operationoperator: 32
operands: 33
25ExprTuple68, 77
26ExprTuple34
27NamedExprselement: 35
targets: 40
28Literal
29ExprTuple80
30NamedExprselement: 36
targets: 40
31ExprTuple37, 38
32Literal
33NamedExprselement: 39
targets: 40
34Literal
35Operationoperator: 41
operands: 48
36Operationoperator: 42
operands: 43
37Operationoperator: 69
operands: 44
38Operationoperator: 45
operands: 46
39Operationoperator: 47
operands: 48
40Operationoperator: 49
operands: 50
41Literal
42Literal
43NamedExprsoperation: 51
part: 56
44ExprTuple77, 52
45Literal
46ExprTuple53, 54
47Literal
48NamedExprsstate: 55
part: 56
49Literal
50ExprTuple80, 57
51Variable
52Operationoperator: 71
operands: 58
53Operationoperator: 73
operand: 65
54Operationoperator: 60
operands: 61
55Variable
56Variable
57Operationoperator: 62
operands: 63
58ExprTuple80, 64
59ExprTuple65
60Literal
61ExprTuple66, 67
62Literal
63ExprTuple68, 80
64Operationoperator: 69
operands: 70
65Literal
66Operationoperator: 71
operands: 72
67Operationoperator: 73
operand: 77
68Variable
69Literal
70ExprTuple77, 80
71Literal
72ExprTuple75, 76
73Literal
74ExprTuple77
75Literal
76Operationoperator: 78
operands: 79
77Literal
78Literal
79ExprTuple80, 81, 82, 83
80Literal
81Literal
82Literal
83Variable