commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <>
Subject Re: [math] UnivariateRealSolver in math3
Date Wed, 18 Apr 2012 22:31:59 GMT

> But isn't this a regression compared to version 2.2 of commons math.
> There is a lot of commonalities between the Newton solver and the other solvers.
> If I have a class representing a problem for which I have derivative,
> lower and upper bounds and initial guess, I can try to solve it with a
> Newton solver but also with the other solvers. So I should be able to
> pass any of the univariate real solvers.
Please give a short code example of what you mean by this.

In Commons Math, you don't pass the solver to the function, you pass the
function to the solver's "solve" method(s). And doing so, nothing prevents
you from passing an instance of a "DifferentiableUnivariateFunction" to a
"solve" method that expects an instance of "UnivariateFunction" (since the
former "extends" the latter).

> However this is not possible
> in math3.0 since there is no common interface anymore bewteen
> NewtonSolver and the other solvers [...]

That's so because they don't provide interchangeable functionalities (one
requires the "derivative" in order to work, while the others do not).

The alternative would have been to check, at runtime (with "instanceof")
whether the provided function is indeed an instance of
"DifferentiableUnivariateFunction" and throw an exception if not.
This is indeed what was done before, but it is more bug-prone since this
bypasses the strong type-checking provided by the compiler.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message