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, Variable, VertExprArray, l
from proveit.logic import InSet
from proveit.numbers import Add, Interval, one
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import ModAdd, QPE, _U, _b_floor, _full_domain, _ket_u, _s, _s_wire, _t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = Add(_t, one)
sub_expr3 = Add(_t, _s)
sub_expr4 = Interval(sub_expr2, sub_expr3)
sub_expr5 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = Interval(one, sub_expr3))
expr = Conditional(Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)], [ExprRange(sub_expr1, sub_expr5, one, _t), ExprRange(sub_expr1, sub_expr5, sub_expr2, sub_expr3)], [ExprRange(sub_expr1, Measure(basis = Z), one, _t), _s_wire], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(ModAdd(_b_floor, l), _t), part = sub_expr1), targets = Interval(one, _t)), one, _t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = _ket_u, part = sub_expr1), targets = sub_expr4), one, _s)])), InSet(l, _full_domain))
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{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} & \ghost{\textrm{QPE}\left(U, t\right)} & \measure{\begin{array}{c}:\\ \left(t - 3\right) \times \\:\end{array}} \qw & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert b_{\textit{f}} \oplus l \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array} \textrm{ if } l \in \{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\}\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, 9, 10
5Literal
6ExprTuple99, 11
7ExprTuple12, 13
8ExprTuple14, 15
9ExprTuple16, 17
10ExprTuple18, 19
11Operationoperator: 69
operands: 20
12ExprRangelambda_map: 21
start_index: 102
end_index: 96
13ExprRangelambda_map: 22
start_index: 102
end_index: 91
14ExprRangelambda_map: 23
start_index: 102
end_index: 96
15ExprRangelambda_map: 23
start_index: 77
end_index: 78
16ExprRangelambda_map: 24
start_index: 102
end_index: 96
17ExprRangelambda_map: 25
start_index: 102
end_index: 91
18ExprRangelambda_map: 26
start_index: 102
end_index: 96
19ExprRangelambda_map: 27
start_index: 102
end_index: 91
20ExprTuple28, 71
21Lambdaparameter: 76
body: 29
22Lambdaparameter: 76
body: 30
23Lambdaparameter: 76
body: 31
24Lambdaparameter: 76
body: 32
25Lambdaparameter: 76
body: 33
26Lambdaparameter: 76
body: 34
27Lambdaparameter: 76
body: 36
28Operationoperator: 92
operands: 37
29Operationoperator: 61
operands: 38
30Operationoperator: 45
operands: 39
31Operationoperator: 45
operands: 40
32Operationoperator: 41
operands: 42
33Operationoperator: 62
operands: 43
34Operationoperator: 45
operands: 44
35ExprTuple76
36Operationoperator: 45
operands: 46
37ExprTuple47, 102
38NamedExprsstate: 48
39NamedExprselement: 49
targets: 57
40NamedExprselement: 50
targets: 51
41Literal
42NamedExprsbasis: 52
43NamedExprsoperation: 53
44NamedExprselement: 54
targets: 55
45Literal
46NamedExprselement: 56
targets: 57
47Operationoperator: 100
operand: 71
48Operationoperator: 59
operand: 72
49Operationoperator: 61
operands: 68
50Operationoperator: 62
operands: 63
51Operationoperator: 69
operands: 64
52Literal
53Literal
54Operationoperator: 67
operands: 65
55Operationoperator: 69
operands: 66
56Operationoperator: 67
operands: 68
57Operationoperator: 69
operands: 70
58ExprTuple71
59Literal
60ExprTuple72
61Literal
62Literal
63NamedExprsoperation: 73
part: 76
64ExprTuple102, 78
65NamedExprsstate: 74
part: 76
66ExprTuple102, 96
67Literal
68NamedExprsstate: 75
part: 76
69Literal
70ExprTuple77, 78
71Operationoperator: 79
operands: 80
72Literal
73Operationoperator: 81
operands: 82
74Operationoperator: 83
operands: 84
75Literal
76Variable
77Operationoperator: 92
operands: 85
78Operationoperator: 92
operands: 86
79Literal
80ExprTuple87, 88
81Literal
82ExprTuple89, 96
83Literal
84ExprTuple90, 96
85ExprTuple96, 102
86ExprTuple96, 91
87Literal
88Operationoperator: 92
operands: 93
89Literal
90Operationoperator: 94
operands: 95
91Literal
92Literal
93ExprTuple96, 97
94Literal
95ExprTuple98, 99
96Literal
97Operationoperator: 100
operand: 102
98Literal
99Variable
100Literal
101ExprTuple102
102Literal