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, Variable, t
from proveit.linear_algebra import ScalarMult, VecAdd
from proveit.numbers import Add, Exp, Interval, 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 MultiQubitElem, Output
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(sub_expr1, t)
sub_expr3 = Output(state = ScalarMult(frac(one, sqrt(two)), VecAdd(ket0, ScalarMult(Exp(e, Mult(two, pi, i, Exp(two, Neg(sub_expr1)), _phase)), ket1))), part = one)
expr = ExprTuple(MultiQubitElem(element = sub_expr3, targets = Interval(Add(Add(sub_expr1, Neg(one), t), one), sub_expr2)), MultiQubitElem(element = sub_expr3, targets = Interval(sub_expr2, sub_expr2)))
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(\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)~\mbox{part}~1~\mbox{on}~\{\left({_{-}a} - 1 + t\right) + 1~\ldotp \ldotp~{_{-}a} + t\}} 
} \end{array}, \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)~\mbox{part}~1~\mbox{on}~\{{_{-}a} + t~\ldotp \ldotp~{_{-}a} + t\}} 
} \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
1Operationoperator: 4
operands: 3
2Operationoperator: 4
operands: 5
3NamedExprselement: 7
targets: 6
4Literal
5NamedExprselement: 7
targets: 8
6Operationoperator: 12
operands: 9
7Operationoperator: 10
operands: 11
8Operationoperator: 12
operands: 13
9ExprTuple14, 16
10Literal
11NamedExprsstate: 15
part: 48
12Literal
13ExprTuple16, 16
14Operationoperator: 23
operands: 17
15Operationoperator: 35
operands: 18
16Operationoperator: 23
operands: 19
17ExprTuple20, 48
18ExprTuple21, 22
19ExprTuple61, 29
20Operationoperator: 23
operands: 24
21Operationoperator: 41
operands: 25
22Operationoperator: 26
operands: 27
23Literal
24ExprTuple61, 28, 29
25ExprTuple48, 30
26Literal
27ExprTuple31, 32
28Operationoperator: 59
operand: 48
29Variable
30Operationoperator: 55
operands: 33
31Operationoperator: 44
operand: 38
32Operationoperator: 35
operands: 36
33ExprTuple57, 37
34ExprTuple38
35Literal
36ExprTuple39, 40
37Operationoperator: 41
operands: 42
38Literal
39Operationoperator: 55
operands: 43
40Operationoperator: 44
operand: 48
41Literal
42ExprTuple48, 57
43ExprTuple46, 47
44Literal
45ExprTuple48
46Literal
47Operationoperator: 49
operands: 50
48Literal
49Literal
50ExprTuple57, 51, 52, 53, 54
51Literal
52Literal
53Operationoperator: 55
operands: 56
54Literal
55Literal
56ExprTuple57, 58
57Literal
58Operationoperator: 59
operand: 61
59Literal
60ExprTuple61
61Variable