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