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 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 = NumKet(k, t)
sub_expr3 = Exp(e, Mult(two, pi, i, _phase, k))
sub_expr4 = Interval(zero, subtract(two_pow_t, one))
expr = ExprTuple(VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr3, TensorProd(ket1, sub_expr2)), domain = sub_expr4), TensorProd(ket1, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr3, sub_expr2), domain = 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(\sum_{k=0}^{2^{t} - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \left(\lvert 1 \rangle {\otimes} \lvert k \rangle_{t}\right)\right), \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)
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: 8
operand: 5
2Operationoperator: 18
operands: 4
3ExprTuple5
4ExprTuple24, 6
5Lambdaparameter: 45
body: 7
6Operationoperator: 8
operand: 11
7Conditionalvalue: 10
condition: 17
8Literal
9ExprTuple11
10Operationoperator: 20
operands: 12
11Lambdaparameter: 45
body: 14
12ExprTuple25, 15
13ExprTuple45
14Conditionalvalue: 16
condition: 17
15Operationoperator: 18
operands: 19
16Operationoperator: 20
operands: 21
17Operationoperator: 22
operands: 23
18Literal
19ExprTuple24, 26
20Literal
21ExprTuple25, 26
22Literal
23ExprTuple45, 27
24Operationoperator: 28
operand: 54
25Operationoperator: 48
operands: 29
26Operationoperator: 30
operands: 31
27Operationoperator: 32
operands: 33
28Literal
29ExprTuple34, 35
30Literal
31ExprTuple45, 53
32Literal
33ExprTuple36, 37
34Literal
35Operationoperator: 38
operands: 39
36Literal
37Operationoperator: 40
operands: 41
38Literal
39ExprTuple52, 42, 43, 44, 45
40Literal
41ExprTuple46, 47
42Literal
43Literal
44Literal
45Variable
46Operationoperator: 48
operands: 49
47Operationoperator: 50
operand: 54
48Literal
49ExprTuple52, 53
50Literal
51ExprTuple54
52Literal
53Variable
54Literal