?

Average Accuracy: 72.0% → 99.7%
Time: 13.9s
Precision: binary64
Cost: 13700

?

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

\mathbf{elif}\;y \leq 6.3 \cdot 10^{+21}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original72.0%
Target99.8%
Herbie99.7%
\[\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 < -1.12e6

    1. Initial program 19.7%

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

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

      [Start]19.7

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

      sub-neg [=>]19.7

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

      log1p-def [=>]19.7

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

      neg-sub0 [=>]19.7

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

      div-sub [=>]19.7

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

      associate--r- [=>]19.7

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

      neg-sub0 [<=]19.7

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

      +-commutative [=>]19.7

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

      sub-neg [<=]19.7

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

      div-sub [<=]19.7

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

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

      [Start]19.7

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

      flip-- [=>]21.2

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

      associate-/r/ [=>]21.9

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

      metadata-eval [=>]21.9

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

      +-commutative [=>]21.9

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

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

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

      [Start]99.5

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

      +-commutative [=>]99.5

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

      +-commutative [=>]99.5

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

      log-div [=>]0.0

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

      associate-+r- [=>]0.0

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

      log-prod [<=]0.0

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

      *-commutative [<=]0.0

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

      unsub-neg [<=]0.0

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

      log-rec [<=]0.0

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

      +-commutative [<=]0.0

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

      associate--r+ [=>]0.0

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

    if -1.12e6 < y < 6.3e21

    1. Initial program 99.9%

      \[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.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 [=>]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 6.3e21 < y

    1. Initial program 49.6%

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

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

      [Start]49.6

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

      sub-neg [=>]49.6

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

      log1p-def [=>]49.6

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

      neg-sub0 [=>]49.6

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

      div-sub [=>]49.6

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

      associate--r- [=>]49.6

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

      neg-sub0 [<=]49.6

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

      +-commutative [=>]49.6

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

      sub-neg [<=]49.6

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

      div-sub [<=]49.6

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

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

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

      [Start]98.6

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

      +-commutative [=>]98.6

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

      log-rec [=>]98.6

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

      unsub-neg [=>]98.6

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

      sub-neg [=>]98.6

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

      metadata-eval [=>]98.6

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

      +-commutative [=>]98.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1120000:\\ \;\;\;\;\left(\left(1 - \mathsf{log1p}\left(-x\right)\right) - \log \left(\frac{-1}{y}\right)\right) + \frac{-1}{y}\\ \mathbf{elif}\;y \leq 6.3 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\log y - \log \left(x + -1\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy90.6%
Cost13512
\[\begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{+20}:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\log y - \log \left(x + -1\right)\right)\\ \end{array} \]
Alternative 2
Accuracy99.6%
Cost13512
\[\begin{array}{l} \mathbf{if}\;y \leq -3550000000:\\ \;\;\;\;1 - \left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right)\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+21}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\log y - \log \left(x + -1\right)\right)\\ \end{array} \]
Alternative 3
Accuracy72.0%
Cost7492
\[\begin{array}{l} \mathbf{if}\;\frac{x - y}{1 - y} \leq 1:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \end{array} \]
Alternative 4
Accuracy80.8%
Cost7048
\[\begin{array}{l} \mathbf{if}\;y \leq -12:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]
Alternative 5
Accuracy84.8%
Cost7044
\[\begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{+20}:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{-x}{1 - y}\right)\\ \end{array} \]
Alternative 6
Accuracy79.3%
Cost6920
\[\begin{array}{l} \mathbf{if}\;y \leq -15.5:\\ \;\;\;\;1 - \log \left(\frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-30}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]
Alternative 7
Accuracy63.1%
Cost6788
\[\begin{array}{l} \mathbf{if}\;y \leq 1.5 \cdot 10^{-30}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y}\\ \end{array} \]
Alternative 8
Accuracy44.7%
Cost704
\[1 + \left(1 + \left(-1 - \frac{x}{y + -1}\right)\right) \]
Alternative 9
Accuracy44.7%
Cost448
\[1 - \frac{x}{y + -1} \]
Alternative 10
Accuracy43.3%
Cost192
\[1 + x \]
Alternative 11
Accuracy43.0%
Cost64
\[1 \]

Error

Reproduce?

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