Average Error: 5.4 → 0.1
Time: 9.3s
Precision: 64
\[x \cdot \left(1 + y \cdot y\right)\]
\[\mathsf{fma}\left(x \cdot y, y, 1 \cdot x\right)\]
x \cdot \left(1 + y \cdot y\right)
\mathsf{fma}\left(x \cdot y, y, 1 \cdot x\right)
double f(double x, double y) {
        double r17276641 = x;
        double r17276642 = 1.0;
        double r17276643 = y;
        double r17276644 = r17276643 * r17276643;
        double r17276645 = r17276642 + r17276644;
        double r17276646 = r17276641 * r17276645;
        return r17276646;
}

double f(double x, double y) {
        double r17276647 = x;
        double r17276648 = y;
        double r17276649 = r17276647 * r17276648;
        double r17276650 = 1.0;
        double r17276651 = r17276650 * r17276647;
        double r17276652 = fma(r17276649, r17276648, r17276651);
        return r17276652;
}

Error

Bits error versus x

Bits error versus y

Target

Original5.4
Target0.1
Herbie0.1
\[x + \left(x \cdot y\right) \cdot y\]

Derivation

  1. Initial program 5.4

    \[x \cdot \left(1 + y \cdot y\right)\]
  2. Simplified5.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, y, 1\right) \cdot x}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt34.6

    \[\leadsto \mathsf{fma}\left(y, y, 1\right) \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}\]
  5. Applied add-sqr-sqrt34.6

    \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)} \cdot \sqrt{\mathsf{fma}\left(y, y, 1\right)}\right)} \cdot \left(\sqrt{x} \cdot \sqrt{x}\right)\]
  6. Applied unswap-sqr34.6

    \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(y, y, 1\right)} \cdot \sqrt{x}\right) \cdot \left(\sqrt{\mathsf{fma}\left(y, y, 1\right)} \cdot \sqrt{x}\right)}\]
  7. Taylor expanded around 0 5.4

    \[\leadsto \color{blue}{1 \cdot x + x \cdot {y}^{2}}\]
  8. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y, y, 1 \cdot x\right)}\]
  9. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(x \cdot y, y, 1 \cdot x\right)\]

Reproduce

herbie shell --seed 2019171 +o rules:numerics
(FPCore (x y)
  :name "Numeric.Integration.TanhSinh:everywhere from integration-0.2.1"

  :herbie-target
  (+ x (* (* x y) y))

  (* x (+ 1.0 (* y y))))