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, TensorProd, 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, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = frac(one, sqrt(two))
expr = ExprTuple(sub_expr2, TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, two_pow_t, _phase)), ket1)), ExprRange(sub_expr1, ScalarMult(sub_expr2, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1))), Add(Neg(t), one), 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}}, \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right){\otimes} \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t - 1} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right) {\otimes}  \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) {\otimes}  \ldots {\otimes}  \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
0ExprTuple17, 1
1Operationoperator: 2
operands: 3
2Literal
3ExprTuple4, 5
4Operationoperator: 22
operands: 6
5ExprRangelambda_map: 7
start_index: 8
end_index: 35
6ExprTuple26, 9
7Lambdaparameter: 60
body: 10
8Operationoperator: 11
operands: 12
9Operationoperator: 31
operands: 13
10Operationoperator: 31
operands: 14
11Literal
12ExprTuple15, 47
13ExprTuple16, 37
14ExprTuple17, 18
15Operationoperator: 58
operand: 44
16Operationoperator: 54
operands: 20
17Operationoperator: 39
operands: 21
18Operationoperator: 22
operands: 23
19ExprTuple44
20ExprTuple45, 24
21ExprTuple47, 25
22Literal
23ExprTuple26, 27
24Operationoperator: 48
operands: 28
25Operationoperator: 54
operands: 29
26Operationoperator: 42
operand: 35
27Operationoperator: 31
operands: 32
28ExprTuple56, 50, 51, 33, 53
29ExprTuple56, 34
30ExprTuple35
31Literal
32ExprTuple36, 37
33Operationoperator: 54
operands: 38
34Operationoperator: 39
operands: 40
35Literal
36Operationoperator: 54
operands: 41
37Operationoperator: 42
operand: 47
38ExprTuple56, 44
39Literal
40ExprTuple47, 56
41ExprTuple45, 46
42Literal
43ExprTuple47
44Variable
45Literal
46Operationoperator: 48
operands: 49
47Literal
48Literal
49ExprTuple56, 50, 51, 52, 53
50Literal
51Literal
52Operationoperator: 54
operands: 55
53Literal
54Literal
55ExprTuple56, 57
56Literal
57Operationoperator: 58
operand: 60
58Literal
59ExprTuple60
60Variable