logo

Expression of type Len

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.core_expr_types import Len
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, subtract, 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}")
expr = Len(operands = [frac(one, Exp(two, subtract(frac(Add(t, one), two), 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} - \frac{t}{2}}}, \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)|
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',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 55
operands: 5
4Operationoperator: 6
operands: 7
5ExprTuple63, 8
6Literal
7ExprTuple9, 10
8Operationoperator: 70
operands: 11
9Operationoperator: 33
operands: 12
10ExprRangelambda_map: 13
start_index: 14
end_index: 51
11ExprTuple72, 15
12ExprTuple39, 16
13Lambdaparameter: 76
body: 17
14Operationoperator: 41
operands: 18
15Operationoperator: 41
operands: 19
16Operationoperator: 47
operands: 20
17Operationoperator: 47
operands: 21
18ExprTuple22, 63
19ExprTuple23, 24
20ExprTuple25, 53
21ExprTuple26, 27
22Operationoperator: 74
operand: 60
23Operationoperator: 55
operands: 29
24Operationoperator: 74
operand: 36
25Operationoperator: 70
operands: 31
26Operationoperator: 55
operands: 32
27Operationoperator: 33
operands: 34
28ExprTuple60
29ExprTuple35, 72
30ExprTuple36
31ExprTuple61, 37
32ExprTuple63, 38
33Literal
34ExprTuple39, 40
35Operationoperator: 41
operands: 42
36Operationoperator: 55
operands: 43
37Operationoperator: 64
operands: 44
38Operationoperator: 70
operands: 45
39Operationoperator: 58
operand: 51
40Operationoperator: 47
operands: 48
41Literal
42ExprTuple60, 63
43ExprTuple60, 72
44ExprTuple72, 66, 67, 69, 49
45ExprTuple72, 50
46ExprTuple51
47Literal
48ExprTuple52, 53
49Operationoperator: 70
operands: 54
50Operationoperator: 55
operands: 56
51Literal
52Operationoperator: 70
operands: 57
53Operationoperator: 58
operand: 63
54ExprTuple72, 60
55Literal
56ExprTuple63, 72
57ExprTuple61, 62
58Literal
59ExprTuple63
60Variable
61Literal
62Operationoperator: 64
operands: 65
63Literal
64Literal
65ExprTuple72, 66, 67, 68, 69
66Literal
67Literal
68Operationoperator: 70
operands: 71
69Literal
70Literal
71ExprTuple72, 73
72Literal
73Operationoperator: 74
operand: 76
74Literal
75ExprTuple76
76Variable