Average Error: 18.4 → 0.2
Time: 17.6s
Precision: binary64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} \mathbf{if}\;y \leq -589143.7095034524:\\ \;\;\;\;1 + \left(\left(\frac{\frac{x}{1 - x}}{y} + \frac{-1}{y \cdot \left(1 - x\right)}\right) - \left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right)\right)\\ \mathbf{elif}\;y \leq 4.2096123486017616 \cdot 10^{+43}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\left(y - x\right) \cdot \frac{-1}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\log y - \log \left(x + -1\right)\right)\\ \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
 :precision binary64
 (if (<= y -589143.7095034524)
   (+
    1.0
    (-
     (+ (/ (/ x (- 1.0 x)) y) (/ -1.0 (* y (- 1.0 x))))
     (+ (log1p (- x)) (log (/ -1.0 y)))))
   (if (<= y 4.2096123486017616e+43)
     (- 1.0 (log1p (* (- y x) (/ -1.0 (+ y -1.0)))))
     (+ 1.0 (- (log y) (log (+ x -1.0)))))))
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 (y <= -589143.7095034524) {
		tmp = 1.0 + ((((x / (1.0 - x)) / y) + (-1.0 / (y * (1.0 - x)))) - (log1p(-x) + log((-1.0 / y))));
	} else if (y <= 4.2096123486017616e+43) {
		tmp = 1.0 - log1p(((y - x) * (-1.0 / (y + -1.0))));
	} else {
		tmp = 1.0 + (log(y) - log((x + -1.0)));
	}
	return tmp;
}
public static double code(double x, double y) {
	return 1.0 - Math.log((1.0 - ((x - y) / (1.0 - y))));
}
public static double code(double x, double y) {
	double tmp;
	if (y <= -589143.7095034524) {
		tmp = 1.0 + ((((x / (1.0 - x)) / y) + (-1.0 / (y * (1.0 - x)))) - (Math.log1p(-x) + Math.log((-1.0 / y))));
	} else if (y <= 4.2096123486017616e+43) {
		tmp = 1.0 - Math.log1p(((y - x) * (-1.0 / (y + -1.0))));
	} else {
		tmp = 1.0 + (Math.log(y) - Math.log((x + -1.0)));
	}
	return tmp;
}
def code(x, y):
	return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
def code(x, y):
	tmp = 0
	if y <= -589143.7095034524:
		tmp = 1.0 + ((((x / (1.0 - x)) / y) + (-1.0 / (y * (1.0 - x)))) - (math.log1p(-x) + math.log((-1.0 / y))))
	elif y <= 4.2096123486017616e+43:
		tmp = 1.0 - math.log1p(((y - x) * (-1.0 / (y + -1.0))))
	else:
		tmp = 1.0 + (math.log(y) - math.log((x + -1.0)))
	return tmp
function code(x, y)
	return Float64(1.0 - log(Float64(1.0 - Float64(Float64(x - y) / Float64(1.0 - y)))))
end
function code(x, y)
	tmp = 0.0
	if (y <= -589143.7095034524)
		tmp = Float64(1.0 + Float64(Float64(Float64(Float64(x / Float64(1.0 - x)) / y) + Float64(-1.0 / Float64(y * Float64(1.0 - x)))) - Float64(log1p(Float64(-x)) + log(Float64(-1.0 / y)))));
	elseif (y <= 4.2096123486017616e+43)
		tmp = Float64(1.0 - log1p(Float64(Float64(y - x) * Float64(-1.0 / Float64(y + -1.0)))));
	else
		tmp = Float64(1.0 + Float64(log(y) - log(Float64(x + -1.0))));
	end
	return tmp
end
code[x_, y_] := N[(1.0 - N[Log[N[(1.0 - N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[y, -589143.7095034524], N[(1.0 + N[(N[(N[(N[(x / N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + N[(-1.0 / N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Log[1 + (-x)], $MachinePrecision] + N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.2096123486017616e+43], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] * N[(-1.0 / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[Log[y], $MachinePrecision] - N[Log[N[(x + -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;y \leq -589143.7095034524:\\
\;\;\;\;1 + \left(\left(\frac{\frac{x}{1 - x}}{y} + \frac{-1}{y \cdot \left(1 - x\right)}\right) - \left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right)\right)\\

\mathbf{elif}\;y \leq 4.2096123486017616 \cdot 10^{+43}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\left(y - x\right) \cdot \frac{-1}{y + -1}\right)\\

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


\end{array}

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.2
\[\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 3 regimes
  2. if y < -589143.70950345241

    1. Initial program 51.5

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

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

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

      \[\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{\frac{x}{1 - x}}{y}\right)\right)} \]

    if -589143.70950345241 < y < 4.2096123486017616e43

    1. Initial program 0.1

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

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

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

    if 4.2096123486017616e43 < y

    1. Initial program 37.1

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

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

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

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

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

Reproduce

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