Average Error: 18.1 → 0.3
Time: 14.2s
Precision: binary64
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 0.0008571594805803388:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \left(\log \left(\frac{x + -1}{y}\right) + \left(\frac{1}{y} - \frac{x}{y \cdot \left(1 - x\right)}\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 (<= (/ (- x y) (- 1.0 y)) 0.0008571594805803388)
   (- 1.0 (log1p (/ (- x y) (+ y -1.0))))
   (- 1.0 (+ (log (/ (+ x -1.0) y)) (- (/ 1.0 y) (/ x (* y (- 1.0 x))))))))
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.0008571594805803388) {
		tmp = 1.0 - log1p(((x - y) / (y + -1.0)));
	} else {
		tmp = 1.0 - (log(((x + -1.0) / y)) + ((1.0 / y) - (x / (y * (1.0 - x)))));
	}
	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 (((x - y) / (1.0 - y)) <= 0.0008571594805803388) {
		tmp = 1.0 - Math.log1p(((x - y) / (y + -1.0)));
	} else {
		tmp = 1.0 - (Math.log(((x + -1.0) / y)) + ((1.0 / y) - (x / (y * (1.0 - x)))));
	}
	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 ((x - y) / (1.0 - y)) <= 0.0008571594805803388:
		tmp = 1.0 - math.log1p(((x - y) / (y + -1.0)))
	else:
		tmp = 1.0 - (math.log(((x + -1.0) / y)) + ((1.0 / y) - (x / (y * (1.0 - x)))))
	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 (Float64(Float64(x - y) / Float64(1.0 - y)) <= 0.0008571594805803388)
		tmp = Float64(1.0 - log1p(Float64(Float64(x - y) / Float64(y + -1.0))));
	else
		tmp = Float64(1.0 - Float64(log(Float64(Float64(x + -1.0) / y)) + Float64(Float64(1.0 / y) - Float64(x / Float64(y * Float64(1.0 - x))))));
	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[N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 0.0008571594805803388], N[(1.0 - N[Log[1 + N[(N[(x - y), $MachinePrecision] / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(N[Log[N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision] + N[(N[(1.0 / y), $MachinePrecision] - N[(x / N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{1 - y} \leq 0.0008571594805803388:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\

\mathbf{else}:\\
\;\;\;\;1 - \left(\log \left(\frac{x + -1}{y}\right) + \left(\frac{1}{y} - \frac{x}{y \cdot \left(1 - x\right)}\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.1
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)) < 8.57159480580338786e-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 8.57159480580338786e-4 < (/.f64 (-.f64 x y) (-.f64 1 y))

    1. Initial program 60.2

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

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

      \[\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.0

      \[\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 log1p-udef_binary6411.0

      \[\leadsto 1 - \left(\left(\color{blue}{\log \left(1 + \left(-x\right)\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) \]
    6. Applied sum-log_binary641.1

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

      \[\leadsto 1 - \left(\log \color{blue}{\left(\frac{x + -1}{y}\right)} + \left(\frac{1}{y \cdot \left(1 - x\right)} - \frac{x}{y \cdot \left(1 - x\right)}\right)\right) \]
    8. Taylor expanded in x around 0 1.2

      \[\leadsto 1 - \left(\log \left(\frac{x + -1}{y}\right) + \left(\color{blue}{\frac{1}{y}} - \frac{x}{y \cdot \left(1 - x\right)}\right)\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.0008571594805803388:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \left(\log \left(\frac{x + -1}{y}\right) + \left(\frac{1}{y} - \frac{x}{y \cdot \left(1 - x\right)}\right)\right)\\ \end{array} \]

Reproduce

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