?

Average Error: 27.98% → 1.1%
Time: 10.8s
Precision: binary64
Cost: 13512

?

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

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original27.98%
Target0.2%
Herbie1.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. Split input into 3 regimes
  2. if y < -8.49999999999999979e22

    1. Initial program 82.47

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

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

      [Start]82.47

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

      sub-neg [=>]82.47

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

      log1p-def [=>]82.47

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

      div-sub [=>]82.46

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

      sub-neg [=>]82.46

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

      +-commutative [=>]82.46

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

      distribute-neg-in [=>]82.46

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

      remove-double-neg [=>]82.46

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

      sub-neg [<=]82.46

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

      div-sub [<=]82.47

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

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

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

      [Start]0.5

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

      sub-neg [=>]0.5

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

      metadata-eval [=>]0.5

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

      distribute-lft-in [=>]0.5

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

      metadata-eval [=>]0.5

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

      +-commutative [<=]0.5

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

      log1p-def [=>]0.5

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

      mul-1-neg [=>]0.5

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

    if -8.49999999999999979e22 < y < 1.8e13

    1. Initial program 1.33

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

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

      [Start]1.33

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

      sub-neg [=>]1.33

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

      log1p-def [=>]1.3

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

      div-sub [=>]1.3

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

      sub-neg [=>]1.3

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

      +-commutative [=>]1.3

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

      distribute-neg-in [=>]1.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 [=>]1.3

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

      sub-neg [<=]1.3

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

      div-sub [<=]1.3

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

    if 1.8e13 < y

    1. Initial program 48.08

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

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

      [Start]48.08

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

      sub-neg [=>]48.08

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

      log1p-def [=>]48.08

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

      div-sub [=>]48.03

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

      sub-neg [=>]48.03

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

      +-commutative [=>]48.03

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

      distribute-neg-in [=>]48.03

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

      remove-double-neg [=>]48.03

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

      sub-neg [<=]48.03

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

      div-sub [<=]48.08

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

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

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

      [Start]1.46

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

      +-commutative [=>]1.46

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

      log-rec [=>]1.46

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

      unsub-neg [=>]1.46

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

      sub-neg [=>]1.46

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

      metadata-eval [=>]1.46

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

      +-commutative [=>]1.46

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

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

Alternatives

Alternative 1
Error10.23%
Cost13512
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{+50}:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+14}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \left(\log \left(x + -1\right) - \log y\right)\\ \end{array} \]
Alternative 2
Error10.34%
Cost13384
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{+50}:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{+14}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\log y - \log x\right)\\ \end{array} \]
Alternative 3
Error9.01%
Cost7620
\[\begin{array}{l} t_0 := \frac{y - x}{1 - y}\\ \mathbf{if}\;1 + t_0 \leq 0:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(t_0\right)\\ \end{array} \]
Alternative 4
Error16.3%
Cost7181
\[\begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{+64}:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{elif}\;y \leq -2.3 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\ \end{array} \]
Alternative 5
Error16.9%
Cost7117
\[\begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{+64}:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{elif}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \end{array} \]
Alternative 6
Error16.32%
Cost6980
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{+64}:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(\frac{x}{y + -1}\right)\\ \end{array} \]
Alternative 7
Error39.64%
Cost6788
\[\begin{array}{l} \mathbf{if}\;y \leq -0.00026:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;1 + x\\ \end{array} \]
Alternative 8
Error21.86%
Cost6788
\[\begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{+22}:\\ \;\;\;\;1 + \log \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;1 - \mathsf{log1p}\left(-x\right)\\ \end{array} \]
Alternative 9
Error56.47%
Cost192
\[1 + x \]
Alternative 10
Error56.73%
Cost64
\[1 \]

Error

Reproduce?

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