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, VecSum
from proveit.numbers import Add, Exp, Interval, Mult, e, i, one, pi, subtract, two, zero
from proveit.physics.quantum import NumKet, ket1
from proveit.physics.quantum.QPE import _phase, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = [k]
sub_expr2 = Exp(e, Mult(two, pi, i, _phase, k))
sub_expr3 = Interval(zero, subtract(two_pow_t, one))
expr = ExprTuple(VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr2, NumKet(k, Add(t, one))), domain = sub_expr3), ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), TensorProd(ket1, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr2, NumKet(k, t)), domain = 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(\sum_{k=0}^{2^{t} - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t + 1}\right), \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)
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: 19
operand: 5
2Operationoperator: 30
operands: 4
3ExprTuple5
4ExprTuple6, 7
5Lambdaparameter: 53
body: 8
6Operationoperator: 56
operands: 9
7Operationoperator: 10
operands: 11
8Conditionalvalue: 12
condition: 28
9ExprTuple42, 13
10Literal
11ExprTuple14, 15
12Operationoperator: 30
operands: 16
13Operationoperator: 46
operands: 17
14Operationoperator: 18
operand: 62
15Operationoperator: 19
operand: 22
16ExprTuple34, 21
17ExprTuple60, 50, 51, 52, 54
18Literal
19Literal
20ExprTuple22
21Operationoperator: 38
operands: 23
22Lambdaparameter: 53
body: 25
23ExprTuple53, 26
24ExprTuple53
25Conditionalvalue: 27
condition: 28
26Operationoperator: 48
operands: 29
27Operationoperator: 30
operands: 31
28Operationoperator: 32
operands: 33
29ExprTuple61, 62
30Literal
31ExprTuple34, 35
32Literal
33ExprTuple53, 36
34Operationoperator: 56
operands: 37
35Operationoperator: 38
operands: 39
36Operationoperator: 40
operands: 41
37ExprTuple42, 43
38Literal
39ExprTuple53, 61
40Literal
41ExprTuple44, 45
42Literal
43Operationoperator: 46
operands: 47
44Literal
45Operationoperator: 48
operands: 49
46Literal
47ExprTuple60, 50, 51, 52, 53
48Literal
49ExprTuple54, 55
50Literal
51Literal
52Literal
53Variable
54Operationoperator: 56
operands: 57
55Operationoperator: 58
operand: 62
56Literal
57ExprTuple60, 61
58Literal
59ExprTuple62
60Literal
61Variable
62Literal