Average Error: 0.1 → 0.1
Time: 14.4s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, x \cdot 9, 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, x \cdot 9, 3 - 12 \cdot x\right)
double f(double x) {
        double r29204769 = 3.0;
        double r29204770 = x;
        double r29204771 = r29204770 * r29204769;
        double r29204772 = r29204771 * r29204770;
        double r29204773 = 4.0;
        double r29204774 = r29204770 * r29204773;
        double r29204775 = r29204772 - r29204774;
        double r29204776 = 1.0;
        double r29204777 = r29204775 + r29204776;
        double r29204778 = r29204769 * r29204777;
        return r29204778;
}

double f(double x) {
        double r29204779 = x;
        double r29204780 = 9.0;
        double r29204781 = r29204779 * r29204780;
        double r29204782 = 3.0;
        double r29204783 = 12.0;
        double r29204784 = r29204783 * r29204779;
        double r29204785 = r29204782 - r29204784;
        double r29204786 = fma(r29204779, r29204781, r29204785);
        return r29204786;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 0.1

    \[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(x, x \cdot 9, 3 - x \cdot 12\right)}\]
  4. Final simplification0.1

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

Reproduce

herbie shell --seed 2019192 +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)))