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 Add, Interval, ModAbs, greater, one
from proveit.physics.quantum import NumKet, Z, ket_plus
from proveit.physics.quantum.QPE import ModAdd, Pfail, QPE, _U, _b_floor, _full_domain, _ket_u, _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 = 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 = Equals(Pfail(e), ProbOfAll(instance_param_or_params = [l], 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_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)])), domain = _full_domain, condition = greater(ModAbs(l, _two_pow_t), e)))
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[P_{\rm fail}\right]\left(e\right) = \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]
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.()()('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: 44
4Operationoperator: 7
operand: 9
5Literal
6ExprTuple44
7Literal
8ExprTuple9
9Lambdaparameter: 118
body: 11
10ExprTuple118
11Conditionalvalue: 12
condition: 13
12Operationoperator: 14
operands: 15
13Operationoperator: 16
operands: 17
14Literal
15ExprTuple18, 19, 20, 21
16Literal
17ExprTuple22, 23
18ExprTuple24, 25
19ExprTuple26, 27
20ExprTuple28, 29
21ExprTuple30, 31
22Operationoperator: 32
operands: 33
23Operationoperator: 34
operands: 35
24ExprRangelambda_map: 36
start_index: 125
end_index: 121
25ExprRangelambda_map: 37
start_index: 125
end_index: 110
26ExprRangelambda_map: 38
start_index: 125
end_index: 121
27ExprRangelambda_map: 38
start_index: 98
end_index: 99
28ExprRangelambda_map: 39
start_index: 125
end_index: 121
29ExprRangelambda_map: 40
start_index: 125
end_index: 110
30ExprRangelambda_map: 41
start_index: 125
end_index: 121
31ExprRangelambda_map: 42
start_index: 125
end_index: 110
32Literal
33ExprTuple118, 43
34Literal
35ExprTuple44, 45
36Lambdaparameter: 97
body: 46
37Lambdaparameter: 97
body: 47
38Lambdaparameter: 97
body: 48
39Lambdaparameter: 97
body: 49
40Lambdaparameter: 97
body: 50
41Lambdaparameter: 97
body: 51
42Lambdaparameter: 97
body: 53
43Operationoperator: 90
operands: 54
44Variable
45Operationoperator: 55
operands: 56
46Operationoperator: 82
operands: 57
47Operationoperator: 64
operands: 58
48Operationoperator: 64
operands: 59
49Operationoperator: 60
operands: 61
50Operationoperator: 83
operands: 62
51Operationoperator: 64
operands: 63
52ExprTuple97
53Operationoperator: 64
operands: 65
54ExprTuple66, 107
55Literal
56ExprTuple118, 67
57NamedExprsstate: 68
58NamedExprselement: 69
targets: 77
59NamedExprselement: 70
targets: 71
60Literal
61NamedExprsbasis: 72
62NamedExprsoperation: 73
63NamedExprselement: 74
targets: 75
64Literal
65NamedExprselement: 76
targets: 77
66Operationoperator: 119
operands: 78
67Operationoperator: 111
operands: 79
68Operationoperator: 80
operand: 93
69Operationoperator: 82
operands: 89
70Operationoperator: 83
operands: 84
71Operationoperator: 90
operands: 85
72Literal
73Literal
74Operationoperator: 88
operands: 86
75Operationoperator: 90
operands: 87
76Operationoperator: 88
operands: 89
77Operationoperator: 90
operands: 91
78ExprTuple92, 125
79ExprTuple115, 121
80Literal
81ExprTuple93
82Literal
83Literal
84NamedExprsoperation: 94
part: 97
85ExprTuple125, 99
86NamedExprsstate: 95
part: 97
87ExprTuple125, 121
88Literal
89NamedExprsstate: 96
part: 97
90Literal
91ExprTuple98, 99
92Operationoperator: 123
operand: 107
93Literal
94Operationoperator: 101
operands: 102
95Operationoperator: 103
operands: 104
96Literal
97Variable
98Operationoperator: 119
operands: 105
99Operationoperator: 119
operands: 106
100ExprTuple107
101Literal
102ExprTuple108, 121
103Literal
104ExprTuple109, 121
105ExprTuple121, 125
106ExprTuple121, 110
107Operationoperator: 111
operands: 112
108Literal
109Operationoperator: 113
operands: 114
110Literal
111Literal
112ExprTuple115, 116
113Literal
114ExprTuple117, 118
115Literal
116Operationoperator: 119
operands: 120
117Literal
118Variable
119Literal
120ExprTuple121, 122
121Literal
122Operationoperator: 123
operand: 125
123Literal
124ExprTuple125
125Literal