Commit 4aa3615d by MARCHE Claude

trying to use the new floats theory for real

parent 079015c7
 (* Approximated cosine *) module M use import real.RealInfix use import real.Abs use import real.Trigonometry use import floating_point.Rounding use import floating_point.Single val single_of_real_exact (x: real) : single ensures { value result = x } val add (x y: single) : single requires { "expl:floating-point overflow" no_overflow NearestTiesToEven ((value x) +. (value y)) } ensures { value result = round NearestTiesToEven ((value x) +. (value y))} val sub (x y: single) : single requires { "expl:floating-point overflow" no_overflow NearestTiesToEven ((value x) -. (value y)) } ensures { value result = round NearestTiesToEven ((value x) -. (value y))} val mul (x y: single) : single requires { "expl:floating-point overflow" no_overflow NearestTiesToEven ((value x) *. (value y)) } ensures { value result = round NearestTiesToEven ((value x) *. (value y))} let my_cosine (x:single) : single requires { abs (value x) <=. 0x1p-5 } ensures { abs (value result -. cos (value x)) <=. 0x1p-23 } = assert { abs (1.0 -. (value x) *. (value x) *. 0.5 -. cos (value x)) <=. 0x1p-24 }; sub (single_of_real_exact 1.0) (mul (mul x x) (single_of_real_exact 0.5)) end module IEEEfloat use import real.RealInfix use import real.Abs use import real.Trigonometry use import ieee_float.Float32 val add (x y: t) : t requires { "expl:floating-point overflow" t'isFinite (x .+ y) } ensures { result = x .+ y } val sub (x y: t) : t requires { "expl:floating-point overflow" t'isFinite (x .- y)} ensures { result = x .- y } val mul (x y: t) : t requires { "expl:floating-point overflow" t'isFinite (x .* y)} ensures { result = x .* y } let my_cosine (x:t) : t requires { Float32.abs x .<= (0x1p-5:t) } ensures { Abs.abs (t'real result -. cos (t'real x)) <=. 0x1p-23 } = assert { Abs.abs (t'real x) <=. 0x1p-5 }; assert { Abs.abs (1.0 -. (t'real x) *. (t'real x) *. 0.5 -. cos (t'real x)) <=. 0x1p-24 }; sub (1.0:t) (mul (mul x x) (0.5:t)) end module Combined use import real.RealInfix use import real.Abs use import real.Trigonometry use import mach.float.Single let my_cosine (x:t) : t requires { abs x .<= (0x1p-5:t) } ensures { Abs.abs (t'real result -. cos (t'real x)) <=. 0x1p-23 } = assert { Abs.abs (t'real x) <=. 0x1p-5 }; assert { Abs.abs (1.0 -. (t'real x) *. (t'real x) *. 0.5 -. cos (t'real x)) <=. 0x1p-24 }; sub (1.0:t) (mul (mul x x) (0.5:t)) end
This diff is collapsed.
This diff is collapsed.
 (* This file is generated by Why3's Coq driver *) (* Beware! Only edit allowed sections below *) Require Import BuiltIn. Require Reals.Rbasic_fun. Require Reals.R_sqrt. Require Reals.Rtrigo_def. Require Reals.Rtrigo1. Require Reals.Ratan. Require BuiltIn. Require real.Real. Require real.RealInfix. Require real.Abs. Require real.FromInt. Require int.Int. Require real.Square. Require real.Trigonometry. Require floating_point.Rounding. Require floating_point.SingleFormat. Require floating_point.Single. (* Why3 assumption *) Definition unit := unit. Require Import Interval.Interval_tactic. (* Why3 goal *) Theorem WP_parameter_my_cosine : forall (x:floating_point.SingleFormat.single), ((Reals.Rbasic_fun.Rabs (floating_point.Single.value x)) <= (1 / 32)%R)%R -> ((Reals.Rbasic_fun.Rabs ((1%R - (((floating_point.Single.value x) * (floating_point.Single.value x))%R * (05 / 10)%R)%R)%R - (Reals.Rtrigo_def.cos (floating_point.Single.value x)))%R) <= (1 / 16777216)%R)%R. (* Why3 intros x h1. *) (* YOU MAY EDIT THE PROOF BELOW *) intros x H. interval with (i_bisect_diff (Single.value x)). Qed.

 module ExpOld end module Exp use import ieee_float.Float64 use import real.Abs use import real.ExpLog use import real.Real val ( +. ) (x y : t) : t requires {t'isFinite x} requires {t'isFinite y} requires {"expl:no_overflow" t'isFinite (x .+ y)} ensures {result = x .+ y} val ( *. ) (x y : t) : t requires {t'isFinite x} requires {t'isFinite y} requires {"expl:no_overflow" t'isFinite (x .* y)} ensures {result = x .* y} let my_exp (x: t) : t requires { t'isFinite x} requires { .- (1.0:t) .<= x .<= (1.0:t)} requires {abs (t'real x) <= 1.0} ensures { abs (t'real result - exp (t'real x)) <= 0x1p-4} (* 1 * 2 ^ - 4 *) = assert { let x = t'real x in abs(0.9890365552 + 1.130258690*x + 0.5540440796*x*x - exp(x)) <= 0x0.FFFFp-4}; (0x1.FA62FFD643D6Ep-1:t) +. (0x1.2158A22D91DE9p0:t) *. x +. (0x1.1BABAA64D94DBp-1:t) *. x *. x end
This diff is collapsed.