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
from proveit.linear_algebra import TensorProd
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import I
from proveit.physics.quantum.QFT import InverseFourierTransform
from proveit.physics.quantum.QPE import _Psi_ket, _ket_u, _psi__t_ket, _s, _t
from proveit.physics.quantum.circuits import Gate, Input, 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 = Interval(one, _t)
expr = ExprTuple(ExprRange(sub_expr1, MultiQubitElem(element = Input(state = TensorProd(_psi__t_ket, _ket_u), part = sub_expr1), targets = Interval(one, sub_expr2)), one, sub_expr2), ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(_t), part = sub_expr1), targets = sub_expr3), one, _t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, _s), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _Psi_ket, part = sub_expr1), targets = sub_expr3), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = Interval(Add(_t, one), sub_expr2)), one, _s))
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{
& \qin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert \psi_{t} \rangle {\otimes} \lvert u \rangle~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{{\mathrm {FT}}^{\dag}_{t}~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{{\mathrm {FT}}^{\dag}_{t}~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{{\mathrm {FT}}^{\dag}_{t}~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array}, ..\left(s - 3\right) \times.., \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qw & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \Psi \rangle~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \Psi \rangle~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert \Psi \rangle~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t\}} 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \qout{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 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, 4, 5
1ExprRangelambda_map: 6
start_index: 56
end_index: 47
2ExprRangelambda_map: 7
start_index: 56
end_index: 60
3ExprRangelambda_map: 8
start_index: 56
end_index: 57
4ExprRangelambda_map: 9
start_index: 56
end_index: 60
5ExprRangelambda_map: 10
start_index: 56
end_index: 57
6Lambdaparameter: 45
body: 11
7Lambdaparameter: 45
body: 12
8Lambdaparameter: 45
body: 13
9Lambdaparameter: 45
body: 14
10Lambdaparameter: 45
body: 16
11Operationoperator: 21
operands: 17
12Operationoperator: 21
operands: 18
13Operationoperator: 34
operands: 19
14Operationoperator: 21
operands: 20
15ExprTuple45
16Operationoperator: 21
operands: 22
17NamedExprselement: 23
targets: 24
18NamedExprselement: 25
targets: 28
19NamedExprsoperation: 26
20NamedExprselement: 27
targets: 28
21Literal
22NamedExprselement: 29
targets: 30
23Operationoperator: 31
operands: 32
24Operationoperator: 40
operands: 33
25Operationoperator: 34
operands: 35
26Literal
27Operationoperator: 38
operands: 36
28Operationoperator: 40
operands: 37
29Operationoperator: 38
operands: 39
30Operationoperator: 40
operands: 41
31Literal
32NamedExprsstate: 42
part: 45
33ExprTuple56, 47
34Literal
35NamedExprsoperation: 43
part: 45
36NamedExprsstate: 44
part: 45
37ExprTuple56, 60
38Literal
39NamedExprsstate: 55
part: 45
40Literal
41ExprTuple46, 47
42Operationoperator: 48
operands: 49
43Operationoperator: 50
operand: 60
44Literal
45Variable
46Operationoperator: 52
operands: 51
47Operationoperator: 52
operands: 53
48Literal
49ExprTuple54, 55
50Literal
51ExprTuple60, 56
52Literal
53ExprTuple60, 57
54Operationoperator: 58
operand: 60
55Literal
56Literal
57Literal
58Literal
59ExprTuple60
60Literal