Average Error: 60.8 → 0.5
Time: 19.8s
Precision: 64
\[-1 \lt x \land x \lt 1\]
\[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}\]
\[\mathsf{fma}\left(\left(\mathsf{fma}\left(x, \frac{-1}{2}, -1\right)\right), x, -1\right)\]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\mathsf{fma}\left(\left(\mathsf{fma}\left(x, \frac{-1}{2}, -1\right)\right), x, -1\right)
double f(double x) {
        double r4324443 = 1.0;
        double r4324444 = x;
        double r4324445 = r4324443 - r4324444;
        double r4324446 = log(r4324445);
        double r4324447 = r4324443 + r4324444;
        double r4324448 = log(r4324447);
        double r4324449 = r4324446 / r4324448;
        return r4324449;
}

double f(double x) {
        double r4324450 = x;
        double r4324451 = -0.5;
        double r4324452 = -1.0;
        double r4324453 = fma(r4324450, r4324451, r4324452);
        double r4324454 = fma(r4324453, r4324450, r4324452);
        return r4324454;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 60.8

    \[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}\]
  2. Simplified59.9

    \[\leadsto \color{blue}{\frac{\log \left(1 - x\right)}{\mathsf{log1p}\left(x\right)}}\]
  3. Taylor expanded around 0 0.5

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

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

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

Reproduce

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

  :herbie-target
  (- (+ (+ (+ 1 x) (/ (* x x) 2)) (* 5/12 (pow x 3))))

  (/ (log (- 1 x)) (log (+ 1 x))))