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, sqrt(two))
sub_expr3 = ExprRange(sub_expr1, ScalarMult(sub_expr2, 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(ScalarMult(sub_expr2, TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, two_pow_t, _phase)), ket1)), sub_expr3)), ScalarMult(frac(one, Exp(two, subtract(frac(Add(t, one), two), frac(t, two)))), TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)), 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(\frac{1}{\sqrt{2}} \cdot \left(\left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t} \cdot \varphi} \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), \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: 59
operands: 3
2Operationoperator: 59
operands: 4
3ExprTuple35, 5
4ExprTuple6, 7
5Operationoperator: 10
operands: 8
6Operationoperator: 67
operands: 9
7Operationoperator: 10
operands: 11
8ExprTuple12, 15
9ExprTuple75, 13
10Literal
11ExprTuple14, 15
12Operationoperator: 43
operands: 16
13Operationoperator: 82
operands: 17
14Operationoperator: 43
operands: 18
15ExprRangelambda_map: 19
start_index: 20
end_index: 63
16ExprTuple50, 21
17ExprTuple84, 22
18ExprTuple50, 23
19Lambdaparameter: 88
body: 24
20Operationoperator: 53
operands: 25
21Operationoperator: 59
operands: 26
22Operationoperator: 53
operands: 27
23Operationoperator: 59
operands: 28
24Operationoperator: 59
operands: 29
25ExprTuple30, 75
26ExprTuple31, 65
27ExprTuple32, 33
28ExprTuple34, 65
29ExprTuple35, 36
30Operationoperator: 86
operand: 72
31Operationoperator: 82
operands: 38
32Operationoperator: 67
operands: 39
33Operationoperator: 86
operand: 47
34Operationoperator: 82
operands: 41
35Operationoperator: 67
operands: 42
36Operationoperator: 43
operands: 44
37ExprTuple72
38ExprTuple73, 45
39ExprTuple46, 84
40ExprTuple47
41ExprTuple73, 48
42ExprTuple75, 49
43Literal
44ExprTuple50, 51
45Operationoperator: 76
operands: 52
46Operationoperator: 53
operands: 54
47Operationoperator: 67
operands: 55
48Operationoperator: 76
operands: 56
49Operationoperator: 82
operands: 57
50Operationoperator: 70
operand: 63
51Operationoperator: 59
operands: 60
52ExprTuple84, 78, 79, 61, 81
53Literal
54ExprTuple72, 75
55ExprTuple72, 84
56ExprTuple84, 78, 79, 81, 61
57ExprTuple84, 62
58ExprTuple63
59Literal
60ExprTuple64, 65
61Operationoperator: 82
operands: 66
62Operationoperator: 67
operands: 68
63Literal
64Operationoperator: 82
operands: 69
65Operationoperator: 70
operand: 75
66ExprTuple84, 72
67Literal
68ExprTuple75, 84
69ExprTuple73, 74
70Literal
71ExprTuple75
72Variable
73Literal
74Operationoperator: 76
operands: 77
75Literal
76Literal
77ExprTuple84, 78, 79, 80, 81
78Literal
79Literal
80Operationoperator: 82
operands: 83
81Literal
82Literal
83ExprTuple84, 85
84Literal
85Operationoperator: 86
operand: 88
86Literal
87ExprTuple88
88Variable