Average Error: 61.4 → 0.4
Time: 19.2s
Precision: 64
\[-1 \lt x \land x \lt 1\]
\[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}\]
\[\frac{1}{\frac{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \mathsf{fma}\left(x, 1, \log 1\right)\right)}{\log 1 - \mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{1}{2}, 1 \cdot x\right)}}\]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\frac{1}{\frac{\mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \mathsf{fma}\left(x, 1, \log 1\right)\right)}{\log 1 - \mathsf{fma}\left(\frac{x}{1} \cdot \frac{x}{1}, \frac{1}{2}, 1 \cdot x\right)}}
double f(double x) {
        double r3104719 = 1.0;
        double r3104720 = x;
        double r3104721 = r3104719 - r3104720;
        double r3104722 = log(r3104721);
        double r3104723 = r3104719 + r3104720;
        double r3104724 = log(r3104723);
        double r3104725 = r3104722 / r3104724;
        return r3104725;
}

double f(double x) {
        double r3104726 = 1.0;
        double r3104727 = x;
        double r3104728 = 1.0;
        double r3104729 = r3104727 / r3104728;
        double r3104730 = r3104729 * r3104729;
        double r3104731 = -0.5;
        double r3104732 = log(r3104728);
        double r3104733 = fma(r3104727, r3104728, r3104732);
        double r3104734 = fma(r3104730, r3104731, r3104733);
        double r3104735 = 0.5;
        double r3104736 = r3104728 * r3104727;
        double r3104737 = fma(r3104730, r3104735, r3104736);
        double r3104738 = r3104732 - r3104737;
        double r3104739 = r3104734 / r3104738;
        double r3104740 = r3104726 / r3104739;
        return r3104740;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 61.4

    \[\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(x, 1, \log 1\right)\right)}}\]
  4. Taylor expanded around 0 0.4

    \[\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(x, 1, \log 1\right)\right)}\]
  5. Simplified0.4

    \[\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{x}{1} \cdot \frac{x}{1}, \frac{-1}{2}, \mathsf{fma}\left(x, 1, \log 1\right)\right)}\]
  6. Using strategy rm
  7. Applied clear-num0.4

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

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

Reproduce

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