Average Error: 18.4 → 0.1
Time: 6.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 r321124 = 1.0;
        double r321125 = x;
        double r321126 = y;
        double r321127 = r321125 - r321126;
        double r321128 = r321124 - r321126;
        double r321129 = r321127 / r321128;
        double r321130 = r321124 - r321129;
        double r321131 = log(r321130);
        double r321132 = r321124 - r321131;
        return r321132;
}

double f(double x, double y) {
        double r321133 = y;
        double r321134 = -270508391.61573327;
        bool r321135 = r321133 <= r321134;
        double r321136 = 148253897.0245374;
        bool r321137 = r321133 <= r321136;
        double r321138 = !r321137;
        bool r321139 = r321135 || r321138;
        double r321140 = 1.0;
        double r321141 = exp(r321140);
        double r321142 = x;
        double r321143 = 2.0;
        double r321144 = pow(r321133, r321143);
        double r321145 = r321142 / r321144;
        double r321146 = 1.0;
        double r321147 = r321146 / r321133;
        double r321148 = r321145 - r321147;
        double r321149 = r321142 / r321133;
        double r321150 = fma(r321140, r321148, r321149);
        double r321151 = r321141 / r321150;
        double r321152 = log(r321151);
        double r321153 = r321142 - r321133;
        double r321154 = r321140 - r321133;
        double r321155 = r321153 / r321154;
        double r321156 = r321140 - r321155;
        double r321157 = r321141 / r321156;
        double r321158 = log(r321157);
        double r321159 = r321139 ? r321152 : r321158;
        return r321159;
}

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