?

Average Accuracy: 71.7% → 99.9%
Time: 14.0s
Precision: binary64
Cost: 7240

?

\[1 - \log \left(1 - \frac{x - y}{1 - y}\right) \]
\[\begin{array}{l} \mathbf{if}\;y \leq -2060000000:\\ \;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{elif}\;y \leq 200000000000:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \log \left(\frac{y}{x + -1}\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 -2060000000.0)
   (- 1.0 (log (/ (+ x -1.0) y)))
   (if (<= y 200000000000.0)
     (- 1.0 (log1p (/ (- y x) (- 1.0 y))))
     (+ 1.0 (log (/ y (+ 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 <= -2060000000.0) {
		tmp = 1.0 - log(((x + -1.0) / y));
	} else if (y <= 200000000000.0) {
		tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
	} else {
		tmp = 1.0 + log((y / (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 <= -2060000000.0) {
		tmp = 1.0 - Math.log(((x + -1.0) / y));
	} else if (y <= 200000000000.0) {
		tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
	} else {
		tmp = 1.0 + Math.log((y / (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 <= -2060000000.0:
		tmp = 1.0 - math.log(((x + -1.0) / y))
	elif y <= 200000000000.0:
		tmp = 1.0 - math.log1p(((y - x) / (1.0 - y)))
	else:
		tmp = 1.0 + math.log((y / (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 <= -2060000000.0)
		tmp = Float64(1.0 - log(Float64(Float64(x + -1.0) / y)));
	elseif (y <= 200000000000.0)
		tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y))));
	else
		tmp = Float64(1.0 + log(Float64(y / 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, -2060000000.0], N[(1.0 - N[Log[N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 200000000000.0], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[Log[N[(y / 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 -2060000000:\\
\;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original71.7%
Target99.8%
Herbie99.9%
\[\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 < -2.06e9

    1. Initial program 18.7%

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

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

      [Start]18.7

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

      sub-neg [=>]18.7

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

      log1p-def [=>]18.7

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

      neg-sub0 [=>]18.7

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

      div-sub [=>]18.7

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

      associate--r- [=>]18.7

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

      neg-sub0 [<=]18.7

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

      +-commutative [=>]18.7

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

      sub-neg [<=]18.7

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

      div-sub [<=]18.7

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

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

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

      [Start]0.0

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

      +-commutative [=>]0.0

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

      log-rec [=>]0.0

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

      unsub-neg [=>]0.0

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

      sub-neg [=>]0.0

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

      metadata-eval [=>]0.0

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

      +-commutative [=>]0.0

      \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right) \]
    5. Taylor expanded in y around 0 0.0%

      \[\leadsto 1 - \color{blue}{\left(\log \left(x - 1\right) - \log y\right)} \]
    6. Simplified99.8%

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

      [Start]0.0

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

      sub-neg [=>]0.0

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

      metadata-eval [=>]0.0

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

      +-commutative [<=]0.0

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

      log-div [<=]99.8

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

      +-commutative [=>]99.8

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

      metadata-eval [<=]99.8

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

      sub-neg [<=]99.8

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

    if -2.06e9 < y < 2e11

    1. Initial program 99.8%

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

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

      [Start]99.8

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

      sub-neg [=>]99.8

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

      log1p-def [=>]99.9

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

      neg-sub0 [=>]99.9

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

      div-sub [=>]99.9

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

      associate--r- [=>]99.9

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

      neg-sub0 [<=]99.9

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

      +-commutative [=>]99.9

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

      sub-neg [<=]99.9

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

      div-sub [<=]99.9

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

    if 2e11 < y

    1. Initial program 50.3%

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

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

      [Start]50.3

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

      sub-neg [=>]50.3

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

      log1p-def [=>]50.3

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

      neg-sub0 [=>]50.3

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

      div-sub [=>]50.4

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

      associate--r- [=>]50.4

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

      neg-sub0 [<=]50.4

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

      +-commutative [=>]50.4

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

      sub-neg [<=]50.4

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

      div-sub [<=]50.3

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

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

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

      [Start]98.5

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

      +-commutative [=>]98.5

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

      log-rec [=>]98.5

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

      unsub-neg [=>]98.5

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

      sub-neg [=>]98.5

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

      metadata-eval [=>]98.5

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

      +-commutative [=>]98.5

      \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right) \]
    5. Applied egg-rr99.9%

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

      [Start]98.5

      \[ 1 - \left(\log \left(-1 + x\right) - \log y\right) \]

      diff-log [=>]100.0

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

      clear-num [=>]99.9

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

      log-rec [=>]99.9

      \[ 1 - \color{blue}{\left(-\log \left(\frac{y}{-1 + x}\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy98.8%
Cost7113
\[\begin{array}{l} \mathbf{if}\;y \leq -1.7 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \end{array} \]
Alternative 2
Accuracy98.6%
Cost7113
\[\begin{array}{l} \mathbf{if}\;y \leq -105 \lor \neg \left(y \leq 4 \cdot 10^{+14}\right):\\ \;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y + -1}\right)\\ \end{array} \]
Alternative 3
Accuracy98.6%
Cost7112
\[\begin{array}{l} \mathbf{if}\;y \leq -500:\\ \;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+15}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y + -1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \log \left(\frac{y}{x + -1}\right)\\ \end{array} \]
Alternative 4
Accuracy80.5%
Cost6916
\[\begin{array}{l} \mathbf{if}\;y \leq -10:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \end{array} \]
Alternative 5
Accuracy79.9%
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq -17:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \end{array} \]
Alternative 6
Accuracy63.4%
Cost6656
\[1 - \mathsf{log1p}\left(-x\right) \]
Alternative 7
Accuracy44.1%
Cost708
\[\begin{array}{l} \mathbf{if}\;y \leq -0.092:\\ \;\;\;\;1 + \frac{-1 - \frac{0.5}{y}}{y}\\ \mathbf{else}:\\ \;\;\;\;1 - \left(y - x\right)\\ \end{array} \]
Alternative 8
Accuracy42.0%
Cost320
\[1 - \left(y - x\right) \]
Alternative 9
Accuracy40.9%
Cost192
\[1 - y \]

Error

Reproduce?

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