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(TensorProd(ket1, VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr3, sub_expr2), domain = sub_expr4)), VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr3, TensorProd(ket1, 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(\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), \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)\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: 22
operands: 3
2Operationoperator: 7
operand: 6
3ExprTuple26, 5
4ExprTuple6
5Operationoperator: 7
operand: 10
6Lambdaparameter: 45
body: 9
7Literal
8ExprTuple10
9Conditionalvalue: 11
condition: 16
10Lambdaparameter: 45
body: 13
11Operationoperator: 18
operands: 14
12ExprTuple45
13Conditionalvalue: 15
condition: 16
14ExprTuple24, 17
15Operationoperator: 18
operands: 19
16Operationoperator: 20
operands: 21
17Operationoperator: 22
operands: 23
18Literal
19ExprTuple24, 27
20Literal
21ExprTuple45, 25
22Literal
23ExprTuple26, 27
24Operationoperator: 48
operands: 28
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operand: 54
27Operationoperator: 32
operands: 33
28ExprTuple34, 35
29Literal
30ExprTuple36, 37
31Literal
32Literal
33ExprTuple45, 53
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