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 = VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1))
sub_expr4 = 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(frac(one, Exp(two, sub_expr2)), TensorProd(sub_expr3, sub_expr4)), TensorProd(ScalarMult(frac(one, Exp(two, subtract(sub_expr2, sub_expr1))), sub_expr3), ScalarMult(frac(one, Exp(two, sub_expr1)), 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(\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), \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(\frac{1}{2^{\frac{t}{2}}} \cdot \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: 45
operands: 3
2Operationoperator: 10
operands: 4
3ExprTuple5, 6
4ExprTuple7, 8
5Operationoperator: 70
operands: 9
6Operationoperator: 10
operands: 11
7Operationoperator: 45
operands: 12
8Operationoperator: 45
operands: 13
9ExprTuple88, 14
10Literal
11ExprTuple16, 18
12ExprTuple15, 16
13ExprTuple17, 18
14Operationoperator: 82
operands: 19
15Operationoperator: 70
operands: 20
16Operationoperator: 21
operands: 22
17Operationoperator: 70
operands: 23
18Operationoperator: 24
operand: 30
19ExprTuple86, 49
20ExprTuple88, 26
21Literal
22ExprTuple27, 28
23ExprTuple88, 29
24Literal
25ExprTuple30
26Operationoperator: 82
operands: 31
27Operationoperator: 44
operand: 67
28Operationoperator: 45
operands: 33
29Operationoperator: 82
operands: 34
30Lambdaparameter: 79
body: 36
31ExprTuple86, 37
32ExprTuple67
33ExprTuple38, 39
34ExprTuple86, 64
35ExprTuple79
36Conditionalvalue: 40
condition: 41
37Operationoperator: 74
operands: 42
38Operationoperator: 82
operands: 43
39Operationoperator: 44
operand: 88
40Operationoperator: 45
operands: 46
41Operationoperator: 47
operands: 48
42ExprTuple49, 50
43ExprTuple65, 51
44Literal
45Literal
46ExprTuple52, 53
47Literal
48ExprTuple79, 54
49Operationoperator: 70
operands: 55
50Operationoperator: 84
operand: 64
51Operationoperator: 72
operands: 57
52Operationoperator: 82
operands: 58
53Operationoperator: 59
operands: 60
54Operationoperator: 61
operands: 62
55ExprTuple63, 86
56ExprTuple64
57ExprTuple86, 76, 77, 78, 80
58ExprTuple65, 66
59Literal
60ExprTuple79, 87
61Literal
62ExprTuple67, 68
63Operationoperator: 74
operands: 69
64Operationoperator: 70
operands: 71
65Literal
66Operationoperator: 72
operands: 73
67Literal
68Operationoperator: 74
operands: 75
69ExprTuple87, 88
70Literal
71ExprTuple87, 86
72Literal
73ExprTuple86, 76, 77, 78, 79
74Literal
75ExprTuple80, 81
76Literal
77Literal
78Literal
79Variable
80Operationoperator: 82
operands: 83
81Operationoperator: 84
operand: 88
82Literal
83ExprTuple86, 87
84Literal
85ExprTuple88
86Literal
87Variable
88Literal