[PPL-devel] [GIT] ppl/ppl(master): Improved the documentation and removed an useless function.

Fabio Bossi bossi at cs.unipr.it
Mon May 9 18:48:03 CEST 2011


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

Author: Fabio Bossi <bossi at cs.unipr.it>
Date:   Mon May  9 18:47:30 2011 +0200

Improved the documentation and removed an useless function.

---

 src/Interval.defs.hh                     |    5 --
 src/Interval.inlines.hh                  |   11 -----
 src/Linear_Form.defs.hh                  |   71 +++++++++++++++---------------
 src/Linear_Form.templates.hh             |    6 +-
 tests/Concrete_Expression/linearform1.cc |   20 ++++++++
 5 files changed, 59 insertions(+), 54 deletions(-)

diff --git a/src/Interval.defs.hh b/src/Interval.defs.hh
index 9d0d241..a9d8ffd 100644
--- a/src/Interval.defs.hh
+++ b/src/Interval.defs.hh
@@ -56,11 +56,6 @@ struct Is_Singleton : public Is_Native_Or_Checked<T> {};
 template <typename T>
 struct Is_Interval : public Is_Same_Or_Derived<Interval_Base, T> {};
 
-// FIXME: This has been added as a workaraound.
-template <typename From>
-typename Enable_If<Is_Interval<From>::value, I_Result>::type
-neg_assign(From& x);
-
 //! A generic, not necessarily closed, possibly restricted interval.
 /*! \ingroup PPL_CXX_interface
   The class template type parameter \p Boundary represents the type
diff --git a/src/Interval.inlines.hh b/src/Interval.inlines.hh
index a6936a1..2fdba70 100644
--- a/src/Interval.inlines.hh
+++ b/src/Interval.inlines.hh
@@ -26,17 +26,6 @@ site: http://www.cs.unipr.it/ppl/ . */
 
 namespace Parma_Polyhedra_Library {
 
-template <typename From>
-typename Enable_If<Is_Interval<From>::value, I_Result>::type
-neg_assign(From& x) {
-  // FIXME: Avoid the creation of a temporary.
-  From y;
-  typename Enable_If<Is_Interval<From>::value, I_Result>::type res =
-                                                               y.neg_assign(x);
-  x = y;
-  return res;
-}
-
 template <typename Boundary, typename Info>
 inline memory_size_type
 Interval<Boundary, Info>::external_memory_in_bytes() const {
diff --git a/src/Linear_Form.defs.hh b/src/Linear_Form.defs.hh
index 0316301..658fdc2 100644
--- a/src/Linear_Form.defs.hh
+++ b/src/Linear_Form.defs.hh
@@ -212,9 +212,9 @@ void swap(Parma_Polyhedra_Library::Linear_Form<C>& x,
 
 } // namespace std
 
-//! A linear form.
+//! A linear form with interval coefficients.
 /*! \ingroup PPL_CXX_interface
-  An object of the class Linear_Form represents the linear form
+  An object of the class Linear_Form represents the interval linear form
   \f[
     \sum_{i=0}^{n-1} a_i x_i + b
   \f]
@@ -222,43 +222,44 @@ void swap(Parma_Polyhedra_Library::Linear_Form<C>& x,
   each \f$a_i\f$ is the coefficient
   of the \f$i\f$-th variable \f$x_i\f$
   and \f$b\f$ is the inhomogeneous term.
-  The coefficiens and the inhomogeneous terms of the linear form
-  are element of the template parameter \p C.
-
-  \par How to build a linear form.
-
-  A full set of functions is defined to provide a convenient interface
-  for building complex linear forms starting from simpler ones
-  and from objects of the classes Variable and \p C:
-  available operators include unary negation,
-  binary addition and subtraction,
-  as well as multiplication by a Coefficient.
-  The space dimension of a linear form is defined as the maximum
-  space dimension of the arguments used to build it:
-  in particular, the space dimension of a Variable <CODE>x</CODE>
-  is defined as <CODE>x.id()+1</CODE>,
-  whereas all the objects of the class \p C have space dimension zero.
-
-  FIXME: the following needs rewriting.
+  The coefficients and the inhomogeneous term of the linear form
+  have the template parameter \p C as their type. \p C must be the
+  type of an Interval.
+
+  \par How to build a linear form. 
+  A full set of functions is defined in order to provide a convenient
+  interface for building complex linear forms starting from simpler ones
+  and from objects of the classes Variable and \p C. Available operators
+  include binary addition and subtraction, as well as multiplication and
+  division by a coefficient.
+  The space dimension of a linear form is defined as
+  the highest variable dimension among variables that have a nonzero
+  coefficient in the linear form, or zero if no such variable exists.
+  The space dimension for each variable \f$x_i\f$ is given by \f$i + 1\f$.
 
   \par Example
-  The following code builds the linear form \f$4x - 2y - z + 14\f$,
-  having space dimension \f$3\f$:
-  \code
-  Linear_Form e = 4*x - 2*y - z + 14;
-  \endcode
-  Another way to build the same linear form is:
+  Given the type \p T of an Interval with floating point coefficients (though
+  any integral type may also be used), the following code builds the interval
+  linear form \f$lf = x_5 - x_2 + 1\f$ with space dimension 6:
   \code
-  Linear_Form e1 = 4*x;
-  Linear_Form e2 = 2*y;
-  Linear_Form e3 = z;
-  Linear_Form e = Linear_Form(14);
-  e += e1 - e2 - e3;
+  Variable x5(5);
+  Variable x2(2);
+  T x5_coefficient;
+  x5_coefficient.lower() = 2.0;
+  x5_coefficient.upper() = 3.0;
+  T inhomogeneous_term;
+  inhomogeneous_term.lower() = 4.0;
+  inhomogeneous_term.upper() = 8.0;
+  Linear_Form<T> lf(x2);
+  lf = -lf;
+  lf += Linear_Form<T>(x2);
+  Linear_Form<T> lx5(x5);
+  lx5 *= x5_coefficient;
+  lf += lx5;
   \endcode
-  Note that \p e1, \p e2 and \p e3 have space dimension 1, 2 and 3,
-  respectively; also, in the fourth line of code, \p e is created
-  with space dimension zero and then extended to space dimension 3
-  in the fifth line.
+  Note that \p lx5 is created with space dimension 6, while \p lf is created
+  with space dimension 0 and then extended first to space dimension 2 when x2
+  is subtracted and finally to space dimension 6 when lx5 is added.
 */
 template <typename C>
 class Parma_Polyhedra_Library::Linear_Form {
diff --git a/src/Linear_Form.templates.hh b/src/Linear_Form.templates.hh
index 1dffd6e..0621ff5 100644
--- a/src/Linear_Form.templates.hh
+++ b/src/Linear_Form.templates.hh
@@ -148,7 +148,7 @@ Linear_Form<C>
 operator-(const Linear_Form<C>& f) {
   Linear_Form<C> r(f);
   for (dimension_type i = f.size(); i-- > 0; )
-    neg_assign(r[i]);
+    r[i].neg_assign(r[i]);
   return r;
 }
 
@@ -230,7 +230,7 @@ Linear_Form<C>
 operator-(const C& n, const Linear_Form<C>& f) {
   Linear_Form<C> r(f);
   for (dimension_type i = f.size(); i-- > 0; )
-    neg_assign(r[i]);
+    r[i].neg_assign(r[i]);
   r[0] += n;
   return r;
 }
@@ -356,7 +356,7 @@ template <typename C>
 void
 Linear_Form<C>::negate() {
   for (dimension_type i = vec.size(); i-- > 0; )
-    neg_assign(vec[i]);
+    vec[i].neg_assign(vec[i]);
   return;
 }
 
diff --git a/tests/Concrete_Expression/linearform1.cc b/tests/Concrete_Expression/linearform1.cc
index d89a656..0ac4381 100644
--- a/tests/Concrete_Expression/linearform1.cc
+++ b/tests/Concrete_Expression/linearform1.cc
@@ -307,6 +307,25 @@ test09() {
   return ok1 && ok2 && ok3;
 }
 
+bool
+test10() {
+  Variable x5(5);
+  Variable x2(2);
+  FP_Interval x5_coefficient;
+  x5_coefficient.lower() = 2.0;
+  x5_coefficient.upper() = 3.0;
+  FP_Interval inhomogeneous_term;
+  inhomogeneous_term.lower() = 4.0;
+  inhomogeneous_term.upper() = 8.0;
+  FP_Linear_Form lf(x2);
+  lf = -lf;
+  lf += FP_Linear_Form(x2);
+  FP_Linear_Form lx5(x5);
+  lx5 *= x5_coefficient;
+  lf += lx5;
+  return lf.space_dimension() == 6;
+}
+
 } // namespace
 
 BEGIN_MAIN
@@ -319,4 +338,5 @@ BEGIN_MAIN
   DO_TEST(test07);
   DO_TEST(test08);
   DO_TEST(test09);
+  DO_TEST(test10);
 END_MAIN




More information about the PPL-devel mailing list