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
from proveit.linear_algebra import ScalarMult, VecAdd, VecSum
from proveit.numbers import Exp, Interval, Mult, e, i, one, pi, two, zero
from proveit.physics.quantum import Ket, ket0, ket1
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
expr = ExprTuple(VecSum(index_or_indices = [k], summand = ScalarMult(Exp(e, Mult(two, pi, i, _phase, k)), Ket(k)), domain = Interval(zero, one)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase)), ket1)))
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}^{1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle\right), \lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi} \cdot \lvert 1 \rangle\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: 3
operand: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8, 9
7Lambdaparameter: 44
body: 10
8Operationoperator: 29
operand: 36
9Operationoperator: 17
operands: 12
10Conditionalvalue: 13
condition: 14
11ExprTuple36
12ExprTuple15, 16
13Operationoperator: 17
operands: 18
14Operationoperator: 19
operands: 20
15Operationoperator: 27
operands: 21
16Operationoperator: 29
operand: 37
17Literal
18ExprTuple23, 24
19Literal
20ExprTuple44, 25
21ExprTuple34, 26
22ExprTuple37
23Operationoperator: 27
operands: 28
24Operationoperator: 29
operand: 44
25Operationoperator: 31
operands: 32
26Operationoperator: 38
operands: 33
27Literal
28ExprTuple34, 35
29Literal
30ExprTuple44
31Literal
32ExprTuple36, 37
33ExprTuple40, 41, 42, 43
34Literal
35Operationoperator: 38
operands: 39
36Literal
37Literal
38Literal
39ExprTuple40, 41, 42, 43, 44
40Literal
41Literal
42Literal
43Literal
44Variable