Average Error: 17.5 → 0.3
Time: 16.4s
Precision: 64
\[1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1.0 - y} \le 0.5242927222148749:\\ \;\;\;\;\log \left(\frac{e^{1.0}}{1.0 - \frac{x - y}{1.0 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1.0}}{\mathsf{fma}\left(1.0, \frac{x}{y \cdot y}, \frac{x}{y}\right) - \frac{1.0}{y}}\right)\\ \end{array}\]
1.0 - \log \left(1.0 - \frac{x - y}{1.0 - y}\right)
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{1.0 - y} \le 0.5242927222148749:\\
\;\;\;\;\log \left(\frac{e^{1.0}}{1.0 - \frac{x - y}{1.0 - y}}\right)\\

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

\end{array}
double f(double x, double y) {
        double r6020741 = 1.0;
        double r6020742 = x;
        double r6020743 = y;
        double r6020744 = r6020742 - r6020743;
        double r6020745 = r6020741 - r6020743;
        double r6020746 = r6020744 / r6020745;
        double r6020747 = r6020741 - r6020746;
        double r6020748 = log(r6020747);
        double r6020749 = r6020741 - r6020748;
        return r6020749;
}

double f(double x, double y) {
        double r6020750 = x;
        double r6020751 = y;
        double r6020752 = r6020750 - r6020751;
        double r6020753 = 1.0;
        double r6020754 = r6020753 - r6020751;
        double r6020755 = r6020752 / r6020754;
        double r6020756 = 0.5242927222148749;
        bool r6020757 = r6020755 <= r6020756;
        double r6020758 = exp(r6020753);
        double r6020759 = r6020753 - r6020755;
        double r6020760 = r6020758 / r6020759;
        double r6020761 = log(r6020760);
        double r6020762 = r6020751 * r6020751;
        double r6020763 = r6020750 / r6020762;
        double r6020764 = r6020750 / r6020751;
        double r6020765 = fma(r6020753, r6020763, r6020764);
        double r6020766 = r6020753 / r6020751;
        double r6020767 = r6020765 - r6020766;
        double r6020768 = r6020758 / r6020767;
        double r6020769 = log(r6020768);
        double r6020770 = r6020757 ? r6020761 : r6020769;
        return r6020770;
}

Error

Bits error versus x

Bits error versus y

Target

Original17.5
Target0.1
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;y \lt -81284752.61947241:\\ \;\;\;\;1.0 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1.0}{y} - \frac{x}{y}\right)\right)\\ \mathbf{elif}\;y \lt 3.0094271212461764 \cdot 10^{+25}:\\ \;\;\;\;\log \left(\frac{e^{1.0}}{1.0 - \frac{x - y}{1.0 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;1.0 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1.0}{y} - \frac{x}{y}\right)\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (- x y) (- 1.0 y)) < 0.5242927222148749

    1. Initial program 0.0

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

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

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

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

    1. Initial program 59.0

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{1.0 - y} \le 0.5242927222148749:\\ \;\;\;\;\log \left(\frac{e^{1.0}}{1.0 - \frac{x - y}{1.0 - y}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{1.0}}{\mathsf{fma}\left(1.0, \frac{x}{y \cdot y}, \frac{x}{y}\right) - \frac{1.0}{y}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 +o rules:numerics
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"

  :herbie-target
  (if (< y -81284752.61947241) (- 1.0 (log (- (/ x (* y y)) (- (/ 1.0 y) (/ x y))))) (if (< y 3.0094271212461764e+25) (log (/ (exp 1.0) (- 1.0 (/ (- x y) (- 1.0 y))))) (- 1.0 (log (- (/ x (* y y)) (- (/ 1.0 y) (/ x y)))))))

  (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))