Debian Codegraph @

theories/Corelib/Floats/FloatAxioms.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 From Corelib Require Import BinNums IntDef Uint63Axioms.
12 From Corelib Require Import SpecFloat PrimFloat FloatOps.
13
14 (** * Properties of the primitive operators for the Binary64 format *)
15
16 Abbreviation valid_binary := (valid_binary prec emax).
17
18 Definition SF64classify := SFclassify prec.
19 Definition SF64mul := SFmul prec emax.
20 Definition SF64add := SFadd prec emax.
21 Definition SF64sub := SFsub prec emax.
22 Definition SF64div := SFdiv prec emax.
23 Definition SF64sqrt := SFsqrt prec emax.
24 Definition SF64succ := SFsucc prec emax.
25 Definition SF64pred := SFpred prec emax.
26
27 Axiom Prim2SF_valid : forall x, valid_binary (Prim2SF x) = true.
28 Axiom SF2Prim_Prim2SF : forall x, SF2Prim (Prim2SF x) = x.
29 Axiom Prim2SF_SF2Prim : forall x, valid_binary x = true -> Prim2SF (SF2Prim x) = x.
30
31 Theorem Prim2SF_inj : forall x y, Prim2SF x = Prim2SF y -> x = y.
32 intros. rewrite <- SF2Prim_Prim2SF. symmetry. rewrite <- SF2Prim_Prim2SF. now rewrite H.
33 Qed.
34
35 Theorem SF2Prim_inj : forall x y, SF2Prim x = SF2Prim y -> valid_binary x = true -> valid_binary y = true -> x = y.
36 intros. rewrite <- Prim2SF_SF2Prim by assumption. symmetry. rewrite <- Prim2SF_SF2Prim by assumption. rewrite H. reflexivity.
37 Qed.
38
39 Axiom opp_spec : forall x, Prim2SF (-x)%float = SFopp (Prim2SF x).
40 Axiom abs_spec : forall x, Prim2SF (abs x) = SFabs (Prim2SF x).
41
42 Axiom eqb_spec : forall x y, (x =? y)%float = SFeqb (Prim2SF x) (Prim2SF y).
43 Axiom ltb_spec : forall x y, (x <? y)%float = SFltb (Prim2SF x) (Prim2SF y).
44 Axiom leb_spec : forall x y, (x <=? y)%float = SFleb (Prim2SF x) (Prim2SF y).
45
46 Definition flatten_cmp_opt c :=
47 match c with
48 | None => FNotComparable
49 | Some Eq => FEq
50 | Some Lt => FLt
51 | Some Gt => FGt
52 end.
53 Axiom compare_spec : forall x y, (x ?= y)%float = flatten_cmp_opt (SFcompare (Prim2SF x) (Prim2SF y)).
54
55 Module Leibniz.
56 Axiom eqb_spec : forall x y, Leibniz.eqb x y = true <-> x = y.
57 End Leibniz.
58
59 Axiom classify_spec : forall x, classify x = SF64classify (Prim2SF x).
60 Axiom mul_spec : forall x y, Prim2SF (x * y)%float = SF64mul (Prim2SF x) (Prim2SF y).
61 Axiom add_spec : forall x y, Prim2SF (x + y)%float = SF64add (Prim2SF x) (Prim2SF y).
62 Axiom sub_spec : forall x y, Prim2SF (x - y)%float = SF64sub (Prim2SF x) (Prim2SF y).
63 Axiom div_spec : forall x y, Prim2SF (x / y)%float = SF64div (Prim2SF x) (Prim2SF y).
64 Axiom sqrt_spec : forall x, Prim2SF (sqrt x) = SF64sqrt (Prim2SF x).
65
66 Axiom of_uint63_spec : forall n, Prim2SF (of_uint63 n) = binary_normalize prec emax (to_Z n) Z0 false.
67 Axiom normfr_mantissa_spec : forall f, to_Z (normfr_mantissa f) = Z.of_N (SFnormfr_mantissa prec (Prim2SF f)).
68
69 Axiom frshiftexp_spec : forall f,
70 let (m,e) := frshiftexp f in
71 (Prim2SF m, Z.sub (to_Z e) shift) = SFfrexp prec emax (Prim2SF f).
72 Axiom ldshiftexp_spec : forall f e,
73 Prim2SF (ldshiftexp f e) = SFldexp prec emax (Prim2SF f) (Z.sub (to_Z e) shift).
74
75 Axiom next_up_spec : forall x, Prim2SF (next_up x) = SF64succ (Prim2SF x).
76 Axiom next_down_spec : forall x, Prim2SF (next_down x) = SF64pred (Prim2SF x).