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 Conditional, ConditionalSet, ExprRange, IndexedVar, Lambda, U, Variable, m, t
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import CONTROL, I
from proveit.physics.quantum.circuits import Gate, MultiQubitElem
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}")
sub_expr3 = Add(t, one)
expr = Lambda(sub_expr1, [ExprRange(sub_expr2, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr1, sub_expr2)), Conditional(Gate(operation = I).with_implicit_representation(), NotEquals(sub_expr1, sub_expr2))), one, t).with_case_simplification(), ExprRange(sub_expr2, MultiQubitElem(element = Gate(operation = IndexedVar(U, sub_expr1), part = sub_expr2), targets = Interval(sub_expr3, Add(t, m))), 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())
{_{-}b} \mapsto \left(\left\{\begin{array}{ccc}\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array} \textrm{ if } {_{-}b} = 1 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } {_{-}b} \neq 1\end{array}\right.., \left\{\begin{array}{ccc}\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array} \textrm{ if } {_{-}b} = 2 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } {_{-}b} \neq 2\end{array}\right.., \ldots, \left\{\begin{array}{ccc}\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{CONTROL~\mbox{on}~\left\{t + 1\right\}} & \qw 
} \end{array} \textrm{ if } {_{-}b} = t \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } {_{-}b} \neq t\end{array}\right..,\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{{_{-}b}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{{_{-}b}}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U_{{_{-}b}}~\mbox{part}~m~\mbox{on}~\{t + 1~\ldotp \ldotp~t + m\}} & \qw 
} \end{array}\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 41
body: 1
1ExprTuple2, 3
2ExprRangelambda_map: 4
start_index: 47
end_index: 46
3ExprRangelambda_map: 5
start_index: 47
end_index: 42
4Lambdaparameter: 35
body: 6
5Lambdaparameter: 35
body: 8
6Operationoperator: 9
operands: 10
7ExprTuple35
8Operationoperator: 23
operands: 11
9Literal
10ExprTuple12, 13
11NamedExprselement: 14
targets: 15
12Conditionalvalue: 16
condition: 17
13Conditionalvalue: 18
condition: 19
14Operationoperator: 26
operands: 20
15Operationoperator: 21
operands: 22
16Operationoperator: 23
operands: 24
17Operationoperator: 25
operands: 29
18Operationoperator: 26
operands: 27
19Operationoperator: 28
operands: 29
20NamedExprsoperation: 30
part: 35
21Literal
22ExprTuple43, 31
23Literal
24NamedExprselement: 32
targets: 33
25Literal
26Literal
27NamedExprsoperation: 34
28Literal
29ExprTuple41, 35
30IndexedVarvariable: 36
index: 41
31Operationoperator: 44
operands: 38
32Literal
33Operationoperator: 39
operand: 43
34Literal
35Variable
36Variable
37ExprTuple41
38ExprTuple46, 42
39Literal
40ExprTuple43
41Variable
42Variable
43Operationoperator: 44
operands: 45
44Literal
45ExprTuple46, 47
46Variable
47Literal