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 And, Forall, InSet
from proveit.numbers import Add, Exp, Interval, NaturalPos, 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(Forall(instance_param_or_params = [U], instance_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)]))), domain = Unitary(Exp(two, s))), And(InSet(s, NaturalPos), InSet(t, NaturalPos)))
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\{\forall_{U \in \textrm{U}\left(2^{s}\right)}~\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)\right) \textrm{ if } s \in \mathbb{N}^+ ,  t \in \mathbb{N}^+\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
operand: 7
2Operationoperator: 5
operands: 6
3Literal
4ExprTuple7
5Literal
6ExprTuple8, 9
7Lambdaparameter: 84
body: 11
8Operationoperator: 19
operands: 12
9Operationoperator: 19
operands: 13
10ExprTuple84
11Conditionalvalue: 14
condition: 15
12ExprTuple85, 16
13ExprTuple86, 16
14Operationoperator: 17
operands: 18
15Operationoperator: 19
operands: 20
16Literal
17Literal
18ExprTuple21, 22
19Literal
20ExprTuple84, 23
21Operationoperator: 25
operand: 29
22Operationoperator: 25
operands: 26
23Operationoperator: 27
operand: 32
24ExprTuple29
25Literal
26ExprTuple30, 31
27Literal
28ExprTuple32
29ExprTuple33, 34
30ExprTuple35, 36
31ExprTuple37, 38
32Operationoperator: 39
operands: 40
33ExprRangelambda_map: 41
start_index: 76
end_index: 86
34ExprRangelambda_map: 41
start_index: 43
end_index: 73
35ExprRangelambda_map: 42
start_index: 76
end_index: 86
36ExprRangelambda_map: 42
start_index: 43
end_index: 73
37ExprRangelambda_map: 44
start_index: 76
end_index: 86
38ExprRangelambda_map: 45
start_index: 76
end_index: 85
39Literal
40ExprTuple46, 85
41Lambdaparameter: 75
body: 47
42Lambdaparameter: 75
body: 48
43Operationoperator: 80
operands: 49
44Lambdaparameter: 75
body: 50
45Lambdaparameter: 75
body: 52
46Literal
47Operationoperator: 55
operands: 53
48Operationoperator: 55
operands: 54
49ExprTuple86, 76
50Operationoperator: 55
operands: 56
51ExprTuple75
52Operationoperator: 67
operands: 57
53NamedExprselement: 58
targets: 60
54NamedExprselement: 59
targets: 60
55Literal
56NamedExprselement: 61
targets: 62
57NamedExprsoperation: 63
58Operationoperator: 67
operands: 64
59Operationoperator: 67
operands: 65
60Operationoperator: 69
operands: 66
61Operationoperator: 67
operands: 68
62Operationoperator: 69
operands: 70
63Literal
64NamedExprsoperation: 71
part: 75
65NamedExprsoperation: 72
part: 75
66ExprTuple76, 73
67Literal
68NamedExprsoperation: 74
part: 75
69Literal
70ExprTuple76, 86
71Operationoperator: 77
operands: 79
72Operationoperator: 78
operands: 79
73Operationoperator: 80
operands: 81
74Operationoperator: 82
operand: 86
75Variable
76Literal
77Literal
78Literal
79ExprTuple84, 86
80Literal
81ExprTuple86, 85
82Literal
83ExprTuple86
84Variable
85Variable
86Variable