| Alternative 1 | |
|---|---|
| Error | 0.22% |
| Cost | 7492 |
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ x -1.0) y)))
(if (<= y -410000000.0)
(- 1.0 (log t_0))
(if (<= y 33000000000000.0)
(- 1.0 (log1p (/ (- y x) (- 1.0 y))))
(log (/ E t_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 t_0 = (x + -1.0) / y;
double tmp;
if (y <= -410000000.0) {
tmp = 1.0 - log(t_0);
} else if (y <= 33000000000000.0) {
tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
} else {
tmp = log((((double) M_E) / t_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 t_0 = (x + -1.0) / y;
double tmp;
if (y <= -410000000.0) {
tmp = 1.0 - Math.log(t_0);
} else if (y <= 33000000000000.0) {
tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
} else {
tmp = Math.log((Math.E / t_0));
}
return tmp;
}
def code(x, y): return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
def code(x, y): t_0 = (x + -1.0) / y tmp = 0 if y <= -410000000.0: tmp = 1.0 - math.log(t_0) elif y <= 33000000000000.0: tmp = 1.0 - math.log1p(((y - x) / (1.0 - y))) else: tmp = math.log((math.e / t_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) t_0 = Float64(Float64(x + -1.0) / y) tmp = 0.0 if (y <= -410000000.0) tmp = Float64(1.0 - log(t_0)); elseif (y <= 33000000000000.0) tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y)))); else tmp = log(Float64(exp(1) / t_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_] := Block[{t$95$0 = N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[y, -410000000.0], N[(1.0 - N[Log[t$95$0], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 33000000000000.0], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Log[N[(E / t$95$0), $MachinePrecision]], $MachinePrecision]]]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
t_0 := \frac{x + -1}{y}\\
\mathbf{if}\;y \leq -410000000:\\
\;\;\;\;1 - \log t_0\\
\mathbf{elif}\;y \leq 33000000000000:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{e}{t_0}\right)\\
\end{array}
Results
| Original | 28.4% |
|---|---|
| Target | 0.19% |
| Herbie | 0.17% |
if y < -4.1e8Initial program 82.2
Simplified82.2
[Start]82.2 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]82.2 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]82.2 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]82.18 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]82.18 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]82.18 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]82.18 | \[ 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.18 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]82.18 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]82.2 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Applied egg-rr80.15
Taylor expanded in y around inf 100
Simplified100
[Start]100 | \[ 1 - \left(\log \left(\frac{1}{y}\right) + \log \left(x - 1\right)\right)
\] |
|---|---|
associate--r+ [=>]100 | \[ \color{blue}{\left(1 - \log \left(\frac{1}{y}\right)\right) - \log \left(x - 1\right)}
\] |
log-div [=>]100 | \[ \left(1 - \color{blue}{\left(\log 1 - \log y\right)}\right) - \log \left(x - 1\right)
\] |
metadata-eval [=>]100 | \[ \left(1 - \left(\color{blue}{0} - \log y\right)\right) - \log \left(x - 1\right)
\] |
associate--r- [=>]100 | \[ \color{blue}{\left(\left(1 - 0\right) + \log y\right)} - \log \left(x - 1\right)
\] |
metadata-eval [=>]100 | \[ \left(\color{blue}{1} + \log y\right) - \log \left(x - 1\right)
\] |
sub-neg [=>]100 | \[ \left(1 + \log y\right) - \log \color{blue}{\left(x + \left(-1\right)\right)}
\] |
metadata-eval [=>]100 | \[ \left(1 + \log y\right) - \log \left(x + \color{blue}{-1}\right)
\] |
+-commutative [=>]100 | \[ \left(1 + \log y\right) - \log \color{blue}{\left(-1 + x\right)}
\] |
Taylor expanded in y around 0 100
Simplified0.31
[Start]100 | \[ \left(1 + \log y\right) - \log \left(x - 1\right)
\] |
|---|---|
sub-neg [=>]100 | \[ \left(1 + \log y\right) - \log \color{blue}{\left(x + \left(-1\right)\right)}
\] |
metadata-eval [=>]100 | \[ \left(1 + \log y\right) - \log \left(x + \color{blue}{-1}\right)
\] |
+-commutative [<=]100 | \[ \left(1 + \log y\right) - \log \color{blue}{\left(-1 + x\right)}
\] |
+-commutative [=>]100 | \[ \color{blue}{\left(\log y + 1\right)} - \log \left(-1 + x\right)
\] |
associate-+r- [<=]100 | \[ \color{blue}{\log y + \left(1 - \log \left(-1 + x\right)\right)}
\] |
+-commutative [=>]100 | \[ \color{blue}{\left(1 - \log \left(-1 + x\right)\right) + \log y}
\] |
associate-+l- [=>]100 | \[ \color{blue}{1 - \left(\log \left(-1 + x\right) - \log y\right)}
\] |
log-div [<=]0.31 | \[ 1 - \color{blue}{\log \left(\frac{-1 + x}{y}\right)}
\] |
+-commutative [=>]0.31 | \[ 1 - \log \left(\frac{\color{blue}{x + -1}}{y}\right)
\] |
if -4.1e8 < y < 3.3e13Initial program 0.17
Simplified0.13
[Start]0.17 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]0.17 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]0.13 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]0.13 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]0.13 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]0.13 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]0.13 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]0.13 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]0.13 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]0.13 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
if 3.3e13 < y Initial program 47.13
Simplified47.13
[Start]47.13 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]47.13 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]47.13 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]47.1 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]47.1 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]47.1 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]47.1 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]47.1 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]47.1 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]47.13 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Applied egg-rr46.1
Taylor expanded in y around inf 1.48
Simplified1.48
[Start]1.48 | \[ 1 - \left(\log \left(\frac{1}{y}\right) + \log \left(x - 1\right)\right)
\] |
|---|---|
associate--r+ [=>]1.48 | \[ \color{blue}{\left(1 - \log \left(\frac{1}{y}\right)\right) - \log \left(x - 1\right)}
\] |
log-div [=>]1.48 | \[ \left(1 - \color{blue}{\left(\log 1 - \log y\right)}\right) - \log \left(x - 1\right)
\] |
metadata-eval [=>]1.48 | \[ \left(1 - \left(\color{blue}{0} - \log y\right)\right) - \log \left(x - 1\right)
\] |
associate--r- [=>]1.48 | \[ \color{blue}{\left(\left(1 - 0\right) + \log y\right)} - \log \left(x - 1\right)
\] |
metadata-eval [=>]1.48 | \[ \left(\color{blue}{1} + \log y\right) - \log \left(x - 1\right)
\] |
sub-neg [=>]1.48 | \[ \left(1 + \log y\right) - \log \color{blue}{\left(x + \left(-1\right)\right)}
\] |
metadata-eval [=>]1.48 | \[ \left(1 + \log y\right) - \log \left(x + \color{blue}{-1}\right)
\] |
+-commutative [=>]1.48 | \[ \left(1 + \log y\right) - \log \color{blue}{\left(-1 + x\right)}
\] |
Applied egg-rr0.02
Final simplification0.17
| Alternative 1 | |
|---|---|
| Error | 0.22% |
| Cost | 7492 |
| Alternative 2 | |
|---|---|
| Error | 1.25% |
| Cost | 7113 |
| Alternative 3 | |
|---|---|
| Error | 1.53% |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Error | 14.6% |
| Cost | 7048 |
| Alternative 5 | |
|---|---|
| Error | 15.88% |
| Cost | 6984 |
| Alternative 6 | |
|---|---|
| Error | 20.36% |
| Cost | 6920 |
| Alternative 7 | |
|---|---|
| Error | 36.25% |
| Cost | 6788 |
| Alternative 8 | |
|---|---|
| Error | 55.41% |
| Cost | 448 |
| Alternative 9 | |
|---|---|
| Error | 56.86% |
| Cost | 192 |
| Alternative 10 | |
|---|---|
| Error | 57.09% |
| Cost | 64 |
herbie shell --seed 2023090
(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))))))