[PPL-devel] [GIT] ppl/ppl(floating_point): Added a first implementation of the relative_error and intervalize

Fabio Bossi bossi at cs.unipr.it
Wed Sep 2 14:45:41 CEST 2009


Module: ppl/ppl
Branch: floating_point
Commit: 67bec8827d8c0ce1db133ae9f20dd36830ffffe8
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=67bec8827d8c0ce1db133ae9f20dd36830ffffe8

Author: Fabio Bossi <bossi at cs.unipr.it>
Date:   Wed Sep  2 14:41:51 2009 +0200

Added a first implementation of the relative_error and intervalize
methods.
Fixed a mistake with loops over linear forms.
Several style improvements.

---

 src/Constant_Floating_Point_Expression.inlines.hh |    3 +-
 src/Floating_Point_Expression.defs.hh             |    5 +-
 src/Floating_Point_Expression.inlines.hh          |    6 +-
 src/Floating_Point_Expression.templates.hh        |   87 +++++++++++++++++++++
 src/Makefile.am                                   |    1 +
 5 files changed, 95 insertions(+), 7 deletions(-)

diff --git a/src/Constant_Floating_Point_Expression.inlines.hh b/src/Constant_Floating_Point_Expression.inlines.hh
index d1edd38..1fa15fb 100644
--- a/src/Constant_Floating_Point_Expression.inlines.hh
+++ b/src/Constant_Floating_Point_Expression.inlines.hh
@@ -34,6 +34,7 @@ Constant_Floating_Point_Expression(const boundary_type lb,
                                    const boundary_type ub)
   : value(lb) {
   assert(lb <= ub);
+  // FIXME: this may be incorrect for some policies.
   value.join_assign(ub);
 }
 
@@ -54,10 +55,8 @@ inline typename Constant_Floating_Point_Expression<FP_Interval_Type,
                                                    FP_Format>::FP_Linear_Form
 Constant_Floating_Point_Expression<FP_Interval_Type, FP_Format>
 ::linearize(const FP_Interval_Abstract_Store& store) const {
-
   FP_Linear_Form result = FP_Linear_Form(value);
   return result;
-
 }
 
 } // namespace Parma_Polyhedra_Library
diff --git a/src/Floating_Point_Expression.defs.hh b/src/Floating_Point_Expression.defs.hh
index 0d4e854..e712fd4 100644
--- a/src/Floating_Point_Expression.defs.hh
+++ b/src/Floating_Point_Expression.defs.hh
@@ -71,11 +71,11 @@ public:
 
   static bool overflows(const FP_Linear_Form& lf);
 
+  static FP_Linear_Form relative_error(const FP_Linear_Form&);
+
   static FP_Linear_Form intervalize(const FP_Linear_Form&,
                                     const FP_Interval_Abstract_Store& store);
 
-  static FP_Linear_Form relative_error(const FP_Linear_Form&);
-
 }; // class Floating_Point_Expression
 
 // Initialize static members of the class.
@@ -90,5 +90,6 @@ Floating_Point_Expression<FP_Interval_Type, FP_Format>::absolute_error =
 } // namespace Parma_Polyhedra_Library
 
 #include "Floating_Point_Expression.inlines.hh"
+#include "Floating_Point_Expression.templates.hh"
 
 #endif // !defined(PPL_Floating_Point_Expression_defs_hh)
diff --git a/src/Floating_Point_Expression.inlines.hh b/src/Floating_Point_Expression.inlines.hh
index 20f37e9..3e38dd2 100644
--- a/src/Floating_Point_Expression.inlines.hh
+++ b/src/Floating_Point_Expression.inlines.hh
@@ -36,12 +36,12 @@ template <typename FP_Interval_Type, typename FP_Format>
 inline bool
 Floating_Point_Expression<FP_Interval_Type, FP_Format>
 ::overflows(const FP_Linear_Form& lf) {
-  if(!lf.inhomogeneous_term().is_bounded())
+  if (!lf.inhomogeneous_term().is_bounded())
     return true;
 
   dimension_type dimension = lf.space_dimension();
-  for(dimension_type i = 0; i <= dimension; ++i) {
-    if(!lf.coefficient(Variable(i)).is_bounded())
+  for (dimension_type i = 0; i < dimension; ++i) {
+    if (!lf.coefficient(Variable(i)).is_bounded())
       return true;
   }
 
diff --git a/src/Floating_Point_Expression.templates.hh b/src/Floating_Point_Expression.templates.hh
new file mode 100644
index 0000000..3ea080a
--- /dev/null
+++ b/src/Floating_Point_Expression.templates.hh
@@ -0,0 +1,87 @@
+/* Floating_Point_Expression class implementation:
+   non-inline template functions.
+   Copyright (C) 2001-2009 Roberto Bagnara <bagnara at cs.unipr.it>
+
+This file is part of the Parma Polyhedra Library (PPL).
+
+The PPL is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The PPL 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 GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software Foundation,
+Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
+
+For the most up-to-date information see the Parma Polyhedra Library
+site: http://www.cs.unipr.it/ppl/ . */
+
+#ifndef PPL_Floating_Point_Expression_templates_hh
+#define PPL_Floating_Point_Expression_templates_hh 1
+
+#include "Floating_Point_Expression.defs.hh"
+#include <cmath>
+
+namespace Parma_Polyhedra_Library {
+
+template<typename FP_Interval_Type, typename FP_Format>
+typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::FP_Linear_Form
+Floating_Point_Expression<FP_Interval_Type, FP_Format>
+::relative_error(const FP_Linear_Form& lf) {
+  /* FIXME: here we assume that boundary_type can represent
+     (2)^(-FP_Format::fraction_bits) precisely. */
+  FP_Interval_Type error_propagator(pow(-2, -FP_Format::fraction_bits));
+  // FIXME: this may be incorrect for some policies.
+  error_propagator.join_assign(FP_Interval_Type(
+                               pow(2, -FP_Format::fraction_bits)));
+
+  // Handle the inhomogeneous term.
+  FP_Interval_Type current_term = lf.inhomogeneous_term();
+  boundary_type current_multiplier = std::max(abs(current_term.lower()),
+                                              abs(current_term.upper()));
+  FP_Linear_Form current_result_term = FP_Linear_Form(current_multiplier *
+                                                      error_propagator);
+  FP_Linear_Form result = FP_Linear_Form(current_result_term);
+
+  // Handle the other terms.
+  dimension_type dimension = lf.space_dimension();
+  for (dimension_type i = 0; i < dimension; ++i) {
+    current_term = lf.coefficient(Variable(i));
+    current_multiplier = std::max(abs(current_term.lower()),
+                                  abs(current_term.upper()));
+    current_result_term = FP_Linear_Form(Variable(i)) * current_multiplier *
+                          error_propagator;
+    result += current_result_term;
+  }
+
+  return result;
+}
+
+template<typename FP_Interval_Type, typename FP_Format>
+typename Floating_Point_Expression<FP_Interval_Type, FP_Format>::FP_Linear_Form
+Floating_Point_Expression<FP_Interval_Type, FP_Format>
+::intervalize(const FP_Linear_Form& lf,
+              const FP_Interval_Abstract_Store& store) {
+  FP_Interval_Type resulting_interval = lf.inhomogeneous_term();
+  dimension_type dimension = lf.space_dimension();
+  for (dimension_type i = 0; i < dimension; ++i) {
+    typename FP_Interval_Abstract_Store::const_iterator
+             next_variable_value = store.find(i);
+    if (next_variable_value != store.end()) {
+      FP_Interval_Type current_coefficient = lf.coefficient(Variable(i));
+      resulting_interval += current_coefficient * (*next_variable_value);
+    }
+  }
+
+  FP_Linear_Form result = FP_Interval_Type(resulting_interval);
+  return result;
+}
+
+} // namespace Parma_Polyhedra_Library
+
+#endif // !defined(PPL_Floating_Point_Expression_templates_hh)
diff --git a/src/Makefile.am b/src/Makefile.am
index 89c9d1e..9fd2582 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -344,6 +344,7 @@ wrap_string.hh \
 Floating_Point_Expression.types.hh \
 Floating_Point_Expression.defs.hh \
 Floating_Point_Expression.inlines.hh \
+Floating_Point_Expression.templates.hh \
 Constant_Floating_Point_Expression.types.hh \
 Constant_Floating_Point_Expression.defs.hh \
 Constant_Floating_Point_Expression.inlines.hh \




More information about the PPL-devel mailing list