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 ExprRange, ExprTuple, Variable, t
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
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("_a", latex_format = r"{_{-}a}")
sub_expr2 = Neg(t)
sub_expr3 = Add(sub_expr2, one)
sub_expr4 = frac(one, sqrt(two))
sub_expr5 = ScalarMult(sub_expr4, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))
expr = ExprTuple([ScalarMult(sub_expr4, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr3)), _phase)), ket1))), ExprRange(sub_expr1, sub_expr5, Add(sub_expr2, two), zero).with_decreasing_order(), _ket_u], [ExprRange(sub_expr1, sub_expr5, sub_expr3, zero).with_decreasing_order(), _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(\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),\left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 2} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 3} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \ldots, \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{0} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \lvert u \rangle\right), \left(\left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 1} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 2} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \ldots, \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{0} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \lvert u \rangle\right)\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
1ExprTuple3, 4, 6
2ExprTuple5, 6
3Operationoperator: 29
operands: 7
4ExprRangelambda_map: 9
start_index: 8
end_index: 33
5ExprRangelambda_map: 9
start_index: 56
end_index: 33
6Literal
7ExprTuple16, 10
8Operationoperator: 59
operands: 11
9Lambdaparameter: 64
body: 12
10Operationoperator: 20
operands: 13
11ExprTuple62, 57
12Operationoperator: 29
operands: 14
13ExprTuple24, 15
14ExprTuple16, 17
15Operationoperator: 29
operands: 18
16Operationoperator: 37
operands: 19
17Operationoperator: 20
operands: 21
18ExprTuple22, 35
19ExprTuple63, 23
20Literal
21ExprTuple24, 25
22Operationoperator: 54
operands: 26
23Operationoperator: 54
operands: 27
24Operationoperator: 40
operand: 33
25Operationoperator: 29
operands: 30
26ExprTuple43, 31
27ExprTuple57, 32
28ExprTuple33
29Literal
30ExprTuple34, 35
31Operationoperator: 46
operands: 36
32Operationoperator: 37
operands: 38
33Literal
34Operationoperator: 54
operands: 39
35Operationoperator: 40
operand: 63
36ExprTuple57, 49, 50, 42, 52
37Literal
38ExprTuple63, 57
39ExprTuple43, 44
40Literal
41ExprTuple63
42Operationoperator: 54
operands: 45
43Literal
44Operationoperator: 46
operands: 47
45ExprTuple57, 48
46Literal
47ExprTuple57, 49, 50, 51, 52
48Operationoperator: 65
operand: 56
49Literal
50Literal
51Operationoperator: 54
operands: 55
52Literal
53ExprTuple56
54Literal
55ExprTuple57, 58
56Operationoperator: 59
operands: 60
57Literal
58Operationoperator: 65
operand: 64
59Literal
60ExprTuple62, 63
61ExprTuple64
62Operationoperator: 65
operand: 67
63Literal
64Variable
65Literal
66ExprTuple67
67Variable