logo

Expression of type Lambda

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, Lambda, N, Variable, 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 = Lambda(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))
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())
{_{-}b} \mapsto \begin{array}{l} \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{{_{-}b}}~\mbox{part}~1~\mbox{on}~\{N_{{_{-}b} - 1} + 1~\ldotp \ldotp~N_{{_{-}b}}\}} 
} \end{array},  \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{{_{-}b}}~\mbox{part}~2~\mbox{on}~\{N_{{_{-}b} - 1} + 1~\ldotp \ldotp~N_{{_{-}b}}\}} 
} \end{array}, \ldots,  \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{A_{{_{-}b}}~\mbox{part}~n_{{_{-}b}}~\mbox{on}~\{N_{{_{-}b} - 1} + 1~\ldotp \ldotp~N_{{_{-}b}}\}} 
} \end{array} \end{array}
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 28
body: 1
1ExprRangelambda_map: 2
start_index: 32
end_index: 3
2Lambdaparameter: 16
body: 5
3IndexedVarvariable: 6
index: 28
4ExprTuple16
5Operationoperator: 7
operands: 8
6Variable
7Literal
8NamedExprselement: 9
targets: 10
9Operationoperator: 11
operands: 12
10Operationoperator: 13
operands: 14
11Literal
12NamedExprsstate: 15
part: 16
13Literal
14ExprTuple17, 18
15IndexedVarvariable: 19
index: 28
16Variable
17Operationoperator: 26
operands: 20
18IndexedVarvariable: 23
index: 28
19Variable
20ExprTuple22, 32
21ExprTuple28
22IndexedVarvariable: 23
index: 25
23Variable
24ExprTuple25
25Operationoperator: 26
operands: 27
26Literal
27ExprTuple28, 29
28Variable
29Operationoperator: 30
operand: 32
30Literal
31ExprTuple32
32Literal