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, VertExprArray, t
from proveit.linear_algebra import TensorProd
from proveit.numbers import Add, Interval, Neg, one, two, zero
from proveit.physics.quantum.QPE import _ket_u, _psi_t_ket, _s
from proveit.physics.quantum.circuits import MultiQubitElem, Output, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, _s)
sub_expr3 = TensorProd(_psi_t_ket, _ket_u)
sub_expr4 = Interval(one, sub_expr2)
expr = ExprTuple(Qcircuit(vert_expr_array = VertExprArray(Variable("_b", latex_format = r"{_{-}b}"))), Qcircuit(vert_expr_array = VertExprArray([MultiQubitElem(element = Output(state = sub_expr3, part = one), targets = sub_expr4), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr3, part = Add(sub_expr1, t)), targets = sub_expr4), Add(Neg(t), two), zero), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr3, part = sub_expr1), targets = sub_expr4), Add(t, one), sub_expr2).with_wrapping_at(2,6)])))
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{
& \gate{\begin{array}{c} \uparrow \\{_{-}b} \\ \downarrow\end{array}} & \qw
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multiqout{2}{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \ghostqout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle} \\
& \qout{\vdots} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~0 + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} \qwx[1] \\
& \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}}
} \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
operand: 6
2Operationoperator: 4
operand: 7
3ExprTuple6
4Literal
5ExprTuple7
6Variable
7ExprTuple8, 9, 10
8Operationoperator: 27
operands: 11
9ExprRangelambda_map: 12
start_index: 13
end_index: 14
10ExprRangelambda_map: 15
start_index: 16
end_index: 41
11NamedExprselement: 17
targets: 32
12Lambdaparameter: 47
body: 18
13Operationoperator: 45
operands: 19
14Literal
15Lambdaparameter: 47
body: 21
16Operationoperator: 45
operands: 22
17Operationoperator: 34
operands: 23
18Operationoperator: 27
operands: 24
19ExprTuple25, 26
20ExprTuple47
21Operationoperator: 27
operands: 28
22ExprTuple53, 40
23NamedExprsstate: 39
part: 40
24NamedExprselement: 29
targets: 32
25Operationoperator: 30
operand: 53
26Literal
27Literal
28NamedExprselement: 31
targets: 32
29Operationoperator: 34
operands: 33
30Literal
31Operationoperator: 34
operands: 35
32Operationoperator: 36
operands: 37
33NamedExprsstate: 39
part: 38
34Literal
35NamedExprsstate: 39
part: 47
36Literal
37ExprTuple40, 41
38Operationoperator: 45
operands: 42
39Operationoperator: 43
operands: 44
40Literal
41Operationoperator: 45
operands: 46
42ExprTuple47, 53
43Literal
44ExprTuple48, 49
45Literal
46ExprTuple53, 50
47Variable
48Operationoperator: 51
operand: 53
49Literal
50Literal
51Literal
52ExprTuple53
53Variable