logo

Expression of type Len

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, t
from proveit.core_expr_types import Len
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _ket_u, _phase
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 = frac(one, sqrt(two))
expr = Len(operands = [Lambda(sub_expr1, ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(Add(Neg(t), one))), _phase)), ket1)))), Lambda(sub_expr2, ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr2)), _phase)), ket1)))), Lambda(sub_expr1, _ket_u)])
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())
|\left({_{-}b} \mapsto \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-\left(-t + 1\right)} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), {_{-}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), {_{-}b} \mapsto \lvert u \rangle\right)|
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4, 5
3Lambdaparameter: 12
body: 6
4Lambdaparameter: 60
body: 7
5Lambdaparameter: 12
body: 9
6Operationoperator: 27
operands: 10
7Operationoperator: 27
operands: 11
8ExprTuple12
9Literal
10ExprTuple14, 13
11ExprTuple14, 15
12Variable
13Operationoperator: 18
operands: 16
14Operationoperator: 35
operands: 17
15Operationoperator: 18
operands: 19
16ExprTuple22, 20
17ExprTuple64, 21
18Literal
19ExprTuple22, 23
20Operationoperator: 27
operands: 24
21Operationoperator: 52
operands: 25
22Operationoperator: 38
operand: 31
23Operationoperator: 27
operands: 28
24ExprTuple29, 33
25ExprTuple55, 30
26ExprTuple31
27Literal
28ExprTuple32, 33
29Operationoperator: 52
operands: 34
30Operationoperator: 35
operands: 36
31Literal
32Operationoperator: 52
operands: 37
33Operationoperator: 38
operand: 64
34ExprTuple41, 40
35Literal
36ExprTuple64, 55
37ExprTuple41, 42
38Literal
39ExprTuple64
40Operationoperator: 44
operands: 43
41Literal
42Operationoperator: 44
operands: 45
43ExprTuple55, 47, 48, 46, 50
44Literal
45ExprTuple55, 47, 48, 49, 50
46Operationoperator: 52
operands: 51
47Literal
48Literal
49Operationoperator: 52
operands: 53
50Literal
51ExprTuple55, 54
52Literal
53ExprTuple55, 56
54Operationoperator: 65
operand: 59
55Literal
56Operationoperator: 65
operand: 60
57ExprTuple59
58ExprTuple60
59Operationoperator: 61
operands: 62
60Variable
61Literal
62ExprTuple63, 64
63Operationoperator: 65
operand: 67
64Literal
65Literal
66ExprTuple67
67Variable