Wiki Agenda Contact English version

Approximated Cosine in Why3

This is a Why3 version of the Approximated Cosine example


Auteurs: Claude Marché

Catégories: Floating-Point Computations / Non-linear Arithmetic

Outils: Why3 / Gappa / Coq

Voir aussi: 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 real.RealInfix
  use real.Abs
  use real.Trigonometry
  use floating_point.Rounding
  use 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

ObligationsAlt-Ergo 2.1.0Coq 8.11.2Gappa 1.3.0MetiTarski 2.4
VC for my_cosine------------
split_goal_right
assertion---1.01---0.14
precondition0.01---------
precondition0.05---------
precondition------0.00---
postcondition------0.01---