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(Add(t, one), two)
sub_expr3 = Exp(e, Mult(two, pi, i, _phase, two_pow_t))
sub_expr4 = 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(frac(one, Exp(two, sub_expr2)), VecAdd(TensorProd(ket0, sub_expr4), ScalarMult(sub_expr3, TensorProd(ket1, sub_expr4)))), TensorProd(ScalarMult(frac(one, Exp(two, subtract(sub_expr2, sub_expr1))), VecAdd(ket0, ScalarMult(sub_expr3, ket1))), ScalarMult(frac(one, Exp(two, sub_expr1)), 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}}} \cdot \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) = \left(\left(\frac{1}{2^{\frac{t + 1}{2} - \frac{t}{2}}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \lvert 1 \rangle\right)\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',)
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: 61
operands: 5
4Operationoperator: 33
operands: 6
5ExprTuple7, 8
6ExprTuple9, 10
7Operationoperator: 66
operands: 11
8Operationoperator: 25
operands: 12
9Operationoperator: 61
operands: 13
10Operationoperator: 61
operands: 14
11ExprTuple96, 15
12ExprTuple16, 17
13ExprTuple18, 19
14ExprTuple20, 39
15Operationoperator: 90
operands: 21
16Operationoperator: 33
operands: 22
17Operationoperator: 61
operands: 23
18Operationoperator: 66
operands: 24
19Operationoperator: 25
operands: 26
20Operationoperator: 66
operands: 27
21ExprTuple94, 49
22ExprTuple30, 39
23ExprTuple41, 28
24ExprTuple96, 29
25Literal
26ExprTuple30, 31
27ExprTuple96, 32
28Operationoperator: 33
operands: 34
29Operationoperator: 90
operands: 35
30Operationoperator: 47
operand: 78
31Operationoperator: 61
operands: 37
32Operationoperator: 90
operands: 38
33Literal
34ExprTuple42, 39
35ExprTuple94, 40
36ExprTuple78
37ExprTuple41, 42
38ExprTuple94, 60
39Operationoperator: 43
operand: 48
40Operationoperator: 82
operands: 45
41Operationoperator: 90
operands: 46
42Operationoperator: 47
operand: 96
43Literal
44ExprTuple48
45ExprTuple49, 50
46ExprTuple76, 51
47Literal
48Lambdaparameter: 87
body: 53
49Operationoperator: 66
operands: 54
50Operationoperator: 92
operand: 60
51Operationoperator: 80
operands: 56
52ExprTuple87
53Conditionalvalue: 57
condition: 58
54ExprTuple59, 94
55ExprTuple60
56ExprTuple94, 84, 85, 86, 88
57Operationoperator: 61
operands: 62
58Operationoperator: 63
operands: 64
59Operationoperator: 82
operands: 65
60Operationoperator: 66
operands: 67
61Literal
62ExprTuple68, 69
63Literal
64ExprTuple87, 70
65ExprTuple95, 96
66Literal
67ExprTuple95, 94
68Operationoperator: 90
operands: 71
69Operationoperator: 72
operands: 73
70Operationoperator: 74
operands: 75
71ExprTuple76, 77
72Literal
73ExprTuple87, 95
74Literal
75ExprTuple78, 79
76Literal
77Operationoperator: 80
operands: 81
78Literal
79Operationoperator: 82
operands: 83
80Literal
81ExprTuple94, 84, 85, 86, 87
82Literal
83ExprTuple88, 89
84Literal
85Literal
86Literal
87Variable
88Operationoperator: 90
operands: 91
89Operationoperator: 92
operand: 96
90Literal
91ExprTuple94, 95
92Literal
93ExprTuple96
94Literal
95Variable
96Literal