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 = frac(one, Exp(two, subtract(frac(Add(t, one), two), frac(t, two))))
sub_expr3 = VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1))
sub_expr4 = 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(ScalarMult(sub_expr2, sub_expr3), TensorProd(sub_expr4)), ScalarMult(sub_expr2, TensorProd(sub_expr3, sub_expr4)))
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), \frac{1}{2^{\frac{t + 1}{2} - \frac{t}{2}}} \cdot \left(\left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \lvert 1 \rangle\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)\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: 10
operands: 3
2Operationoperator: 48
operands: 4
3ExprTuple5, 6
4ExprTuple12, 7
5Operationoperator: 48
operands: 8
6Operationoperator: 10
operands: 9
7Operationoperator: 10
operands: 11
8ExprTuple12, 13
9ExprTuple14
10Literal
11ExprTuple13, 14
12Operationoperator: 61
operands: 15
13Operationoperator: 35
operands: 16
14ExprRangelambda_map: 17
start_index: 18
end_index: 54
15ExprTuple69, 19
16ExprTuple41, 20
17Lambdaparameter: 82
body: 21
18Operationoperator: 57
operands: 22
19Operationoperator: 76
operands: 23
20Operationoperator: 48
operands: 24
21Operationoperator: 48
operands: 25
22ExprTuple26, 69
23ExprTuple78, 27
24ExprTuple28, 56
25ExprTuple29, 30
26Operationoperator: 80
operand: 66
27Operationoperator: 57
operands: 32
28Operationoperator: 76
operands: 33
29Operationoperator: 61
operands: 34
30Operationoperator: 35
operands: 36
31ExprTuple66
32ExprTuple37, 38
33ExprTuple67, 39
34ExprTuple69, 40
35Literal
36ExprTuple41, 42
37Operationoperator: 61
operands: 43
38Operationoperator: 80
operand: 51
39Operationoperator: 70
operands: 45
40Operationoperator: 76
operands: 46
41Operationoperator: 64
operand: 54
42Operationoperator: 48
operands: 49
43ExprTuple50, 78
44ExprTuple51
45ExprTuple78, 72, 73, 75, 52
46ExprTuple78, 53
47ExprTuple54
48Literal
49ExprTuple55, 56
50Operationoperator: 57
operands: 58
51Operationoperator: 61
operands: 59
52Operationoperator: 76
operands: 60
53Operationoperator: 61
operands: 62
54Literal
55Operationoperator: 76
operands: 63
56Operationoperator: 64
operand: 69
57Literal
58ExprTuple66, 69
59ExprTuple66, 78
60ExprTuple78, 66
61Literal
62ExprTuple69, 78
63ExprTuple67, 68
64Literal
65ExprTuple69
66Variable
67Literal
68Operationoperator: 70
operands: 71
69Literal
70Literal
71ExprTuple78, 72, 73, 74, 75
72Literal
73Literal
74Operationoperator: 76
operands: 77
75Literal
76Literal
77ExprTuple78, 79
78Literal
79Operationoperator: 80
operand: 82
80Literal
81ExprTuple82
82Variable