Average Error: 18.3 → 0.2
Time: 9.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.99999880692138432:\\ \;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}} - \frac{1}{y}, \frac{x}{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.99999880692138432:\\
\;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\right)\right)\\

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

\end{array}
double f(double x, double y) {
        double r397577 = 1.0;
        double r397578 = x;
        double r397579 = y;
        double r397580 = r397578 - r397579;
        double r397581 = r397577 - r397579;
        double r397582 = r397580 / r397581;
        double r397583 = r397577 - r397582;
        double r397584 = log(r397583);
        double r397585 = r397577 - r397584;
        return r397585;
}

double f(double x, double y) {
        double r397586 = x;
        double r397587 = y;
        double r397588 = r397586 - r397587;
        double r397589 = 1.0;
        double r397590 = r397589 - r397587;
        double r397591 = r397588 / r397590;
        double r397592 = 0.9999988069213843;
        bool r397593 = r397591 <= r397592;
        double r397594 = exp(r397589);
        double r397595 = r397589 - r397591;
        double r397596 = r397594 / r397595;
        double r397597 = log1p(r397596);
        double r397598 = expm1(r397597);
        double r397599 = log(r397598);
        double r397600 = 2.0;
        double r397601 = pow(r397587, r397600);
        double r397602 = r397586 / r397601;
        double r397603 = 1.0;
        double r397604 = r397603 / r397587;
        double r397605 = r397602 - r397604;
        double r397606 = r397586 / r397587;
        double r397607 = fma(r397589, r397605, r397606);
        double r397608 = r397594 / r397607;
        double r397609 = log(r397608);
        double r397610 = r397593 ? r397599 : r397609;
        return r397610;
}

Error

Bits error versus x

Bits error versus y

Target

Original18.3
Target0.1
Herbie0.2
\[\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 (/ (- x y) (- 1.0 y)) < 0.9999988069213843

    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)}\]
    5. Using strategy rm
    6. Applied expm1-log1p-u0.1

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

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

    1. Initial program 62.5

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

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

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

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

      \[\leadsto \log \left(\frac{e^{1}}{\color{blue}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}} - \frac{1}{y}, \frac{x}{y}\right)}}\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.99999880692138432:\\ \;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{e^{1}}{1 - \frac{x - y}{1 - y}}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1}}{\mathsf{fma}\left(1, \frac{x}{{y}^{2}} - \frac{1}{y}, \frac{x}{y}\right)}\right)\\ \end{array}\]

Reproduce

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