Average Error: 18.5 → 0.1
Time: 12.8s
Precision: binary64
Cost: 19904
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} t_0 := \frac{e}{1 - x}\\ \log \left(t_0 - t_0 \cdot y\right) \end{array} \]
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ E (- 1.0 x)))) (log (- t_0 (* t_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 t_0 = ((double) M_E) / (1.0 - x);
	return log((t_0 - (t_0 * y)));
}
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 t_0 = Math.E / (1.0 - x);
	return Math.log((t_0 - (t_0 * y)));
}
def code(x, y):
	return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
def code(x, y):
	t_0 = math.e / (1.0 - x)
	return math.log((t_0 - (t_0 * y)))
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)
	t_0 = Float64(exp(1) / Float64(1.0 - x))
	return log(Float64(t_0 - Float64(t_0 * y)))
end
function tmp = code(x, y)
	tmp = 1.0 - log((1.0 - ((x - y) / (1.0 - y))));
end
function tmp = code(x, y)
	t_0 = 2.71828182845904523536 / (1.0 - x);
	tmp = log((t_0 - (t_0 * y)));
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_] := Block[{t$95$0 = N[(E / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, N[Log[N[(t$95$0 - N[(t$95$0 * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
t_0 := \frac{e}{1 - x}\\
\log \left(t_0 - t_0 \cdot y\right)
\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original18.5
Target0.1
Herbie0.1
\[\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. Initial program 18.5

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

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

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

    \[\leadsto \log \color{blue}{\left(\frac{e}{1 - x} - \frac{e}{1 - x} \cdot y\right)} \]
    Proof
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (*.f64 (/.f64 (E.f64) (-.f64 1 x)) y)): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (*.f64 (/.f64 (E.f64) (Rewrite=> sub-neg_binary64 (+.f64 1 (neg.f64 x)))) y)): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (*.f64 (/.f64 (E.f64) (+.f64 1 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 x)))) y)): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (Rewrite<= associate-/r/_binary64 (/.f64 (E.f64) (/.f64 (+.f64 1 (*.f64 -1 x)) y)))): 16 points increase in error, 16 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (E.f64) y) (+.f64 1 (*.f64 -1 x))))): 18 points increase in error, 14 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 y (E.f64))) (+.f64 1 (*.f64 -1 x)))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (Rewrite=> associate-/l*_binary64 (/.f64 y (/.f64 (+.f64 1 (*.f64 -1 x)) (E.f64))))): 14 points increase in error, 12 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (Rewrite<= *-rgt-identity_binary64 (*.f64 (/.f64 (+.f64 1 (*.f64 -1 x)) (E.f64)) 1)))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (*.f64 (/.f64 (+.f64 1 (*.f64 -1 x)) (E.f64)) (Rewrite<= *-inverses_binary64 (/.f64 (+.f64 1 (*.f64 -1 x)) (+.f64 1 (*.f64 -1 x))))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (Rewrite<= times-frac_binary64 (/.f64 (*.f64 (+.f64 1 (*.f64 -1 x)) (+.f64 1 (*.f64 -1 x))) (*.f64 (E.f64) (+.f64 1 (*.f64 -1 x))))))): 13 points increase in error, 32 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 (+.f64 1 (*.f64 -1 x)) 2)) (*.f64 (E.f64) (+.f64 1 (*.f64 -1 x)))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (/.f64 (pow.f64 (+.f64 1 (Rewrite=> mul-1-neg_binary64 (neg.f64 x))) 2) (*.f64 (E.f64) (+.f64 1 (*.f64 -1 x)))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (/.f64 (pow.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 x)) 2) (*.f64 (E.f64) (+.f64 1 (*.f64 -1 x)))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (/.f64 (pow.f64 (-.f64 1 x) 2) (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 1 (*.f64 -1 x)) (E.f64)))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (/.f64 y (/.f64 (pow.f64 (-.f64 1 x) 2) (*.f64 (+.f64 1 (*.f64 -1 x)) (Rewrite=> e-exp-1_binary64 (exp.f64 1)))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 (E.f64) (-.f64 1 x)) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y (*.f64 (+.f64 1 (*.f64 -1 x)) (exp.f64 1))) (pow.f64 (-.f64 1 x) 2)))): 28 points increase in error, 12 points decrease in error
    (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 (E.f64) (-.f64 1 x)) (neg.f64 (/.f64 (*.f64 y (*.f64 (+.f64 1 (*.f64 -1 x)) (exp.f64 1))) (pow.f64 (-.f64 1 x) 2))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 (E.f64) (-.f64 1 x)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 y (*.f64 (+.f64 1 (*.f64 -1 x)) (exp.f64 1))) (pow.f64 (-.f64 1 x) 2))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 y (*.f64 (+.f64 1 (*.f64 -1 x)) (exp.f64 1))) (pow.f64 (-.f64 1 x) 2))) (/.f64 (E.f64) (-.f64 1 x)))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.1

    \[\leadsto \log \left(\frac{e}{1 - x} - \frac{e}{1 - x} \cdot y\right) \]

Alternatives

Alternative 1
Error0.1
Cost7492
\[\begin{array}{l} t_0 := \frac{x + -1}{y}\\ \mathbf{if}\;y \leq -10000000:\\ \;\;\;\;1 - \log \left(t_0 + \frac{x + -1}{y \cdot y}\right)\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log t_0\\ \end{array} \]
Alternative 2
Error0.8
Cost7244
\[\begin{array}{l} t_0 := 1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{if}\;y \leq -2950000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{-5}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y}{1 - y}\right)\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.2
Cost7240
\[\begin{array}{l} t_0 := 1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{if}\;y \leq -1000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.2
Cost7112
\[\begin{array}{l} t_0 := 1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+21}:\\ \;\;\;\;\left(1 - y\right) - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.9
Cost7112
\[\begin{array}{l} t_0 := 1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{if}\;y \leq -6400:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error6.8
Cost7048
\[\begin{array}{l} \mathbf{if}\;y \leq -400:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 0.0029:\\ \;\;\;\;\left(1 - y\right) - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x}{y}\right)\\ \end{array} \]
Alternative 7
Error7.6
Cost6984
\[\begin{array}{l} \mathbf{if}\;y \leq -400:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x}{y}\right)\\ \end{array} \]
Alternative 8
Error12.9
Cost6920
\[\begin{array}{l} \mathbf{if}\;y \leq -400:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(x\right)\\ \end{array} \]
Alternative 9
Error23.5
Cost6788
\[\begin{array}{l} \mathbf{if}\;y \leq 9 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(x\right)\\ \end{array} \]
Alternative 10
Error35.8
Cost448
\[1 - \frac{x}{y + -1} \]
Alternative 11
Error36.7
Cost192
\[1 + x \]
Alternative 12
Error36.9
Cost64
\[1 \]

Error

Reproduce

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