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, Union
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, _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 = Union(_neg_domain, _pos_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~-\left(e + 1\right)\} \cup \{e + 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: 148
operands: 7
5Literal
6ExprTuple8
7ExprTuple9, 10
8Lambdaparameter: 143
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: 143
body: 23
18Lambdaparameter: 143
body: 25
19Literal
20ExprTuple26, 27, 28, 29
21Literal
22ExprTuple30, 31
23Conditionalvalue: 33
condition: 32
24ExprTuple143
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: 144
operands: 47
34Operationoperator: 48
operands: 49
35ExprRangelambda_map: 50
start_index: 154
end_index: 150
36ExprRangelambda_map: 51
start_index: 154
end_index: 135
37ExprRangelambda_map: 52
start_index: 154
end_index: 150
38ExprRangelambda_map: 52
start_index: 121
end_index: 122
39ExprRangelambda_map: 53
start_index: 154
end_index: 150
40ExprRangelambda_map: 54
start_index: 154
end_index: 135
41ExprRangelambda_map: 55
start_index: 154
end_index: 150
42ExprRangelambda_map: 56
start_index: 154
end_index: 135
43ExprTuple143, 57
44Literal
45ExprTuple141, 58
46ExprTuple143, 83
47ExprTuple59, 146
48Literal
49ExprTuple143, 84
50Lambdaparameter: 120
body: 60
51Lambdaparameter: 120
body: 61
52Lambdaparameter: 120
body: 62
53Lambdaparameter: 120
body: 63
54Lambdaparameter: 120
body: 64
55Lambdaparameter: 120
body: 65
56Lambdaparameter: 120
body: 67
57Operationoperator: 68
operands: 69
58Operationoperator: 70
operands: 71
59Operationoperator: 72
operand: 86
60Operationoperator: 104
operands: 74
61Operationoperator: 81
operands: 75
62Operationoperator: 81
operands: 76
63Operationoperator: 77
operands: 78
64Operationoperator: 105
operands: 79
65Operationoperator: 81
operands: 80
66ExprTuple120
67Operationoperator: 81
operands: 82
68Literal
69ExprTuple83, 84
70Literal
71ExprTuple143, 85
72Literal
73ExprTuple86
74NamedExprsstate: 87
75NamedExprselement: 88
targets: 96
76NamedExprselement: 89
targets: 90
77Literal
78NamedExprsbasis: 91
79NamedExprsoperation: 92
80NamedExprselement: 93
targets: 94
81Literal
82NamedExprselement: 95
targets: 96
83Operationoperator: 112
operands: 97
84Operationoperator: 112
operands: 98
85Operationoperator: 144
operands: 99
86Operationoperator: 100
operand: 134
87Operationoperator: 102
operand: 116
88Operationoperator: 104
operands: 111
89Operationoperator: 105
operands: 106
90Operationoperator: 112
operands: 107
91Literal
92Literal
93Operationoperator: 110
operands: 108
94Operationoperator: 112
operands: 109
95Operationoperator: 110
operands: 111
96Operationoperator: 112
operands: 113
97ExprTuple114, 115
98ExprTuple132, 140
99ExprTuple146, 150
100Literal
101ExprTuple134
102Literal
103ExprTuple116
104Literal
105Literal
106NamedExprsoperation: 117
part: 120
107ExprTuple154, 122
108NamedExprsstate: 118
part: 120
109ExprTuple154, 150
110Literal
111NamedExprsstate: 119
part: 120
112Literal
113ExprTuple121, 122
114Operationoperator: 148
operands: 123
115Operationoperator: 152
operand: 132
116Literal
117Operationoperator: 125
operands: 126
118Operationoperator: 127
operands: 128
119Literal
120Variable
121Operationoperator: 148
operands: 129
122Operationoperator: 148
operands: 130
123ExprTuple131, 154
124ExprTuple132
125Literal
126ExprTuple133, 150
127Literal
128ExprTuple134, 150
129ExprTuple150, 154
130ExprTuple150, 135
131Operationoperator: 152
operand: 140
132Operationoperator: 148
operands: 137
133Literal
134Operationoperator: 138
operands: 139
135Literal
136ExprTuple140
137ExprTuple141, 154
138Literal
139ExprTuple142, 143
140Operationoperator: 144
operands: 145
141Variable
142Literal
143Variable
144Literal
145ExprTuple146, 147
146Literal
147Operationoperator: 148
operands: 149
148Literal
149ExprTuple150, 151
150Literal
151Operationoperator: 152
operand: 154
152Literal
153ExprTuple154
154Literal