Average Error: 17.9 → 0.2
Time: 13.6s
Precision: 64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \le 0.8815880565365850074499576294329017400742:\\ \;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{e^{1}}\right) + \log \left(\frac{\sqrt{e^{1}}}{\mathsf{fma}\left(\frac{x}{{y}^{2}}, 1, \frac{x}{y}\right) - \frac{1}{y}}\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.8815880565365850074499576294329017400742:\\
\;\;\;\;\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\\

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

\end{array}
double f(double x, double y) {
        double r275208 = 1.0;
        double r275209 = x;
        double r275210 = y;
        double r275211 = r275209 - r275210;
        double r275212 = r275208 - r275210;
        double r275213 = r275211 / r275212;
        double r275214 = r275208 - r275213;
        double r275215 = log(r275214);
        double r275216 = r275208 - r275215;
        return r275216;
}

double f(double x, double y) {
        double r275217 = x;
        double r275218 = y;
        double r275219 = r275217 - r275218;
        double r275220 = 1.0;
        double r275221 = r275220 - r275218;
        double r275222 = r275219 / r275221;
        double r275223 = 0.881588056536585;
        bool r275224 = r275222 <= r275223;
        double r275225 = exp(r275220);
        double r275226 = r275220 - r275222;
        double r275227 = r275225 / r275226;
        double r275228 = log(r275227);
        double r275229 = sqrt(r275225);
        double r275230 = log(r275229);
        double r275231 = 2.0;
        double r275232 = pow(r275218, r275231);
        double r275233 = r275217 / r275232;
        double r275234 = r275217 / r275218;
        double r275235 = fma(r275233, r275220, r275234);
        double r275236 = r275220 / r275218;
        double r275237 = r275235 - r275236;
        double r275238 = r275229 / r275237;
        double r275239 = log(r275238);
        double r275240 = r275230 + r275239;
        double r275241 = r275224 ? r275228 : r275240;
        return r275241;
}

Error

Bits error versus x

Bits error versus y

Target

Original17.9
Target0.1
Herbie0.2
\[\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.881588056536585

    1. Initial program 0.0

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

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

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

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

    1. Initial program 61.6

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

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

      \[\leadsto \color{blue}{\log \left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity61.6

      \[\leadsto \log \left(\frac{e^{1}}{\color{blue}{1 \cdot \left(1 - \frac{x - y}{1 - y}\right)}}\right)\]
    7. Applied add-sqr-sqrt61.6

      \[\leadsto \log \left(\frac{\color{blue}{\sqrt{e^{1}} \cdot \sqrt{e^{1}}}}{1 \cdot \left(1 - \frac{x - y}{1 - y}\right)}\right)\]
    8. Applied times-frac61.6

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

      \[\leadsto \color{blue}{\log \left(\frac{\sqrt{e^{1}}}{1}\right) + \log \left(\frac{\sqrt{e^{1}}}{1 - \frac{x - y}{1 - y}}\right)}\]
    10. Simplified61.6

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

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

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

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

Reproduce

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