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.core_expr_types import Len
from proveit.numbers import Add, Interval, one, two
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import QPE, _U, _ket_u, _s, _t
from proveit.physics.quantum.circuits import Gate, Input, MultiQubitElem
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(_t, one)
sub_expr3 = Add(_t, _s)
sub_expr4 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = ExprTuple(Len(operands = [[ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = Interval(sub_expr2, sub_expr3)), one, _s)], [ExprRange(sub_expr1, sub_expr4, one, _t), ExprRange(sub_expr1, sub_expr4, sub_expr2, sub_expr3)]]), Len(operands = [ExprRange(sub_expr1, sub_expr1, one, two)]))
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(|\left(\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array}, ..\left(t - 3\right) \times.., \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert + \rangle} & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~1~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~2~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \qin{\lvert u \rangle~\mbox{part}~s~\mbox{on}~\{t + 1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}\right), \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array},\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 1~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + 2~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}, \ldots, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& & \gate{\textrm{QPE}\left(U, t\right)~\mbox{part}~t + s~\mbox{on}~\{1~\ldotp \ldotp~t + s\}} & \qw 
} \end{array}\right)\right)|, |\left(1, \ldots, 2\right)|\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
3ExprTuple6, 7
4Literal
5ExprTuple8
6ExprTuple9, 10
7ExprTuple11, 12
8ExprRangelambda_map: 13
start_index: 51
end_index: 14
9ExprRangelambda_map: 15
start_index: 51
end_index: 53
10ExprRangelambda_map: 16
start_index: 51
end_index: 54
11ExprRangelambda_map: 17
start_index: 51
end_index: 53
12ExprRangelambda_map: 17
start_index: 42
end_index: 45
13Lambdaparameter: 44
body: 44
14Literal
15Lambdaparameter: 44
body: 18
16Lambdaparameter: 44
body: 19
17Lambdaparameter: 44
body: 21
18Operationoperator: 33
operands: 22
19Operationoperator: 24
operands: 23
20ExprTuple44
21Operationoperator: 24
operands: 25
22NamedExprsstate: 26
23NamedExprselement: 27
targets: 28
24Literal
25NamedExprselement: 29
targets: 30
26Operationoperator: 31
operand: 40
27Operationoperator: 33
operands: 34
28Operationoperator: 38
operands: 35
29Operationoperator: 36
operands: 37
30Operationoperator: 38
operands: 39
31Literal
32ExprTuple40
33Literal
34NamedExprsstate: 41
part: 44
35ExprTuple42, 45
36Literal
37NamedExprsoperation: 43
part: 44
38Literal
39ExprTuple51, 45
40Literal
41Literal
42Operationoperator: 49
operands: 46
43Operationoperator: 47
operands: 48
44Variable
45Operationoperator: 49
operands: 50
46ExprTuple53, 51
47Literal
48ExprTuple52, 53
49Literal
50ExprTuple53, 54
51Literal
52Literal
53Literal
54Literal