Program: 57327
Project: 57327
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public double integrate(final FirstOrderDifferentialEquations equations,final double t0,final double[] y0,final double t,final double[] y) throws MathUserException, 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 double[] predictedScaled=new double[y0.length];
  Array2DRowRealMatrix nordsieckTmp=null;
  final NordsieckStepInterpolator interpolator=new NordsieckStepInterpolator();
  interpolator.reinitialize(y,forward);
  for (  StepHandler handler : stepHandlers) {
    handler.reset();
  }
  statesInitialized=false;
  start(t0,y,t);
  interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
  interpolator.storeTime(stepStart);
  double hNew=stepSize;
  interpolator.rescale(hNew);
  isLastStep=false;
  do {
    double error=10;
    while (error >= 1.0) {
      stepSize=hNew;
      final double stepEnd=stepStart + stepSize;
      interpolator.setInterpolatedTime(stepEnd);
      System.arraycopy(interpolator.getInterpolatedState(),0,yTmp,0,y0.length);
      computeDerivatives(stepEnd,yTmp,yDot);
      for (int j=0; j < y0.length; ++j) {
        predictedScaled[j]=stepSize * yDot[j];
      }
      nordsieckTmp=updateHighOrderDerivativesPhase1(nordsieck);
      updateHighOrderDerivativesPhase2(scaled,predictedScaled,nordsieckTmp);
      error=nordsieckTmp.walkInOptimizedOrder(new Corrector(y,predictedScaled,yTmp));
      if (error >= 1.0) {
        final double factor=computeStepGrowShrinkFactor(error);
        hNew=filterStep(stepSize * factor,forward,false);
        interpolator.rescale(hNew);
      }
    }
    final double stepEnd=stepStart + stepSize;
    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);
    System.arraycopy(yTmp,0,y,0,n);
    interpolator.reinitialize(stepEnd,stepSize,correctedScaled,nordsieckTmp);
    interpolator.storeTime(stepStart);
    interpolator.shift();
    interpolator.storeTime(stepEnd);
    stepStart=acceptStep(interpolator,y,yDot,t);
    scaled=correctedScaled;
    nordsieck=nordsieckTmp;
    if (!isLastStep) {
      interpolator.storeTime(stepStart);
      if (resetOccurred) {
        start(stepStart,y,t);
        interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
      }
      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);
      final double filteredNextT=stepStart + hNew;
      final boolean filteredNextIsLast=forward ? (filteredNextT >= t) : (filteredNextT <= t);
      if (filteredNextIsLast) {
        hNew=t - stepStart;
      }
      interpolator.rescale(hNew);
    }
  }
 while (!isLastStep);
  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 MathUserException, 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 double[] predictedScaled=new double[y0.length];
  Array2DRowRealMatrix nordsieckTmp=null;
  final NordsieckStepInterpolator interpolator=new NordsieckStepInterpolator();
  interpolator.reinitialize(y,forward);
  for (  StepHandler handler : stepHandlers) {
    handler.reset();
  }
  setStateInitialized(false);
  start(t0,y,t);
  interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
  interpolator.storeTime(stepStart);
  double hNew=stepSize;
  interpolator.rescale(hNew);
  isLastStep=false;
  do {
    double error=10;
    while (error >= 1.0) {
      stepSize=hNew;
      final double stepEnd=stepStart + stepSize;
      interpolator.setInterpolatedTime(stepEnd);
      System.arraycopy(interpolator.getInterpolatedState(),0,yTmp,0,y0.length);
      computeDerivatives(stepEnd,yTmp,yDot);
      for (int j=0; j < y0.length; ++j) {
        predictedScaled[j]=stepSize * yDot[j];
      }
      nordsieckTmp=updateHighOrderDerivativesPhase1(nordsieck);
      updateHighOrderDerivativesPhase2(scaled,predictedScaled,nordsieckTmp);
      error=nordsieckTmp.walkInOptimizedOrder(new Corrector(y,predictedScaled,yTmp));
      if (error >= 1.0) {
        final double factor=computeStepGrowShrinkFactor(error);
        hNew=filterStep(stepSize * factor,forward,false);
        interpolator.rescale(hNew);
      }
    }
    final double stepEnd=stepStart + stepSize;
    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);
    System.arraycopy(yTmp,0,y,0,n);
    interpolator.reinitialize(stepEnd,stepSize,correctedScaled,nordsieckTmp);
    interpolator.storeTime(stepStart);
    interpolator.shift();
    interpolator.storeTime(stepEnd);
    stepStart=acceptStep(interpolator,y,yDot,t);
    scaled=correctedScaled;
    nordsieck=nordsieckTmp;
    if (!isLastStep) {
      interpolator.storeTime(stepStart);
      if (resetOccurred) {
        start(stepStart,y,t);
        interpolator.reinitialize(stepStart,stepSize,scaled,nordsieck);
      }
      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);
      final double filteredNextT=stepStart + hNew;
      final boolean filteredNextIsLast=forward ? (filteredNextT >= t) : (filteredNextT <= t);
      if (filteredNextIsLast) {
        hNew=t - stepStart;
      }
      interpolator.rescale(hNew);
    }
  }
 while (!isLastStep);
  final double stopTime=stepStart;
  stepStart=Double.NaN;
  stepSize=Double.NaN;
  return stopTime;
}