Average Error: 61.2 → 0.5
Time: 9.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{1}{\frac{\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}{\log 1 - \left(1 \cdot x + \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}}\right)\right)\]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\frac{\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}{\log 1 - \left(1 \cdot x + \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)}}\right)\right)
double f(double x) {
        double r87409 = 1.0;
        double r87410 = x;
        double r87411 = r87409 - r87410;
        double r87412 = log(r87411);
        double r87413 = r87409 + r87410;
        double r87414 = log(r87413);
        double r87415 = r87412 / r87414;
        return r87415;
}

double f(double x) {
        double r87416 = 1.0;
        double r87417 = x;
        double r87418 = 1.0;
        double r87419 = log(r87418);
        double r87420 = 0.5;
        double r87421 = 2.0;
        double r87422 = pow(r87417, r87421);
        double r87423 = pow(r87418, r87421);
        double r87424 = r87422 / r87423;
        double r87425 = r87420 * r87424;
        double r87426 = r87419 - r87425;
        double r87427 = fma(r87417, r87418, r87426);
        double r87428 = r87418 * r87417;
        double r87429 = r87428 + r87425;
        double r87430 = r87419 - r87429;
        double r87431 = r87427 / r87430;
        double r87432 = r87416 / r87431;
        double r87433 = expm1(r87432);
        double r87434 = log1p(r87433);
        return r87434;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 61.2

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

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

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

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

Reproduce

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