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.numbers import Add, Interval, one
from proveit.physics.quantum import ket_plus
from proveit.physics.quantum.QPE import _ket_u, _s, _t
from proveit.physics.quantum.circuits import Input, MultiQubitElem
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
expr = ExprTuple([ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = Interval(Add(_t, one), Add(_t, _s))), 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(\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)\right)
In [5]:
stored_expr.style_options()
no style options
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0ExprTuple1
1ExprTuple2, 3
2ExprRangelambda_map: 4
start_index: 29
end_index: 30
3ExprRangelambda_map: 5
start_index: 29
end_index: 31
4Lambdaparameter: 23
body: 6
5Lambdaparameter: 23
body: 8
6Operationoperator: 17
operands: 9
7ExprTuple23
8Operationoperator: 10
operands: 11
9NamedExprsstate: 12
10Literal
11NamedExprselement: 13
targets: 14
12Operationoperator: 15
operand: 21
13Operationoperator: 17
operands: 18
14Operationoperator: 19
operands: 20
15Literal
16ExprTuple21
17Literal
18NamedExprsstate: 22
part: 23
19Literal
20ExprTuple24, 25
21Literal
22Literal
23Variable
24Operationoperator: 27
operands: 26
25Operationoperator: 27
operands: 28
26ExprTuple30, 29
27Literal
28ExprTuple30, 31
29Literal
30Literal
31Literal