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 = Exp(e, Mult(two, pi, i, _phase, two_pow_t))
sub_expr2 = frac(one, Exp(two, frac(Add(t, one), two)))
sub_expr3 = 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(sub_expr2, VecAdd(TensorProd(ket0, sub_expr3), ScalarMult(sub_expr1, TensorProd(ket1, sub_expr3)))), ScalarMult(sub_expr2, TensorProd(VecAdd(ket0, ScalarMult(sub_expr1, 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}{2^{\frac{t + 1}{2}}} \cdot \left(\left(\lvert 0 \rangle {\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(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \left(\lvert 1 \rangle {\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)\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: 46
operands: 3
2Operationoperator: 46
operands: 4
3ExprTuple6, 5
4ExprTuple6, 7
5Operationoperator: 18
operands: 8
6Operationoperator: 26
operands: 9
7Operationoperator: 24
operands: 10
8ExprTuple11, 12
9ExprTuple78, 13
10ExprTuple14, 30
11Operationoperator: 24
operands: 15
12Operationoperator: 46
operands: 16
13Operationoperator: 72
operands: 17
14Operationoperator: 18
operands: 19
15ExprTuple22, 30
16ExprTuple32, 20
17ExprTuple76, 21
18Literal
19ExprTuple22, 23
20Operationoperator: 24
operands: 25
21Operationoperator: 26
operands: 27
22Operationoperator: 38
operand: 60
23Operationoperator: 46
operands: 29
24Literal
25ExprTuple33, 30
26Literal
27ExprTuple31, 76
28ExprTuple60
29ExprTuple32, 33
30Operationoperator: 34
operand: 39
31Operationoperator: 64
operands: 36
32Operationoperator: 72
operands: 37
33Operationoperator: 38
operand: 78
34Literal
35ExprTuple39
36ExprTuple77, 78
37ExprTuple58, 40
38Literal
39Lambdaparameter: 69
body: 42
40Operationoperator: 62
operands: 43
41ExprTuple69
42Conditionalvalue: 44
condition: 45
43ExprTuple76, 66, 67, 68, 70
44Operationoperator: 46
operands: 47
45Operationoperator: 48
operands: 49
46Literal
47ExprTuple50, 51
48Literal
49ExprTuple69, 52
50Operationoperator: 72
operands: 53
51Operationoperator: 54
operands: 55
52Operationoperator: 56
operands: 57
53ExprTuple58, 59
54Literal
55ExprTuple69, 77
56Literal
57ExprTuple60, 61
58Literal
59Operationoperator: 62
operands: 63
60Literal
61Operationoperator: 64
operands: 65
62Literal
63ExprTuple76, 66, 67, 68, 69
64Literal
65ExprTuple70, 71
66Literal
67Literal
68Literal
69Variable
70Operationoperator: 72
operands: 73
71Operationoperator: 74
operand: 78
72Literal
73ExprTuple76, 77
74Literal
75ExprTuple78
76Literal
77Variable
78Literal