?

Average Accuracy: 71.5% → 99.6%
Time: 17.4s
Precision: binary64
Cost: 26889

?

\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} \mathbf{if}\;y \leq -285000 \lor \neg \left(y \leq 2.3 \cdot 10^{-8}\right):\\ \;\;\;\;\log \left(\frac{y \cdot e}{x + -1} + \frac{e \cdot \left(1 - x\right)}{{\left(x + -1\right)}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - 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 (or (<= y -285000.0) (not (<= y 2.3e-8)))
   (log (+ (/ (* y E) (+ x -1.0)) (/ (* E (- 1.0 x)) (pow (+ x -1.0) 2.0))))
   (- 1.0 (log1p (/ (- y 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 ((y <= -285000.0) || !(y <= 2.3e-8)) {
		tmp = log((((y * ((double) M_E)) / (x + -1.0)) + ((((double) M_E) * (1.0 - x)) / pow((x + -1.0), 2.0))));
	} else {
		tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
	}
	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 <= -285000.0) || !(y <= 2.3e-8)) {
		tmp = Math.log((((y * Math.E) / (x + -1.0)) + ((Math.E * (1.0 - x)) / Math.pow((x + -1.0), 2.0))));
	} else {
		tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
	}
	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 <= -285000.0) or not (y <= 2.3e-8):
		tmp = math.log((((y * math.e) / (x + -1.0)) + ((math.e * (1.0 - x)) / math.pow((x + -1.0), 2.0))))
	else:
		tmp = 1.0 - math.log1p(((y - x) / (1.0 - y)))
	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 <= -285000.0) || !(y <= 2.3e-8))
		tmp = log(Float64(Float64(Float64(y * exp(1)) / Float64(x + -1.0)) + Float64(Float64(exp(1) * Float64(1.0 - x)) / (Float64(x + -1.0) ^ 2.0))));
	else
		tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y))));
	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[Or[LessEqual[y, -285000.0], N[Not[LessEqual[y, 2.3e-8]], $MachinePrecision]], N[Log[N[(N[(N[(y * E), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(E * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[Power[N[(x + -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;y \leq -285000 \lor \neg \left(y \leq 2.3 \cdot 10^{-8}\right):\\
\;\;\;\;\log \left(\frac{y \cdot e}{x + -1} + \frac{e \cdot \left(1 - x\right)}{{\left(x + -1\right)}^{2}}\right)\\

\mathbf{else}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original71.5%
Target99.8%
Herbie99.6%
\[\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 y < -285000 or 2.3000000000000001e-8 < y

    1. Initial program 29.3%

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

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

      [Start]29.3

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

      sub-neg [=>]29.3

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

      log1p-def [=>]29.3

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

      div-sub [=>]29.3

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

      sub-neg [=>]29.3

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

      +-commutative [=>]29.3

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

      distribute-neg-in [=>]29.3

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

      remove-double-neg [=>]29.3

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

      sub-neg [<=]29.3

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

      div-sub [<=]29.3

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

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

      [Start]29.3

      \[ 1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right) \]

      add-log-exp [=>]29.3

      \[ \color{blue}{\log \left(e^{1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)}\right)} \]

      exp-diff [=>]29.3

      \[ \log \color{blue}{\left(\frac{e^{1}}{e^{\mathsf{log1p}\left(\frac{y - x}{1 - y}\right)}}\right)} \]

      exp-1-e [=>]29.3

      \[ \log \left(\frac{\color{blue}{e}}{e^{\mathsf{log1p}\left(\frac{y - x}{1 - y}\right)}}\right) \]

      log1p-udef [=>]29.3

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

      add-exp-log [<=]29.3

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

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

    if -285000 < y < 2.3000000000000001e-8

    1. Initial program 99.9%

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

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

      [Start]99.9

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

      sub-neg [=>]99.9

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

      log1p-def [=>]100.0

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

      div-sub [=>]100.0

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

      sub-neg [=>]100.0

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

      +-commutative [=>]100.0

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

      distribute-neg-in [=>]100.0

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

      remove-double-neg [=>]100.0

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

      sub-neg [<=]100.0

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

      div-sub [<=]100.0

      \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -285000 \lor \neg \left(y \leq 2.3 \cdot 10^{-8}\right):\\ \;\;\;\;\log \left(\frac{y \cdot e}{x + -1} + \frac{e \cdot \left(1 - x\right)}{{\left(x + -1\right)}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.0%
Cost14212
\[\begin{array}{l} t_0 := \frac{x + -1}{y}\\ \mathbf{if}\;\frac{x - y}{1 - y} \leq 10^{-6}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e}{\frac{t_0}{y} + t_0}\right)\\ \end{array} \]
Alternative 2
Accuracy99.2%
Cost13316
\[\begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{+19}:\\ \;\;\;\;\log \left(\frac{y \cdot e}{x + -1}\right)\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x}{y + -1}\right)\\ \end{array} \]
Alternative 3
Accuracy90.7%
Cost7876
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 0.9995:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\frac{-1}{y} + \left(\frac{-0.5}{y \cdot y} - \log \left(\frac{-1}{y}\right)\right)\right)\\ \end{array} \]
Alternative 4
Accuracy90.6%
Cost7492
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 0.9995:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{-1}{y}\right) - \log \left(\frac{-1}{y}\right)\\ \end{array} \]
Alternative 5
Accuracy90.5%
Cost7240
\[\begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+19}:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x}{y + -1}\right)\\ \end{array} \]
Alternative 6
Accuracy89.5%
Cost7112
\[\begin{array}{l} \mathbf{if}\;y \leq -46:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 0.55:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{x}{y + -1}\right)\\ \end{array} \]
Alternative 7
Accuracy88.3%
Cost7112
\[\begin{array}{l} t_0 := \frac{x}{y + -1}\\ \mathbf{if}\;y \leq -5.5 \cdot 10^{+46}:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \mathsf{log1p}\left(t_0\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log t_0\\ \end{array} \]
Alternative 8
Accuracy84.9%
Cost7048
\[\begin{array}{l} \mathbf{if}\;y \leq -90:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y}\right)\\ \end{array} \]
Alternative 9
Accuracy84.1%
Cost6984
\[\begin{array}{l} \mathbf{if}\;y \leq -90000:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-8}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y}\right)\\ \end{array} \]
Alternative 10
Accuracy79.0%
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq -90000:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \end{array} \]
Alternative 11
Accuracy62.6%
Cost6656
\[1 - \mathsf{log1p}\left(-x\right) \]
Alternative 12
Accuracy43.8%
Cost452
\[\begin{array}{l} \mathbf{if}\;y \leq -10.2:\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\left(x + 1\right) - y\\ \end{array} \]
Alternative 13
Accuracy44.4%
Cost448
\[1 + \frac{x}{1 - y} \]
Alternative 14
Accuracy42.7%
Cost64
\[1 \]

Error

Reproduce?

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