library colibrilib.product — module ApowThe 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).
module Apow83use real.RealInfix84use real.Abs85use real.ExpLog86use real.PowerReal8788function apow (x q:real) : real =89if x = 0. then (if q = 0. then 1. else 0.) else pow (abs x) q90Valid (35ms) (colibri2)91let ghost apow_nonneg (x q:real) : unit92ensures { 0. <=. apow x q }93ensures { apow x q = 0. <-> (x = 0. /\ q <> 0.) }94= ()95Valid (29ms) (colibri2)96let ghost apow_zero (x:real) : unit97ensures { apow x 0. = 1. }98= ()99Valid (30ms) (colibri2)100let ghost apow_one (x:real) : unit101ensures { apow x 1. = abs x }102= ()103
Trusted by the power of the stdlib: unconditional
Valid (179ms) (colibri2)let ghost apow_prod (x y q:real) : unit106ensures { apow (x *. y) q = apow x q *. apow y q }107= {proof…} if x <> 0. && y <> 0. then begin108assert { abs (x *. y) = abs x *. abs y };109assert { log (abs x *. abs y) = log (abs x) +. log (abs y) };110assert { pow (abs x *. abs y) q = exp (q *. log (abs x) +. q *. log (abs y)) }111end {qed}112Valid (37ms) (colibri2)113let ghost apow_apow (x q c:real) : unit114ensures { apow (apow x q) c = apow x (q *. c) }115= {proof…} if x <> 0. then assert { abs (apow x q) = apow x q } {qed}116
The sum of the exponents: a zero x has non negative exponents
Valid (39ms) (colibri2)let ghost apow_add (x q1 q2:real) : unit119requires { x <> 0. \/ (0. <=. q1 /\ 0. <=. q2) }120ensures { apow x (q1 +. q2) = apow x q1 *. apow x q2 }121= ()122
The inverse
Valid (26ms) (colibri2)let ghost apow_neg (x q:real) : unit125requires { x <> 0. }126ensures { apow x (-. q) *. apow x q = 1. }127= apow_add x (-. q) q128Valid (27ms) (colibri2)129let ghost apow_abs (x q:real) : unit130ensures { apow (abs x) q = apow x q }131= ()132133use int.Int134use real.FromInt135use real.PowerInt136
The power of the reals at an integer is the power at an integer
Valid (84ms) (colibri2)let rec ghost pow_from_int (x:real) (n:int) : unit139requires { 0. <. x }140requires { 0 <= n }141ensures { pow x (from_int n) = power x n }142variant { n }143= {proof…} if n > 0 then begin144pow_from_int x (n - 1);145assert { from_int n = from_int (n - 1) +. 1. };146assert { pow x (from_int n) = pow x (from_int (n - 1)) *. pow x 1. }147end {qed}148
The power at a positive integer is increasing on the non negative reals
Valid (707ms) (colibri2 8) (split_vc) (depth 1)let rec ghost power_lt (x y:real) (d:int) : unit151requires { 0. <=. x <. y }152requires { 0 < d }153ensures { 0. <=. power x d <. power y d }154variant { d }155= {proof…} if d > 1 then begin156power_lt x y (d - 1);157assert { power x d = x *. power x (d - 1) };158assert { power y d = y *. power y (d - 1) };159assert { x *. power x (d - 1) <=. y *. power x (d - 1) };160assert { y *. power x (d - 1) <. y *. power y (d - 1) }161end {qed}162
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)let ghost root_pow (x r:real) (n d:int) : unit166requires { 0 < d }167requires { 0. <=. r }168requires { 0. <. x }169requires { 0 <= n -> power r d = power x n }170requires { n < 0 -> power r d *. power x (- n) = 1. }171ensures { r = apow x (from_int n /. from_int d) }172= {proof…}173let ghost s = pow x (from_int n /. from_int d) in174pow_from_int s d;175assert { from_int n /. from_int d *. from_int d = from_int n };176assert { power s d = pow x (from_int n) };177if 0 <= n then pow_from_int x n178else begin179pow_from_int x (- n);180assert { pow x (from_int n) *. pow x (from_int (- n)) = 1.181by pow x (from_int n +. from_int (- n)) = pow x 0. };182power_lt 0. x (- n);183assert { power r d = power s d }184end;185if pure { r <. s } then power_lt r s d;186if pure { s <. r } then power_lt s r d187{qed}188end189