Average Error: 0.2 → 0.1
Time: 4.7s
Precision: 64
\[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}\]
\[\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - 1}{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right)}\right)\right)}{\frac{1}{6}}\]
\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}
\frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - 1}{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right)}\right)\right)}{\frac{1}{6}}
double f(double x) {
        double r975787 = 6.0;
        double r975788 = x;
        double r975789 = 1.0;
        double r975790 = r975788 - r975789;
        double r975791 = r975787 * r975790;
        double r975792 = r975788 + r975789;
        double r975793 = 4.0;
        double r975794 = sqrt(r975788);
        double r975795 = r975793 * r975794;
        double r975796 = r975792 + r975795;
        double r975797 = r975791 / r975796;
        return r975797;
}

double f(double x) {
        double r975798 = x;
        double r975799 = 1.0;
        double r975800 = r975798 - r975799;
        double r975801 = sqrt(r975798);
        double r975802 = 4.0;
        double r975803 = r975798 + r975799;
        double r975804 = fma(r975801, r975802, r975803);
        double r975805 = r975800 / r975804;
        double r975806 = log1p(r975805);
        double r975807 = expm1(r975806);
        double r975808 = 1.0;
        double r975809 = 6.0;
        double r975810 = r975808 / r975809;
        double r975811 = r975807 / r975810;
        return r975811;
}

Error

Bits error versus x

Target

Original0.2
Target0.0
Herbie0.1
\[\frac{6}{\frac{\left(x + 1\right) + 4 \cdot \sqrt{x}}{x - 1}}\]

Derivation

  1. Initial program 0.2

    \[\frac{6 \cdot \left(x - 1\right)}{\left(x + 1\right) + 4 \cdot \sqrt{x}}\]
  2. Simplified0.0

    \[\leadsto \color{blue}{\frac{x - 1}{\frac{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right)}{6}}}\]
  3. Using strategy rm
  4. Applied div-inv0.2

    \[\leadsto \frac{x - 1}{\color{blue}{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right) \cdot \frac{1}{6}}}\]
  5. Applied associate-/r*0.1

    \[\leadsto \color{blue}{\frac{\frac{x - 1}{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right)}}{\frac{1}{6}}}\]
  6. Using strategy rm
  7. Applied expm1-log1p-u0.1

    \[\leadsto \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - 1}{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right)}\right)\right)}}{\frac{1}{6}}\]
  8. Final simplification0.1

    \[\leadsto \frac{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x - 1}{\mathsf{fma}\left(\sqrt{x}, 4, x + 1\right)}\right)\right)}{\frac{1}{6}}\]

Reproduce

herbie shell --seed 2020027 +o rules:numerics
(FPCore (x)
  :name "Data.Approximate.Numerics:blog from approximate-0.2.2.1"
  :precision binary64

  :herbie-target
  (/ 6 (/ (+ (+ x 1) (* 4 (sqrt x))) (- x 1)))

  (/ (* 6 (- x 1)) (+ (+ x 1) (* 4 (sqrt x)))))