logo

Expression of type ScalarMult

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, Variable, t
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, subtract, 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}")
expr = ScalarMult(frac(one, Exp(two, subtract(frac(Add(t, one), two), frac(t, two)))), TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)), ExprRange(sub_expr1, ScalarMult(frac(one, sqrt(two)), 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())
\frac{1}{2^{\frac{t + 1}{2} - \frac{t}{2}}} \cdot \left(\left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \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
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 46
operands: 1
1ExprTuple2, 3
2Operationoperator: 54
operands: 4
3Operationoperator: 5
operands: 6
4ExprTuple62, 7
5Literal
6ExprTuple8, 9
7Operationoperator: 69
operands: 10
8Operationoperator: 32
operands: 11
9ExprRangelambda_map: 12
start_index: 13
end_index: 50
10ExprTuple71, 14
11ExprTuple38, 15
12Lambdaparameter: 75
body: 16
13Operationoperator: 40
operands: 17
14Operationoperator: 40
operands: 18
15Operationoperator: 46
operands: 19
16Operationoperator: 46
operands: 20
17ExprTuple21, 62
18ExprTuple22, 23
19ExprTuple24, 52
20ExprTuple25, 26
21Operationoperator: 73
operand: 59
22Operationoperator: 54
operands: 28
23Operationoperator: 73
operand: 35
24Operationoperator: 69
operands: 30
25Operationoperator: 54
operands: 31
26Operationoperator: 32
operands: 33
27ExprTuple59
28ExprTuple34, 71
29ExprTuple35
30ExprTuple60, 36
31ExprTuple62, 37
32Literal
33ExprTuple38, 39
34Operationoperator: 40
operands: 41
35Operationoperator: 54
operands: 42
36Operationoperator: 63
operands: 43
37Operationoperator: 69
operands: 44
38Operationoperator: 57
operand: 50
39Operationoperator: 46
operands: 47
40Literal
41ExprTuple59, 62
42ExprTuple59, 71
43ExprTuple71, 65, 66, 68, 48
44ExprTuple71, 49
45ExprTuple50
46Literal
47ExprTuple51, 52
48Operationoperator: 69
operands: 53
49Operationoperator: 54
operands: 55
50Literal
51Operationoperator: 69
operands: 56
52Operationoperator: 57
operand: 62
53ExprTuple71, 59
54Literal
55ExprTuple62, 71
56ExprTuple60, 61
57Literal
58ExprTuple62
59Variable
60Literal
61Operationoperator: 63
operands: 64
62Literal
63Literal
64ExprTuple71, 65, 66, 67, 68
65Literal
66Literal
67Operationoperator: 69
operands: 70
68Literal
69Literal
70ExprTuple71, 72
71Literal
72Operationoperator: 73
operand: 75
73Literal
74ExprTuple75
75Variable