logo

Expression of type Conditional

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 Conditional, ExprRange, U, Variable, VertExprArray, s, t
from proveit.linear_algebra import Unitary
from proveit.logic import InSet
from proveit.numbers import Add, Exp, Interval, one, two
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 = Conditional(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)]))), InSet(U, Unitary(Exp(two, 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{
& \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) \textrm{ if } U \in \textrm{U}\left(2^{s}\right)\right..
In [5]:
stored_expr.style_options()
namedescriptiondefaultcurrent valuerelated methods
condition_delimiter'comma' or 'and'commacomma('with_comma_delimiter', 'with_conjunction_delimiter')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Conditionalvalue: 1
condition: 2
1Operationoperator: 3
operands: 4
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7, 8
5Literal
6ExprTuple70, 9
7Operationoperator: 11
operand: 15
8Operationoperator: 11
operands: 12
9Operationoperator: 13
operand: 18
10ExprTuple15
11Literal
12ExprTuple16, 17
13Literal
14ExprTuple18
15ExprTuple19, 20
16ExprTuple21, 22
17ExprTuple23, 24
18Operationoperator: 25
operands: 26
19ExprRangelambda_map: 27
start_index: 62
end_index: 72
20ExprRangelambda_map: 27
start_index: 29
end_index: 59
21ExprRangelambda_map: 28
start_index: 62
end_index: 72
22ExprRangelambda_map: 28
start_index: 29
end_index: 59
23ExprRangelambda_map: 30
start_index: 62
end_index: 72
24ExprRangelambda_map: 31
start_index: 62
end_index: 71
25Literal
26ExprTuple32, 71
27Lambdaparameter: 61
body: 33
28Lambdaparameter: 61
body: 34
29Operationoperator: 66
operands: 35
30Lambdaparameter: 61
body: 36
31Lambdaparameter: 61
body: 38
32Literal
33Operationoperator: 41
operands: 39
34Operationoperator: 41
operands: 40
35ExprTuple72, 62
36Operationoperator: 41
operands: 42
37ExprTuple61
38Operationoperator: 53
operands: 43
39NamedExprselement: 44
targets: 46
40NamedExprselement: 45
targets: 46
41Literal
42NamedExprselement: 47
targets: 48
43NamedExprsoperation: 49
44Operationoperator: 53
operands: 50
45Operationoperator: 53
operands: 51
46Operationoperator: 55
operands: 52
47Operationoperator: 53
operands: 54
48Operationoperator: 55
operands: 56
49Literal
50NamedExprsoperation: 57
part: 61
51NamedExprsoperation: 58
part: 61
52ExprTuple62, 59
53Literal
54NamedExprsoperation: 60
part: 61
55Literal
56ExprTuple62, 72
57Operationoperator: 63
operands: 65
58Operationoperator: 64
operands: 65
59Operationoperator: 66
operands: 67
60Operationoperator: 68
operand: 72
61Variable
62Literal
63Literal
64Literal
65ExprTuple70, 72
66Literal
67ExprTuple72, 71
68Literal
69ExprTuple72
70Variable
71Variable
72Variable