logo

Expression of type Equals

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.logic import Equals
from proveit.numbers import Add, Exp, Interval, Mult, e, 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 = [k]
sub_expr2 = Exp(e, Mult(two, pi, i, _phase, k))
sub_expr3 = ScalarMult(sub_expr2, NumKet(k, Add(t, one)))
sub_expr4 = Interval(zero, subtract(two_pow_t, one))
sub_expr5 = VecSum(index_or_indices = sub_expr1, summand = ScalarMult(sub_expr2, NumKet(k, t)), domain = sub_expr4)
sub_expr6 = VecSum(index_or_indices = sub_expr1, summand = sub_expr3, domain = Interval(zero, subtract(Mult(two, two_pow_t), one)))
sub_expr7 = ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), TensorProd(ket1, sub_expr5))
expr = Equals(Equals(sub_expr6, VecAdd(VecSum(index_or_indices = sub_expr1, summand = sub_expr3, domain = sub_expr4), sub_expr7)), Equals(sub_expr6, VecAdd(TensorProd(ket0, sub_expr5), sub_expr7)))
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(\sum_{k=0}^{\left(2 \cdot 2^{t}\right) - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t + 1}\right)\right) = \left(\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 + 1}\right)\right) + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \left(\lvert 1 \rangle {\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)\right)\right)\right) = \left(\left(\sum_{k=0}^{\left(2 \cdot 2^{t}\right) - 1} \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot k} \cdot \lvert k \rangle_{t + 1}\right)\right) = \left(\left(\lvert 0 \rangle {\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) + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \left(\lvert 1 \rangle {\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)\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',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 5
operands: 1
1ExprTuple2, 3
2Operationoperator: 5
operands: 4
3Operationoperator: 5
operands: 6
4ExprTuple8, 7
5Literal
6ExprTuple8, 9
7Operationoperator: 12
operands: 10
8Operationoperator: 42
operand: 15
9Operationoperator: 12
operands: 13
10ExprTuple14, 17
11ExprTuple15
12Literal
13ExprTuple16, 17
14Operationoperator: 42
operand: 22
15Lambdaparameter: 80
body: 19
16Operationoperator: 31
operands: 20
17Operationoperator: 57
operands: 21
18ExprTuple22
19Conditionalvalue: 33
condition: 23
20ExprTuple24, 37
21ExprTuple25, 26
22Lambdaparameter: 80
body: 27
23Operationoperator: 59
operands: 28
24Operationoperator: 41
operand: 71
25Operationoperator: 83
operands: 30
26Operationoperator: 31
operands: 32
27Conditionalvalue: 33
condition: 54
28ExprTuple80, 34
29ExprTuple71
30ExprTuple69, 35
31Literal
32ExprTuple36, 37
33Operationoperator: 57
operands: 38
34Operationoperator: 67
operands: 39
35Operationoperator: 73
operands: 40
36Operationoperator: 41
operand: 89
37Operationoperator: 42
operand: 46
38ExprTuple61, 44
39ExprTuple71, 45
40ExprTuple87, 77, 78, 79, 81
41Literal
42Literal
43ExprTuple46
44Operationoperator: 65
operands: 47
45Operationoperator: 75
operands: 48
46Lambdaparameter: 80
body: 50
47ExprTuple80, 51
48ExprTuple52, 82
49ExprTuple80
50Conditionalvalue: 53
condition: 54
51Operationoperator: 75
operands: 55
52Operationoperator: 73
operands: 56
53Operationoperator: 57
operands: 58
54Operationoperator: 59
operands: 60
55ExprTuple88, 89
56ExprTuple87, 81
57Literal
58ExprTuple61, 62
59Literal
60ExprTuple80, 63
61Operationoperator: 83
operands: 64
62Operationoperator: 65
operands: 66
63Operationoperator: 67
operands: 68
64ExprTuple69, 70
65Literal
66ExprTuple80, 88
67Literal
68ExprTuple71, 72
69Literal
70Operationoperator: 73
operands: 74
71Literal
72Operationoperator: 75
operands: 76
73Literal
74ExprTuple87, 77, 78, 79, 80
75Literal
76ExprTuple81, 82
77Literal
78Literal
79Literal
80Variable
81Operationoperator: 83
operands: 84
82Operationoperator: 85
operand: 89
83Literal
84ExprTuple87, 88
85Literal
86ExprTuple89
87Literal
88Variable
89Literal