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 ExprRange, ExprTuple, Variable, k, t
from proveit.core_expr_types import Len
from proveit.linear_algebra import ScalarMult, VecAdd, VecSum
from proveit.numbers import Exp, Interval, Mult, e, 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 = Variable("_a", latex_format = r"{_{-}a}")
expr = ExprTuple(Len(operands = [VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, _phase, two_pow_t)), ket1)), 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)))]), Len(operands = [ExprRange(sub_expr1, sub_expr1, one, two)]))
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(|\left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot \varphi \cdot 2^{t}} \cdot \lvert 1 \rangle\right), \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)|, |\left(1, \ldots, 2\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: 4
operands: 3
2Operationoperator: 4
operands: 5
3ExprTuple6, 7
4Literal
5ExprTuple8
6Operationoperator: 9
operands: 10
7Operationoperator: 11
operand: 16
8ExprRangelambda_map: 13
start_index: 63
end_index: 61
9Literal
10ExprTuple14, 15
11Literal
12ExprTuple16
13Lambdaparameter: 22
body: 22
14Operationoperator: 28
operand: 45
15Operationoperator: 29
operands: 19
16Lambdaparameter: 54
body: 21
17ExprTuple22
18ExprTuple45
19ExprTuple23, 24
20ExprTuple54
21Conditionalvalue: 25
condition: 26
22Variable
23Operationoperator: 57
operands: 27
24Operationoperator: 28
operand: 63
25Operationoperator: 29
operands: 30
26Operationoperator: 31
operands: 32
27ExprTuple43, 33
28Literal
29Literal
30ExprTuple34, 35
31Literal
32ExprTuple54, 36
33Operationoperator: 47
operands: 37
34Operationoperator: 57
operands: 38
35Operationoperator: 39
operands: 40
36Operationoperator: 41
operands: 42
37ExprTuple61, 51, 52, 53, 55
38ExprTuple43, 44
39Literal
40ExprTuple54, 62
41Literal
42ExprTuple45, 46
43Literal
44Operationoperator: 47
operands: 48
45Literal
46Operationoperator: 49
operands: 50
47Literal
48ExprTuple61, 51, 52, 53, 54
49Literal
50ExprTuple55, 56
51Literal
52Literal
53Literal
54Variable
55Operationoperator: 57
operands: 58
56Operationoperator: 59
operand: 63
57Literal
58ExprTuple61, 62
59Literal
60ExprTuple63
61Literal
62Variable
63Literal