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 ExprTuple, k, t
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd, VecSum
from proveit.numbers import Add, Exp, Interval, Mult, e, frac, i, one, pi, subtract, two, zero
from proveit.physics.quantum import NumKet, ket0, ket1
from proveit.physics.quantum.QPE import _phase, _psi_t_ket, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Add(t, one)
sub_expr2 = frac(sub_expr1, two)
expr = ExprTuple(ScalarMult(frac(one, Exp(two, sub_expr2)), VecSum(index_or_indices = [k], summand = ScalarMult(Exp(e, Mult(two, pi, i, _phase, k)), NumKet(k, sub_expr1)), domain = Interval(zero, subtract(Mult(two, two_pow_t), one)))), TensorProd(ScalarMult(frac(one, Exp(two, subtract(sub_expr2, frac(t, two)))), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1))), _psi_t_ket))
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}}} \cdot \left(\sum_{k=0}^{\left(2 \cdot 2^{t}\right) - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t + 1}\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} \lvert \psi_{t} \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: 36
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8, 9
6Operationoperator: 78
operands: 10
7Operationoperator: 11
operand: 17
8Operationoperator: 36
operands: 13
9Operationoperator: 14
operand: 85
10ExprTuple81, 16
11Literal
12ExprTuple17
13ExprTuple18, 19
14Literal
15ExprTuple85
16Operationoperator: 82
operands: 20
17Lambdaparameter: 64
body: 22
18Operationoperator: 78
operands: 23
19Operationoperator: 24
operands: 25
20ExprTuple84, 55
21ExprTuple64
22Conditionalvalue: 26
condition: 27
23ExprTuple81, 28
24Literal
25ExprTuple29, 30
26Operationoperator: 36
operands: 31
27Operationoperator: 32
operands: 33
28Operationoperator: 82
operands: 34
29Operationoperator: 51
operand: 53
30Operationoperator: 36
operands: 37
31ExprTuple38, 39
32Literal
33ExprTuple64, 40
34ExprTuple84, 41
35ExprTuple53
36Literal
37ExprTuple42, 43
38Operationoperator: 82
operands: 44
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operands: 48
41Operationoperator: 76
operands: 49
42Operationoperator: 82
operands: 50
43Operationoperator: 51
operand: 81
44ExprTuple57, 52
45Literal
46ExprTuple64, 67
47Literal
48ExprTuple53, 54
49ExprTuple55, 56
50ExprTuple57, 58
51Literal
52Operationoperator: 72
operands: 59
53Literal
54Operationoperator: 76
operands: 60
55Operationoperator: 78
operands: 61
56Operationoperator: 74
operand: 68
57Literal
58Operationoperator: 72
operands: 63
59ExprTuple84, 69, 70, 71, 64
60ExprTuple65, 66
61ExprTuple67, 84
62ExprTuple68
63ExprTuple84, 69, 70, 71, 80
64Variable
65Operationoperator: 72
operands: 73
66Operationoperator: 74
operand: 81
67Operationoperator: 76
operands: 77
68Operationoperator: 78
operands: 79
69Literal
70Literal
71Literal
72Literal
73ExprTuple84, 80
74Literal
75ExprTuple81
76Literal
77ExprTuple85, 81
78Literal
79ExprTuple85, 84
80Operationoperator: 82
operands: 83
81Literal
82Literal
83ExprTuple84, 85
84Literal
85Variable