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, t
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Mult, Neg, e, frac, i, one, pi, sqrt, two
from proveit.physics.quantum import ket0, ket1
from proveit.physics.quantum.QPE import _phase
from proveit.physics.quantum.circuits import Output
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}"), Output(state = ScalarMult(sub_expr2, VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(Add(Neg(t), one))), _phase)), ket1))))), Lambda(sub_expr1, Output(state = 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 \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\frac{1}{\sqrt{2}} \cdot \left(\lvert 0 \rangle + \left(\mathsf{e}^{2 \cdot \pi \cdot \mathsf{i} \cdot 2^{-\left(-t + 1\right)} \cdot \varphi} \cdot \lvert 1 \rangle\right)\right)} 
} \end{array}, {_{-}a} \mapsto \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\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)} 
} \end{array}\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: 61
body: 5
3ExprTuple6
4Operationoperator: 8
operands: 7
5Operationoperator: 8
operands: 9
6Variable
7NamedExprsstate: 10
8Literal
9NamedExprsstate: 11
10Operationoperator: 28
operands: 12
11Operationoperator: 28
operands: 13
12ExprTuple15, 14
13ExprTuple15, 16
14Operationoperator: 19
operands: 17
15Operationoperator: 36
operands: 18
16Operationoperator: 19
operands: 20
17ExprTuple23, 21
18ExprTuple65, 22
19Literal
20ExprTuple23, 24
21Operationoperator: 28
operands: 25
22Operationoperator: 53
operands: 26
23Operationoperator: 39
operand: 32
24Operationoperator: 28
operands: 29
25ExprTuple30, 34
26ExprTuple56, 31
27ExprTuple32
28Literal
29ExprTuple33, 34
30Operationoperator: 53
operands: 35
31Operationoperator: 36
operands: 37
32Literal
33Operationoperator: 53
operands: 38
34Operationoperator: 39
operand: 65
35ExprTuple42, 41
36Literal
37ExprTuple65, 56
38ExprTuple42, 43
39Literal
40ExprTuple65
41Operationoperator: 45
operands: 44
42Literal
43Operationoperator: 45
operands: 46
44ExprTuple56, 48, 49, 47, 51
45Literal
46ExprTuple56, 48, 49, 50, 51
47Operationoperator: 53
operands: 52
48Literal
49Literal
50Operationoperator: 53
operands: 54
51Literal
52ExprTuple56, 55
53Literal
54ExprTuple56, 57
55Operationoperator: 66
operand: 60
56Literal
57Operationoperator: 66
operand: 61
58ExprTuple60
59ExprTuple61
60Operationoperator: 62
operands: 63
61Variable
62Literal
63ExprTuple64, 65
64Operationoperator: 66
operand: 68
65Literal
66Literal
67ExprTuple68
68Variable