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, 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)
sub_expr2 = frac(one, Exp(two, sub_expr1))
sub_expr3 = frac(one, Exp(two, subtract(frac(Add(t, one), two), sub_expr1)))
sub_expr4 = 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 = Equals(ScalarMult(sub_expr3, ScalarMult(sub_expr2, sub_expr4)), ScalarMult(Mult(sub_expr3, sub_expr2), sub_expr4))
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 \left(\frac{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(\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) = \left(\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)\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: 45
operands: 5
4Operationoperator: 45
operands: 6
5ExprTuple12, 7
6ExprTuple8, 11
7Operationoperator: 45
operands: 9
8Operationoperator: 70
operands: 10
9ExprTuple13, 11
10ExprTuple12, 13
11Operationoperator: 14
operands: 15
12Operationoperator: 64
operands: 16
13Operationoperator: 64
operands: 17
14Literal
15ExprTuple18, 19
16ExprTuple86, 20
17ExprTuple86, 21
18Operationoperator: 22
operands: 23
19Operationoperator: 24
operand: 30
20Operationoperator: 80
operands: 26
21Operationoperator: 80
operands: 27
22Literal
23ExprTuple28, 29
24Literal
25ExprTuple30
26ExprTuple84, 31
27ExprTuple84, 56
28Operationoperator: 44
operand: 68
29Operationoperator: 45
operands: 33
30Lambdaparameter: 77
body: 35
31Operationoperator: 72
operands: 36
32ExprTuple68
33ExprTuple37, 38
34ExprTuple77
35Conditionalvalue: 39
condition: 40
36ExprTuple41, 42
37Operationoperator: 80
operands: 43
38Operationoperator: 44
operand: 86
39Operationoperator: 45
operands: 46
40Operationoperator: 47
operands: 48
41Operationoperator: 64
operands: 49
42Operationoperator: 82
operand: 56
43ExprTuple66, 51
44Literal
45Literal
46ExprTuple52, 53
47Literal
48ExprTuple77, 54
49ExprTuple55, 84
50ExprTuple56
51Operationoperator: 70
operands: 57
52Operationoperator: 80
operands: 58
53Operationoperator: 59
operands: 60
54Operationoperator: 61
operands: 62
55Operationoperator: 72
operands: 63
56Operationoperator: 64
operands: 65
57ExprTuple84, 74, 75, 76, 78
58ExprTuple66, 67
59Literal
60ExprTuple77, 85
61Literal
62ExprTuple68, 69
63ExprTuple85, 86
64Literal
65ExprTuple85, 84
66Literal
67Operationoperator: 70
operands: 71
68Literal
69Operationoperator: 72
operands: 73
70Literal
71ExprTuple84, 74, 75, 76, 77
72Literal
73ExprTuple78, 79
74Literal
75Literal
76Literal
77Variable
78Operationoperator: 80
operands: 81
79Operationoperator: 82
operand: 86
80Literal
81ExprTuple84, 85
82Literal
83ExprTuple86
84Literal
85Variable
86Literal