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, U, Variable, VertExprArray, s, t
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 QPE, QPE1
from proveit.physics.quantum.circuits import Gate, MultiQubitElem, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(t, s)
sub_expr3 = Add(t, one)
sub_expr4 = Interval(one, sub_expr2)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(U, t), part = sub_expr1), targets = sub_expr4)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = sub_expr4)
expr = ExprTuple(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr5, one, t), ExprRange(sub_expr1, sub_expr5, sub_expr3, sub_expr2)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr6, one, t), ExprRange(sub_expr1, sub_expr6, sub_expr3, sub_expr2)], [ExprRange(sub_expr1, MultiQubitElem(element = Gate(operation = InverseFourierTransform(t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), 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{
& \multigate{1}{\textrm{QPE}\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw
} \end{array}, \begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \multigate{1}{\textrm{QPE}_1\left(U, t\right)} & \gate{{\mathrm {FT}}^{\dag}_{t}} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw & { /^{s} } \qw
} \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
1Operationoperator: 4
operand: 6
2Operationoperator: 4
operands: 5
3ExprTuple6
4Literal
5ExprTuple7, 8
6ExprTuple9, 10
7ExprTuple11, 12
8ExprTuple13, 14
9ExprRangelambda_map: 15
start_index: 49
end_index: 59
10ExprRangelambda_map: 15
start_index: 17
end_index: 46
11ExprRangelambda_map: 16
start_index: 49
end_index: 59
12ExprRangelambda_map: 16
start_index: 17
end_index: 46
13ExprRangelambda_map: 18
start_index: 49
end_index: 59
14ExprRangelambda_map: 19
start_index: 49
end_index: 58
15Lambdaparameter: 48
body: 20
16Lambdaparameter: 48
body: 21
17Operationoperator: 53
operands: 22
18Lambdaparameter: 48
body: 23
19Lambdaparameter: 48
body: 25
20Operationoperator: 28
operands: 26
21Operationoperator: 28
operands: 27
22ExprTuple59, 49
23Operationoperator: 28
operands: 29
24ExprTuple48
25Operationoperator: 40
operands: 30
26NamedExprselement: 31
targets: 33
27NamedExprselement: 32
targets: 33
28Literal
29NamedExprselement: 34
targets: 35
30NamedExprsoperation: 36
31Operationoperator: 40
operands: 37
32Operationoperator: 40
operands: 38
33Operationoperator: 42
operands: 39
34Operationoperator: 40
operands: 41
35Operationoperator: 42
operands: 43
36Literal
37NamedExprsoperation: 44
part: 48
38NamedExprsoperation: 45
part: 48
39ExprTuple49, 46
40Literal
41NamedExprsoperation: 47
part: 48
42Literal
43ExprTuple49, 59
44Operationoperator: 50
operands: 52
45Operationoperator: 51
operands: 52
46Operationoperator: 53
operands: 54
47Operationoperator: 55
operand: 59
48Variable
49Literal
50Literal
51Literal
52ExprTuple57, 59
53Literal
54ExprTuple59, 58
55Literal
56ExprTuple59
57Variable
58Variable
59Variable