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(frac(one, Exp(two, subtract(frac(Add(t, one), two), sub_expr1))), TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)), ScalarMult(frac(one, Exp(two, sub_expr1)), 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())
\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}{2^{\frac{t}{2}}} \cdot \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)\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: 47
operands: 1
1ExprTuple2, 3
2Operationoperator: 45
operands: 4
3Operationoperator: 5
operands: 6
4ExprTuple79, 7
5Literal
6ExprTuple8, 9
7Operationoperator: 73
operands: 10
8Operationoperator: 11
operands: 12
9Operationoperator: 47
operands: 13
10ExprTuple77, 14
11Literal
12ExprTuple15, 16
13ExprTuple17, 18
14Operationoperator: 65
operands: 19
15Operationoperator: 34
operand: 61
16Operationoperator: 47
operands: 21
17Operationoperator: 45
operands: 22
18Operationoperator: 23
operand: 30
19ExprTuple25, 26
20ExprTuple61
21ExprTuple27, 28
22ExprTuple79, 29
23Literal
24ExprTuple30
25Operationoperator: 45
operands: 31
26Operationoperator: 75
operand: 40
27Operationoperator: 73
operands: 33
28Operationoperator: 34
operand: 79
29Operationoperator: 73
operands: 35
30Lambdaparameter: 70
body: 37
31ExprTuple38, 77
32ExprTuple40
33ExprTuple59, 39
34Literal
35ExprTuple77, 40
36ExprTuple70
37Conditionalvalue: 41
condition: 42
38Operationoperator: 65
operands: 43
39Operationoperator: 63
operands: 44
40Operationoperator: 45
operands: 46
41Operationoperator: 47
operands: 48
42Operationoperator: 49
operands: 50
43ExprTuple78, 79
44ExprTuple77, 67, 68, 69, 71
45Literal
46ExprTuple78, 77
47Literal
48ExprTuple51, 52
49Literal
50ExprTuple70, 53
51Operationoperator: 73
operands: 54
52Operationoperator: 55
operands: 56
53Operationoperator: 57
operands: 58
54ExprTuple59, 60
55Literal
56ExprTuple70, 78
57Literal
58ExprTuple61, 62
59Literal
60Operationoperator: 63
operands: 64
61Literal
62Operationoperator: 65
operands: 66
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