Average Error: 0.1 → 0.1
Time: 2.5s
Precision: 64
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)\]
\[\mathsf{fma}\left(x, 9 \cdot x - 12, 3\right)\]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\mathsf{fma}\left(x, 9 \cdot x - 12, 3\right)
double f(double x) {
        double r783833 = 3.0;
        double r783834 = x;
        double r783835 = r783834 * r783833;
        double r783836 = r783835 * r783834;
        double r783837 = 4.0;
        double r783838 = r783834 * r783837;
        double r783839 = r783836 - r783838;
        double r783840 = 1.0;
        double r783841 = r783839 + r783840;
        double r783842 = r783833 * r783841;
        return r783842;
}

double f(double x) {
        double r783843 = x;
        double r783844 = 9.0;
        double r783845 = r783844 * r783843;
        double r783846 = 12.0;
        double r783847 = r783845 - r783846;
        double r783848 = 3.0;
        double r783849 = fma(r783843, r783847, r783848);
        return r783849;
}

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

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

Reproduce

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