logo

Expression of type ExprTuple

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 ExprTuple, Lambda, Variable, t
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 = ExprTuple(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
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2, 3
1Lambdaparameter: 10
body: 4
2Lambdaparameter: 58
body: 5
3Lambdaparameter: 10
body: 7
4Operationoperator: 25
operands: 8
5Operationoperator: 25
operands: 9
6ExprTuple10
7Literal
8ExprTuple12, 11
9ExprTuple12, 13
10Variable
11Operationoperator: 16
operands: 14
12Operationoperator: 33
operands: 15
13Operationoperator: 16
operands: 17
14ExprTuple20, 18
15ExprTuple62, 19
16Literal
17ExprTuple20, 21
18Operationoperator: 25
operands: 22
19Operationoperator: 50
operands: 23
20Operationoperator: 36
operand: 29
21Operationoperator: 25
operands: 26
22ExprTuple27, 31
23ExprTuple53, 28
24ExprTuple29
25Literal
26ExprTuple30, 31
27Operationoperator: 50
operands: 32
28Operationoperator: 33
operands: 34
29Literal
30Operationoperator: 50
operands: 35
31Operationoperator: 36
operand: 62
32ExprTuple39, 38
33Literal
34ExprTuple62, 53
35ExprTuple39, 40
36Literal
37ExprTuple62
38Operationoperator: 42
operands: 41
39Literal
40Operationoperator: 42
operands: 43
41ExprTuple53, 45, 46, 44, 48
42Literal
43ExprTuple53, 45, 46, 47, 48
44Operationoperator: 50
operands: 49
45Literal
46Literal
47Operationoperator: 50
operands: 51
48Literal
49ExprTuple53, 52
50Literal
51ExprTuple53, 54
52Operationoperator: 63
operand: 57
53Literal
54Operationoperator: 63
operand: 58
55ExprTuple57
56ExprTuple58
57Operationoperator: 59
operands: 60
58Variable
59Literal
60ExprTuple61, 62
61Operationoperator: 63
operand: 65
62Literal
63Literal
64ExprTuple65
65Variable