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, 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(Len(operands = [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())]), Len(operands = [ExprRange(sub_expr1, sub_expr1, one, two)]))
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}}, \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)|, |\left(1, \ldots, 2\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: 4
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple24, 6
4Literal
5ExprTuple7
6Operationoperator: 8
operands: 9
7ExprRangelambda_map: 10
start_index: 54
end_index: 63
8Literal
9ExprTuple11, 12
10Lambdaparameter: 67
body: 67
11Operationoperator: 29
operands: 13
12ExprRangelambda_map: 14
start_index: 15
end_index: 42
13ExprTuple33, 16
14Lambdaparameter: 67
body: 17
15Operationoperator: 18
operands: 19
16Operationoperator: 38
operands: 20
17Operationoperator: 38
operands: 21
18Literal
19ExprTuple22, 54
20ExprTuple23, 44
21ExprTuple24, 25
22Operationoperator: 65
operand: 51
23Operationoperator: 61
operands: 27
24Operationoperator: 46
operands: 28
25Operationoperator: 29
operands: 30
26ExprTuple51
27ExprTuple52, 31
28ExprTuple54, 32
29Literal
30ExprTuple33, 34
31Operationoperator: 55
operands: 35
32Operationoperator: 61
operands: 36
33Operationoperator: 49
operand: 42
34Operationoperator: 38
operands: 39
35ExprTuple63, 57, 58, 40, 60
36ExprTuple63, 41
37ExprTuple42
38Literal
39ExprTuple43, 44
40Operationoperator: 61
operands: 45
41Operationoperator: 46
operands: 47
42Literal
43Operationoperator: 61
operands: 48
44Operationoperator: 49
operand: 54
45ExprTuple63, 51
46Literal
47ExprTuple54, 63
48ExprTuple52, 53
49Literal
50ExprTuple54
51Variable
52Literal
53Operationoperator: 55
operands: 56
54Literal
55Literal
56ExprTuple63, 57, 58, 59, 60
57Literal
58Literal
59Operationoperator: 61
operands: 62
60Literal
61Literal
62ExprTuple63, 64
63Literal
64Operationoperator: 65
operand: 67
65Literal
66ExprTuple67
67Variable