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 ExprRange, Variable, k, t
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd, VecSum
from proveit.logic import Equals
from proveit.numbers import Add, Exp, Interval, Mult, Neg, e, frac, i, one, pi, sqrt, 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 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, one)
sub_expr3 = frac(sub_expr2, two)
expr = Equals(ScalarMult(frac(one, Exp(two, sub_expr3)), VecSum(index_or_indices = [k], summand = ScalarMult(Exp(e, Mult(two, pi, i, _phase, k)), NumKet(k, sub_expr2)), domain = Interval(zero, subtract(Mult(two, two_pow_t), one)))), ScalarMult(frac(one, Exp(two, subtract(sub_expr3, 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())
\left(\frac{1}{2^{\frac{t + 1}{2}}} \cdot \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)\right) = \left(\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)\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: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 78
operands: 5
4Operationoperator: 78
operands: 6
5ExprTuple7, 8
6ExprTuple9, 10
7Operationoperator: 88
operands: 11
8Operationoperator: 12
operand: 18
9Operationoperator: 88
operands: 14
10Operationoperator: 15
operands: 16
11ExprTuple96, 17
12Literal
13ExprTuple18
14ExprTuple96, 19
15Literal
16ExprTuple20, 21
17Operationoperator: 105
operands: 22
18Lambdaparameter: 80
body: 24
19Operationoperator: 105
operands: 25
20Operationoperator: 60
operands: 26
21ExprRangelambda_map: 27
start_index: 28
end_index: 84
22ExprTuple107, 45
23ExprTuple80
24Conditionalvalue: 29
condition: 30
25ExprTuple107, 31
26ExprTuple68, 32
27Lambdaparameter: 111
body: 33
28Operationoperator: 72
operands: 34
29Operationoperator: 78
operands: 35
30Operationoperator: 36
operands: 37
31Operationoperator: 72
operands: 38
32Operationoperator: 78
operands: 39
33Operationoperator: 78
operands: 40
34ExprTuple41, 96
35ExprTuple42, 43
36Literal
37ExprTuple80, 44
38ExprTuple45, 46
39ExprTuple47, 86
40ExprTuple48, 49
41Operationoperator: 109
operand: 100
42Operationoperator: 105
operands: 51
43Operationoperator: 52
operands: 53
44Operationoperator: 54
operands: 55
45Operationoperator: 88
operands: 56
46Operationoperator: 109
operand: 65
47Operationoperator: 105
operands: 58
48Operationoperator: 88
operands: 59
49Operationoperator: 60
operands: 61
50ExprTuple100
51ExprTuple94, 62
52Literal
53ExprTuple80, 64
54Literal
55ExprTuple84, 63
56ExprTuple64, 107
57ExprTuple65
58ExprTuple94, 66
59ExprTuple96, 67
60Literal
61ExprTuple68, 69
62Operationoperator: 98
operands: 70
63Operationoperator: 72
operands: 71
64Operationoperator: 72
operands: 73
65Operationoperator: 88
operands: 74
66Operationoperator: 98
operands: 75
67Operationoperator: 105
operands: 76
68Operationoperator: 91
operand: 84
69Operationoperator: 78
operands: 79
70ExprTuple107, 101, 102, 104, 80
71ExprTuple81, 82
72Literal
73ExprTuple100, 96
74ExprTuple100, 107
75ExprTuple107, 101, 102, 104, 93
76ExprTuple107, 83
77ExprTuple84
78Literal
79ExprTuple85, 86
80Variable
81Operationoperator: 98
operands: 87
82Operationoperator: 109
operand: 96
83Operationoperator: 88
operands: 89
84Literal
85Operationoperator: 105
operands: 90
86Operationoperator: 91
operand: 96
87ExprTuple107, 93
88Literal
89ExprTuple96, 107
90ExprTuple94, 95
91Literal
92ExprTuple96
93Operationoperator: 105
operands: 97
94Literal
95Operationoperator: 98
operands: 99
96Literal
97ExprTuple107, 100
98Literal
99ExprTuple107, 101, 102, 103, 104
100Variable
101Literal
102Literal
103Operationoperator: 105
operands: 106
104Literal
105Literal
106ExprTuple107, 108
107Literal
108Operationoperator: 109
operand: 111
109Literal
110ExprTuple111
111Variable