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, Lambda, Variable
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two
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))
expr = ExprTuple(Lambda(Variable("_b", latex_format = r"{_{-}b}"), ScalarMult(sub_expr2, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, two_pow_t, _phase)), ket1)))), Lambda(sub_expr1, ScalarMult(sub_expr2, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1)))))
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({_{-}b} \mapsto \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), {_{-}a} \mapsto \left(\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-{_{-}a}} \cdot \varphi} \cdot \lvert 1 \rangle\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
1Lambdaparameter: 6
body: 4
2Lambdaparameter: 56
body: 5
3ExprTuple6
4Operationoperator: 23
operands: 7
5Operationoperator: 23
operands: 8
6Variable
7ExprTuple10, 9
8ExprTuple10, 11
9Operationoperator: 14
operands: 12
10Operationoperator: 31
operands: 13
11Operationoperator: 14
operands: 15
12ExprTuple18, 16
13ExprTuple39, 17
14Literal
15ExprTuple18, 19
16Operationoperator: 23
operands: 20
17Operationoperator: 49
operands: 21
18Operationoperator: 34
operand: 27
19Operationoperator: 23
operands: 24
20ExprTuple25, 29
21ExprTuple52, 26
22ExprTuple27
23Literal
24ExprTuple28, 29
25Operationoperator: 49
operands: 30
26Operationoperator: 31
operands: 32
27Literal
28Operationoperator: 49
operands: 33
29Operationoperator: 34
operand: 39
30ExprTuple37, 36
31Literal
32ExprTuple39, 52
33ExprTuple37, 38
34Literal
35ExprTuple39
36Operationoperator: 41
operands: 40
37Literal
38Operationoperator: 41
operands: 42
39Literal
40ExprTuple52, 44, 45, 43, 47
41Literal
42ExprTuple52, 44, 45, 46, 47
43Operationoperator: 49
operands: 48
44Literal
45Literal
46Operationoperator: 49
operands: 50
47Literal
48ExprTuple52, 51
49Literal
50ExprTuple52, 53
51Variable
52Literal
53Operationoperator: 54
operand: 56
54Literal
55ExprTuple56
56Variable