Average Error: 18.3 → 0.2
Time: 9.8s
Precision: 64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;y \le -189652252.65805757 \lor \neg \left(y \le 6752698.7732027788\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 -189652252.65805757 \lor \neg \left(y \le 6752698.7732027788\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 r464600 = 1.0;
        double r464601 = x;
        double r464602 = y;
        double r464603 = r464601 - r464602;
        double r464604 = r464600 - r464602;
        double r464605 = r464603 / r464604;
        double r464606 = r464600 - r464605;
        double r464607 = log(r464606);
        double r464608 = r464600 - r464607;
        return r464608;
}

double f(double x, double y) {
        double r464609 = y;
        double r464610 = -189652252.65805757;
        bool r464611 = r464609 <= r464610;
        double r464612 = 6752698.773202779;
        bool r464613 = r464609 <= r464612;
        double r464614 = !r464613;
        bool r464615 = r464611 || r464614;
        double r464616 = 1.0;
        double r464617 = exp(r464616);
        double r464618 = x;
        double r464619 = 2.0;
        double r464620 = pow(r464609, r464619);
        double r464621 = r464618 / r464620;
        double r464622 = 1.0;
        double r464623 = r464622 / r464609;
        double r464624 = r464621 - r464623;
        double r464625 = r464618 / r464609;
        double r464626 = fma(r464616, r464624, r464625);
        double r464627 = r464617 / r464626;
        double r464628 = log(r464627);
        double r464629 = r464618 - r464609;
        double r464630 = r464616 - r464609;
        double r464631 = r464629 / r464630;
        double r464632 = r464616 - r464631;
        double r464633 = r464617 / r464632;
        double r464634 = log(r464633);
        double r464635 = r464615 ? r464628 : r464634;
        return r464635;
}

Error

Bits error versus x

Bits error versus y

Target

Original18.3
Target0.1
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;y \lt -81284752.619472414:\\ \;\;\;\;1 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1}{y} - \frac{x}{y}\right)\right)\\ \mathbf{elif}\;y \lt 3.0094271212461764 \cdot 10^{25}:\\ \;\;\;\;\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 < -189652252.65805757 or 6752698.773202779 < y

    1. Initial program 47.3

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

      \[\leadsto \color{blue}{\log \left(e^{1}\right)} - \log \left(1 - \frac{x - y}{1 - y}\right)\]
    4. Applied diff-log47.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 -189652252.65805757 < y < 6752698.773202779

    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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -189652252.65805757 \lor \neg \left(y \le 6752698.7732027788\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 2020083 +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))))))