Average Error: 61.5 → 0.4
Time: 15.7s
Precision: 64
\[-1 \lt x \land x \lt 1\]
\[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}\]
\[\log \left(e^{\frac{1}{\frac{\mathsf{fma}\left(\frac{x \cdot \frac{-1}{2}}{1}, \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}{\log 1 - \mathsf{fma}\left(1, x, x \cdot \left(\frac{\frac{1}{2}}{1} \cdot \frac{x}{1}\right)\right)}}}\right)\]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\log \left(e^{\frac{1}{\frac{\mathsf{fma}\left(\frac{x \cdot \frac{-1}{2}}{1}, \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)}{\log 1 - \mathsf{fma}\left(1, x, x \cdot \left(\frac{\frac{1}{2}}{1} \cdot \frac{x}{1}\right)\right)}}}\right)
double f(double x) {
        double r65635 = 1.0;
        double r65636 = x;
        double r65637 = r65635 - r65636;
        double r65638 = log(r65637);
        double r65639 = r65635 + r65636;
        double r65640 = log(r65639);
        double r65641 = r65638 / r65640;
        return r65641;
}

double f(double x) {
        double r65642 = 1.0;
        double r65643 = x;
        double r65644 = -0.5;
        double r65645 = r65643 * r65644;
        double r65646 = 1.0;
        double r65647 = r65645 / r65646;
        double r65648 = r65643 / r65646;
        double r65649 = log(r65646);
        double r65650 = fma(r65646, r65643, r65649);
        double r65651 = fma(r65647, r65648, r65650);
        double r65652 = 0.5;
        double r65653 = r65652 / r65646;
        double r65654 = r65653 * r65648;
        double r65655 = r65643 * r65654;
        double r65656 = fma(r65646, r65643, r65655);
        double r65657 = r65649 - r65656;
        double r65658 = r65651 / r65657;
        double r65659 = r65642 / r65658;
        double r65660 = exp(r65659);
        double r65661 = log(r65660);
        return r65661;
}

Error

Bits error versus x

Target

Original61.5
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.5

    \[\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{\frac{1}{2}}{1}, \frac{x \cdot x}{1}, 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 add-log-exp0.4

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

    \[\leadsto \log \color{blue}{\left(e^{\frac{\log 1 - \mathsf{fma}\left(\frac{x \cdot x}{1}, \frac{\frac{1}{2}}{1}, x \cdot 1\right)}{\mathsf{fma}\left(\frac{x}{1}, \frac{x \cdot \frac{-1}{2}}{1}, \mathsf{fma}\left(x, 1, \log 1\right)\right)}}\right)}\]
  9. Using strategy rm
  10. Applied clear-num0.4

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

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

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

Reproduce

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