logo

Expression of type Equals

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, e, l
from proveit.logic import Equals
from proveit.numbers import Abs, Add, Exp, Interval, ModAbs, Sum, greater, one, two
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import ModAdd, QPE, _U, _b_floor, _full_domain, _ket_u, _neg_domain, _pos_domain, _rel_indexed_alpha, _s, _s_wire, _t, _two_pow_t
from proveit.physics.quantum.circuits import Gate, Input, Measure, MultiQubitElem, Output, Qcircuit
from proveit.statistics import ProbOfAll
In [2]:
# build up the expression from sub-expressions
sub_expr1 = Variable("_a", latex_format = r"{_{-}a}")
sub_expr2 = [l]
sub_expr3 = Add(_t, one)
sub_expr4 = Add(_t, _s)
sub_expr5 = Interval(sub_expr3, sub_expr4)
sub_expr6 = MultiQubitElem(element = Gate(operation = QPE(_U, _t), part = sub_expr1), targets = Interval(one, sub_expr4))
sub_expr7 = Exp(Abs(_rel_indexed_alpha), two)
expr = Equals(ProbOfAll(instance_param_or_params = sub_expr2, instance_element = 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_expr5), one, _s)], [ExprRange(sub_expr1, sub_expr6, one, _t), ExprRange(sub_expr1, sub_expr6, sub_expr3, sub_expr4)], [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_expr5), one, _s)])), domain = _full_domain, condition = greater(ModAbs(l, _two_pow_t), e)), Add(Sum(index_or_indices = sub_expr2, summand = sub_expr7, domain = _neg_domain), Sum(index_or_indices = sub_expr2, summand = sub_expr7, domain = _pos_domain))).with_wrapping_at(2)
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())
\begin{array}{c} \begin{array}{l} \left[\textrm{Prob}_{l \in \{-2^{t - 1} + 1~\ldotp \ldotp~2^{t - 1}\}~|~\left|l\right|_{\textup{mod}\thinspace 2^{t}} > e}~\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}\right)\right] =  \\ \left(\left(\sum_{l = -2^{t - 1} + 1}^{-\left(e + 1\right)} \left|\alpha_{b_{\textit{f}} \oplus l}\right|^{2}\right) + \left(\sum_{l = e + 1}^{2^{t - 1}} \left|\alpha_{b_{\textit{f}} \oplus l}\right|^{2}\right)\right) \end{array} \end{array}
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.()(2)('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: 5
operand: 8
4Operationoperator: 147
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameter: 146
body: 11
9Operationoperator: 13
operand: 17
10Operationoperator: 13
operand: 18
11Conditionalvalue: 15
condition: 16
12ExprTuple17
13Literal
14ExprTuple18
15Operationoperator: 19
operands: 20
16Operationoperator: 21
operands: 22
17Lambdaparameter: 146
body: 23
18Lambdaparameter: 146
body: 25
19Literal
20ExprTuple26, 27, 28, 29
21Literal
22ExprTuple30, 31
23Conditionalvalue: 33
condition: 32
24ExprTuple146
25Conditionalvalue: 33
condition: 34
26ExprTuple35, 36
27ExprTuple37, 38
28ExprTuple39, 40
29ExprTuple41, 42
30Operationoperator: 48
operands: 43
31Operationoperator: 44
operands: 45
32Operationoperator: 48
operands: 46
33Operationoperator: 139
operands: 47
34Operationoperator: 48
operands: 49
35ExprRangelambda_map: 50
start_index: 153
end_index: 149
36ExprRangelambda_map: 51
start_index: 153
end_index: 138
37ExprRangelambda_map: 52
start_index: 153
end_index: 149
38ExprRangelambda_map: 52
start_index: 124
end_index: 125
39ExprRangelambda_map: 53
start_index: 153
end_index: 149
40ExprRangelambda_map: 54
start_index: 153
end_index: 138
41ExprRangelambda_map: 55
start_index: 153
end_index: 149
42ExprRangelambda_map: 56
start_index: 153
end_index: 138
43ExprTuple146, 57
44Literal
45ExprTuple135, 58
46ExprTuple146, 59
47ExprTuple60, 143
48Literal
49ExprTuple146, 61
50Lambdaparameter: 123
body: 62
51Lambdaparameter: 123
body: 63
52Lambdaparameter: 123
body: 64
53Lambdaparameter: 123
body: 65
54Lambdaparameter: 123
body: 66
55Lambdaparameter: 123
body: 67
56Lambdaparameter: 123
body: 69
57Operationoperator: 115
operands: 70
58Operationoperator: 71
operands: 72
59Operationoperator: 115
operands: 73
60Operationoperator: 74
operand: 89
61Operationoperator: 115
operands: 76
62Operationoperator: 107
operands: 77
63Operationoperator: 84
operands: 78
64Operationoperator: 84
operands: 79
65Operationoperator: 80
operands: 81
66Operationoperator: 108
operands: 82
67Operationoperator: 84
operands: 83
68ExprTuple123
69Operationoperator: 84
operands: 85
70ExprTuple87, 134
71Literal
72ExprTuple146, 86
73ExprTuple87, 88
74Literal
75ExprTuple89
76ExprTuple118, 134
77NamedExprsstate: 90
78NamedExprselement: 91
targets: 99
79NamedExprselement: 92
targets: 93
80Literal
81NamedExprsbasis: 94
82NamedExprsoperation: 95
83NamedExprselement: 96
targets: 97
84Literal
85NamedExprselement: 98
targets: 99
86Operationoperator: 139
operands: 100
87Operationoperator: 147
operands: 101
88Operationoperator: 151
operand: 118
89Operationoperator: 103
operand: 137
90Operationoperator: 105
operand: 119
91Operationoperator: 107
operands: 114
92Operationoperator: 108
operands: 109
93Operationoperator: 115
operands: 110
94Literal
95Literal
96Operationoperator: 113
operands: 111
97Operationoperator: 115
operands: 112
98Operationoperator: 113
operands: 114
99Operationoperator: 115
operands: 116
100ExprTuple143, 149
101ExprTuple117, 153
102ExprTuple118
103Literal
104ExprTuple137
105Literal
106ExprTuple119
107Literal
108Literal
109NamedExprsoperation: 120
part: 123
110ExprTuple153, 125
111NamedExprsstate: 121
part: 123
112ExprTuple153, 149
113Literal
114NamedExprsstate: 122
part: 123
115Literal
116ExprTuple124, 125
117Operationoperator: 151
operand: 134
118Operationoperator: 147
operands: 127
119Literal
120Operationoperator: 128
operands: 129
121Operationoperator: 130
operands: 131
122Literal
123Variable
124Operationoperator: 147
operands: 132
125Operationoperator: 147
operands: 133
126ExprTuple134
127ExprTuple135, 153
128Literal
129ExprTuple136, 149
130Literal
131ExprTuple137, 149
132ExprTuple149, 153
133ExprTuple149, 138
134Operationoperator: 139
operands: 140
135Variable
136Literal
137Operationoperator: 141
operands: 142
138Literal
139Literal
140ExprTuple143, 144
141Literal
142ExprTuple145, 146
143Literal
144Operationoperator: 147
operands: 148
145Literal
146Variable
147Literal
148ExprTuple149, 150
149Literal
150Operationoperator: 151
operand: 153
151Literal
152ExprTuple153
153Literal