Average Error: 0.2 → 0.1
Time: 18.3s
Precision: 64
\[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
\[\mathsf{fma}\left(x, x \cdot 9.0 - 12.0, 3.0\right)\]
3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)
\mathsf{fma}\left(x, x \cdot 9.0 - 12.0, 3.0\right)
double f(double x) {
        double r36945496 = 3.0;
        double r36945497 = x;
        double r36945498 = r36945497 * r36945496;
        double r36945499 = r36945498 * r36945497;
        double r36945500 = 4.0;
        double r36945501 = r36945497 * r36945500;
        double r36945502 = r36945499 - r36945501;
        double r36945503 = 1.0;
        double r36945504 = r36945502 + r36945503;
        double r36945505 = r36945496 * r36945504;
        return r36945505;
}

double f(double x) {
        double r36945506 = x;
        double r36945507 = 9.0;
        double r36945508 = r36945506 * r36945507;
        double r36945509 = 12.0;
        double r36945510 = r36945508 - r36945509;
        double r36945511 = 3.0;
        double r36945512 = fma(r36945506, r36945510, r36945511);
        return r36945512;
}

Error

Bits error versus x

Target

Original0.2
Target0.1
Herbie0.1
\[3.0 + \left(\left(9.0 \cdot x\right) \cdot x - 12.0 \cdot x\right)\]

Derivation

  1. Initial program 0.2

    \[3.0 \cdot \left(\left(\left(x \cdot 3.0\right) \cdot x - x \cdot 4.0\right) + 1.0\right)\]
  2. Taylor expanded around 0 0.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(9.0, x \cdot x, 3.0\right) - x \cdot 12.0}\]
  4. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{\left(9.0 \cdot {x}^{2} + 3.0\right) - 12.0 \cdot x}\]
  5. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 9.0 \cdot x - 12.0, 3.0\right)}\]
  6. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(x, x \cdot 9.0 - 12.0, 3.0\right)\]

Reproduce

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