Average Error: 18.4 → 0.4
Time: 5.4s
Precision: binary64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 0.00013641523025847621:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{e^{\frac{\frac{1}{1 - x} - \frac{x}{1 - x}}{y}} \cdot \left(x + -1\right)}{y}\right)\\ \end{array} \]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{1 - y} \leq 0.00013641523025847621:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\

\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{e^{\frac{\frac{1}{1 - x} - \frac{x}{1 - x}}{y}} \cdot \left(x + -1\right)}{y}\right)\\


\end{array}
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
 :precision binary64
 (if (<= (/ (- x y) (- 1.0 y)) 0.00013641523025847621)
   (- 1.0 (log1p (/ (- x y) (+ y -1.0))))
   (-
    1.0
    (log
     (/ (* (exp (/ (- (/ 1.0 (- 1.0 x)) (/ x (- 1.0 x))) y)) (+ x -1.0)) y)))))
double code(double x, double y) {
	return 1.0 - log(1.0 - ((x - y) / (1.0 - y)));
}
double code(double x, double y) {
	double tmp;
	if (((x - y) / (1.0 - y)) <= 0.00013641523025847621) {
		tmp = 1.0 - log1p((x - y) / (y + -1.0));
	} else {
		tmp = 1.0 - log((exp(((1.0 / (1.0 - x)) - (x / (1.0 - x))) / y) * (x + -1.0)) / y);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original18.4
Target0.1
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;y < -81284752.61947241:\\ \;\;\;\;1 - \log \left(\frac{x}{y \cdot y} - \left(\frac{1}{y} - \frac{x}{y}\right)\right)\\ \mathbf{elif}\;y < 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 (/.f64 (-.f64 x y) (-.f64 1 y)) < 1.3641523025847621e-4

    1. Initial program 0.0

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
    2. Simplified0.0

      \[\leadsto \color{blue}{1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)} \]

    if 1.3641523025847621e-4 < (/.f64 (-.f64 x y) (-.f64 1 y))

    1. Initial program 60.3

      \[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
    2. Simplified60.3

      \[\leadsto \color{blue}{1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)} \]
    3. Taylor expanded in y around -inf 11.9

      \[\leadsto 1 - \color{blue}{\left(\left(\frac{1}{\left(1 - x\right) \cdot y} + \left(\log \left(\frac{-1}{y}\right) + \log \left(1 - x\right)\right)\right) - \frac{x}{\left(1 - x\right) \cdot y}\right)} \]
    4. Simplified11.9

      \[\leadsto 1 - \color{blue}{\left(\left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right) + \left(\frac{1}{y \cdot \left(1 - x\right)} - \frac{x}{y \cdot \left(1 - x\right)}\right)\right)} \]
    5. Applied add-log-exp_binary6411.9

      \[\leadsto 1 - \left(\left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right) + \left(\frac{1}{y \cdot \left(1 - x\right)} - \color{blue}{\log \left(e^{\frac{x}{y \cdot \left(1 - x\right)}}\right)}\right)\right) \]
    6. Applied add-log-exp_binary6411.9

      \[\leadsto 1 - \left(\left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right) + \left(\color{blue}{\log \left(e^{\frac{1}{y \cdot \left(1 - x\right)}}\right)} - \log \left(e^{\frac{x}{y \cdot \left(1 - x\right)}}\right)\right)\right) \]
    7. Applied diff-log_binary6411.9

      \[\leadsto 1 - \left(\left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right) + \color{blue}{\log \left(\frac{e^{\frac{1}{y \cdot \left(1 - x\right)}}}{e^{\frac{x}{y \cdot \left(1 - x\right)}}}\right)}\right) \]
    8. Applied log1p-udef_binary6411.9

      \[\leadsto 1 - \left(\left(\color{blue}{\log \left(1 + \left(-x\right)\right)} + \log \left(\frac{-1}{y}\right)\right) + \log \left(\frac{e^{\frac{1}{y \cdot \left(1 - x\right)}}}{e^{\frac{x}{y \cdot \left(1 - x\right)}}}\right)\right) \]
    9. Applied sum-log_binary641.3

      \[\leadsto 1 - \left(\color{blue}{\log \left(\left(1 + \left(-x\right)\right) \cdot \frac{-1}{y}\right)} + \log \left(\frac{e^{\frac{1}{y \cdot \left(1 - x\right)}}}{e^{\frac{x}{y \cdot \left(1 - x\right)}}}\right)\right) \]
    10. Applied sum-log_binary641.3

      \[\leadsto 1 - \color{blue}{\log \left(\left(\left(1 + \left(-x\right)\right) \cdot \frac{-1}{y}\right) \cdot \frac{e^{\frac{1}{y \cdot \left(1 - x\right)}}}{e^{\frac{x}{y \cdot \left(1 - x\right)}}}\right)} \]
    11. Simplified1.3

      \[\leadsto 1 - \log \color{blue}{\left(\frac{-\left(1 - x\right)}{y} \cdot e^{\frac{\frac{1}{1 - x} - \frac{x}{1 - x}}{y}}\right)} \]
    12. Taylor expanded in y around 0 1.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 0.00013641523025847621:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{e^{\frac{\frac{1}{1 - x} - \frac{x}{1 - x}}{y}} \cdot \left(x + -1\right)}{y}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2021313 
(FPCore (x y)
  :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, B"
  :precision binary64

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