logo

Expression of type LessEq

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, U, Variable, VertExprArray, eps, m, n, s, t
from proveit.numbers import Add, Exp, Interval, LessEq, ModAbs, Neg, frac, greater_eq, one, subtract, two, zero
from proveit.physics.quantum import I, NumKet, Z, ket_plus, var_ket_u
from proveit.physics.quantum.QPE import QPE, phase, 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 = greater_eq(ProbOfAll(instance_param_or_params = [m], instance_element = Qcircuit(vert_expr_array = VertExprArray([ExprRange(sub_expr1, Input(state = ket_plus), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Input(state = var_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), ExprRange(sub_expr1, Gate(operation = I).with_implicit_representation(), one, s)], [ExprRange(sub_expr1, MultiQubitElem(element = Output(state = NumKet(m, t), part = sub_expr1), targets = Interval(one, t)), one, t), ExprRange(sub_expr1, MultiQubitElem(element = Output(state = var_ket_u, part = sub_expr1), targets = sub_expr4), one, s)])), domain = Interval(zero, subtract(two_pow_t, one)), condition = LessEq(ModAbs(subtract(frac(m, two_pow_t), phase), one), Exp(two, Neg(n)))).with_wrapping(), subtract(one, eps))
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}{l}\textrm{Prob}_{m \in \{0~\ldotp \ldotp~2^{t} - 1\}~|~\left|\frac{m}{2^{t}} - \varphi\right|_{\textup{mod}\thinspace 1} \leq 2^{-n}}~\\
\left(\begin{array}{c} \Qcircuit@C=1em @R=.7em{
\qin{\lvert + \rangle} & \multigate{4}{\textrm{QPE}\left(U, t\right)} & \meter & \multiqout{3}{\lvert m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \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 m \rangle_{t}} \\
\qin{\lvert + \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & \meter & \ghostqout{\lvert m \rangle_{t}} \\
\qin{\lvert u \rangle} & \ghost{\textrm{QPE}\left(U, t\right)} & { /^{s} } \qw & \qout{\lvert u \rangle}
} \end{array}\right)\end{array}\right] \geq \left(1 - \epsilon\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)normalreversed('with_direction_reversed', 'is_reversed')
In [6]:
# display the expression information
stored_expr.expr_info()
 core typesub-expressionsexpression
0Operationoperator: 35
operands: 1
1ExprTuple2, 3
2Operationoperator: 118
operands: 4
3Operationoperator: 5
operand: 8
4ExprTuple124, 7
5Literal
6ExprTuple8
7Operationoperator: 111
operand: 12
8Lambdaparameter: 123
body: 11
9ExprTuple12
10ExprTuple123
11Conditionalvalue: 13
condition: 14
12Variable
13Operationoperator: 15
operands: 16
14Operationoperator: 17
operands: 18
15Literal
16ExprTuple19, 20, 21, 22
17Literal
18ExprTuple23, 24
19ExprTuple25, 26
20ExprTuple27, 28
21ExprTuple29, 30
22ExprTuple31, 32
23Operationoperator: 33
operands: 34
24Operationoperator: 35
operands: 36
25ExprRangelambda_map: 37
start_index: 124
end_index: 129
26ExprRangelambda_map: 38
start_index: 124
end_index: 125
27ExprRangelambda_map: 39
start_index: 124
end_index: 129
28ExprRangelambda_map: 39
start_index: 106
end_index: 107
29ExprRangelambda_map: 40
start_index: 124
end_index: 129
30ExprRangelambda_map: 41
start_index: 124
end_index: 125
31ExprRangelambda_map: 42
start_index: 124
end_index: 129
32ExprRangelambda_map: 43
start_index: 124
end_index: 125
33Literal
34ExprTuple123, 44
35Literal
36ExprTuple45, 46
37Lambdaparameter: 105
body: 47
38Lambdaparameter: 105
body: 48
39Lambdaparameter: 105
body: 49
40Lambdaparameter: 105
body: 50
41Lambdaparameter: 105
body: 51
42Lambdaparameter: 105
body: 52
43Lambdaparameter: 105
body: 54
44Operationoperator: 95
operands: 55
45Operationoperator: 56
operands: 57
46Operationoperator: 126
operands: 58
47Operationoperator: 87
operands: 59
48Operationoperator: 66
operands: 60
49Operationoperator: 66
operands: 61
50Operationoperator: 62
operands: 63
51Operationoperator: 88
operands: 64
52Operationoperator: 66
operands: 65
53ExprTuple105
54Operationoperator: 66
operands: 67
55ExprTuple68, 69
56Literal
57ExprTuple70, 124
58ExprTuple128, 71
59NamedExprsstate: 72
60NamedExprselement: 73
targets: 81
61NamedExprselement: 74
targets: 75
62Literal
63NamedExprsbasis: 76
64NamedExprsoperation: 77
65NamedExprselement: 78
targets: 79
66Literal
67NamedExprselement: 80
targets: 81
68Literal
69Operationoperator: 118
operands: 82
70Operationoperator: 118
operands: 83
71Operationoperator: 111
operand: 100
72Operationoperator: 85
operand: 101
73Operationoperator: 87
operands: 94
74Operationoperator: 88
operands: 89
75Operationoperator: 95
operands: 90
76Literal
77Literal
78Operationoperator: 93
operands: 91
79Operationoperator: 95
operands: 92
80Operationoperator: 93
operands: 94
81Operationoperator: 95
operands: 96
82ExprTuple120, 97
83ExprTuple98, 99
84ExprTuple100
85Literal
86ExprTuple101
87Literal
88Literal
89NamedExprsoperation: 102
part: 105
90ExprTuple124, 107
91NamedExprsstate: 103
part: 105
92ExprTuple124, 129
93Literal
94NamedExprsstate: 104
part: 105
95Literal
96ExprTuple106, 107
97Operationoperator: 111
operand: 124
98Operationoperator: 109
operands: 110
99Operationoperator: 111
operand: 121
100Variable
101Literal
102Operationoperator: 113
operands: 114
103Operationoperator: 115
operands: 116
104Variable
105Variable
106Operationoperator: 118
operands: 117
107Operationoperator: 118
operands: 119
108ExprTuple124
109Literal
110ExprTuple123, 120
111Literal
112ExprTuple121
113Literal
114ExprTuple122, 129
115Literal
116ExprTuple123, 129
117ExprTuple129, 124
118Literal
119ExprTuple129, 125
120Operationoperator: 126
operands: 127
121Variable
122Variable
123Variable
124Literal
125Variable
126Literal
127ExprTuple128, 129
128Literal
129Variable