TwoSum

# Library TwoSum

`Require Export Fast2Sum.
Section EFast.
Variable b : Fbound.
Variable precision : nat.
Let radix := 2%Z.
Let TMTO : (1 < radix)%Z := TwoMoreThanOne.
Hint Resolve TMTO: zarith.
Coercion Local FtoRradix := FtoR radix.
Hypothesis precisionGreaterThanOne : 1 < precision.
Hypothesis pGivesBound : Zpos (vNum b) = Zpower_nat radix precision.
Variable Iplus : float -> float -> float.
Hypothesis
IplusCorrect :
forall p q : float,
Fbounded b p -> Fbounded b q -> Closest b radix (p + q) (Iplus p q).
Hypothesis
IplusComp :
forall p q r s : float,
Fbounded b p ->
Fbounded b q ->
Fbounded b r ->
Fbounded b s -> p = r :>R -> q = s :>R -> Iplus p q = Iplus r s :>R.
Hypothesis IplusSym : forall p q : float, Iplus p q = Iplus q p.
Hypothesis
IplusOp : forall p q : float, Fopp (Iplus p q) = Iplus (Fopp p) (Fopp q).
Variable Iminus : float -> float -> float.
Hypothesis IminusPlus : forall p q : float, Iminus p q = Iplus p (Fopp q).
Theorem IplusOl :
forall p q : float,
Fbounded b p -> Fbounded b q -> p = 0%R :>R -> Iplus p q = q :>R.
Let IminusCorrect := IminusCorrect b Iplus IplusCorrect Iminus IminusPlus.
Let IplusBounded := IplusBounded b Iplus IplusCorrect.
Let IminusBounded := IminusBounded b Iplus IplusCorrect Iminus IminusPlus.
Let IminusId := IminusId b Iplus IplusCorrect Iminus IminusPlus.
Theorem MKnuth :
forall p q : float,
Fbounded b p ->
Fbounded b q ->
Iminus (Iplus p q) p = (Iplus p q - p)%R :>R ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem IplusCorrectEq :
forall (p q pq : float) (r : R),
Fbounded b p ->
Fbounded b q ->
Fbounded b pq -> r = pq :>R -> (p + q)%R = pq :>R -> Iplus p q = r :>R.
Theorem IminusCorrectEq :
forall (p q pq : float) (r : R),
Fbounded b p ->
Fbounded b q ->
Fbounded b pq -> r = pq :>R -> (p - q)%R = pq :>R -> Iminus p q = r :>R.
Theorem Iminus2Exact :
forall p q : float,
(0 <= p)%R ->
(p <= q)%R ->
Fbounded b p ->
Fbounded b q -> Iminus q (Iminus q p) = (q - Iminus q p)%R :>R.
Theorem MKnuth1 :
forall p q : float,
Fbounded b p ->
Fbounded b q ->
Iminus q (Iminus (Iplus p q) p) = (q - Iminus (Iplus p q) p)%R :>R ->
Iminus (Iplus p q) (Iminus (Iplus p q) p) =
(Iplus p q - Iminus (Iplus p q) p)%R :>R ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem MKnuth2 :
forall p q : float,
(Rabs q <= Rabs p)%R ->
Fbounded b p ->
Fbounded b q ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem IminusOp :
forall p q : float, Fopp (Iminus p q) = Iminus (Fopp p) (Fopp q).
Theorem MKnuthOpp :
forall p q : float,
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) =
Fopp
(Iplus
(Iminus (Fopp p)
(Iminus (Iplus (Fopp p) (Fopp q))
(Iminus (Iplus (Fopp p) (Fopp q)) (Fopp p))))
(Iminus (Fopp q) (Iminus (Iplus (Fopp p) (Fopp q)) (Fopp p)))) :>R.
Theorem MKnuth3 :
forall p q : float,
(0 <= q)%R ->
(q <= radix * - p)%R ->
(- p <= q)%R ->
Fbounded b p ->
Fbounded b q ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem MKnuth4 :
forall p q : float,
(0 < - p)%R ->
(0 < q)%R ->
(radix * - p < q)%R ->
Fbounded b p ->
Fbounded b q ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem MKnuth5 :
forall p q : float,
(0 < p)%R ->
(p < q)%R ->
Fbounded b p ->
Fbounded b q ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem MKnuth6 :
forall p q : float,
Iplus p q = (p + q)%R :>R ->
Fbounded b p ->
Fbounded b q ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem MKnuth7 :
forall p q : float,
(Rabs p < q)%R ->
Fbounded b p ->
Fbounded b q ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
Theorem Knuth :
forall p q : float,
Fbounded b p ->
Fbounded b q ->
Iplus (Iminus p (Iminus (Iplus p q) (Iminus (Iplus p q) p)))
(Iminus q (Iminus (Iplus p q) p)) = (p + q - Iplus p q)%R :>R.
End EFast.
`