Wiki Agenda Contact Version française

Approximated Cosine in Why3

This is a Why3 version of the Approximated Cosine example


Authors: Claude Marché

Topics: Floating-Point Computations / Non-linear Arithmetic

Tools: Why3 / Gappa / Coq

See also: Approximated Cosine in C annotated in ACSL

see also the index (by topic, by tool, by reference, by year)


(* Approximated cosine

   Claude Marché (Inria) *)

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 { no_overflow NearestTiesToEven ((value x) +. (value y)) }
  ensures  { value result = round NearestTiesToEven ((value x) +. (value y))}

val sub (x y: single) : single
  requires { no_overflow NearestTiesToEven ((value x) -. (value y)) }
  ensures  { value result = round NearestTiesToEven ((value x) -. (value y))}

val mul (x y: single) : single
  requires { 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

download ZIP archive

Why3 Proof Results for Project "my_cosine"

Theory "my_cosine.M": fully verified in 4.24 s

ObligationsCoq (8.4pl6)Gappa (1.2.0)MetiTarski (2.4)
VC for my_cosine---------
split_goal_wp
  1. assertion4.07---0.17
2. precondition---0.00---
3. precondition---0.00---
4. precondition---0.00---
5. postcondition---0.00---