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, Lambda, 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, three, two
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("_b", latex_format = r"{_{-}b}")
sub_expr2 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr3 = frac(one, sqrt(two))
expr = ExprTuple(Len(operands = [Lambda(sub_expr1, ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(Add(Neg(t), one))), _phase)), ket1)))), Lambda(sub_expr2, ScalarMult(sub_expr3, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr2)), _phase)), ket1)))), Lambda(sub_expr1, _ket_u)]), Len(operands = [ExprRange(sub_expr2, sub_expr2, one, three)]))
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({_{-}b} \mapsto \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)\right), {_{-}a} \mapsto \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-{_{-}a}} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)\right), {_{-}b} \mapsto \lvert u \rangle\right)|, |\left(1, 2, \ldots, 3\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
3ExprTuple6, 7, 8
4Literal
5ExprTuple9
6Lambdaparameter: 18
body: 10
7Lambdaparameter: 66
body: 11
8Lambdaparameter: 18
body: 13
9ExprRangelambda_map: 14
start_index: 70
end_index: 15
10Operationoperator: 33
operands: 16
11Operationoperator: 33
operands: 17
12ExprTuple18
13Literal
14Lambdaparameter: 66
body: 66
15Literal
16ExprTuple20, 19
17ExprTuple20, 21
18Variable
19Operationoperator: 24
operands: 22
20Operationoperator: 41
operands: 23
21Operationoperator: 24
operands: 25
22ExprTuple28, 26
23ExprTuple70, 27
24Literal
25ExprTuple28, 29
26Operationoperator: 33
operands: 30
27Operationoperator: 58
operands: 31
28Operationoperator: 44
operand: 37
29Operationoperator: 33
operands: 34
30ExprTuple35, 39
31ExprTuple61, 36
32ExprTuple37
33Literal
34ExprTuple38, 39
35Operationoperator: 58
operands: 40
36Operationoperator: 41
operands: 42
37Literal
38Operationoperator: 58
operands: 43
39Operationoperator: 44
operand: 70
40ExprTuple47, 46
41Literal
42ExprTuple70, 61
43ExprTuple47, 48
44Literal
45ExprTuple70
46Operationoperator: 50
operands: 49
47Literal
48Operationoperator: 50
operands: 51
49ExprTuple61, 53, 54, 52, 56
50Literal
51ExprTuple61, 53, 54, 55, 56
52Operationoperator: 58
operands: 57
53Literal
54Literal
55Operationoperator: 58
operands: 59
56Literal
57ExprTuple61, 60
58Literal
59ExprTuple61, 62
60Operationoperator: 71
operand: 65
61Literal
62Operationoperator: 71
operand: 66
63ExprTuple65
64ExprTuple66
65Operationoperator: 67
operands: 68
66Variable
67Literal
68ExprTuple69, 70
69Operationoperator: 71
operand: 73
70Literal
71Literal
72ExprTuple73
73Variable