Program: 57389
Project: 57389
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public double integrate(final FirstOrderDifferentialEquations equations,final double t0,final double[] y0,final double t,final double[] y) throws DerivativeException, IntegratorException {
  final int n=y0.length;
  sanityChecks(equations,t0,y0,t,y);
  setEquations(equations);
  resetEvaluations();
  final boolean forward=t > t0;
  if (y != y0) {
    System.arraycopy(y0,0,y,0,n);
  }
  final double[] yDot=new double[y0.length];
  final double[] yTmp=new double[y0.length];
  final NordsieckStepInterpolator interpolator=new NordsieckStepInterpolator();
  interpolator.reinitialize(y,forward);
  final NordsieckStepInterpolator interpolatorTmp=new NordsieckStepInterpolator();
  interpolatorTmp.reinitialize(yTmp,forward);
  for (  StepHandler handler : stepHandlers) {
    handler.reset();
  }
  CombinedEventsManager manager=addEndTimeChecker(t0,t,eventsHandlersManager);
  start(t0,y,t);
  interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
  interpolator.storeTime(stepStart);
  double hNew=stepSize;
  interpolator.rescale(hNew);
  boolean lastStep=false;
  while (!lastStep) {
    interpolator.shift();
    double error=0;
    for (boolean loop=true; loop; ) {
      stepSize=hNew;
      final double stepEnd=stepStart + stepSize;
      interpolator.setInterpolatedTime(stepEnd);
      System.arraycopy(interpolator.getInterpolatedState(),0,yTmp,0,y0.length);
      computeDerivatives(stepEnd,yTmp,yDot);
      final double[] predictedScaled=new double[y0.length];
      for (int j=0; j < y0.length; ++j) {
        predictedScaled[j]=stepSize * yDot[j];
      }
      final Array2DRowRealMatrix nordsieckTmp=updateHighOrderDerivativesPhase1(nordsieck);
      updateHighOrderDerivativesPhase2(scaled,predictedScaled,nordsieckTmp);
      error=nordsieckTmp.walkInOptimizedOrder(new Corrector(y,predictedScaled,yTmp));
      if (error <= 1.0) {
        computeDerivatives(stepEnd,yTmp,yDot);
        final double[] correctedScaled=new double[y0.length];
        for (int j=0; j < y0.length; ++j) {
          correctedScaled[j]=stepSize * yDot[j];
        }
        updateHighOrderDerivativesPhase2(predictedScaled,correctedScaled,nordsieckTmp);
        interpolatorTmp.reinitialize(stepEnd,stepSize,correctedScaled,nordsieckTmp);
        interpolatorTmp.storeTime(stepStart);
        interpolatorTmp.shift();
        interpolatorTmp.storeTime(stepEnd);
        if (manager.evaluateStep(interpolatorTmp)) {
          final double dt=manager.getEventTime() - stepStart;
          if (Math.abs(dt) <= Math.ulp(stepStart)) {
            loop=false;
          }
 else {
            hNew=dt;
            interpolator.rescale(hNew);
          }
        }
 else {
          scaled=correctedScaled;
          nordsieck=nordsieckTmp;
          interpolator.reinitialize(stepEnd,stepSize,scaled,nordsieck);
          loop=false;
        }
      }
 else {
        final double factor=computeStepGrowShrinkFactor(error);
        hNew=filterStep(stepSize * factor,forward,false);
        interpolator.rescale(hNew);
      }
    }
    final double nextStep=stepStart + stepSize;
    System.arraycopy(yTmp,0,y,0,n);
    interpolator.storeTime(nextStep);
    manager.stepAccepted(nextStep,y);
    lastStep=manager.stop();
    for (    StepHandler handler : stepHandlers) {
      interpolator.setInterpolatedTime(nextStep);
      handler.handleStep(interpolator,lastStep);
    }
    stepStart=nextStep;
    if (!lastStep && manager.reset(stepStart,y)) {
      start(stepStart,y,t);
      interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
    }
    if (!lastStep) {
      stepSize=filterStep(stepSize,forward,true);
      final double factor=computeStepGrowShrinkFactor(error);
      final double scaledH=stepSize * factor;
      final double nextT=stepStart + scaledH;
      final boolean nextIsLast=forward ? (nextT >= t) : (nextT <= t);
      hNew=filterStep(scaledH,forward,nextIsLast);
      interpolator.rescale(hNew);
    }
  }
  final double stopTime=stepStart;
  stepStart=Double.NaN;
  stepSize=Double.NaN;
  return stopTime;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public double integrate(final FirstOrderDifferentialEquations equations,final double t0,final double[] y0,final double t,final double[] y) throws DerivativeException, IntegratorException {
  final int n=y0.length;
  sanityChecks(equations,t0,y0,t,y);
  setEquations(equations);
  resetEvaluations();
  final boolean forward=t > t0;
  if (y != y0) {
    System.arraycopy(y0,0,y,0,n);
  }
  final double[] yDot=new double[y0.length];
  final double[] yTmp=new double[y0.length];
  final NordsieckStepInterpolator interpolator=new NordsieckStepInterpolator();
  interpolator.reinitialize(y,forward);
  final NordsieckStepInterpolator interpolatorTmp=new NordsieckStepInterpolator();
  interpolatorTmp.reinitialize(yTmp,forward);
  for (  StepHandler handler : stepHandlers) {
    handler.reset();
  }
  CombinedEventsManager manager=addEndTimeChecker(t0,t,eventsHandlersManager);
  start(t0,y,t);
  interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
  interpolator.storeTime(stepStart);
  double hNew=stepSize;
  interpolator.rescale(hNew);
  boolean lastStep=false;
  while (!lastStep) {
    interpolator.shift();
    double error=0;
    for (boolean loop=true; loop; ) {
      stepSize=hNew;
      final double stepEnd=stepStart + stepSize;
      interpolator.setInterpolatedTime(stepEnd);
      System.arraycopy(interpolator.getInterpolatedState(),0,yTmp,0,y0.length);
      computeDerivatives(stepEnd,yTmp,yDot);
      final double[] predictedScaled=new double[y0.length];
      for (int j=0; j < y0.length; ++j) {
        predictedScaled[j]=stepSize * yDot[j];
      }
      final Array2DRowRealMatrix nordsieckTmp=updateHighOrderDerivativesPhase1(nordsieck);
      updateHighOrderDerivativesPhase2(scaled,predictedScaled,nordsieckTmp);
      error=nordsieckTmp.walkInOptimizedOrder(new Corrector(y,predictedScaled,yTmp));
      if (error <= 1.0) {
        computeDerivatives(stepEnd,yTmp,yDot);
        final double[] correctedScaled=new double[y0.length];
        for (int j=0; j < y0.length; ++j) {
          correctedScaled[j]=stepSize * yDot[j];
        }
        updateHighOrderDerivativesPhase2(predictedScaled,correctedScaled,nordsieckTmp);
        interpolatorTmp.reinitialize(stepEnd,stepSize,correctedScaled,nordsieckTmp);
        interpolatorTmp.storeTime(stepStart);
        interpolatorTmp.shift();
        interpolatorTmp.storeTime(stepEnd);
        if (manager.evaluateStep(interpolatorTmp)) {
          final double dt=manager.getEventTime() - stepStart;
          if (Math.abs(dt) <= Math.ulp(stepStart)) {
            interpolator.storeTime(stepStart);
            System.arraycopy(y,0,yTmp,0,y0.length);
            hNew=0;
            stepSize=0;
            loop=false;
          }
 else {
            hNew=dt;
            interpolator.rescale(hNew);
          }
        }
 else {
          scaled=correctedScaled;
          nordsieck=nordsieckTmp;
          interpolator.reinitialize(stepEnd,stepSize,scaled,nordsieck);
          loop=false;
        }
      }
 else {
        final double factor=computeStepGrowShrinkFactor(error);
        hNew=filterStep(stepSize * factor,forward,false);
        interpolator.rescale(hNew);
      }
    }
    final double nextStep=stepStart + stepSize;
    System.arraycopy(yTmp,0,y,0,n);
    interpolator.storeTime(nextStep);
    manager.stepAccepted(nextStep,y);
    lastStep=manager.stop();
    for (    StepHandler handler : stepHandlers) {
      interpolator.setInterpolatedTime(nextStep);
      handler.handleStep(interpolator,lastStep);
    }
    stepStart=nextStep;
    if (!lastStep && manager.reset(stepStart,y)) {
      start(stepStart,y,t);
      interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
    }
    if (!lastStep) {
      stepSize=filterStep(stepSize,forward,true);
      final double factor=computeStepGrowShrinkFactor(error);
      final double scaledH=stepSize * factor;
      final double nextT=stepStart + scaledH;
      final boolean nextIsLast=forward ? (nextT >= t) : (nextT <= t);
      hNew=filterStep(scaledH,forward,nextIsLast);
      interpolator.rescale(hNew);
    }
  }
  final double stopTime=stepStart;
  stepStart=Double.NaN;
  stepSize=Double.NaN;
  return stopTime;
}