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 = VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1))
sub_expr5 = 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, TensorProd(sub_expr4, ScalarMult(sub_expr2, sub_expr5))), ScalarMult(sub_expr3, ScalarMult(sub_expr2, TensorProd(sub_expr4, sub_expr5))))
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(\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)\right) = \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)
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: 54
operands: 5
4Operationoperator: 54
operands: 6
5ExprTuple8, 7
6ExprTuple8, 9
7Operationoperator: 18
operands: 10
8Operationoperator: 50
operands: 11
9Operationoperator: 54
operands: 12
10ExprTuple22, 13
11ExprTuple88, 14
12ExprTuple20, 15
13Operationoperator: 54
operands: 16
14Operationoperator: 82
operands: 17
15Operationoperator: 18
operands: 19
16ExprTuple20, 23
17ExprTuple86, 21
18Literal
19ExprTuple22, 23
20Operationoperator: 50
operands: 24
21Operationoperator: 74
operands: 25
22Operationoperator: 26
operands: 27
23Operationoperator: 28
operand: 35
24ExprTuple88, 30
25ExprTuple31, 32
26Literal
27ExprTuple33, 34
28Literal
29ExprTuple35
30Operationoperator: 82
operands: 36
31Operationoperator: 50
operands: 37
32Operationoperator: 84
operand: 44
33Operationoperator: 53
operand: 70
34Operationoperator: 54
operands: 40
35Lambdaparameter: 79
body: 42
36ExprTuple86, 44
37ExprTuple43, 86
38ExprTuple44
39ExprTuple70
40ExprTuple45, 46
41ExprTuple79
42Conditionalvalue: 47
condition: 48
43Operationoperator: 74
operands: 49
44Operationoperator: 50
operands: 51
45Operationoperator: 82
operands: 52
46Operationoperator: 53
operand: 88
47Operationoperator: 54
operands: 55
48Operationoperator: 56
operands: 57
49ExprTuple87, 88
50Literal
51ExprTuple87, 86
52ExprTuple68, 58
53Literal
54Literal
55ExprTuple59, 60
56Literal
57ExprTuple79, 61
58Operationoperator: 72
operands: 62
59Operationoperator: 82
operands: 63
60Operationoperator: 64
operands: 65
61Operationoperator: 66
operands: 67
62ExprTuple86, 76, 77, 78, 80
63ExprTuple68, 69
64Literal
65ExprTuple79, 87
66Literal
67ExprTuple70, 71
68Literal
69Operationoperator: 72
operands: 73
70Literal
71Operationoperator: 74
operands: 75
72Literal
73ExprTuple86, 76, 77, 78, 79
74Literal
75ExprTuple80, 81
76Literal
77Literal
78Literal
79Variable
80Operationoperator: 82
operands: 83
81Operationoperator: 84
operand: 88
82Literal
83ExprTuple86, 87
84Literal
85ExprTuple88
86Literal
87Variable
88Literal