FmaEmul

# Library FmaEmul

`Require Export DblRndOdd.
Require Export FboundI.
Require Export MinOrMax.
Require Export DoubleRound.
Section Prelim.
Variable b : Fbound.
Variable radix : Z.
Variable precision : nat.
Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.
Hypothesis radixMoreThanOne : (1 < radix)%Z.
Let radixMoreThanZERO := Zlt_1_O _ (Zlt_le_weak _ _ radixMoreThanOne).
Hint Resolve radixMoreThanZERO: zarith.
Hypothesis precisionGreaterThanOne : 1 < precision.
Hypothesis pGivesBound : Zpos (vNum b) = Zpower_nat radix precision.
Theorem plusExactSub: forall (P : R -> float -> Prop) (x y r : float),
(RoundedModeP b radix P) ->
(Fsubnormal radix b x) -> (Fsubnormal radix b y) ->
(P (x+y)%R r)
-> (FtoRradix r=x+y)%R.
End Prelim.
Section Sec1.
Variable bo : Fbound.
Let radix := 2%Z.
Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.
Variable p : nat.
Hypotheses pGreaterThanOne : (lt (S O) p).
Hypotheses pGivesBound : (Zpos (vNum bo)) = (Zpower_nat radix p).
Theorem AddOddEven_aux_aux: forall (x y:float),
(5* (Rabs y) <= x)%R -> (0 < x)%R
-> (5*(firstNormalPos radix bo p) <= x)%R
-> (Fcanonic radix bo y) ->(Fcanonic radix bo x) ->
(exists k:nat, exists be:Fbound, exists xy:float,
(1 < k) /\ (Zpos (vNum be)) = (Zpower_nat radix (p+k))
/\ (- dExp be <= Zpred (Zpred (- dExp bo)))%Z
/\ (FtoRradix xy =x+y)%R
/\ (Fnormal radix be xy) /\ (Fexp xy=Fexp y)).
Theorem AddOddEven_aux: forall (x y f1 f2:float) (z:R),
(5* (Rabs y) <= x)%R -> (0 < x)%R ->
(5*(firstNormalPos radix bo p) <= x)%R ->
(Fcanonic radix bo y) ->(Fcanonic radix bo x) ->
(To_Odd bo radix p z y) ->
(EvenClosest bo radix p (x+y)%R f1) ->
(EvenClosest bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
Theorem AddOddEven_can: forall (x y f1 f2:float) (z:R),
(5*(Rabs y) <= Rabs x)%R ->
(5*(firstNormalPos radix bo p) <= Rabs x)%R ->
Fcanonic radix bo y ->(Fcanonic radix bo x) ->
(To_Odd bo radix p z y) ->
(EvenClosest bo radix p (x+y)%R f1) ->
(EvenClosest bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
Theorem AddOddEven: forall (x y f1 f2:float) (z:R),
(Fbounded bo x) ->
(5*(Rabs y) <= Rabs x)%R ->
(5*(firstNormalPos radix bo p) <= Rabs x)%R ->
(To_Odd bo radix p z y) ->
(EvenClosest bo radix p (x+y)%R f1) ->
(EvenClosest bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
Theorem AddOddEven2: forall (x y f1 f2:float) (z:R),
(3 < p) ->
(6*(Rabs z) <= Rabs x)%R ->
(5*(firstNormalPos radix bo p) <= Rabs x)%R ->
Fcanonic radix bo y ->(Fcanonic radix bo x) ->
(To_Odd bo radix p z y) ->
(EvenClosest bo radix p (x+y)%R f1) ->
(EvenClosest bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
End Sec1.
Section Sec2.
Variable bo : Fbound.
Let radix := 2%Z.
Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.
Variable p : nat.
Hypotheses pGreaterThanOne : (lt (S O) p).
Hypotheses pGivesBound : (Zpos (vNum bo)) = (Zpower_nat radix p).
Hypotheses pGe : (5 <= p).
Variable a b c uh ul th tl v z:float.
Hypothesis Fa : Fbounded bo a.
Hypothesis Fb : Fbounded bo b.
Hypothesis Fc : Fbounded bo c.
Hypothesis Fuh: Fbounded bo uh.
Hypothesis Ful: Fbounded bo ul.
Hypothesis Fth: Fbounded bo th.
Hypothesis Ftl: Fbounded bo tl.
Hypothesis Fv : Fbounded bo v.
Hypothesis Fz : Fbounded bo z.
Hypothesis Cth: Fcanonic radix bo th.
Hypothesis Cuh: Fcanonic radix bo uh.
Hypothesis Ctl: Fcanonic radix bo tl.
Hypothesis Cul: Fcanonic radix bo ul.
Hypothesis uhDef: (Closest bo radix (a*b)%R uh).
Hypothesis ulDef: (FtoRradix ul=a*b-uh)%R.
Hypothesis thDef: (Closest bo radix (c+uh)%R th).
Hypothesis tlDef: (FtoRradix tl=c+uh-th)%R.
Hypothesis vDef: (To_Odd bo radix p (tl+ul)%R v).
Hypothesis zDef: (EvenClosest bo radix p (th+v)%R z).
Theorem FmaEmulAux: (EvenClosest bo radix p (a*b+c)%R z).
End Sec2.
Section Sec3.
Variable bo : Fbound.
Let radix := 2%Z.
Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.
Variable p : nat.
Hypotheses pGivesBound : (Zpos (vNum bo)) = (Zpower_nat radix p).
Hypotheses pGe : (5 <= p).
Variable a b c uh ul th tl v z:float.
Hypothesis Fa : Fbounded bo a.
Hypothesis Fb : Fbounded bo b.
Hypothesis Fc : Fbounded bo c.
Hypothesis Ful: Fbounded bo ul.
Hypothesis uhDef: (Closest bo radix (a*b)%R uh).
Hypothesis ulDef: (FtoRradix ul=a*b-uh)%R.
Hypothesis thDef: (Closest bo radix (c+uh)%R th).
Hypothesis tlDef: (FtoRradix tl=c+uh-th)%R.
Hypothesis vDef: (To_Odd bo radix p (tl+ul)%R v).
Hypothesis zDef: (EvenClosest bo radix p (th+v)%R z).
Theorem FmaEmul: (EvenClosest bo radix p (a*b+c)%R z).
End Sec3.
Section Sec4.
Variables b be : Fbound.
Variables p k : nat.
Variables y z v: float.
Variables x : R.
Let radix := 2%Z.
Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.
Theorem Zpos_eq_eq: forall (a b:positive),
(Zpos a=Zpos b) -> a=b.
Hypotheses pGreaterThanOne : (lt (S O) p).
Hypotheses kGreaterThanOne : (le O k).
Hypotheses pGivesBound : (Zpos (vNum b)) = (Zpower_nat radix p).
Hypotheses pkGivesBounde : (Zpos (vNum be)) = (Zpower_nat radix (plus p k)).
Hypothesis Cy: (Fcanonic radix be y).
Hypothesis Cz: (Fcanonic radix b z).
Hypotheses ydef : (To_Odd be radix (plus p k) x y).
Hypotheses zdef : (To_Odd b radix p y z).
Hypotheses vdef : (To_Odd b radix p x v).
Hypotheses rangeext: (-(dExp be) = ( -k-(dExp b)))%Z.
Theorem FevenMakesFNeven: forall b:Fbound, forall p:nat, forall f g:float,
Zpos (vNum b) = Zpower_nat radix p -> (0 < p) ->
Fbounded b g -> Fbounded b f ->
Feven g -> FtoRradix g=f -> FNeven b radix p f.
Theorem To_Odd_Odd_is_Odd: ((FtoRradix v)=(FtoRradix z))%R.
End Sec4.
Section Sec5.
Variable bo : Fbound.
Let radix := 2%Z.
Let FtoRradix := FtoR radix.
Coercion FtoRradix : float >-> R.
Variable p : nat.
Hypotheses pGreaterThanOne: (lt (S O) p).
Hypotheses pGivesBound : (Zpos (vNum bo)) = (Zpower_nat radix p).
Hypotheses dExpBig : (p <= dExp bo)%Z.
Theorem AddOddOdd_aux_aux: forall (x y:float),
(2* (Rabs y) <= x)%R -> (0 < x)%R
-> (2*(firstNormalPos radix bo p) <= x)%R
-> (Fcanonic radix bo y) ->(Fcanonic radix bo x) ->
(exists k:nat, exists be:Fbound, exists xy:float,
(0 <= k) /\ (Zpos (vNum be)) = (Zpower_nat radix (p+k))
/\ (- dExp be = -k - dExp bo)%Z
/\ (FtoRradix xy =x+y)%R
/\ (Fnormal radix be xy) /\ (Fexp xy=Fexp y)).
Theorem AddOddOdd_aux: forall (x y f1 f2:float) (z:R),
(2* (Rabs y) <= x)%R -> (0 < x)%R ->
(2*(firstNormalPos radix bo p) <= x)%R ->
(Fcanonic radix bo y) ->(Fcanonic radix bo x) ->
(To_Odd bo radix p z y) ->
(To_Odd bo radix p (x+y)%R f1) ->
(To_Odd bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
Theorem AddOddOdd_can: forall (x y f1 f2:float) (z:R),
(2*(Rabs y) <= Rabs x)%R ->
(2*(firstNormalPos radix bo p) <= Rabs x)%R ->
Fcanonic radix bo y ->(Fcanonic radix bo x) ->
(To_Odd bo radix p z y) ->
(To_Odd bo radix p (x+y)%R f1) ->
(To_Odd bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
Theorem AddOddOdd: forall (x y f1 f2:float) (z:R),
(Fbounded bo x) ->
(2*(Rabs y) <= Rabs x)%R ->
(2*(firstNormalPos radix bo p) <= Rabs x)%R ->
(To_Odd bo radix p z y) ->
(To_Odd bo radix p (x+y)%R f1) ->
(To_Odd bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
Theorem AddOddOdd2_can: forall (x y f1 f2:float) (z:R),
(2*(Rabs z) <= Rabs x)%R ->
(2*(firstNormalPos radix bo p) <= Rabs x)%R ->
Fcanonic radix bo y ->(Fcanonic radix bo x) ->
(To_Odd bo radix p z y) ->
(To_Odd bo radix p (x+y)%R f1) ->
(To_Odd bo radix p (x+z)%R f2) ->
(FtoRradix f1=f2)%R.
Theorem AddOddOdd2:
forall (x y f1 f2:float) (z:R),
Fbounded bo x ->
(2*(Rabs z) <= Rabs x)%R ->
(2*(firstNormalPos radix bo p) <= Rabs x)%R ->
To_Odd bo radix p z y ->
To_Odd bo radix p (x+y)%R f1 ->
To_Odd bo radix p (x+z)%R f2 ->
(FtoRradix f1 = f2)%R.
End Sec5.
`