Common — library colibrilib.product — module Apow

The absolute value to a real power, with 0^0 = 1 and 0^q = 0 otherwise. A product of colibri2 is c * |x1|^q1 * ... * |xn|^qn; a negative exponent means that the node is not zero (Prod.valid).

83
module Apow
84
use real.RealInfix
85
use real.Abs
86
use real.ExpLog
87
use real.PowerReal
88
89
function
apow
(x q:real) : real =
90
if x = 0. then (if q = 0. then 1. else 0.) else pow (abs x) q
91
Valid (35ms) (colibri2)
92
let ghost
apow_nonneg
(x q:real) : unit
93
ensures { 0. <=. apow x q }
94
ensures { apow x q = 0. <-> (x = 0. /\ q <> 0.) }
95
= ()
96
Valid (29ms) (colibri2)
97
let ghost
apow_zero
(x:real) : unit
98
ensures { apow x 0. = 1. }
99
= ()
100
Valid (30ms) (colibri2)
101
let ghost
apow_one
(x:real) : unit
102
ensures { apow x 1. = abs x }
103
= ()

Trusted by the power of the stdlib: unconditional

  Valid (179ms) (colibri2)
106
let ghost
apow_prod
(x y q:real) : unit
107
ensures { apow (x *. y) q = apow x q *. apow y q }
108
= {proof…} if x <> 0. && y <> 0. then begin
109
assert { abs (x *. y) = abs x *. abs y };
110
assert { log (abs x *. abs y) = log (abs x) +. log (abs y) };
111
assert { pow (abs x *. abs y) q = exp (q *. log (abs x) +. q *. log (abs y)) }
112
end {qed}
113
Valid (37ms) (colibri2)
114
let ghost
apow_apow
(x q c:real) : unit
115
ensures { apow (apow x q) c = apow x (q *. c) }
116
= {proof…} if x <> 0. then assert { abs (apow x q) = apow x q } {qed}

The sum of the exponents: a zero x has non negative exponents

  Valid (39ms) (colibri2)
119
let ghost
apow_add
(x q1 q2:real) : unit
120
requires { x <> 0. \/ (0. <=. q1 /\ 0. <=. q2) }
121
ensures { apow x (q1 +. q2) = apow x q1 *. apow x q2 }
122
= ()

The inverse

  Valid (26ms) (colibri2)
125
let ghost
apow_neg
(x q:real) : unit
126
requires { x <> 0. }
127
ensures { apow x (-. q) *. apow x q = 1. }
128
= apow_add x (-. q) q
129
Valid (27ms) (colibri2)
130
let ghost
apow_abs
(x q:real) : unit
131
ensures { apow (abs x) q = apow x q }
132
= ()
133
134
use int.Int
135
use real.FromInt
136
use real.PowerInt

The power of the reals at an integer is the power at an integer

  Valid (84ms) (colibri2)
139
let rec ghost
pow_from_int
(x:real) (n:int) : unit
140
requires { 0. <. x }
141
requires { 0 <= n }
142
ensures { pow x (from_int n) = power x n }
143
variant { n }
144
= {proof…} if n > 0 then begin
145
pow_from_int x (n - 1);
146
assert { from_int n = from_int (n - 1) +. 1. };
147
assert { pow x (from_int n) = pow x (from_int (n - 1)) *. pow x 1. }
148
end {qed}

The power at a positive integer is increasing on the non negative reals

  Valid (707ms) (colibri2 8) (split_vc) (depth 1)
151
let rec ghost
power_lt
(x y:real) (d:int) : unit
152
requires { 0. <=. x <. y }
153
requires { 0 < d }
154
ensures { 0. <=. power x d <. power y d }
155
variant { d }
156
= {proof…} if d > 1 then begin
157
power_lt x y (d - 1);
158
assert { power x d = x *. power x (d - 1) };
159
assert { power y d = y *. power y (d - 1) };
160
assert { x *. power x (d - 1) <=. y *. power x (d - 1) };
161
assert { y *. power x (d - 1) <. y *. power y (d - 1) }
162
end {qed}

The non negative d–th root of x^n is the power of the reals at n/d (the specification of Std.A.positive_pow)

  Valid (604ms) (colibri2)
166
let ghost
root_pow
(x r:real) (n d:int) : unit
167
requires { 0 < d }
168
requires { 0. <=. r }
169
requires { 0. <. x }
170
requires { 0 <= n -> power r d = power x n }
171
requires { n < 0 -> power r d *. power x (- n) = 1. }
172
ensures { r = apow x (from_int n /. from_int d) }
173
= {proof…}
174
let ghost s = pow x (from_int n /. from_int d) in
175
pow_from_int s d;
176
assert { from_int n /. from_int d *. from_int d = from_int n };
177
assert { power s d = pow x (from_int n) };
178
if 0 <= n then pow_from_int x n
179
else begin
180
pow_from_int x (- n);
181
assert { pow x (from_int n) *. pow x (from_int (- n)) = 1.
182
by pow x (from_int n +. from_int (- n)) = pow x 0. };
183
power_lt 0. x (- n);
184
assert { power r d = power s d }
185
end;
186
if pure { r <. s } then power_lt r s d;
187
if pure { s <. r } then power_lt s r d
188
{qed}
189
end