Average Error: 17.6 → 0.3
Time: 4.8s
Precision: binary64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 0.1044509381889951:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x + -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} \leq 0.1044509381889951:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\

\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{x + -1}{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.1044509381889951)
   (- 1.0 (log1p (/ (- x y) (+ y -1.0))))
   (- 1.0 (log (/ (+ 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.1044509381889951) {
		tmp = 1.0 - log1p((x - y) / (y + -1.0));
	} else {
		tmp = 1.0 - log((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

Original17.6
Target0.1
Herbie0.3
\[\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)) < 0.104450938188995104

    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 0.104450938188995104 < (/.f64 (-.f64 x y) (-.f64 1 y))

    1. Initial program 61.0

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

      \[\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(\log \left(\frac{-1}{y}\right) + \log \left(1 - x\right)\right)} \]
    4. Simplified11.9

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

      \[\leadsto 1 - \left(\color{blue}{\log \left(1 + \left(-x\right)\right)} + \log \left(\frac{-1}{y}\right)\right) \]
    6. Applied sum-log_binary640.8

      \[\leadsto 1 - \color{blue}{\log \left(\left(1 + \left(-x\right)\right) \cdot \frac{-1}{y}\right)} \]
    7. Simplified0.8

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

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

Reproduce

herbie shell --seed 2022076 
(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))))))