Average Error: 18.1 → 0.1
Time: 18.7s
Precision: 64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;y \le -212491914.1913111507892608642578125 \lor \neg \left(y \le 758763659.74992859363555908203125\right):\\ \;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}}, \frac{x}{y}\right) - \frac{1}{y}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\ \end{array}\]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;y \le -212491914.1913111507892608642578125 \lor \neg \left(y \le 758763659.74992859363555908203125\right):\\
\;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}}, \frac{x}{y}\right) - \frac{1}{y}}\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\

\end{array}
double f(double x, double y) {
        double r214432 = 1.0;
        double r214433 = x;
        double r214434 = y;
        double r214435 = r214433 - r214434;
        double r214436 = r214432 - r214434;
        double r214437 = r214435 / r214436;
        double r214438 = r214432 - r214437;
        double r214439 = log(r214438);
        double r214440 = r214432 - r214439;
        return r214440;
}

double f(double x, double y) {
        double r214441 = y;
        double r214442 = -212491914.19131115;
        bool r214443 = r214441 <= r214442;
        double r214444 = 758763659.7499286;
        bool r214445 = r214441 <= r214444;
        double r214446 = !r214445;
        bool r214447 = r214443 || r214446;
        double r214448 = 1.0;
        double r214449 = exp(r214448);
        double r214450 = x;
        double r214451 = 2.0;
        double r214452 = pow(r214441, r214451);
        double r214453 = r214450 / r214452;
        double r214454 = r214450 / r214441;
        double r214455 = fma(r214448, r214453, r214454);
        double r214456 = r214448 / r214441;
        double r214457 = r214455 - r214456;
        double r214458 = r214449 / r214457;
        double r214459 = log(r214458);
        double r214460 = r214450 - r214441;
        double r214461 = r214448 - r214441;
        double r214462 = r214460 / r214461;
        double r214463 = r214448 - r214462;
        double r214464 = r214449 / r214463;
        double r214465 = log(r214464);
        double r214466 = r214447 ? r214459 : r214465;
        return r214466;
}

Error

Bits error versus x

Bits error versus y

Target

Original18.1
Target0.1
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;y \lt -81284752.6194724142551422119140625:\\ \;\;\;\;1 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1}{y} - \frac{x}{y}\right)\right)\\ \mathbf{elif}\;y \lt 30094271212461763678175232:\\ \;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1}{y} - \frac{x}{y}\right)\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -212491914.19131115 or 758763659.7499286 < y

    1. Initial program 46.8

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
    2. Using strategy rm
    3. Applied add-log-exp46.8

      \[\leadsto \color{blue}{\log \left(e^{1}\right)} - \log \left(1 - \frac{x - y}{1 - y}\right)\]
    4. Applied diff-log46.8

      \[\leadsto \color{blue}{\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)}\]
    5. Taylor expanded around inf 0.2

      \[\leadsto \log \left(\frac{e^{1}}{\color{blue}{\left(\frac{x}{y} + 1 \cdot \frac{x}{{y}^{2}}\right) - 1 \cdot \frac{1}{y}}}\right)\]
    6. Simplified0.2

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

    if -212491914.19131115 < y < 758763659.7499286

    1. Initial program 0.1

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
    2. Using strategy rm
    3. Applied add-log-exp0.1

      \[\leadsto \color{blue}{\log \left(e^{1}\right)} - \log \left(1 - \frac{x - y}{1 - y}\right)\]
    4. Applied diff-log0.1

      \[\leadsto \color{blue}{\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -212491914.1913111507892608642578125 \lor \neg \left(y \le 758763659.74992859363555908203125\right):\\ \;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}}, \frac{x}{y}\right) - \frac{1}{y}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019323 +o rules:numerics
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"
  :precision binary64

  :herbie-target
  (if (< y -81284752.61947241) (- 1 (log (- (/ x (* y y)) (- (/ 1 y) (/ x y))))) (if (< y 3.0094271212461764e+25) (log (/ (exp 1) (- 1 (/ (- x y) (- 1 y))))) (- 1 (log (- (/ x (* y y)) (- (/ 1 y) (/ x y)))))))

  (- 1 (log (- 1 (/ (- x y) (- 1 y))))))