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 ExprRange, IndexedVar, Lambda, N, Variable
from proveit.core_expr_types import A_1_to_m
from proveit.linear_algebra import TensorProd
from proveit.numbers import Add, Interval, one, subtract
from proveit.physics.quantum.circuits import Input, MultiQubitElem, N_m
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_c", latex_format = r"{_{-}c}")
sub_expr2 = Variable("_b", latex_format = r"{_{-}b}")
expr = Lambda(sub_expr1, ExprRange(sub_expr2, MultiQubitElem(element = Input(state = TensorProd(A_1_to_m), part = sub_expr2), targets = Interval(one, N_m)), Add(IndexedVar(N, subtract(sub_expr1, one)), 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())
{_{-}c} \mapsto \begin{array}{l} \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{{_{-}c} - 1} + 1~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw 
} \end{array},  \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{{_{-}c} - 1} + 2~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw 
} \end{array}, \ldots,  \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{A_{1} {\otimes}  A_{2} {\otimes}  \ldots {\otimes}  A_{m}~\mbox{part}~N_{{_{-}c}}~\mbox{on}~\{1~\ldotp \ldotp~N_{m}\}} & \qw 
} \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: 29
body: 1
1ExprRangelambda_map: 2
start_index: 3
end_index: 4
2Lambdaparameter: 21
body: 6
3Operationoperator: 23
operands: 7
4IndexedVarvariable: 27
index: 29
5ExprTuple21
6Operationoperator: 9
operands: 10
7ExprTuple11, 36
8ExprTuple29
9Literal
10NamedExprselement: 12
targets: 13
11IndexedVarvariable: 27
index: 19
12Operationoperator: 15
operands: 16
13Operationoperator: 17
operands: 18
14ExprTuple19
15Literal
16NamedExprsstate: 20
part: 21
17Literal
18ExprTuple36, 22
19Operationoperator: 23
operands: 24
20Operationoperator: 25
operands: 26
21Variable
22IndexedVarvariable: 27
index: 35
23Literal
24ExprTuple29, 30
25Literal
26ExprTuple31
27Variable
28ExprTuple35
29Variable
30Operationoperator: 32
operand: 36
31ExprRangelambda_map: 34
start_index: 36
end_index: 35
32Literal
33ExprTuple36
34Lambdaparameter: 40
body: 37
35Variable
36Literal
37IndexedVarvariable: 38
index: 40
38Variable
39ExprTuple40
40Variable