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 B, Function, IndexedVar, Lambda, S, Variable, p
from proveit.logic import InvImage
from proveit.physics.quantum.circuits import MultiQubitElem
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = [Function(p, [Variable("_b", latex_format = r"{_{-}b}")]), sub_expr1]
expr = Lambda(sub_expr1, MultiQubitElem(element = IndexedVar(B, sub_expr2), targets = Function(InvImage(p), [IndexedVar(S, sub_expr2)])))
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())
{_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{B_{p\left({_{-}b}\right), {_{-}a}}~\mbox{on}~p^{\leftarrow}\left(S_{p\left({_{-}b}\right), {_{-}a}}\right)} & \qw 
} \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: 16
body: 2
1ExprTuple16
2Operationoperator: 3
operands: 4
3Literal
4NamedExprselement: 5
targets: 6
5IndexedVarvariable: 7
indices: 14
6Operationoperator: 8
operand: 12
7Variable
8Operationoperator: 10
operand: 17
9ExprTuple12
10Literal
11ExprTuple17
12IndexedVarvariable: 13
indices: 14
13Variable
14ExprTuple15, 16
15Operationoperator: 17
operand: 19
16Variable
17Variable
18ExprTuple19
19Variable