Average Error: 61.3 → 0.5
Time: 22.4s
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(1, x, \frac{\frac{1}{2}}{\frac{1}{x} \cdot \frac{1}{x}}\right)}{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \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(1, x, \frac{\frac{1}{2}}{\frac{1}{x} \cdot \frac{1}{x}}\right)}{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right) + 1\right)
double f(double x) {
        double r4516876 = 1.0;
        double r4516877 = x;
        double r4516878 = r4516876 - r4516877;
        double r4516879 = log(r4516878);
        double r4516880 = r4516876 + r4516877;
        double r4516881 = log(r4516880);
        double r4516882 = r4516879 / r4516881;
        return r4516882;
}

double f(double x) {
        double r4516883 = 1.0;
        double r4516884 = log(r4516883);
        double r4516885 = x;
        double r4516886 = 0.5;
        double r4516887 = r4516883 / r4516885;
        double r4516888 = r4516887 * r4516887;
        double r4516889 = r4516886 / r4516888;
        double r4516890 = fma(r4516883, r4516885, r4516889);
        double r4516891 = r4516884 - r4516890;
        double r4516892 = r4516885 / r4516883;
        double r4516893 = r4516892 * r4516892;
        double r4516894 = -0.5;
        double r4516895 = fma(r4516883, r4516885, r4516884);
        double r4516896 = fma(r4516893, r4516894, r4516895);
        double r4516897 = r4516891 / r4516896;
        double r4516898 = expm1(r4516897);
        double r4516899 = 1.0;
        double r4516900 = r4516898 + r4516899;
        double r4516901 = log(r4516900);
        return r4516901;
}

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{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \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{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\]
  5. Simplified0.5

    \[\leadsto \frac{\color{blue}{\log 1 - \mathsf{fma}\left(1, x, \frac{\frac{1}{2}}{\frac{1}{x} \cdot \frac{1}{x}}\right)}}{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \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(1, x, \frac{\frac{1}{2}}{\frac{1}{x} \cdot \frac{1}{x}}\right)}{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \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(1, x, \frac{\frac{1}{2}}{\frac{1}{x} \cdot \frac{1}{x}}\right)}{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \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(1, x, \frac{\frac{1}{2}}{\frac{1}{x} \cdot \frac{1}{x}}\right)}{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \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))))