(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*          Jacques-Henri Jourdan, INRIA Paris-Rocquencourt            *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the GNU General Public License as published by  *)
(*  the Free Software Foundation, either version 2 of the License, or  *)
(*  (at your option) any later version.  This file is also distributed *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** Formalization of floating-point numbers, using the Flocq library. *)
Require Archi.
Close Scope R_scope.
Definition float := binary64. (**r the type of IEE754 double-precision FP numbers *)
Definition float32 := binary32. (**r the type of IEE754 single-precision FP numbers *)
(** Boolean-valued comparisons *)
Definition cmp_of_comparison (c: comparison) (x: option Datatypes.comparison) : bool :=
match c with
| Ceq =>
match x with Some Eq => true | _ => false end
| Cne =>
match x with Some Eq => false | _ => true end
| Clt =>
match x with Some Lt => true | _ => false end
| Cle =>
match x with Some(Lt|Eq) => true | _ => false end
| Cgt =>
match x with Some Gt => true | _ => false end
| Cge =>
match x with Some(Gt|Eq) => true | _ => false end
end.

(* Specifications: *)
Lemma cmp_of_comparison_swap:
forall c x,
cmp_of_comparison (swap_comparison c) x =
cmp_of_comparison c (match x with None => None | Some x => Some (CompOpp x) end).
Lemma cmp_of_comparison_ne_eq:
forall x, cmp_of_comparison Cne x = negb (cmp_of_comparison Ceq x).
Lemma cmp_of_comparison_lt_eq_false:
forall x, cmp_of_comparison Clt x = true -> cmp_of_comparison Ceq x = true -> False.
Lemma cmp_of_comparison_le_lt_eq:
forall x, cmp_of_comparison Cle x = cmp_of_comparison Clt x || cmp_of_comparison Ceq x.
Lemma cmp_of_comparison_gt_eq_false:
forall x, cmp_of_comparison Cgt x = true -> cmp_of_comparison Ceq x = true -> False.
Lemma cmp_of_comparison_ge_gt_eq:
forall x, cmp_of_comparison Cge x = cmp_of_comparison Cgt x || cmp_of_comparison Ceq x.
Lemma cmp_of_comparison_lt_gt_false:
forall x, cmp_of_comparison Clt x = true -> cmp_of_comparison Cgt x = true -> False.
Lemma cmp_of_comparison_swap:
forall c x,
cmp_of_comparison (swap_comparison c) x =
cmp_of_comparison c (match x with None => None | Some x => Some (CompOpp x) end).
Lemma cmp_of_comparison_ne_eq:
forall x, cmp_of_comparison Cne x = negb (cmp_of_comparison Ceq x).
Lemma cmp_of_comparison_lt_eq_false:
forall x, cmp_of_comparison Clt x = true -> cmp_of_comparison Ceq x = true -> False.
Lemma cmp_of_comparison_le_lt_eq:
forall x, cmp_of_comparison Cle x = cmp_of_comparison Clt x || cmp_of_comparison Ceq x.
Lemma cmp_of_comparison_gt_eq_false:
forall x, cmp_of_comparison Cgt x = true -> cmp_of_comparison Ceq x = true -> False.
Lemma cmp_of_comparison_ge_gt_eq:
forall x, cmp_of_comparison Cge x = cmp_of_comparison Cgt x || cmp_of_comparison Ceq x.
Lemma cmp_of_comparison_lt_gt_false:
forall x, cmp_of_comparison Clt x = true -> cmp_of_comparison Cgt x = true -> False.