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, 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
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(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{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~\left(-t + 2\right) + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~\left(-t + 3\right) + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~0 + t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + 2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + s~\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, 3
1Operationoperator: 20
operands: 4
2ExprRangelambda_map: 5
start_index: 6
end_index: 7
3ExprRangelambda_map: 8
start_index: 9
end_index: 34
4NamedExprselement: 10
targets: 25
5Lambdaparameter: 40
body: 11
6Operationoperator: 38
operands: 12
7Literal
8Lambdaparameter: 40
body: 14
9Operationoperator: 38
operands: 15
10Operationoperator: 27
operands: 16
11Operationoperator: 20
operands: 17
12ExprTuple18, 19
13ExprTuple40
14Operationoperator: 20
operands: 21
15ExprTuple46, 33
16NamedExprsstate: 32
part: 33
17NamedExprselement: 22
targets: 25
18Operationoperator: 23
operand: 46
19Literal
20Literal
21NamedExprselement: 24
targets: 25
22Operationoperator: 27
operands: 26
23Literal
24Operationoperator: 27
operands: 28
25Operationoperator: 29
operands: 30
26NamedExprsstate: 32
part: 31
27Literal
28NamedExprsstate: 32
part: 40
29Literal
30ExprTuple33, 34
31Operationoperator: 38
operands: 35
32Operationoperator: 36
operands: 37
33Literal
34Operationoperator: 38
operands: 39
35ExprTuple40, 46
36Literal
37ExprTuple41, 42
38Literal
39ExprTuple46, 43
40Variable
41Operationoperator: 44
operand: 46
42Literal
43Literal
44Literal
45ExprTuple46
46Variable