[ 
https://issues.apache.org/jira/browse/MATH-1612?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17369105#comment-17369105
 ] 

Alex Herbert commented on MATH-1612:
------------------------------------

Underlying the SimpsonIntegrator is a TrapezoidIntegrator which computes 2^p 
function evaluations per stage where the stage is p. So if you set the minimum 
number of iterations (stages of the underlying TrapezoidIntegrator) of the 
SimpsonIntegrator to 10 you will require 2^10 + 2^9 + ... + 2^1 function 
evaluations. This is roughly 2^11 = 2048. This is over the limit you have set 
of 1100 function evaluations. With a minimum number of stages of 9 then you 
only need roughly 2^10 = 1024 function evaluations. This is under the limit of 
1100 and all is OK as the function is evaluated as converged after 9 stages at 
the first test for convergence.

It does seem odd that you can specify the minimalIterationCount to the 
SimpsonIntegrator and then call it to do an integration with a number of 
function evaluations that will throw an error because it cannot possibly finish 
before it reaches this level. It is not a regression, just a problem with the 
API. The maximum number of iterations you can use for the SimpsonIntegrator is 
63. That would do nearly 2^64 function evaluations. If you wait long enough for 
it to complete doing that it will definitely have done more function 
evaluations than Integer.MAX_VALUE which is the limit imposed by using a 
IntegerSequence.Incrementor. This class supports incrementing up to an integer 
limit. It is not using an unsigned integer either. To really reach the limit of 
a SimpsonIntegrator (63 iterations, nearly 2^64 function evaluations) you would 
require a max function evaluations specified as a long and then compared to the 
limit using unsigned arithmetic to support up to 2^64 - 1 function calls.

A simpler fix would be to change the SimpsonIntegrator (and the 
TrapezoidIntegrator) to have maximumIterationCount of 31 and not 63. I do not 
think anyone will realistically want to evaluate a function more than this. A 
different integrator should be used with a more advanced integration method.

 

> Regression in "SimpsonIntegrator"?
> ----------------------------------
>
>                 Key: MATH-1612
>                 URL: https://issues.apache.org/jira/browse/MATH-1612
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Gilles Sadowski
>            Priority: Major
>             Fix For: 4.0
>
>
> The following code:
> {code}
> final UnivariateFunction f = PolynomialsUtils.createHermitePolynomial(deg);
> final double integ = new SimpsonIntegrator(9, 50).integrate(1100, f, 0, 0.5);
> {code}
> terminates as expected, while this one
> {code}
> final UnivariateFunction f = PolynomialsUtils.createHermitePolynomial(deg);
> final double integ = new SimpsonIntegrator(10, 50).integrate(1100, f, 0, 0.5);
> {code}
> raises an exception:
> {noformat}
> TooManyEvaluationsException: illegal state: maximal count (1,100) exceeded: 
> evaluations
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to