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, 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(ExprRange(sub_expr1, MultiQubitElem(element = Output(state = sub_expr3, part = Add(sub_expr1, t)), targets = sub_expr4), Add(Neg(t), one), 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}~\left(-t + 1\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 + 2\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
1ExprRangelambda_map: 3
start_index: 4
end_index: 5
2ExprRangelambda_map: 6
start_index: 7
end_index: 29
3Lambdaparameter: 35
body: 8
4Operationoperator: 33
operands: 9
5Literal
6Lambdaparameter: 35
body: 11
7Operationoperator: 33
operands: 12
8Operationoperator: 15
operands: 13
9ExprTuple14, 28
10ExprTuple35
11Operationoperator: 15
operands: 16
12ExprTuple41, 28
13NamedExprselement: 17
targets: 20
14Operationoperator: 18
operand: 41
15Literal
16NamedExprselement: 19
targets: 20
17Operationoperator: 22
operands: 21
18Literal
19Operationoperator: 22
operands: 23
20Operationoperator: 24
operands: 25
21NamedExprsstate: 27
part: 26
22Literal
23NamedExprsstate: 27
part: 35
24Literal
25ExprTuple28, 29
26Operationoperator: 33
operands: 30
27Operationoperator: 31
operands: 32
28Literal
29Operationoperator: 33
operands: 34
30ExprTuple35, 41
31Literal
32ExprTuple36, 37
33Literal
34ExprTuple41, 38
35Variable
36Operationoperator: 39
operand: 41
37Literal
38Literal
39Literal
40ExprTuple41
41Variable