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, Lambda, k
from proveit.linear_algebra import ScalarMult
from proveit.logic import Equals, InSet
from proveit.numbers import Add, Exp, Interval, Mult, e, i, one, pi, two, zero
from proveit.physics.quantum import Ket
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = ScalarMult(Exp(e, Mult(two, pi, i, _phase, k)), Ket(k))
expr = Lambda(k, Equals(Conditional(sub_expr1, InSet(k, Interval(Add(zero, one), one))), Conditional(sub_expr1, InSet(k, Interval(one, one)))))
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())
k \mapsto \left(\left\{\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle \textrm{ if } k \in \{0 + 1~\ldotp \ldotp~1\}\right.. = \left\{\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle \textrm{ if } k \in \{1~\ldotp \ldotp~1\}\right..\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Lambdaparameter: 38
body: 1
1Operationoperator: 2
operands: 3
2Literal
3ExprTuple4, 5
4Conditionalvalue: 7
condition: 6
5Conditionalvalue: 7
condition: 8
6Operationoperator: 12
operands: 9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operands: 13
9ExprTuple38, 14
10Literal
11ExprTuple15, 16
12Literal
13ExprTuple38, 17
14Operationoperator: 23
operands: 18
15Operationoperator: 19
operands: 20
16Operationoperator: 21
operand: 38
17Operationoperator: 23
operands: 24
18ExprTuple25, 33
19Literal
20ExprTuple26, 27
21Literal
22ExprTuple38
23Literal
24ExprTuple33, 33
25Operationoperator: 28
operands: 29
26Literal
27Operationoperator: 30
operands: 31
28Literal
29ExprTuple32, 33
30Literal
31ExprTuple34, 35, 36, 37, 38
32Literal
33Literal
34Literal
35Literal
36Literal
37Literal
38Variable