logo

Expression of type Qcircuit

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, N, Variable, VertExprArray, m, n
from proveit.numbers import Add, Interval, one, subtract
from proveit.physics.quantum.circuits import Input, MultiQubitElem, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_b", latex_format = r"{_{-}b}")
sub_expr2 = Variable("_a", latex_format = r"{_{-}a}")
expr = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, ExprRange(sub_expr2, MultiQubitElem(element = Input(state = IndexedVar(A, sub_expr1), part = sub_expr2), targets = Interval(Add(IndexedVar(N, subtract(sub_expr1, one)), one), IndexedVar(N, sub_expr1))), one, IndexedVar(n, sub_expr1)).with_wrapping_at(2,6), 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}{c} \Qcircuit@C=1em @R=.7em{
\qin{A_{1}~\mbox{part}~1~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} & \qw \\
\qin{A_{1}~\mbox{part}~2~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{1}~\mbox{part}~n_{1}~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} & \qw \\
\qin{A_{2}~\mbox{part}~1~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} & \qw \\
\qin{A_{2}~\mbox{part}~2~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{2}~\mbox{part}~n_{2}~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} & \qw \\
\qin{\begin{array}{c}\vdots\\ \vdots\end{array}} & \qw \\
\qin{A_{m}~\mbox{part}~1~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{A_{m}~\mbox{part}~2~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} & \qw \\
\qin{\vdots} & \qw \\
\qin{A_{m}~\mbox{part}~n_{m}~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} & \qw
} \end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
spacingchange the spacing of a circuit using the format '@C=1em @R=.7em' where C is the column spacing and R is the row spacing@C=1em @R=.7em@C=1em @R=.7em
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operand: 3
1Literal
2ExprTuple3
3ExprTuple4
4ExprRangelambda_map: 5
start_index: 38
end_index: 6
5Lambdaparameter: 34
body: 7
6Variable
7ExprRangelambda_map: 8
start_index: 38
end_index: 9
8Lambdaparameter: 22
body: 11
9IndexedVarvariable: 12
index: 34
10ExprTuple22
11Operationoperator: 13
operands: 14
12Variable
13Literal
14NamedExprselement: 15
targets: 16
15Operationoperator: 17
operands: 18
16Operationoperator: 19
operands: 20
17Literal
18NamedExprsstate: 21
part: 22
19Literal
20ExprTuple23, 24
21IndexedVarvariable: 25
index: 34
22Variable
23Operationoperator: 32
operands: 26
24IndexedVarvariable: 29
index: 34
25Variable
26ExprTuple28, 38
27ExprTuple34
28IndexedVarvariable: 29
index: 31
29Variable
30ExprTuple31
31Operationoperator: 32
operands: 33
32Literal
33ExprTuple34, 35
34Variable
35Operationoperator: 36
operand: 38
36Literal
37ExprTuple38
38Literal