Average Error: 18.3 → 1.2
Time: 17.4s
Precision: 64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
\[\begin{array}{l} \mathbf{if}\;y \le -9.186493886184318 \cdot 10^{36} \lor \neg \left(y \le 49288711.7499881461\right):\\ \;\;\;\;1 - \log \left(\mathsf{fma}\left(\frac{x}{{y}^{2}}, 1, \frac{x}{y}\right) - \frac{1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\mathsf{fma}\left(\mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right), -\frac{x - y}{{1}^{3} - {y}^{3}}, {\left(\sqrt[3]{1}\right)}^{3}\right) + \frac{x - y}{{1}^{3} - {y}^{3}} \cdot \left(\left(-\mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right)\right) + \mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right)\right)\right)\\ \end{array}\]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;y \le -9.186493886184318 \cdot 10^{36} \lor \neg \left(y \le 49288711.7499881461\right):\\
\;\;\;\;1 - \log \left(\mathsf{fma}\left(\frac{x}{{y}^{2}}, 1, \frac{x}{y}\right) - \frac{1}{y}\right)\\

\mathbf{else}:\\
\;\;\;\;1 - \log \left(\mathsf{fma}\left(\mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right), -\frac{x - y}{{1}^{3} - {y}^{3}}, {\left(\sqrt[3]{1}\right)}^{3}\right) + \frac{x - y}{{1}^{3} - {y}^{3}} \cdot \left(\left(-\mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right)\right) + \mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right)\right)\right)\\

\end{array}
double f(double x, double y) {
        double r314858 = 1.0;
        double r314859 = x;
        double r314860 = y;
        double r314861 = r314859 - r314860;
        double r314862 = r314858 - r314860;
        double r314863 = r314861 / r314862;
        double r314864 = r314858 - r314863;
        double r314865 = log(r314864);
        double r314866 = r314858 - r314865;
        return r314866;
}

double f(double x, double y) {
        double r314867 = y;
        double r314868 = -9.186493886184318e+36;
        bool r314869 = r314867 <= r314868;
        double r314870 = 49288711.749988146;
        bool r314871 = r314867 <= r314870;
        double r314872 = !r314871;
        bool r314873 = r314869 || r314872;
        double r314874 = 1.0;
        double r314875 = x;
        double r314876 = 2.0;
        double r314877 = pow(r314867, r314876);
        double r314878 = r314875 / r314877;
        double r314879 = r314875 / r314867;
        double r314880 = fma(r314878, r314874, r314879);
        double r314881 = r314874 / r314867;
        double r314882 = r314880 - r314881;
        double r314883 = log(r314882);
        double r314884 = r314874 - r314883;
        double r314885 = r314874 + r314867;
        double r314886 = r314867 * r314885;
        double r314887 = fma(r314874, r314874, r314886);
        double r314888 = r314875 - r314867;
        double r314889 = 3.0;
        double r314890 = pow(r314874, r314889);
        double r314891 = pow(r314867, r314889);
        double r314892 = r314890 - r314891;
        double r314893 = r314888 / r314892;
        double r314894 = -r314893;
        double r314895 = cbrt(r314874);
        double r314896 = pow(r314895, r314889);
        double r314897 = fma(r314887, r314894, r314896);
        double r314898 = -r314887;
        double r314899 = r314898 + r314887;
        double r314900 = r314893 * r314899;
        double r314901 = r314897 + r314900;
        double r314902 = log(r314901);
        double r314903 = r314874 - r314902;
        double r314904 = r314873 ? r314884 : r314903;
        return r314904;
}

Error

Bits error versus x

Bits error versus y

Target

Original18.3
Target0.1
Herbie1.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 y < -9.186493886184318e+36 or 49288711.749988146 < y

    1. Initial program 48.0

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right)\]
    2. Taylor expanded around inf 0.0

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

      \[\leadsto 1 - \log \color{blue}{\left(\mathsf{fma}\left(\frac{x}{{y}^{2}}, 1, \frac{x}{y}\right) - \frac{1}{y}\right)}\]

    if -9.186493886184318e+36 < y < 49288711.749988146

    1. Initial program 2.0

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

      \[\leadsto 1 - \log \left(1 - \frac{x - y}{\color{blue}{\frac{{1}^{3} - {y}^{3}}{1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)}}}\right)\]
    4. Applied associate-/r/1.9

      \[\leadsto 1 - \log \left(1 - \color{blue}{\frac{x - y}{{1}^{3} - {y}^{3}} \cdot \left(1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)\right)}\right)\]
    5. Applied add-cube-cbrt1.9

      \[\leadsto 1 - \log \left(\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}} - \frac{x - y}{{1}^{3} - {y}^{3}} \cdot \left(1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)\right)\right)\]
    6. Applied prod-diff1.8

      \[\leadsto 1 - \log \color{blue}{\left(\mathsf{fma}\left(\sqrt[3]{1} \cdot \sqrt[3]{1}, \sqrt[3]{1}, -\left(1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)\right) \cdot \frac{x - y}{{1}^{3} - {y}^{3}}\right) + \mathsf{fma}\left(-\left(1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)\right), \frac{x - y}{{1}^{3} - {y}^{3}}, \left(1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)\right) \cdot \frac{x - y}{{1}^{3} - {y}^{3}}\right)\right)}\]
    7. Simplified1.8

      \[\leadsto 1 - \log \left(\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right), -\frac{x - y}{{1}^{3} - {y}^{3}}, {\left(\sqrt[3]{1}\right)}^{3}\right)} + \mathsf{fma}\left(-\left(1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)\right), \frac{x - y}{{1}^{3} - {y}^{3}}, \left(1 \cdot 1 + \left(y \cdot y + 1 \cdot y\right)\right) \cdot \frac{x - y}{{1}^{3} - {y}^{3}}\right)\right)\]
    8. Simplified1.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -9.186493886184318 \cdot 10^{36} \lor \neg \left(y \le 49288711.7499881461\right):\\ \;\;\;\;1 - \log \left(\mathsf{fma}\left(\frac{x}{{y}^{2}}, 1, \frac{x}{y}\right) - \frac{1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\mathsf{fma}\left(\mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right), -\frac{x - y}{{1}^{3} - {y}^{3}}, {\left(\sqrt[3]{1}\right)}^{3}\right) + \frac{x - y}{{1}^{3} - {y}^{3}} \cdot \left(\left(-\mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right)\right) + \mathsf{fma}\left(1, 1, y \cdot \left(1 + y\right)\right)\right)\right)\\ \end{array}\]

Reproduce

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