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

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

\end{array}
double f(double x, double y) {
        double r522516 = 1.0;
        double r522517 = x;
        double r522518 = y;
        double r522519 = r522517 - r522518;
        double r522520 = r522516 - r522518;
        double r522521 = r522519 / r522520;
        double r522522 = r522516 - r522521;
        double r522523 = log(r522522);
        double r522524 = r522516 - r522523;
        return r522524;
}

double f(double x, double y) {
        double r522525 = y;
        double r522526 = -339938991.33710843;
        bool r522527 = r522525 <= r522526;
        double r522528 = 19835852.98699539;
        bool r522529 = r522525 <= r522528;
        double r522530 = !r522529;
        bool r522531 = r522527 || r522530;
        double r522532 = 1.0;
        double r522533 = exp(r522532);
        double r522534 = sqrt(r522533);
        double r522535 = x;
        double r522536 = 2.0;
        double r522537 = pow(r522525, r522536);
        double r522538 = r522535 / r522537;
        double r522539 = -r522532;
        double r522540 = exp(r522539);
        double r522541 = sqrt(r522540);
        double r522542 = r522538 * r522541;
        double r522543 = r522535 / r522525;
        double r522544 = r522543 * r522541;
        double r522545 = fma(r522532, r522542, r522544);
        double r522546 = 1.0;
        double r522547 = r522546 / r522525;
        double r522548 = r522541 * r522547;
        double r522549 = r522548 * r522532;
        double r522550 = r522545 - r522549;
        double r522551 = r522534 / r522550;
        double r522552 = log(r522551);
        double r522553 = r522535 - r522525;
        double r522554 = r522532 - r522525;
        double r522555 = r522553 / r522554;
        double r522556 = r522532 - r522555;
        double r522557 = r522556 / r522534;
        double r522558 = r522534 / r522557;
        double r522559 = log(r522558);
        double r522560 = r522531 ? r522552 : r522559;
        return r522560;
}

Error

Bits error versus x

Bits error versus y

Target

Original18.7
Target0.1
Herbie0.1
\[\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 < -339938991.33710843 or 19835852.98699539 < y

    1. Initial program 47.2

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

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

      \[\leadsto \color{blue}{\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt47.2

      \[\leadsto \log \left(\frac{\color{blue}{\sqrt{e^{1}} \cdot \sqrt{e^{1}}}}{1 - \frac{x - y}{1 - y}}\right)\]
    7. Applied associate-/l*47.2

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

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

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

    if -339938991.33710843 < y < 19835852.98699539

    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)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt0.1

      \[\leadsto \log \left(\frac{\color{blue}{\sqrt{e^{1}} \cdot \sqrt{e^{1}}}}{1 - \frac{x - y}{1 - y}}\right)\]
    7. Applied associate-/l*0.1

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

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

Reproduce

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