Average Error: 61.4 → 0.4
Time: 18.4s
Precision: 64
\[-1 \lt x \land x \lt 1\]
\[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}\]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log 1 - \mathsf{fma}\left(1, x, \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}{\mathsf{fma}\left(\frac{-1}{2}, \frac{{x}^{2}}{{1}^{2}}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right)\right)\]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log 1 - \mathsf{fma}\left(1, x, \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}{\mathsf{fma}\left(\frac{-1}{2}, \frac{{x}^{2}}{{1}^{2}}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\right)\right)
double f(double x) {
        double r69107 = 1.0;
        double r69108 = x;
        double r69109 = r69107 - r69108;
        double r69110 = log(r69109);
        double r69111 = r69107 + r69108;
        double r69112 = log(r69111);
        double r69113 = r69110 / r69112;
        return r69113;
}

double f(double x) {
        double r69114 = 1.0;
        double r69115 = log(r69114);
        double r69116 = x;
        double r69117 = 0.5;
        double r69118 = 2.0;
        double r69119 = pow(r69116, r69118);
        double r69120 = pow(r69114, r69118);
        double r69121 = r69119 / r69120;
        double r69122 = r69117 * r69121;
        double r69123 = fma(r69114, r69116, r69122);
        double r69124 = r69115 - r69123;
        double r69125 = -0.5;
        double r69126 = fma(r69114, r69116, r69115);
        double r69127 = fma(r69125, r69121, r69126);
        double r69128 = r69124 / r69127;
        double r69129 = expm1(r69128);
        double r69130 = log1p(r69129);
        return r69130;
}

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

    \[\leadsto \frac{\color{blue}{\log 1 - \mathsf{fma}\left(1, x, \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}}{\mathsf{fma}\left(\frac{-1}{2}, \frac{{x}^{2}}{{1}^{2}}, \mathsf{fma}\left(1, x, \log 1\right)\right)}\]
  6. Using strategy rm
  7. Applied log1p-expm1-u0.4

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

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

Reproduce

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

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

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