MullerNewtonSolver implements IRootsSolver { @VisibleForTesting static Complex computeB2(Complex f2, Complex f1, Complex q2, Complex f0) { double tmp; double re0, re1, re2, re3; double im0, im1, im2, im3; re0 = f2.getRe() - f1.getRe(); im0 = f2.getIm() - f1.getIm(); re1 = q2.getRe(); im1 = q2.getIm(); re2 = q2.getRe(); im2 = q2.getIm(); re3 = f0.getRe() - f1.getRe(); im3 = f0.getIm() - f1.getIm(); tmp = re2 * re3 - im2 * im3; im2 = re2 * im3 + im2 * re3; re2 = tmp; re3 = f2.getRe() - f1.getRe(); im3 = f2.getIm() - f1.getIm(); re3 *= 2; im3 *= 2; re2 += re3; im2 += im3; tmp = re1 * re2 - im1 * im2; im1 = re1 * im2 + im1 * re2; re1 = tmp; re0 += re1; im0 += im1; return Complex.cart(re0, im0); } MullerNewtonSolver(); @Override void clear(); @Override MullerNewtonSolver exemplar(); @Override boolean factorize(final Polynomial p); @Override Polynomial remainder(); @Override Complex[] roots(); boolean isLeastSquaresDivision(); void setLeastSquaresDivision(boolean lq);  }
@Test public void testComputeB2() { for (int i = 0; i < 10; i++) { Complex q2 = random(), f0 = random(), f1 = random(), f2 = random(); Complex result = f2.minus(f1).plus(q2.times(q2.times(f0.minus(f1)).plus(f2.minus(f1).times(2)))); assertEquals(result, computeB2(f2, f1, q2, f0), 0); } }