Average Error: 61.3 → 0.5
Time: 19.5s
Precision: 64
\[-1 \lt x \land x \lt 1\]
\[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}\]
\[\log \left(\mathsf{expm1}\left(\frac{\log 1 - \mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{1}{2}, x \cdot 1\right)}{\mathsf{fma}\left(\frac{-1}{2}, \frac{x}{1} \cdot \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right) + 1\right)\]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\log \left(\mathsf{expm1}\left(\frac{\log 1 - \mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{1}{2}, x \cdot 1\right)}{\mathsf{fma}\left(\frac{-1}{2}, \frac{x}{1} \cdot \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right) + 1\right)
double f(double x) {
        double r4040875 = 1.0;
        double r4040876 = x;
        double r4040877 = r4040875 - r4040876;
        double r4040878 = log(r4040877);
        double r4040879 = r4040875 + r4040876;
        double r4040880 = log(r4040879);
        double r4040881 = r4040878 / r4040880;
        return r4040881;
}

double f(double x) {
        double r4040882 = 1.0;
        double r4040883 = log(r4040882);
        double r4040884 = x;
        double r4040885 = r4040884 / r4040882;
        double r4040886 = r4040885 * r4040885;
        double r4040887 = 0.5;
        double r4040888 = r4040884 * r4040882;
        double r4040889 = fma(r4040886, r4040887, r4040888);
        double r4040890 = r4040883 - r4040889;
        double r4040891 = -0.5;
        double r4040892 = fma(r4040882, r4040884, r4040883);
        double r4040893 = fma(r4040891, r4040886, r4040892);
        double r4040894 = r4040890 / r4040893;
        double r4040895 = expm1(r4040894);
        double r4040896 = 1.0;
        double r4040897 = r4040895 + r4040896;
        double r4040898 = log(r4040897);
        return r4040898;
}

Error

Bits error versus x

Target

Original61.3
Target0.4
Herbie0.5
\[-\left(\left(\left(1 + x\right) + \frac{x \cdot x}{2}\right) + 0.4166666666666666851703837437526090070605 \cdot {x}^{3}\right)\]

Derivation

  1. Initial program 61.3

    \[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}\]
  2. Taylor expanded around 0 60.5

    \[\leadsto \frac{\log \left(1 - x\right)}{\color{blue}{\left(\log 1 + 1 \cdot x\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}}}\]
  3. Simplified60.5

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

    \[\leadsto \frac{\color{blue}{\log 1 - \left(1 \cdot x + \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}}{\mathsf{fma}\left(\frac{-1}{2}, \frac{x}{1} \cdot \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\]
  5. Simplified0.5

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

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log 1 - \mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{1}{2}, 1 \cdot x\right)}{\mathsf{fma}\left(\frac{-1}{2}, \frac{x}{1} \cdot \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right)\right)}\]
  8. Using strategy rm
  9. Applied log1p-udef0.5

    \[\leadsto \color{blue}{\log \left(1 + \mathsf{expm1}\left(\frac{\log 1 - \mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{1}{2}, 1 \cdot x\right)}{\mathsf{fma}\left(\frac{-1}{2}, \frac{x}{1} \cdot \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right)\right)}\]
  10. Final simplification0.5

    \[\leadsto \log \left(\mathsf{expm1}\left(\frac{\log 1 - \mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{1}{2}, x \cdot 1\right)}{\mathsf{fma}\left(\frac{-1}{2}, \frac{x}{1} \cdot \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right) + 1\right)\]

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x)
  :name "qlog (example 3.10)"
  :pre (and (< -1.0 x) (< x 1.0))

  :herbie-target
  (- (+ (+ (+ 1.0 x) (/ (* x x) 2.0)) (* 0.4166666666666667 (pow x 3.0))))

  (/ (log (- 1.0 x)) (log (+ 1.0 x))))