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 Conditional, ConditionalSet, ExprRange, IndexedVar, U, Variable, VertExprArray, m, t
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Exp, Interval, Mult, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import CONTROL, I, 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 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr3 = Add(t, one)
sub_expr4 = Interval(sub_expr3, Add(t, m))
expr = 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, m)], ExprRange(sub_expr2, [ExprRange(sub_expr1, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr2, sub_expr1)), Conditional(Gate(operation = I).with_implicit_representation(), NotEquals(sub_expr2, sub_expr1))), one, t).with_case_simplification(), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = IndexedVar(U, sub_expr2), part = sub_expr1), targets = sub_expr4), one, m)], one, t).with_case_simplification(), [ExprRange(sub_expr1, Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, IndexedVar(varphi, sub_expr1))), ket1)))), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, 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 + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \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{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{1}} \cdot \lvert 1 \rangle\right)\right)} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \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{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi_{2}} \cdot \lvert 1 \rangle\right)\right)} 
} \end{array} \\
\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array} & \vdots & \vdots & \ddots & \vdots & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \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{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\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_{t}} \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}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{1}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{2}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{t}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \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 + m\}} 
} \end{array} \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{1}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{2}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{t}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \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 + m\}} 
} \end{array} \\
\vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\
\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~m~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{1}~\mbox{part}~m~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{2}~\mbox{part}~m~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \cdots & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{t}~\mbox{part}~m~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array} & \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~m~\mbox{on}~\{t + 1~\ldotp \ldotp~t + 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: 100
end_index: 99
3ExprTuple7, 8
4ExprRangelambda_map: 9
start_index: 100
end_index: 99
5ExprRangelambda_map: 10
start_index: 100
end_index: 83
6Lambdaparameter: 82
body: 11
7ExprRangelambda_map: 12
start_index: 100
end_index: 99
8ExprRangelambda_map: 13
start_index: 100
end_index: 83
9Lambdaparameter: 109
body: 14
10Lambdaparameter: 109
body: 15
11ExprTuple16, 17
12Lambdaparameter: 109
body: 18
13Lambdaparameter: 109
body: 19
14Operationoperator: 33
operands: 20
15Operationoperator: 58
operands: 21
16ExprRangelambda_map: 22
start_index: 100
end_index: 99
17ExprRangelambda_map: 23
start_index: 100
end_index: 83
18Operationoperator: 38
operands: 24
19Operationoperator: 58
operands: 25
20NamedExprsstate: 26
21NamedExprselement: 27
targets: 44
22Lambdaparameter: 109
body: 28
23Lambdaparameter: 109
body: 29
24NamedExprsstate: 30
25NamedExprselement: 31
targets: 44
26Operationoperator: 93
operand: 40
27Operationoperator: 33
operands: 39
28Operationoperator: 34
operands: 35
29Operationoperator: 58
operands: 36
30Operationoperator: 78
operands: 37
31Operationoperator: 38
operands: 39
32ExprTuple40
33Literal
34Literal
35ExprTuple41, 42
36NamedExprselement: 43
targets: 44
37ExprTuple45, 46
38Literal
39NamedExprsstate: 47
part: 109
40Literal
41Conditionalvalue: 48
condition: 49
42Conditionalvalue: 50
condition: 51
43Operationoperator: 61
operands: 52
44Operationoperator: 53
operands: 54
45Operationoperator: 89
operands: 55
46Operationoperator: 56
operands: 57
47Variable
48Operationoperator: 58
operands: 59
49Operationoperator: 60
operands: 64
50Operationoperator: 61
operands: 62
51Operationoperator: 63
operands: 64
52NamedExprsoperation: 65
part: 109
53Literal
54ExprTuple88, 66
55ExprTuple100, 67
56Literal
57ExprTuple68, 69
58Literal
59NamedExprselement: 70
targets: 71
60Literal
61Literal
62NamedExprsoperation: 72
63Literal
64ExprTuple82, 109
65IndexedVarvariable: 73
index: 82
66Operationoperator: 95
operands: 75
67Operationoperator: 91
operands: 76
68Operationoperator: 93
operand: 85
69Operationoperator: 78
operands: 79
70Literal
71Operationoperator: 80
operand: 88
72Literal
73Variable
74ExprTuple82
75ExprTuple99, 83
76ExprTuple103, 84
77ExprTuple85
78Literal
79ExprTuple86, 87
80Literal
81ExprTuple88
82Variable
83Variable
84Operationoperator: 89
operands: 90
85Literal
86Operationoperator: 91
operands: 92
87Operationoperator: 93
operand: 100
88Operationoperator: 95
operands: 96
89Literal
90ExprTuple100, 103
91Literal
92ExprTuple97, 98
93Literal
94ExprTuple100
95Literal
96ExprTuple99, 100
97Literal
98Operationoperator: 101
operands: 102
99Variable
100Literal
101Literal
102ExprTuple103, 104, 105, 106
103Literal
104Literal
105Literal
106IndexedVarvariable: 107
index: 109
107Variable
108ExprTuple109
109Variable