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, Variable, VertExprArray
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, _U, _s, _t
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 = QPE1(_U, _t), part = sub_expr1), targets = sub_expr4)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(_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)], [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)])), Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr6, one, _t), ExprRange(sub_expr1, sub_expr6, sub_expr3, sub_expr2)])))
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}_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) \cong \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)
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
operands: 5
4Operationoperator: 6
operand: 10
5ExprTuple8, 9
6Literal
7ExprTuple10
8ExprTuple11, 12
9ExprTuple13, 14
10ExprTuple15, 16
11ExprRangelambda_map: 17
start_index: 50
end_index: 60
12ExprRangelambda_map: 17
start_index: 21
end_index: 51
13ExprRangelambda_map: 18
start_index: 50
end_index: 60
14ExprRangelambda_map: 19
start_index: 50
end_index: 61
15ExprRangelambda_map: 20
start_index: 50
end_index: 60
16ExprRangelambda_map: 20
start_index: 21
end_index: 51
17Lambdaparameter: 49
body: 22
18Lambdaparameter: 49
body: 23
19Lambdaparameter: 49
body: 24
20Lambdaparameter: 49
body: 26
21Operationoperator: 57
operands: 27
22Operationoperator: 31
operands: 28
23Operationoperator: 31
operands: 29
24Operationoperator: 42
operands: 30
25ExprTuple49
26Operationoperator: 31
operands: 32
27ExprTuple60, 50
28NamedExprselement: 33
targets: 38
29NamedExprselement: 34
targets: 35
30NamedExprsoperation: 36
31Literal
32NamedExprselement: 37
targets: 38
33Operationoperator: 42
operands: 39
34Operationoperator: 42
operands: 40
35Operationoperator: 44
operands: 41
36Literal
37Operationoperator: 42
operands: 43
38Operationoperator: 44
operands: 45
39NamedExprsoperation: 46
part: 49
40NamedExprsoperation: 47
part: 49
41ExprTuple50, 60
42Literal
43NamedExprsoperation: 48
part: 49
44Literal
45ExprTuple50, 51
46Operationoperator: 52
operands: 56
47Operationoperator: 53
operand: 60
48Operationoperator: 55
operands: 56
49Variable
50Literal
51Operationoperator: 57
operands: 58
52Literal
53Literal
54ExprTuple60
55Literal
56ExprTuple59, 60
57Literal
58ExprTuple60, 61
59Literal
60Literal
61Literal