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 k, t
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd, VecSum
from proveit.numbers import Add, Exp, Interval, Mult, e, frac, i, one, pi, subtract, two, zero
from proveit.physics.quantum import NumKet, ket0, ket1
from proveit.physics.quantum.QPE import _phase, two_pow_t
In [2]:
# build up the expression from sub-expressions
sub_expr1 = frac(t, two)
expr = ScalarMult(Mult(frac(one, Exp(two, subtract(frac(Add(t, one), two), sub_expr1))), frac(one, Exp(two, sub_expr1))), TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)), VecSum(index_or_indices = [k], summand = ScalarMult(Exp(e, Mult(two, pi, i, _phase, k)), NumKet(k, t)), domain = Interval(zero, subtract(two_pow_t, one)))))
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}{2^{\frac{t + 1}{2} - \frac{t}{2}}} \cdot \frac{1}{2^{\frac{t}{2}}}\right) \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(\sum_{k=0}^{2^{t} - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t}\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: 36
operands: 1
1ExprTuple2, 3
2Operationoperator: 63
operands: 4
3Operationoperator: 5
operands: 6
4ExprTuple7, 8
5Literal
6ExprTuple9, 10
7Operationoperator: 61
operands: 11
8Operationoperator: 61
operands: 12
9Operationoperator: 13
operands: 14
10Operationoperator: 15
operand: 21
11ExprTuple79, 17
12ExprTuple79, 18
13Literal
14ExprTuple19, 20
15Literal
16ExprTuple21
17Operationoperator: 73
operands: 22
18Operationoperator: 73
operands: 23
19Operationoperator: 35
operand: 58
20Operationoperator: 36
operands: 25
21Lambdaparameter: 70
body: 27
22ExprTuple77, 28
23ExprTuple77, 55
24ExprTuple58
25ExprTuple29, 30
26ExprTuple70
27Conditionalvalue: 31
condition: 32
28Operationoperator: 65
operands: 33
29Operationoperator: 73
operands: 34
30Operationoperator: 35
operand: 79
31Operationoperator: 36
operands: 37
32Operationoperator: 38
operands: 39
33ExprTuple40, 41
34ExprTuple56, 42
35Literal
36Literal
37ExprTuple43, 44
38Literal
39ExprTuple70, 45
40Operationoperator: 61
operands: 46
41Operationoperator: 75
operand: 55
42Operationoperator: 63
operands: 48
43Operationoperator: 73
operands: 49
44Operationoperator: 50
operands: 51
45Operationoperator: 52
operands: 53
46ExprTuple54, 77
47ExprTuple55
48ExprTuple77, 67, 68, 69, 71
49ExprTuple56, 57
50Literal
51ExprTuple70, 78
52Literal
53ExprTuple58, 59
54Operationoperator: 65
operands: 60
55Operationoperator: 61
operands: 62
56Literal
57Operationoperator: 63
operands: 64
58Literal
59Operationoperator: 65
operands: 66
60ExprTuple78, 79
61Literal
62ExprTuple78, 77
63Literal
64ExprTuple77, 67, 68, 69, 70
65Literal
66ExprTuple71, 72
67Literal
68Literal
69Literal
70Variable
71Operationoperator: 73
operands: 74
72Operationoperator: 75
operand: 79
73Literal
74ExprTuple77, 78
75Literal
76ExprTuple79
77Literal
78Variable
79Literal