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 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 _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(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).with_decreasing_order())
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^{-\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^{t - 2} \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^{t - 3} \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)\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: 25
operands: 3
2ExprRangelambda_map: 4
start_index: 5
end_index: 29
3ExprTuple12, 6
4Lambdaparameter: 60
body: 7
5Operationoperator: 55
operands: 8
6Operationoperator: 16
operands: 9
7Operationoperator: 25
operands: 10
8ExprTuple58, 53
9ExprTuple20, 11
10ExprTuple12, 13
11Operationoperator: 25
operands: 14
12Operationoperator: 33
operands: 15
13Operationoperator: 16
operands: 17
14ExprTuple18, 31
15ExprTuple59, 19
16Literal
17ExprTuple20, 21
18Operationoperator: 50
operands: 22
19Operationoperator: 50
operands: 23
20Operationoperator: 36
operand: 29
21Operationoperator: 25
operands: 26
22ExprTuple39, 27
23ExprTuple53, 28
24ExprTuple29
25Literal
26ExprTuple30, 31
27Operationoperator: 42
operands: 32
28Operationoperator: 33
operands: 34
29Literal
30Operationoperator: 50
operands: 35
31Operationoperator: 36
operand: 59
32ExprTuple53, 45, 46, 38, 48
33Literal
34ExprTuple59, 53
35ExprTuple39, 40
36Literal
37ExprTuple59
38Operationoperator: 50
operands: 41
39Literal
40Operationoperator: 42
operands: 43
41ExprTuple53, 44
42Literal
43ExprTuple53, 45, 46, 47, 48
44Operationoperator: 61
operand: 52
45Literal
46Literal
47Operationoperator: 50
operands: 51
48Literal
49ExprTuple52
50Literal
51ExprTuple53, 54
52Operationoperator: 55
operands: 56
53Literal
54Operationoperator: 61
operand: 60
55Literal
56ExprTuple58, 59
57ExprTuple60
58Operationoperator: 61
operand: 63
59Literal
60Variable
61Literal
62ExprTuple63
63Variable