Boost logo

Boost Users :

Subject: [Boost-users] [math][tools][units] generic libraries not generic enough
From: alfC (alfredo.correa_at_[hidden])
Date: 2011-08-25 05:50:20


Hi,

 Lately I am using Boost.Units quite intensively for defining lots of
thermodynamic functions. The other day I needed a root finding algorithm
that can work on one of these functions. I look at couple of libraries,and
I ended up rolling and adaptor that adimensionalizes the function on
Boost.Units quantities, etc, etc.

 Then I though, hey! we have Boost.Math tools, even root finding algorithms,
and these functions are *very* generic as Boost is supposed to be. And I
found the function:

 boost::math::tools::bracket_and_solve_root

which has the perfect underlying algorithm for the application.

I started programming and after several compilation errors I realized that,
as happened before, the functions are not generic enough. For example the
arguments are
 bracket_and_solve_root( F f, const T& guess, const T& factor, bool rising,
Tol tol, boost::uintmax_t& max_iter);

in my case "guess" is an argument type of type
boost::units::quantity<si::meter> but then "factor" has to be a *different*
type. For this function to be generic one need that factor is of new type
parameter.

In my opinion the function should be
  template<typename F, typename T, typename Fact, typename Tol>
 bracket_and_solve_root( F f, const T& guess, const T& factor, bool rising,
Tol tol, boost::uintmax_t& max_iter);
to begin with (and then there is a chain of other internal changes).

What do you think? should I open a bug ticket?
Let's put it in more abstract way: T*T=T should not be a requirement for a
root algorithm to work.
Once and for all, can we give a name to the model type of which Boost.Units
quantity models for? so the library writers stop assuming that T*T=T for
numeric values and can improve half-way generic libraries?

Other numeric libraries that suffer from this deficiency are
Boost.Accumulators, Boost.Geometry, and Boost.Interval among the ones I
tried. I think this issues should be addressed, not only to make them work
with Boost.Units but also to bring those libraries to a higher level of
generality.

Just an opinion.

Thank you,
Alfredo



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net