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, TensorProd, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, subtract, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = ScalarMult(frac(one, Exp(two, subtract(frac(Add(t, one), two), frac(t, two)))), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)))
sub_expr3 = ExprRange(sub_expr1, ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1))), Add(Neg(t), one), zero).with_decreasing_order()
expr = ExprTuple(TensorProd(sub_expr2, TensorProd(sub_expr3)), TensorProd(sub_expr2, sub_expr3))
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}{2^{\frac{t + 1}{2} - \frac{t}{2}}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \lvert 1 \rangle\right)\right)\right) {\otimes} \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) {\otimes}  \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) {\otimes}  \ldots {\otimes}  \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)\right), \left(\frac{1}{2^{\frac{t + 1}{2} - \frac{t}{2}}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \lvert 1 \rangle\right)\right)\right){\otimes} \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) {\otimes}  \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) {\otimes}  \ldots {\otimes}  \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)\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
1Operationoperator: 7
operands: 3
2Operationoperator: 7
operands: 4
3ExprTuple6, 5
4ExprTuple6, 10
5Operationoperator: 7
operands: 8
6Operationoperator: 43
operands: 9
7Literal
8ExprTuple10
9ExprTuple11, 12
10ExprRangelambda_map: 13
start_index: 14
end_index: 49
11Operationoperator: 61
operands: 15
12Operationoperator: 31
operands: 16
13Lambdaparameter: 80
body: 17
14Operationoperator: 59
operands: 18
15ExprTuple66, 19
16ExprTuple36, 20
17Operationoperator: 43
operands: 21
18ExprTuple22, 66
19Operationoperator: 74
operands: 23
20Operationoperator: 43
operands: 24
21ExprTuple25, 26
22Operationoperator: 78
operand: 67
23ExprTuple76, 28
24ExprTuple29, 51
25Operationoperator: 61
operands: 30
26Operationoperator: 31
operands: 32
27ExprTuple67
28Operationoperator: 59
operands: 33
29Operationoperator: 74
operands: 34
30ExprTuple66, 35
31Literal
32ExprTuple36, 37
33ExprTuple38, 39
34ExprTuple64, 40
35Operationoperator: 74
operands: 41
36Operationoperator: 57
operand: 49
37Operationoperator: 43
operands: 44
38Operationoperator: 61
operands: 45
39Operationoperator: 78
operand: 53
40Operationoperator: 68
operands: 47
41ExprTuple76, 48
42ExprTuple49
43Literal
44ExprTuple50, 51
45ExprTuple52, 76
46ExprTuple53
47ExprTuple76, 70, 71, 73, 54
48Operationoperator: 61
operands: 55
49Literal
50Operationoperator: 74
operands: 56
51Operationoperator: 57
operand: 66
52Operationoperator: 59
operands: 60
53Operationoperator: 61
operands: 62
54Operationoperator: 74
operands: 63
55ExprTuple66, 76
56ExprTuple64, 65
57Literal
58ExprTuple66
59Literal
60ExprTuple67, 66
61Literal
62ExprTuple67, 76
63ExprTuple76, 67
64Literal
65Operationoperator: 68
operands: 69
66Literal
67Variable
68Literal
69ExprTuple76, 70, 71, 72, 73
70Literal
71Literal
72Operationoperator: 74
operands: 75
73Literal
74Literal
75ExprTuple76, 77
76Literal
77Operationoperator: 78
operand: 80
78Literal
79ExprTuple80
80Variable