logo

Expression of type Lambda

from the theory of proveit.physics.quantum.QPE

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, Lambda, U, Variable, s, t
from proveit.linear_algebra import MatrixExp
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, Exp, Interval, Neg, one, two
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)
sub_expr4 = Add(sub_expr1, t)
expr = Lambda(sub_expr1, [ExprRange(sub_expr2, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(sub_expr3)), Equals(sub_expr4, sub_expr2)), Conditional(Gate(operation = I).with_implicit_representation(), NotEquals(sub_expr4, sub_expr2))), one, t).with_case_simplification(), ExprRange(sub_expr2, MultiQubitElem(element = Gate(operation = MatrixExp(U, Exp(two, Neg(sub_expr1))), part = sub_expr2), targets = Interval(sub_expr3, Add(t, s))), one, s)])
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 } \left({_{-}b} + t\right) = 1 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) \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 } \left({_{-}b} + t\right) = 2 \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) \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 } \left({_{-}b} + t\right) = t \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) \neq t\end{array}\right..,\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{-{_{-}b}}}~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{-{_{-}b}}}~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{U^{2^{-{_{-}b}}}~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \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: 57
body: 1
1ExprTuple2, 3
2ExprRangelambda_map: 4
start_index: 54
end_index: 53
3ExprRangelambda_map: 5
start_index: 54
end_index: 45
4Lambdaparameter: 36
body: 6
5Lambdaparameter: 36
body: 8
6Operationoperator: 9
operands: 10
7ExprTuple36
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: 36
21Literal
22ExprTuple46, 31
23Literal
24NamedExprselement: 32
targets: 33
25Literal
26Literal
27NamedExprsoperation: 34
28Literal
29ExprTuple35, 36
30Operationoperator: 37
operands: 38
31Operationoperator: 49
operands: 39
32Literal
33Operationoperator: 40
operand: 46
34Literal
35Operationoperator: 49
operands: 42
36Variable
37Literal
38ExprTuple43, 44
39ExprTuple53, 45
40Literal
41ExprTuple46
42ExprTuple57, 53
43Variable
44Operationoperator: 47
operands: 48
45Variable
46Operationoperator: 49
operands: 50
47Literal
48ExprTuple51, 52
49Literal
50ExprTuple53, 54
51Literal
52Operationoperator: 55
operand: 57
53Variable
54Literal
55Literal
56ExprTuple57
57Variable