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, t
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd
from proveit.logic import Equals
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two, zero
from proveit.physics.quantum import 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 = frac(one, sqrt(two))
sub_expr3 = VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, two_pow_t, _phase)), ket1))
sub_expr4 = ExprRange(sub_expr1, ScalarMult(sub_expr2, 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 = Equals(TensorProd(ScalarMult(sub_expr2, sub_expr3), sub_expr4), ScalarMult(sub_expr2, TensorProd(sub_expr3, sub_expr4))).with_wrapping_at(1)
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())
\begin{array}{c} \begin{array}{l} \left(\left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t} \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 - 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) \\  = \left(\frac{1}{\sqrt{2}} \cdot \left(\left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{t} \cdot \varphi} \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) \end{array} \end{array}
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.()(1)('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: 10
operands: 5
4Operationoperator: 39
operands: 6
5ExprTuple7, 13
6ExprTuple25, 8
7Operationoperator: 39
operands: 9
8Operationoperator: 10
operands: 11
9ExprTuple25, 12
10Literal
11ExprTuple12, 13
12Operationoperator: 30
operands: 14
13ExprRangelambda_map: 15
start_index: 16
end_index: 43
14ExprTuple34, 17
15Lambdaparameter: 68
body: 18
16Operationoperator: 19
operands: 20
17Operationoperator: 39
operands: 21
18Operationoperator: 39
operands: 22
19Literal
20ExprTuple23, 55
21ExprTuple24, 45
22ExprTuple25, 26
23Operationoperator: 66
operand: 52
24Operationoperator: 62
operands: 28
25Operationoperator: 47
operands: 29
26Operationoperator: 30
operands: 31
27ExprTuple52
28ExprTuple53, 32
29ExprTuple55, 33
30Literal
31ExprTuple34, 35
32Operationoperator: 56
operands: 36
33Operationoperator: 62
operands: 37
34Operationoperator: 50
operand: 43
35Operationoperator: 39
operands: 40
36ExprTuple64, 58, 59, 41, 61
37ExprTuple64, 42
38ExprTuple43
39Literal
40ExprTuple44, 45
41Operationoperator: 62
operands: 46
42Operationoperator: 47
operands: 48
43Literal
44Operationoperator: 62
operands: 49
45Operationoperator: 50
operand: 55
46ExprTuple64, 52
47Literal
48ExprTuple55, 64
49ExprTuple53, 54
50Literal
51ExprTuple55
52Variable
53Literal
54Operationoperator: 56
operands: 57
55Literal
56Literal
57ExprTuple64, 58, 59, 60, 61
58Literal
59Literal
60Operationoperator: 62
operands: 63
61Literal
62Literal
63ExprTuple64, 65
64Literal
65Operationoperator: 66
operand: 68
66Literal
67ExprTuple68
68Variable