Average Error: 0.2 → 0.1
Time: 37.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 - 12, 3\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 - 12, 3\right)
double f(double x) {
        double r33325495 = 3.0;
        double r33325496 = x;
        double r33325497 = r33325496 * r33325495;
        double r33325498 = r33325497 * r33325496;
        double r33325499 = 4.0;
        double r33325500 = r33325496 * r33325499;
        double r33325501 = r33325498 - r33325500;
        double r33325502 = 1.0;
        double r33325503 = r33325501 + r33325502;
        double r33325504 = r33325495 * r33325503;
        return r33325504;
}

double f(double x) {
        double r33325505 = x;
        double r33325506 = 9.0;
        double r33325507 = r33325505 * r33325506;
        double r33325508 = 12.0;
        double r33325509 = r33325507 - r33325508;
        double r33325510 = 3.0;
        double r33325511 = fma(r33325505, r33325509, r33325510);
        return r33325511;
}

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, x \cdot x, 3\right) - x \cdot 12}\]
  4. Taylor expanded around 0 0.1

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

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

    \[\leadsto \mathsf{fma}\left(x, x \cdot 9 - 12, 3\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)))