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, l
from proveit.logic import Equals
from proveit.numbers import Abs, Add, Exp, Interval, Sum, 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, _rel_indexed_alpha, _s, _s_wire, _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))
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 = _neg_domain), Sum(index_or_indices = sub_expr2, summand = Exp(Abs(_rel_indexed_alpha), two), domain = _neg_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)\}}~\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(\sum_{l = -2^{t - 1} + 1}^{-\left(e + 1\right)} \left|\alpha_{b_{\textit{f}} \oplus l}\right|^{2}\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: 9
4Operationoperator: 7
operand: 10
5Literal
6ExprTuple9
7Literal
8ExprTuple10
9Lambdaparameter: 125
body: 11
10Lambdaparameter: 125
body: 13
11Conditionalvalue: 14
condition: 16
12ExprTuple125
13Conditionalvalue: 15
condition: 16
14Operationoperator: 17
operands: 18
15Operationoperator: 105
operands: 19
16Operationoperator: 20
operands: 21
17Literal
18ExprTuple22, 23, 24, 25
19ExprTuple26, 113
20Literal
21ExprTuple125, 27
22ExprTuple28, 29
23ExprTuple30, 31
24ExprTuple32, 33
25ExprTuple34, 35
26Operationoperator: 36
operand: 46
27Operationoperator: 94
operands: 38
28ExprRangelambda_map: 39
start_index: 128
end_index: 122
29ExprRangelambda_map: 40
start_index: 128
end_index: 117
30ExprRangelambda_map: 41
start_index: 128
end_index: 122
31ExprRangelambda_map: 41
start_index: 103
end_index: 104
32ExprRangelambda_map: 42
start_index: 128
end_index: 122
33ExprRangelambda_map: 43
start_index: 128
end_index: 117
34ExprRangelambda_map: 44
start_index: 128
end_index: 122
35ExprRangelambda_map: 45
start_index: 128
end_index: 117
36Literal
37ExprTuple46
38ExprTuple47, 48
39Lambdaparameter: 102
body: 49
40Lambdaparameter: 102
body: 50
41Lambdaparameter: 102
body: 51
42Lambdaparameter: 102
body: 52
43Lambdaparameter: 102
body: 53
44Lambdaparameter: 102
body: 54
45Lambdaparameter: 102
body: 56
46Operationoperator: 57
operand: 116
47Operationoperator: 118
operands: 59
48Operationoperator: 126
operand: 71
49Operationoperator: 86
operands: 61
50Operationoperator: 68
operands: 62
51Operationoperator: 68
operands: 63
52Operationoperator: 64
operands: 65
53Operationoperator: 87
operands: 66
54Operationoperator: 68
operands: 67
55ExprTuple102
56Operationoperator: 68
operands: 69
57Literal
58ExprTuple116
59ExprTuple70, 128
60ExprTuple71
61NamedExprsstate: 72
62NamedExprselement: 73
targets: 81
63NamedExprselement: 74
targets: 75
64Literal
65NamedExprsbasis: 76
66NamedExprsoperation: 77
67NamedExprselement: 78
targets: 79
68Literal
69NamedExprselement: 80
targets: 81
70Operationoperator: 126
operand: 96
71Operationoperator: 118
operands: 83
72Operationoperator: 84
operand: 98
73Operationoperator: 86
operands: 93
74Operationoperator: 87
operands: 88
75Operationoperator: 94
operands: 89
76Literal
77Literal
78Operationoperator: 92
operands: 90
79Operationoperator: 94
operands: 91
80Operationoperator: 92
operands: 93
81Operationoperator: 94
operands: 95
82ExprTuple96
83ExprTuple97, 128
84Literal
85ExprTuple98
86Literal
87Literal
88NamedExprsoperation: 99
part: 102
89ExprTuple128, 104
90NamedExprsstate: 100
part: 102
91ExprTuple128, 122
92Literal
93NamedExprsstate: 101
part: 102
94Literal
95ExprTuple103, 104
96Operationoperator: 105
operands: 106
97Variable
98Literal
99Operationoperator: 107
operands: 108
100Operationoperator: 109
operands: 110
101Literal
102Variable
103Operationoperator: 118
operands: 111
104Operationoperator: 118
operands: 112
105Literal
106ExprTuple113, 114
107Literal
108ExprTuple115, 122
109Literal
110ExprTuple116, 122
111ExprTuple122, 128
112ExprTuple122, 117
113Literal
114Operationoperator: 118
operands: 119
115Literal
116Operationoperator: 120
operands: 121
117Literal
118Literal
119ExprTuple122, 123
120Literal
121ExprTuple124, 125
122Literal
123Operationoperator: 126
operand: 128
124Literal
125Variable
126Literal
127ExprTuple128
128Literal