Average Error: 61.3 → 0.5
Time: 19.0s
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 r4142607 = 1.0;
        double r4142608 = x;
        double r4142609 = r4142607 - r4142608;
        double r4142610 = log(r4142609);
        double r4142611 = r4142607 + r4142608;
        double r4142612 = log(r4142611);
        double r4142613 = r4142610 / r4142612;
        return r4142613;
}

double f(double x) {
        double r4142614 = 1.0;
        double r4142615 = log(r4142614);
        double r4142616 = x;
        double r4142617 = r4142616 / r4142614;
        double r4142618 = r4142617 * r4142617;
        double r4142619 = 0.5;
        double r4142620 = r4142616 * r4142614;
        double r4142621 = fma(r4142618, r4142619, r4142620);
        double r4142622 = r4142615 - r4142621;
        double r4142623 = -0.5;
        double r4142624 = fma(r4142614, r4142616, r4142615);
        double r4142625 = fma(r4142623, r4142618, r4142624);
        double r4142626 = r4142622 / r4142625;
        double r4142627 = expm1(r4142626);
        double r4142628 = 1.0;
        double r4142629 = r4142627 + r4142628;
        double r4142630 = log(r4142629);
        return r4142630;
}

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))))