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, Lambda, Variable, t
from proveit.logic import Equals, NotEquals, Set
from proveit.numbers import Add, 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("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(Variable("_b", latex_format = r"{_{-}b}"), t)
expr = Lambda(sub_expr1, ConditionalSet(Conditional(MultiQubitElem(element = CONTROL, targets = Set(Add(t, one))), Equals(sub_expr2, sub_expr1)), Conditional(Gate(operation = I).with_implicit_representation(), NotEquals(sub_expr2, sub_expr1))))
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 \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) = {_{-}a} \\ \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array} \textrm{ if } \left({_{-}b} + t\right) \neq {_{-}a}\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: 22
body: 2
1ExprTuple22
2Operationoperator: 3
operands: 4
3Literal
4ExprTuple5, 6
5Conditionalvalue: 7
condition: 8
6Conditionalvalue: 9
condition: 10
7Operationoperator: 11
operands: 12
8Operationoperator: 13
operands: 17
9Operationoperator: 14
operands: 15
10Operationoperator: 16
operands: 17
11Literal
12NamedExprselement: 18
targets: 19
13Literal
14Literal
15NamedExprsoperation: 20
16Literal
17ExprTuple21, 22
18Literal
19Operationoperator: 23
operand: 26
20Literal
21Operationoperator: 28
operands: 25
22Variable
23Literal
24ExprTuple26
25ExprTuple27, 30
26Operationoperator: 28
operands: 29
27Variable
28Literal
29ExprTuple30, 31
30Variable
31Literal