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 SubIndexed, _phase, _psi, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
expr = ExprTuple(ScalarMult(frac(one, Exp(two, subtract(frac(sub_expr2, two), frac(t, two)))), TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)), 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())), SubIndexed(_psi, [sub_expr2]))
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}{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), \lvert \psi_{t + 1} \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
1Operationoperator: 50
operands: 3
2Operationoperator: 4
operand: 38
3ExprTuple6, 7
4Literal
5ExprTuple38
6Operationoperator: 58
operands: 8
7Operationoperator: 9
operands: 10
8ExprTuple66, 11
9Literal
10ExprTuple12, 13
11Operationoperator: 73
operands: 14
12Operationoperator: 36
operands: 15
13ExprRangelambda_map: 16
start_index: 17
end_index: 54
14ExprTuple75, 18
15ExprTuple42, 19
16Lambdaparameter: 79
body: 20
17Operationoperator: 44
operands: 21
18Operationoperator: 44
operands: 22
19Operationoperator: 50
operands: 23
20Operationoperator: 50
operands: 24
21ExprTuple25, 66
22ExprTuple26, 27
23ExprTuple28, 56
24ExprTuple29, 30
25Operationoperator: 77
operand: 63
26Operationoperator: 58
operands: 32
27Operationoperator: 77
operand: 39
28Operationoperator: 73
operands: 34
29Operationoperator: 58
operands: 35
30Operationoperator: 36
operands: 37
31ExprTuple63
32ExprTuple38, 75
33ExprTuple39
34ExprTuple64, 40
35ExprTuple66, 41
36Literal
37ExprTuple42, 43
38Operationoperator: 44
operands: 45
39Operationoperator: 58
operands: 46
40Operationoperator: 67
operands: 47
41Operationoperator: 73
operands: 48
42Operationoperator: 61
operand: 54
43Operationoperator: 50
operands: 51
44Literal
45ExprTuple63, 66
46ExprTuple63, 75
47ExprTuple75, 69, 70, 72, 52
48ExprTuple75, 53
49ExprTuple54
50Literal
51ExprTuple55, 56
52Operationoperator: 73
operands: 57
53Operationoperator: 58
operands: 59
54Literal
55Operationoperator: 73
operands: 60
56Operationoperator: 61
operand: 66
57ExprTuple75, 63
58Literal
59ExprTuple66, 75
60ExprTuple64, 65
61Literal
62ExprTuple66
63Variable
64Literal
65Operationoperator: 67
operands: 68
66Literal
67Literal
68ExprTuple75, 69, 70, 71, 72
69Literal
70Literal
71Operationoperator: 73
operands: 74
72Literal
73Literal
74ExprTuple75, 76
75Literal
76Operationoperator: 77
operand: 79
77Literal
78ExprTuple79
79Variable