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.QPE import QPE1, QPE1_U_t_circuit
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 = MultiQubitElem(element = Gate(operation = QPE1(U, t), part = sub_expr1), targets = Interval(one, sub_expr2))
expr = Conditional(QcircuitEquiv(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, sub_expr3, one, t), ExprRange(sub_expr1, sub_expr3, Add(t, one), sub_expr2)])), QPE1_U_t_circuit), 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}_1\left(U, t\right)} & { /^{t} } \qw \\
& \ghost{\textrm{QPE}_1\left(U, t\right)} & { /^{s} } \qw
} \end{array}\right) \cong \left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
& \control{} \qw \qwx[1] & \qw & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \qw \qwx[1] & \control{} \qw \qwx[1] & \gate{\cdots} \qwx[1] & \qw & \qw \\
& \gate{\vdots} \qwx[1] & \gate{\vdots} \qwx[1] & \gate{\ddots} \qwx[1] & \gate{\vdots} & \qw \\
& \qw \qwx[1] & \qw \qwx[1] & \gate{\cdots} \qwx[1] & \control{} \qw \qwx[1] & \qw \\
& \gate{U^{2^{t - 1}}} & \gate{U^{2^{t - 2}}} & \gate{\cdots} & \gate{U^{2^{0}}} & { /^{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
6ExprTuple79, 9
7Operationoperator: 11
operand: 15
8Operationoperator: 11
operands: 12
9Operationoperator: 13
operand: 17
10ExprTuple15
11Literal
12ExprTuple16
13Literal
14ExprTuple17
15ExprTuple18, 19
16ExprRangelambda_map: 20
start_index: 21
end_index: 22
17Operationoperator: 83
operands: 23
18ExprRangelambda_map: 24
start_index: 90
end_index: 89
19ExprRangelambda_map: 24
start_index: 82
end_index: 67
20Lambdaparameter: 93
body: 25
21Operationoperator: 85
operands: 26
22Literal
23ExprTuple87, 81
24Lambdaparameter: 72
body: 27
25ExprTuple28, 29
26ExprTuple30, 90
27Operationoperator: 59
operands: 31
28ExprRangelambda_map: 32
start_index: 90
end_index: 89
29ExprRangelambda_map: 33
start_index: 90
end_index: 81
30Operationoperator: 91
operand: 89
31NamedExprselement: 35
targets: 36
32Lambdaparameter: 72
body: 37
33Lambdaparameter: 72
body: 39
34ExprTuple89
35Operationoperator: 62
operands: 40
36Operationoperator: 57
operands: 41
37Operationoperator: 42
operands: 43
38ExprTuple72
39Operationoperator: 59
operands: 44
40NamedExprsoperation: 45
part: 72
41ExprTuple90, 67
42Literal
43ExprTuple46, 47
44NamedExprselement: 48
targets: 49
45Operationoperator: 50
operands: 51
46Conditionalvalue: 52
condition: 53
47Conditionalvalue: 54
condition: 55
48Operationoperator: 62
operands: 56
49Operationoperator: 57
operands: 58
50Literal
51ExprTuple79, 89
52Operationoperator: 59
operands: 60
53Operationoperator: 61
operands: 65
54Operationoperator: 62
operands: 63
55Operationoperator: 64
operands: 65
56NamedExprsoperation: 66
part: 72
57Literal
58ExprTuple82, 67
59Literal
60NamedExprselement: 68
targets: 69
61Literal
62Literal
63NamedExprsoperation: 70
64Literal
65ExprTuple71, 72
66Operationoperator: 73
operands: 74
67Operationoperator: 85
operands: 75
68Literal
69Operationoperator: 76
operand: 82
70Literal
71Operationoperator: 85
operands: 78
72Variable
73Literal
74ExprTuple79, 80
75ExprTuple89, 81
76Literal
77ExprTuple82
78ExprTuple93, 89
79Variable
80Operationoperator: 83
operands: 84
81Variable
82Operationoperator: 85
operands: 86
83Literal
84ExprTuple87, 88
85Literal
86ExprTuple89, 90
87Literal
88Operationoperator: 91
operand: 93
89Variable
90Literal
91Literal
92ExprTuple93
93Variable