logo

Expression of type QcircuitEquiv

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, 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, QcircuitEquiv
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 = QcircuitEquiv(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}\right) \cong \left(\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
operation'infix' or 'function' style formattinginfixinfix
wrap_positionsposition(s) at which wrapping is to occur; '2 n - 1' is after the nth operand, '2 n' is after the nth operation.()()('with_wrapping_at', 'with_wrap_before_operator', 'with_wrap_after_operator', 'without_wrapping', 'wrap_positions')
justificationif any wrap positions are set, justify to the 'left', 'center', or 'right'centercenter('with_justification',)
directionDirection of the relation (normal or reversed)normalnormal('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 1
operands: 2
1Literal
2ExprTuple3, 4
3Operationoperator: 6
operand: 8
4Operationoperator: 6
operands: 7
5ExprTuple8
6Literal
7ExprTuple9, 10
8ExprTuple11, 12
9ExprTuple13, 14
10ExprTuple15, 16
11ExprRangelambda_map: 17
start_index: 51
end_index: 61
12ExprRangelambda_map: 17
start_index: 19
end_index: 48
13ExprRangelambda_map: 18
start_index: 51
end_index: 61
14ExprRangelambda_map: 18
start_index: 19
end_index: 48
15ExprRangelambda_map: 20
start_index: 51
end_index: 61
16ExprRangelambda_map: 21
start_index: 51
end_index: 60
17Lambdaparameter: 50
body: 22
18Lambdaparameter: 50
body: 23
19Operationoperator: 55
operands: 24
20Lambdaparameter: 50
body: 25
21Lambdaparameter: 50
body: 27
22Operationoperator: 30
operands: 28
23Operationoperator: 30
operands: 29
24ExprTuple61, 51
25Operationoperator: 30
operands: 31
26ExprTuple50
27Operationoperator: 42
operands: 32
28NamedExprselement: 33
targets: 35
29NamedExprselement: 34
targets: 35
30Literal
31NamedExprselement: 36
targets: 37
32NamedExprsoperation: 38
33Operationoperator: 42
operands: 39
34Operationoperator: 42
operands: 40
35Operationoperator: 44
operands: 41
36Operationoperator: 42
operands: 43
37Operationoperator: 44
operands: 45
38Literal
39NamedExprsoperation: 46
part: 50
40NamedExprsoperation: 47
part: 50
41ExprTuple51, 48
42Literal
43NamedExprsoperation: 49
part: 50
44Literal
45ExprTuple51, 61
46Operationoperator: 52
operands: 54
47Operationoperator: 53
operands: 54
48Operationoperator: 55
operands: 56
49Operationoperator: 57
operand: 61
50Variable
51Literal
52Literal
53Literal
54ExprTuple59, 61
55Literal
56ExprTuple61, 60
57Literal
58ExprTuple61
59Variable
60Variable
61Variable