Average Error: 18.4 → 0.1
Time: 15.1s
Precision: 64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \le 0.999963631452672641053425195423187687993:\\ \;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1}}{\frac{1 \cdot x}{y \cdot y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)\\ \end{array}\]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{1 - y} \le 0.999963631452672641053425195423187687993:\\
\;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\

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

\end{array}
double f(double x, double y) {
        double r318674 = 1.0;
        double r318675 = x;
        double r318676 = y;
        double r318677 = r318675 - r318676;
        double r318678 = r318674 - r318676;
        double r318679 = r318677 / r318678;
        double r318680 = r318674 - r318679;
        double r318681 = log(r318680);
        double r318682 = r318674 - r318681;
        return r318682;
}

double f(double x, double y) {
        double r318683 = x;
        double r318684 = y;
        double r318685 = r318683 - r318684;
        double r318686 = 1.0;
        double r318687 = r318686 - r318684;
        double r318688 = r318685 / r318687;
        double r318689 = 0.9999636314526726;
        bool r318690 = r318688 <= r318689;
        double r318691 = exp(r318686);
        double r318692 = r318686 - r318688;
        double r318693 = r318691 / r318692;
        double r318694 = log(r318693);
        double r318695 = r318686 * r318683;
        double r318696 = r318684 * r318684;
        double r318697 = r318695 / r318696;
        double r318698 = r318683 / r318684;
        double r318699 = r318686 / r318684;
        double r318700 = r318698 - r318699;
        double r318701 = r318697 + r318700;
        double r318702 = r318691 / r318701;
        double r318703 = log(r318702);
        double r318704 = r318690 ? r318694 : r318703;
        return r318704;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original18.4
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 (/ (- x y) (- 1.0 y)) < 0.9999636314526726

    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)}\]

    if 0.9999636314526726 < (/ (- x y) (- 1.0 y))

    1. Initial program 62.4

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

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

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

      \[\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.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \le 0.999963631452672641053425195423187687993:\\ \;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1}}{\frac{1 \cdot x}{y \cdot y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019179 
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"

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

  (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))