Average Error: 18.4 → 0.1
Time: 7.8s
Precision: 64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;y \le -270508391.61573327 \lor \neg \left(y \le 148253897.024537414\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 -270508391.61573327 \lor \neg \left(y \le 148253897.024537414\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 r318048 = 1.0;
        double r318049 = x;
        double r318050 = y;
        double r318051 = r318049 - r318050;
        double r318052 = r318048 - r318050;
        double r318053 = r318051 / r318052;
        double r318054 = r318048 - r318053;
        double r318055 = log(r318054);
        double r318056 = r318048 - r318055;
        return r318056;
}

double f(double x, double y) {
        double r318057 = y;
        double r318058 = -270508391.61573327;
        bool r318059 = r318057 <= r318058;
        double r318060 = 148253897.0245374;
        bool r318061 = r318057 <= r318060;
        double r318062 = !r318061;
        bool r318063 = r318059 || r318062;
        double r318064 = 1.0;
        double r318065 = exp(r318064);
        double r318066 = x;
        double r318067 = 2.0;
        double r318068 = pow(r318057, r318067);
        double r318069 = r318066 / r318068;
        double r318070 = 1.0;
        double r318071 = r318070 / r318057;
        double r318072 = r318069 - r318071;
        double r318073 = r318066 / r318057;
        double r318074 = fma(r318064, r318072, r318073);
        double r318075 = r318065 / r318074;
        double r318076 = log(r318075);
        double r318077 = r318066 - r318057;
        double r318078 = r318064 - r318057;
        double r318079 = r318077 / r318078;
        double r318080 = r318064 - r318079;
        double r318081 = r318065 / r318080;
        double r318082 = log(r318081);
        double r318083 = r318063 ? r318076 : r318082;
        return r318083;
}

Error

Bits error versus x

Bits error versus y

Target

Original18.4
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 < -270508391.61573327 or 148253897.0245374 < 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 -270508391.61573327 < y < 148253897.0245374

    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 -270508391.61573327 \lor \neg \left(y \le 148253897.024537414\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 2020036 +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))))))