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
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase
In [2]:
# build up the expression from sub-expressions
expr = ExprTuple(ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(zero)), _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(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-0} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1Operationoperator: 12
operands: 2
2ExprTuple3, 4
3Operationoperator: 17
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple24, 8
6Literal
7ExprTuple9, 10
8Operationoperator: 31
operands: 11
9Operationoperator: 20
operand: 37
10Operationoperator: 12
operands: 13
11ExprTuple33, 14
12Literal
13ExprTuple15, 16
14Operationoperator: 17
operands: 18
15Operationoperator: 31
operands: 19
16Operationoperator: 20
operand: 24
17Literal
18ExprTuple24, 33
19ExprTuple22, 23
20Literal
21ExprTuple24
22Literal
23Operationoperator: 25
operands: 26
24Literal
25Literal
26ExprTuple33, 27, 28, 29, 30
27Literal
28Literal
29Operationoperator: 31
operands: 32
30Literal
31Literal
32ExprTuple33, 34
33Literal
34Operationoperator: 35
operand: 37
35Literal
36ExprTuple37
37Literal