Average Error: 18.1 → 0.1
Time: 20.1s
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 r238040 = 1.0;
        double r238041 = x;
        double r238042 = y;
        double r238043 = r238041 - r238042;
        double r238044 = r238040 - r238042;
        double r238045 = r238043 / r238044;
        double r238046 = r238040 - r238045;
        double r238047 = log(r238046);
        double r238048 = r238040 - r238047;
        return r238048;
}

double f(double x, double y) {
        double r238049 = y;
        double r238050 = -212491914.19131115;
        bool r238051 = r238049 <= r238050;
        double r238052 = 758763659.7499286;
        bool r238053 = r238049 <= r238052;
        double r238054 = !r238053;
        bool r238055 = r238051 || r238054;
        double r238056 = 1.0;
        double r238057 = exp(r238056);
        double r238058 = x;
        double r238059 = 2.0;
        double r238060 = pow(r238049, r238059);
        double r238061 = r238058 / r238060;
        double r238062 = r238058 / r238049;
        double r238063 = fma(r238056, r238061, r238062);
        double r238064 = r238056 / r238049;
        double r238065 = r238063 - r238064;
        double r238066 = r238057 / r238065;
        double r238067 = log(r238066);
        double r238068 = r238058 - r238049;
        double r238069 = r238056 - r238049;
        double r238070 = r238068 / r238069;
        double r238071 = r238056 - r238070;
        double r238072 = r238057 / r238071;
        double r238073 = log(r238072);
        double r238074 = r238055 ? r238067 : r238073;
        return r238074;
}

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))))))