Average Error: 18.0 → 0.3
Time: 12.5s
Precision: binary64
Cost: 13320
\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} \mathbf{if}\;y \leq -10000000000:\\ \;\;\;\;\log \left(\frac{y \cdot e}{x + -1}\right)\\ \mathbf{elif}\;y \leq 1.98:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{y \cdot e}{x}\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 -10000000000.0)
   (log (/ (* y E) (+ x -1.0)))
   (if (<= y 1.98)
     (- 1.0 (log1p (/ (- x y) (+ y -1.0))))
     (log (/ (* y E) 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 (y <= -10000000000.0) {
		tmp = log(((y * ((double) M_E)) / (x + -1.0)));
	} else if (y <= 1.98) {
		tmp = 1.0 - log1p(((x - y) / (y + -1.0)));
	} else {
		tmp = log(((y * ((double) M_E)) / 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 (y <= -10000000000.0) {
		tmp = Math.log(((y * Math.E) / (x + -1.0)));
	} else if (y <= 1.98) {
		tmp = 1.0 - Math.log1p(((x - y) / (y + -1.0)));
	} else {
		tmp = Math.log(((y * Math.E) / 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 y <= -10000000000.0:
		tmp = math.log(((y * math.e) / (x + -1.0)))
	elif y <= 1.98:
		tmp = 1.0 - math.log1p(((x - y) / (y + -1.0)))
	else:
		tmp = math.log(((y * math.e) / 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 (y <= -10000000000.0)
		tmp = log(Float64(Float64(y * exp(1)) / Float64(x + -1.0)));
	elseif (y <= 1.98)
		tmp = Float64(1.0 - log1p(Float64(Float64(x - y) / Float64(y + -1.0))));
	else
		tmp = log(Float64(Float64(y * exp(1)) / 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[y, -10000000000.0], N[Log[N[(N[(y * E), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[y, 1.98], N[(1.0 - N[Log[1 + N[(N[(x - y), $MachinePrecision] / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Log[N[(N[(y * E), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;y \leq -10000000000:\\
\;\;\;\;\log \left(\frac{y \cdot e}{x + -1}\right)\\

\mathbf{elif}\;y \leq 1.98:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original18.0
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 3 regimes
  2. if y < -1e10

    1. Initial program 51.8

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

      \[\leadsto \color{blue}{1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)} \]
      Proof
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (+.f64 y -1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> +-commutative_binary64 (+.f64 -1 y))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (+.f64 (Rewrite<= metadata-eval (-.f64 0 1)) y)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> sub0-neg_binary64 (neg.f64 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 y) -1))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 (-.f64 x y) (-.f64 1 y)) -1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y)))) -1))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/l*_binary64 (/.f64 1 (/.f64 -1 (/.f64 (-.f64 x y) (-.f64 1 y))))))): 7 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 1 -1) (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 7 points decrease in error
      (-.f64 1 (log1p.f64 (*.f64 (Rewrite=> metadata-eval -1) (/.f64 (-.f64 x y) (-.f64 1 y))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (/.f64 (-.f64 x y) (-.f64 1 y))))))): 2 points increase in error, 0 points decrease in error
      (-.f64 1 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr51.8

      \[\leadsto \color{blue}{\log \left(\frac{e}{\frac{x - y}{y + -1} + 1}\right)} \]
    4. Taylor expanded in y around inf 0.1

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

    if -1e10 < y < 1.98

    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)} \]
      Proof
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (+.f64 y -1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> +-commutative_binary64 (+.f64 -1 y))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (+.f64 (Rewrite<= metadata-eval (-.f64 0 1)) y)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> sub0-neg_binary64 (neg.f64 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 y) -1))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 (-.f64 x y) (-.f64 1 y)) -1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y)))) -1))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/l*_binary64 (/.f64 1 (/.f64 -1 (/.f64 (-.f64 x y) (-.f64 1 y))))))): 7 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 1 -1) (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 7 points decrease in error
      (-.f64 1 (log1p.f64 (*.f64 (Rewrite=> metadata-eval -1) (/.f64 (-.f64 x y) (-.f64 1 y))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (/.f64 (-.f64 x y) (-.f64 1 y))))))): 2 points increase in error, 0 points decrease in error
      (-.f64 1 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error

    if 1.98 < y

    1. Initial program 30.3

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

      \[\leadsto \color{blue}{1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)} \]
      Proof
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (+.f64 y -1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> +-commutative_binary64 (+.f64 -1 y))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (+.f64 (Rewrite<= metadata-eval (-.f64 0 1)) y)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> sub0-neg_binary64 (neg.f64 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (-.f64 x y) (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 y) -1))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 (-.f64 x y) (-.f64 1 y)) -1)))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y)))) -1))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/l*_binary64 (/.f64 1 (/.f64 -1 (/.f64 (-.f64 x y) (-.f64 1 y))))))): 7 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 1 -1) (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 7 points decrease in error
      (-.f64 1 (log1p.f64 (*.f64 (Rewrite=> metadata-eval -1) (/.f64 (-.f64 x y) (-.f64 1 y))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (log1p.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
      (-.f64 1 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (neg.f64 (/.f64 (-.f64 x y) (-.f64 1 y))))))): 2 points increase in error, 0 points decrease in error
      (-.f64 1 (log.f64 (Rewrite<= sub-neg_binary64 (-.f64 1 (/.f64 (-.f64 x y) (-.f64 1 y)))))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr30.3

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

      \[\leadsto \log \color{blue}{\left(\frac{e \cdot y}{x - 1}\right)} \]
    5. Taylor expanded in x around -inf 2.0

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

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

Alternatives

Alternative 1
Error0.3
Cost13320
\[\begin{array}{l} \mathbf{if}\;y \leq -10000000000:\\ \;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{elif}\;y \leq 1.98:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{y \cdot e}{x}\right)\\ \end{array} \]
Alternative 2
Error0.1
Cost7492
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 0.99995:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x - y}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\ \end{array} \]
Alternative 3
Error1.1
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 7.2 \cdot 10^{-10}:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error9.8
Cost7048
\[\begin{array}{l} \mathbf{if}\;y \leq -80:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-10}:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y}\right)\\ \end{array} \]
Alternative 5
Error10.2
Cost6984
\[\begin{array}{l} \mathbf{if}\;y \leq -80:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-19}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y}\right)\\ \end{array} \]
Alternative 6
Error25.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;y \leq -10500:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \frac{\frac{x}{y + -1}}{1 - \frac{y}{y + -1}}\right) - y\\ \end{array} \]
Alternative 7
Error13.3
Cost6788
\[\begin{array}{l} \mathbf{if}\;y \leq -80:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \end{array} \]
Alternative 8
Error36.0
Cost192
\[x + 1 \]
Alternative 9
Error36.2
Cost64
\[1 \]

Error

Reproduce

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