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 Lambda, Variable
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = Lambda(sub_expr1, ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1))))
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(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-{_{-}a}} \cdot \varphi} \cdot \lvert 1 \rangle\right)\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: 39
body: 1
1Operationoperator: 13
operands: 2
2ExprTuple3, 4
3Operationoperator: 19
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple26, 8
6Literal
7ExprTuple9, 10
8Operationoperator: 33
operands: 11
9Operationoperator: 22
operand: 16
10Operationoperator: 13
operands: 14
11ExprTuple35, 15
12ExprTuple16
13Literal
14ExprTuple17, 18
15Operationoperator: 19
operands: 20
16Literal
17Operationoperator: 33
operands: 21
18Operationoperator: 22
operand: 26
19Literal
20ExprTuple26, 35
21ExprTuple24, 25
22Literal
23ExprTuple26
24Literal
25Operationoperator: 27
operands: 28
26Literal
27Literal
28ExprTuple35, 29, 30, 31, 32
29Literal
30Literal
31Operationoperator: 33
operands: 34
32Literal
33Literal
34ExprTuple35, 36
35Literal
36Operationoperator: 37
operand: 39
37Literal
38ExprTuple39
39Variable