logo

Expression of type ExprTuple

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 ExprTuple, k, t
from proveit.linear_algebra import ScalarMult, TensorProd, VecAdd, VecSum
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)
expr = ExprTuple(frac(one, Exp(two, subtract(frac(Add(t, one), two), sub_expr1))), TensorProd(VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)), ScalarMult(frac(one, Exp(two, sub_expr1)), 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:
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}{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
wrap_positionsposition(s) at which wrapping is to occur; 'n' is after the nth comma.()()('with_wrapping_at',)
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'leftleft('with_justification',)
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1, 2
1Operationoperator: 44
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple78, 6
4Literal
5ExprTuple7, 8
6Operationoperator: 72
operands: 9
7Operationoperator: 10
operands: 11
8Operationoperator: 46
operands: 12
9ExprTuple76, 13
10Literal
11ExprTuple14, 15
12ExprTuple16, 17
13Operationoperator: 64
operands: 18
14Operationoperator: 33
operand: 60
15Operationoperator: 46
operands: 20
16Operationoperator: 44
operands: 21
17Operationoperator: 22
operand: 29
18ExprTuple24, 25
19ExprTuple60
20ExprTuple26, 27
21ExprTuple78, 28
22Literal
23ExprTuple29
24Operationoperator: 44
operands: 30
25Operationoperator: 74
operand: 39
26Operationoperator: 72
operands: 32
27Operationoperator: 33
operand: 78
28Operationoperator: 72
operands: 34
29Lambdaparameter: 69
body: 36
30ExprTuple37, 76
31ExprTuple39
32ExprTuple58, 38
33Literal
34ExprTuple76, 39
35ExprTuple69
36Conditionalvalue: 40
condition: 41
37Operationoperator: 64
operands: 42
38Operationoperator: 62
operands: 43
39Operationoperator: 44
operands: 45
40Operationoperator: 46
operands: 47
41Operationoperator: 48
operands: 49
42ExprTuple77, 78
43ExprTuple76, 66, 67, 68, 70
44Literal
45ExprTuple77, 76
46Literal
47ExprTuple50, 51
48Literal
49ExprTuple69, 52
50Operationoperator: 72
operands: 53
51Operationoperator: 54
operands: 55
52Operationoperator: 56
operands: 57
53ExprTuple58, 59
54Literal
55ExprTuple69, 77
56Literal
57ExprTuple60, 61
58Literal
59Operationoperator: 62
operands: 63
60Literal
61Operationoperator: 64
operands: 65
62Literal
63ExprTuple76, 66, 67, 68, 69
64Literal
65ExprTuple70, 71
66Literal
67Literal
68Literal
69Variable
70Operationoperator: 72
operands: 73
71Operationoperator: 74
operand: 78
72Literal
73ExprTuple76, 77
74Literal
75ExprTuple78
76Literal
77Variable
78Literal