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 ExprRange, ExprTuple, Variable, t
from proveit.linear_algebra import MatrixExp, MatrixMult, ScalarMult
from proveit.logic import Equals
from proveit.numbers import Add, Exp, Mult, Neg, e, i, one, pi, two, zero
from proveit.physics.quantum.QPE import _U, _ket_u, _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Exp(two, Neg(sub_expr1))
expr = ExprTuple(ExprRange(sub_expr1, Equals(MatrixMult(MatrixExp(_U, sub_expr2), _ket_u), ScalarMult(Exp(e, Mult(two, pi, i, Mult(sub_expr2, _phase))), _ket_u)), Add(Neg(t), one), zero))
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(\left(\left(U^{2^{-\left(-t + 1\right)}} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \left(2^{-\left(-t + 1\right)} \cdot \varphi\right)} \cdot \lvert u \rangle\right)\right), \left(\left(U^{2^{-\left(-t + 2\right)}} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \left(2^{-\left(-t + 2\right)} \cdot \varphi\right)} \cdot \lvert u \rangle\right)\right), \ldots, \left(\left(U^{2^{-0}} \thinspace \lvert u \rangle\right) = \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \left(2^{-0} \cdot \varphi\right)} \cdot \lvert u \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
1ExprRangelambda_map: 2
start_index: 3
end_index: 4
2Lambdaparameter: 43
body: 5
3Operationoperator: 6
operands: 7
4Literal
5Operationoperator: 8
operands: 9
6Literal
7ExprTuple10, 11
8Literal
9ExprTuple12, 13
10Operationoperator: 41
operand: 19
11Literal
12Operationoperator: 15
operands: 16
13Operationoperator: 17
operands: 18
14ExprTuple19
15Literal
16ExprTuple20, 22
17Literal
18ExprTuple21, 22
19Variable
20Operationoperator: 23
operands: 24
21Operationoperator: 37
operands: 25
22Literal
23Literal
24ExprTuple26, 35
25ExprTuple27, 28
26Literal
27Literal
28Operationoperator: 33
operands: 29
29ExprTuple39, 30, 31, 32
30Literal
31Literal
32Operationoperator: 33
operands: 34
33Literal
34ExprTuple35, 36
35Operationoperator: 37
operands: 38
36Literal
37Literal
38ExprTuple39, 40
39Literal
40Operationoperator: 41
operand: 43
41Literal
42ExprTuple43
43Variable