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.core_expr_types import Len
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _ket_u, _phase
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Neg(t)
sub_expr3 = frac(one, sqrt(two))
expr = ExprTuple(Len(operands = [ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(Add(sub_expr2, one))), _phase)), ket1))), ExprRange(sub_expr1, ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1))), Add(sub_expr2, two), zero), _ket_u]), Add(t, one))
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(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-\left(-t + 1\right)} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right),\left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-\left(-t + 2\right)} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-\left(-t + 3\right)} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), \ldots, \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), \lvert u \rangle\right)|, t + 1\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
operands: 4
2Operationoperator: 61
operands: 5
3Literal
4ExprTuple6, 7, 8
5ExprTuple69, 65
6Operationoperator: 31
operands: 9
7ExprRangelambda_map: 10
start_index: 11
end_index: 35
8Literal
9ExprTuple18, 12
10Lambdaparameter: 66
body: 13
11Operationoperator: 61
operands: 14
12Operationoperator: 22
operands: 15
13Operationoperator: 31
operands: 16
14ExprTuple64, 59
15ExprTuple26, 17
16ExprTuple18, 19
17Operationoperator: 31
operands: 20
18Operationoperator: 39
operands: 21
19Operationoperator: 22
operands: 23
20ExprTuple24, 37
21ExprTuple65, 25
22Literal
23ExprTuple26, 27
24Operationoperator: 56
operands: 28
25Operationoperator: 56
operands: 29
26Operationoperator: 42
operand: 35
27Operationoperator: 31
operands: 32
28ExprTuple45, 33
29ExprTuple59, 34
30ExprTuple35
31Literal
32ExprTuple36, 37
33Operationoperator: 48
operands: 38
34Operationoperator: 39
operands: 40
35Literal
36Operationoperator: 56
operands: 41
37Operationoperator: 42
operand: 65
38ExprTuple59, 51, 52, 44, 54
39Literal
40ExprTuple65, 59
41ExprTuple45, 46
42Literal
43ExprTuple65
44Operationoperator: 56
operands: 47
45Literal
46Operationoperator: 48
operands: 49
47ExprTuple59, 50
48Literal
49ExprTuple59, 51, 52, 53, 54
50Operationoperator: 67
operand: 58
51Literal
52Literal
53Operationoperator: 56
operands: 57
54Literal
55ExprTuple58
56Literal
57ExprTuple59, 60
58Operationoperator: 61
operands: 62
59Literal
60Operationoperator: 67
operand: 66
61Literal
62ExprTuple64, 65
63ExprTuple66
64Operationoperator: 67
operand: 69
65Literal
66Variable
67Literal
68ExprTuple69
69Variable