Average Error: 0.1 → 0.2
Time: 2.8s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, \frac{\mathsf{fma}\left(9, x, 12\right) \cdot \left(9 \cdot x - 12\right)}{\mathsf{fma}\left(9, x, 12\right)}, 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, \frac{\mathsf{fma}\left(9, x, 12\right) \cdot \left(9 \cdot x - 12\right)}{\mathsf{fma}\left(9, x, 12\right)}, 3\right)
double f(double x) {
        double r700649 = 3.0;
        double r700650 = x;
        double r700651 = r700650 * r700649;
        double r700652 = r700651 * r700650;
        double r700653 = 4.0;
        double r700654 = r700650 * r700653;
        double r700655 = r700652 - r700654;
        double r700656 = 1.0;
        double r700657 = r700655 + r700656;
        double r700658 = r700649 * r700657;
        return r700658;
}

double f(double x) {
        double r700659 = x;
        double r700660 = 9.0;
        double r700661 = 12.0;
        double r700662 = fma(r700660, r700659, r700661);
        double r700663 = r700660 * r700659;
        double r700664 = r700663 - r700661;
        double r700665 = r700662 * r700664;
        double r700666 = r700665 / r700662;
        double r700667 = 3.0;
        double r700668 = fma(r700659, r700666, r700667);
        return r700668;
}

Error

Bits error versus x

Target

Original0.1
Target0.1
Herbie0.2
\[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. Simplified0.1

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{2}, 9, 3 - 12 \cdot x\right)}\]
  5. Taylor expanded around 0 0.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 9 \cdot x - 12, 3\right)}\]
  7. Using strategy rm
  8. Applied flip--0.2

    \[\leadsto \mathsf{fma}\left(x, \color{blue}{\frac{\left(9 \cdot x\right) \cdot \left(9 \cdot x\right) - 12 \cdot 12}{9 \cdot x + 12}}, 3\right)\]
  9. Simplified0.2

    \[\leadsto \mathsf{fma}\left(x, \frac{\color{blue}{\mathsf{fma}\left(9, x, 12\right) \cdot \left(9 \cdot x - 12\right)}}{9 \cdot x + 12}, 3\right)\]
  10. Simplified0.2

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

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

Reproduce

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

  :herbie-target
  (+ 3 (- (* (* 9 x) x) (* 12 x)))

  (* 3 (+ (- (* (* x 3) x) (* x 4)) 1)))