Average Error: 0.2 → 0.1
Time: 27.8s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x \cdot 9, x, 3 - 12 \cdot x\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x \cdot 9, x, 3 - 12 \cdot x\right)
double f(double x) {
        double r33745813 = 3.0;
        double r33745814 = x;
        double r33745815 = r33745814 * r33745813;
        double r33745816 = r33745815 * r33745814;
        double r33745817 = 4.0;
        double r33745818 = r33745814 * r33745817;
        double r33745819 = r33745816 - r33745818;
        double r33745820 = 1.0;
        double r33745821 = r33745819 + r33745820;
        double r33745822 = r33745813 * r33745821;
        return r33745822;
}

double f(double x) {
        double r33745823 = x;
        double r33745824 = 9.0;
        double r33745825 = r33745823 * r33745824;
        double r33745826 = 3.0;
        double r33745827 = 12.0;
        double r33745828 = r33745827 * r33745823;
        double r33745829 = r33745826 - r33745828;
        double r33745830 = fma(r33745825, r33745823, r33745829);
        return r33745830;
}

Error

Bits error versus x

Target

Original0.2
Target0.1
Herbie0.1
\[3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)\]

Derivation

  1. Initial program 0.2

    \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
  2. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(9 \cdot {x}^{2} + 3\right) - 12 \cdot x}\]
  3. Simplified0.1

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

    \[\leadsto \mathsf{fma}\left(x \cdot 9, x, 3 - 12 \cdot x\right)\]

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"

  :herbie-target
  (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x)))

  (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))