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(one, Exp(two, sub_expr1))
sub_expr3 = frac(one, Exp(two, subtract(frac(Add(t, one), two), sub_expr1)))
sub_expr4 = VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1))
sub_expr5 = 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_expr3, TensorProd(sub_expr4, ScalarMult(sub_expr2, sub_expr5))), ScalarMult(sub_expr3, ScalarMult(sub_expr2, TensorProd(sub_expr4, sub_expr5))))
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}{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), \frac{1}{2^{\frac{t + 1}{2} - \frac{t}{2}}} \cdot \left(\frac{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(\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)
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: 52
operands: 3
2Operationoperator: 52
operands: 4
3ExprTuple6, 5
4ExprTuple6, 7
5Operationoperator: 16
operands: 8
6Operationoperator: 48
operands: 9
7Operationoperator: 52
operands: 10
8ExprTuple20, 11
9ExprTuple86, 12
10ExprTuple18, 13
11Operationoperator: 52
operands: 14
12Operationoperator: 80
operands: 15
13Operationoperator: 16
operands: 17
14ExprTuple18, 21
15ExprTuple84, 19
16Literal
17ExprTuple20, 21
18Operationoperator: 48
operands: 22
19Operationoperator: 72
operands: 23
20Operationoperator: 24
operands: 25
21Operationoperator: 26
operand: 33
22ExprTuple86, 28
23ExprTuple29, 30
24Literal
25ExprTuple31, 32
26Literal
27ExprTuple33
28Operationoperator: 80
operands: 34
29Operationoperator: 48
operands: 35
30Operationoperator: 82
operand: 42
31Operationoperator: 51
operand: 68
32Operationoperator: 52
operands: 38
33Lambdaparameter: 77
body: 40
34ExprTuple84, 42
35ExprTuple41, 84
36ExprTuple42
37ExprTuple68
38ExprTuple43, 44
39ExprTuple77
40Conditionalvalue: 45
condition: 46
41Operationoperator: 72
operands: 47
42Operationoperator: 48
operands: 49
43Operationoperator: 80
operands: 50
44Operationoperator: 51
operand: 86
45Operationoperator: 52
operands: 53
46Operationoperator: 54
operands: 55
47ExprTuple85, 86
48Literal
49ExprTuple85, 84
50ExprTuple66, 56
51Literal
52Literal
53ExprTuple57, 58
54Literal
55ExprTuple77, 59
56Operationoperator: 70
operands: 60
57Operationoperator: 80
operands: 61
58Operationoperator: 62
operands: 63
59Operationoperator: 64
operands: 65
60ExprTuple84, 74, 75, 76, 78
61ExprTuple66, 67
62Literal
63ExprTuple77, 85
64Literal
65ExprTuple68, 69
66Literal
67Operationoperator: 70
operands: 71
68Literal
69Operationoperator: 72
operands: 73
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