logo

Expression of type ExprRange

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, m, n
from proveit.numbers import Add, Interval, one, subtract
from proveit.physics.quantum.circuits import MultiQubitElem, Output
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 = ExprRange(sub_expr1, ExprRange(sub_expr2, MultiQubitElem(element = Output(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{
& & \qout{A_{1}~\mbox{part}~1~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{1}~\mbox{part}~2~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{1}~\mbox{part}~n_{1}~\mbox{on}~\{N_{1 - 1} + 1~\ldotp \ldotp~N_{1}\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{2}~\mbox{part}~1~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{2}~\mbox{part}~2~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{2}~\mbox{part}~n_{2}~\mbox{on}~\{N_{2 - 1} + 1~\ldotp \ldotp~N_{2}\}} 
} \end{array}, \ldots\ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{m}~\mbox{part}~1~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{m}~\mbox{part}~2~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{m}~\mbox{part}~n_{m}~\mbox{on}~\{N_{m - 1} + 1~\ldotp \ldotp~N_{m}\}} 
} \end{array}
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
parameterization'implicit' (default for LaTeX formatting) hides the parameter the ExprRange so the parameterization may be ambiguous (e.g., x_{1+1}, ..., x_{n+1}); 'explicit' (default for string formatting) reveals the parameterization (e.g. x_{1+1}, ..x_{k+1}.., x_{n+1}).NoneNone/False('with_explicit_parameterization', 'with_implicit_parameterization', 'with_default_parameterization_style')
front_expansionThe number of instances to display at the front of the range (e.g., before the ellipsis). Default is 2.22('with_front_expansion', 'get_front_expansion')
back_expansionThe number of instances to display at the back of the range (e.g., after the ellipsis). Default is 1.11('with_back_expansion', 'get_back_expansion')
orderThe default order is 'increasing' (a_1 ... a_3) but to represent a 'decreasing' ExprRange (a_6 ... a_2) the order must be set to 'decreasing'increasingincreasing('with_decreasing_order', 'with_increasing_order')
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
case_simplifyIf 'True', simplify formatted instances that are ConditionalSets under proper index assumptionsFalseFalse('with_case_simplification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprRangelambda_map: 1
start_index: 34
end_index: 2
1Lambdaparameter: 30
body: 3
2Variable
3ExprRangelambda_map: 4
start_index: 34
end_index: 5
4Lambdaparameter: 18
body: 7
5IndexedVarvariable: 8
index: 30
6ExprTuple18
7Operationoperator: 9
operands: 10
8Variable
9Literal
10NamedExprselement: 11
targets: 12
11Operationoperator: 13
operands: 14
12Operationoperator: 15
operands: 16
13Literal
14NamedExprsstate: 17
part: 18
15Literal
16ExprTuple19, 20
17IndexedVarvariable: 21
index: 30
18Variable
19Operationoperator: 28
operands: 22
20IndexedVarvariable: 25
index: 30
21Variable
22ExprTuple24, 34
23ExprTuple30
24IndexedVarvariable: 25
index: 27
25Variable
26ExprTuple27
27Operationoperator: 28
operands: 29
28Literal
29ExprTuple30, 31
30Variable
31Operationoperator: 32
operand: 34
32Literal
33ExprTuple34
34Literal