Library Flocq.Prop.Plus_error
This file is part of the Flocq formalization of floating-point
arithmetic in Coq: https://flocq.gitlabpages.inria.fr/
Copyright (C) 2010-2018 Sylvie Boldo
Copyright (C) 2010-2018 Guillaume Melquiond
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
COPYING file for more details.
Copyright (C) 2010-2018 Guillaume Melquiond
Error of the rounded-to-nearest addition is representable.
From Coq Require Import ZArith Reals Psatz.
Require Import Core Operations Relative.
Section Fprop_plus_error.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable fexp : Z → Z.
Context { valid_exp : Valid_exp fexp }.
Section round_repr_same_exp.
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
Lemma round_repr_same_exp :
∀ m e,
∃ m',
round beta fexp rnd (F2R (Float beta m e)) = F2R (Float beta m' e).
End round_repr_same_exp.
Context { monotone_exp : Monotone_exp fexp }.
Notation format := (generic_format beta fexp).
Variable choice : Z → bool.
Lemma plus_error_aux :
∀ x y,
(cexp beta fexp x ≤ cexp beta fexp y)%Z →
format x → format y →
format (round beta fexp (Znearest choice) (x + y) - (x + y))%R.
Error of the addition
Theorem plus_error :
∀ x y,
format x → format y →
format (round beta fexp (Znearest choice) (x + y) - (x + y))%R.
End Fprop_plus_error.
Section Fprop_plus_zero.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable fexp : Z → Z.
Context { valid_exp : Valid_exp fexp }.
Context { exp_not_FTZ : Exp_not_FTZ fexp }.
Notation format := (generic_format beta fexp).
Section round_plus_eq_zero_aux.
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
Lemma round_plus_neq_0_aux :
∀ x y,
(cexp beta fexp x ≤ cexp beta fexp y)%Z →
format x → format y →
(0 < x + y)%R →
round beta fexp rnd (x + y) ≠ 0%R.
End round_plus_eq_zero_aux.
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
∀ x y,
format x → format y →
format (round beta fexp (Znearest choice) (x + y) - (x + y))%R.
End Fprop_plus_error.
Section Fprop_plus_zero.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable fexp : Z → Z.
Context { valid_exp : Valid_exp fexp }.
Context { exp_not_FTZ : Exp_not_FTZ fexp }.
Notation format := (generic_format beta fexp).
Section round_plus_eq_zero_aux.
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
Lemma round_plus_neq_0_aux :
∀ x y,
(cexp beta fexp x ≤ cexp beta fexp y)%Z →
format x → format y →
(0 < x + y)%R →
round beta fexp rnd (x + y) ≠ 0%R.
End round_plus_eq_zero_aux.
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
rnd(x+y)=0 -> x+y = 0 provided this is not a FTZ format
Theorem round_plus_neq_0 :
∀ x y,
format x → format y →
(x + y ≠ 0)%R →
round beta fexp rnd (x + y) ≠ 0%R.
Theorem round_plus_eq_0 :
∀ x y,
format x → format y →
round beta fexp rnd (x + y) = 0%R →
(x + y = 0)%R.
End Fprop_plus_zero.
Section Fprop_plus_FLT.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable emin prec : Z.
Context { prec_gt_0_ : Prec_gt_0 prec }.
Theorem FLT_format_plus_small: ∀ x y,
generic_format beta (FLT_exp emin prec) x →
generic_format beta (FLT_exp emin prec) y →
(Rabs (x+y) ≤ bpow (prec+emin))%R →
generic_format beta (FLT_exp emin prec) (x+y).
Variable choice : Z → bool.
Lemma FLT_plus_error_N_ex : ∀ x y,
generic_format beta (FLT_exp emin prec) x →
generic_format beta (FLT_exp emin prec) y →
∃ eps,
(Rabs eps ≤ u_ro beta prec / (1 + u_ro beta prec))%R ∧
round beta (FLT_exp emin prec) (Znearest choice) (x + y)
= ((x + y) × (1 + eps))%R.
Lemma FLT_plus_error_N_round_ex : ∀ x y,
generic_format beta (FLT_exp emin prec) x →
generic_format beta (FLT_exp emin prec) y →
∃ eps,
(Rabs eps ≤ u_ro beta prec)%R ∧
(x + y
= round beta (FLT_exp emin prec) (Znearest choice) (x + y) × (1 + eps))%R.
End Fprop_plus_FLT.
Section Fprop_plus_mult_ulp.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable fexp : Z → Z.
Context { valid_exp : Valid_exp fexp }.
Context { monotone_exp : Monotone_exp fexp }.
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
Notation format := (generic_format beta fexp).
Notation cexp := (cexp beta fexp).
Lemma ex_shift :
∀ x e, format x → (e ≤ cexp x)%Z →
∃ m, (x = IZR m × bpow e)%R.
Lemma mag_minus1 :
∀ z, z ≠ 0%R →
(mag beta z - 1)%Z = mag beta (z / IZR beta).
Theorem round_plus_F2R :
∀ x y, format x → format y → (x ≠ 0)%R →
∃ m,
round beta fexp rnd (x+y) = F2R (Float beta m (cexp (x / IZR beta))).
Context {exp_not_FTZ : Exp_not_FTZ fexp}.
Theorem round_plus_ge_ulp :
∀ x y, format x → format y →
round beta fexp rnd (x+y) ≠ 0%R →
(ulp beta fexp (x/IZR beta) ≤ Rabs (round beta fexp rnd (x+y)))%R.
End Fprop_plus_mult_ulp.
Section Fprop_plus_ge_ulp.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
Variable emin prec : Z.
Context { prec_gt_0_ : Prec_gt_0 prec }.
Theorem round_FLT_plus_ge :
∀ x y e,
generic_format beta (FLT_exp emin prec) x → generic_format beta (FLT_exp emin prec) y →
(bpow (e + prec) ≤ Rabs x)%R →
round beta (FLT_exp emin prec) rnd (x + y) ≠ 0%R →
(bpow e ≤ Rabs (round beta (FLT_exp emin prec) rnd (x + y)))%R.
Lemma round_FLT_plus_ge' :
∀ x y e,
generic_format beta (FLT_exp emin prec) x → generic_format beta (FLT_exp emin prec) y →
(x ≠ 0%R → (bpow (e+prec) ≤ Rabs x)%R) →
(x = 0%R → y ≠ 0%R → (bpow e ≤ Rabs y)%R) →
round beta (FLT_exp emin prec) rnd (x+y) ≠ 0%R →
(bpow e ≤ Rabs (round beta (FLT_exp emin prec) rnd (x+y)))%R.
Theorem round_FLX_plus_ge :
∀ x y e,
generic_format beta (FLX_exp prec) x → generic_format beta (FLX_exp prec) y →
(bpow (e+prec) ≤ Rabs x)%R →
(round beta (FLX_exp prec) rnd (x+y) ≠ 0)%R →
(bpow e ≤ Rabs (round beta (FLX_exp prec) rnd (x+y)))%R.
End Fprop_plus_ge_ulp.
Section Fprop_plus_le_ops.
Variable beta : radix.
Variable fexp : Z → Z.
Context { valid_exp : Valid_exp fexp }.
Variable choice : Z → bool.
Lemma plus_error_le_l :
∀ x y,
generic_format beta fexp x → generic_format beta fexp y →
(Rabs (round beta fexp (Znearest choice) (x + y) - (x + y)) ≤ Rabs x)%R.
Lemma plus_error_le_r :
∀ x y,
generic_format beta fexp x → generic_format beta fexp y →
(Rabs (round beta fexp (Znearest choice) (x + y) - (x + y)) ≤ Rabs y)%R.
End Fprop_plus_le_ops.
∀ x y,
format x → format y →
(x + y ≠ 0)%R →
round beta fexp rnd (x + y) ≠ 0%R.
Theorem round_plus_eq_0 :
∀ x y,
format x → format y →
round beta fexp rnd (x + y) = 0%R →
(x + y = 0)%R.
End Fprop_plus_zero.
Section Fprop_plus_FLT.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable emin prec : Z.
Context { prec_gt_0_ : Prec_gt_0 prec }.
Theorem FLT_format_plus_small: ∀ x y,
generic_format beta (FLT_exp emin prec) x →
generic_format beta (FLT_exp emin prec) y →
(Rabs (x+y) ≤ bpow (prec+emin))%R →
generic_format beta (FLT_exp emin prec) (x+y).
Variable choice : Z → bool.
Lemma FLT_plus_error_N_ex : ∀ x y,
generic_format beta (FLT_exp emin prec) x →
generic_format beta (FLT_exp emin prec) y →
∃ eps,
(Rabs eps ≤ u_ro beta prec / (1 + u_ro beta prec))%R ∧
round beta (FLT_exp emin prec) (Znearest choice) (x + y)
= ((x + y) × (1 + eps))%R.
Lemma FLT_plus_error_N_round_ex : ∀ x y,
generic_format beta (FLT_exp emin prec) x →
generic_format beta (FLT_exp emin prec) y →
∃ eps,
(Rabs eps ≤ u_ro beta prec)%R ∧
(x + y
= round beta (FLT_exp emin prec) (Znearest choice) (x + y) × (1 + eps))%R.
End Fprop_plus_FLT.
Section Fprop_plus_mult_ulp.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable fexp : Z → Z.
Context { valid_exp : Valid_exp fexp }.
Context { monotone_exp : Monotone_exp fexp }.
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
Notation format := (generic_format beta fexp).
Notation cexp := (cexp beta fexp).
Lemma ex_shift :
∀ x e, format x → (e ≤ cexp x)%Z →
∃ m, (x = IZR m × bpow e)%R.
Lemma mag_minus1 :
∀ z, z ≠ 0%R →
(mag beta z - 1)%Z = mag beta (z / IZR beta).
Theorem round_plus_F2R :
∀ x y, format x → format y → (x ≠ 0)%R →
∃ m,
round beta fexp rnd (x+y) = F2R (Float beta m (cexp (x / IZR beta))).
Context {exp_not_FTZ : Exp_not_FTZ fexp}.
Theorem round_plus_ge_ulp :
∀ x y, format x → format y →
round beta fexp rnd (x+y) ≠ 0%R →
(ulp beta fexp (x/IZR beta) ≤ Rabs (round beta fexp rnd (x+y)))%R.
End Fprop_plus_mult_ulp.
Section Fprop_plus_ge_ulp.
Variable beta : radix.
Notation bpow e := (bpow beta e).
Variable rnd : R → Z.
Context { valid_rnd : Valid_rnd rnd }.
Variable emin prec : Z.
Context { prec_gt_0_ : Prec_gt_0 prec }.
Theorem round_FLT_plus_ge :
∀ x y e,
generic_format beta (FLT_exp emin prec) x → generic_format beta (FLT_exp emin prec) y →
(bpow (e + prec) ≤ Rabs x)%R →
round beta (FLT_exp emin prec) rnd (x + y) ≠ 0%R →
(bpow e ≤ Rabs (round beta (FLT_exp emin prec) rnd (x + y)))%R.
Lemma round_FLT_plus_ge' :
∀ x y e,
generic_format beta (FLT_exp emin prec) x → generic_format beta (FLT_exp emin prec) y →
(x ≠ 0%R → (bpow (e+prec) ≤ Rabs x)%R) →
(x = 0%R → y ≠ 0%R → (bpow e ≤ Rabs y)%R) →
round beta (FLT_exp emin prec) rnd (x+y) ≠ 0%R →
(bpow e ≤ Rabs (round beta (FLT_exp emin prec) rnd (x+y)))%R.
Theorem round_FLX_plus_ge :
∀ x y e,
generic_format beta (FLX_exp prec) x → generic_format beta (FLX_exp prec) y →
(bpow (e+prec) ≤ Rabs x)%R →
(round beta (FLX_exp prec) rnd (x+y) ≠ 0)%R →
(bpow e ≤ Rabs (round beta (FLX_exp prec) rnd (x+y)))%R.
End Fprop_plus_ge_ulp.
Section Fprop_plus_le_ops.
Variable beta : radix.
Variable fexp : Z → Z.
Context { valid_exp : Valid_exp fexp }.
Variable choice : Z → bool.
Lemma plus_error_le_l :
∀ x y,
generic_format beta fexp x → generic_format beta fexp y →
(Rabs (round beta fexp (Znearest choice) (x + y) - (x + y)) ≤ Rabs x)%R.
Lemma plus_error_le_r :
∀ x y,
generic_format beta fexp x → generic_format beta fexp y →
(Rabs (round beta fexp (Znearest choice) (x + y) - (x + y)) ≤ Rabs y)%R.
End Fprop_plus_le_ops.