Average Error: 17.9 → 0.1
Time: 6.3s
Precision: 64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;y \le -201288582.2730185985565185546875 \lor \neg \left(y \le 116648832255.3203277587890625\right):\\ \;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}} - \frac{1}{y}, \frac{x}{y}\right)}\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 -201288582.2730185985565185546875 \lor \neg \left(y \le 116648832255.3203277587890625\right):\\
\;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}} - \frac{1}{y}, \frac{x}{y}\right)}\right)\\

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

\end{array}
double f(double x, double y) {
        double r465537 = 1.0;
        double r465538 = x;
        double r465539 = y;
        double r465540 = r465538 - r465539;
        double r465541 = r465537 - r465539;
        double r465542 = r465540 / r465541;
        double r465543 = r465537 - r465542;
        double r465544 = log(r465543);
        double r465545 = r465537 - r465544;
        return r465545;
}

double f(double x, double y) {
        double r465546 = y;
        double r465547 = -201288582.2730186;
        bool r465548 = r465546 <= r465547;
        double r465549 = 116648832255.32033;
        bool r465550 = r465546 <= r465549;
        double r465551 = !r465550;
        bool r465552 = r465548 || r465551;
        double r465553 = 1.0;
        double r465554 = exp(r465553);
        double r465555 = x;
        double r465556 = 2.0;
        double r465557 = pow(r465546, r465556);
        double r465558 = r465555 / r465557;
        double r465559 = 1.0;
        double r465560 = r465559 / r465546;
        double r465561 = r465558 - r465560;
        double r465562 = r465555 / r465546;
        double r465563 = fma(r465553, r465561, r465562);
        double r465564 = r465554 / r465563;
        double r465565 = log(r465564);
        double r465566 = r465555 - r465546;
        double r465567 = r465553 - r465546;
        double r465568 = r465566 / r465567;
        double r465569 = r465553 - r465568;
        double r465570 = r465554 / r465569;
        double r465571 = log(r465570);
        double r465572 = r465552 ? r465565 : r465571;
        return r465572;
}

Error

Bits error versus x

Bits error versus y

Target

Original17.9
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 < -201288582.2730186 or 116648832255.32033 < y

    1. Initial program 46.3

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

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

      \[\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{1}{y}, \frac{x}{y}\right)}}\right)\]

    if -201288582.2730186 < y < 116648832255.32033

    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 -201288582.2730185985565185546875 \lor \neg \left(y \le 116648832255.3203277587890625\right):\\ \;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}} - \frac{1}{y}, \frac{x}{y}\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\ \end{array}\]

Reproduce

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