| Alternative 1 | |
|---|---|
| Error | 0.36% |
| Cost | 14084 |
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
:precision binary64
(if (<= y -680000.0)
(-
(- 1.0 (/ (+ (/ x (+ x -1.0)) (/ -1.0 (+ x -1.0))) y))
(+ (log1p (- x)) (log (/ -1.0 y))))
(if (<= y 0.08)
(- 1.0 (log1p (/ (- y x) (- 1.0 y))))
(- 1.0 (log (/ x (+ y -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 <= -680000.0) {
tmp = (1.0 - (((x / (x + -1.0)) + (-1.0 / (x + -1.0))) / y)) - (log1p(-x) + log((-1.0 / y)));
} else if (y <= 0.08) {
tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - log((x / (y + -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 <= -680000.0) {
tmp = (1.0 - (((x / (x + -1.0)) + (-1.0 / (x + -1.0))) / y)) - (Math.log1p(-x) + Math.log((-1.0 / y)));
} else if (y <= 0.08) {
tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - Math.log((x / (y + -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 <= -680000.0: tmp = (1.0 - (((x / (x + -1.0)) + (-1.0 / (x + -1.0))) / y)) - (math.log1p(-x) + math.log((-1.0 / y))) elif y <= 0.08: tmp = 1.0 - math.log1p(((y - x) / (1.0 - y))) else: tmp = 1.0 - math.log((x / (y + -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 <= -680000.0) tmp = Float64(Float64(1.0 - Float64(Float64(Float64(x / Float64(x + -1.0)) + Float64(-1.0 / Float64(x + -1.0))) / y)) - Float64(log1p(Float64(-x)) + log(Float64(-1.0 / y)))); elseif (y <= 0.08) tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y)))); else tmp = Float64(1.0 - log(Float64(x / Float64(y + -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, -680000.0], N[(N[(1.0 - N[(N[(N[(x / N[(x + -1.0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] - N[(N[Log[1 + (-x)], $MachinePrecision] + N[Log[N[(-1.0 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.08], 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[(x / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;y \leq -680000:\\
\;\;\;\;\left(1 - \frac{\frac{x}{x + -1} + \frac{-1}{x + -1}}{y}\right) - \left(\mathsf{log1p}\left(-x\right) + \log \left(\frac{-1}{y}\right)\right)\\
\mathbf{elif}\;y \leq 0.08:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{x}{y + -1}\right)\\
\end{array}
Results
| Original | 28.43% |
|---|---|
| Target | 0.2% |
| Herbie | 0.36% |
if y < -6.8e5Initial program 81.67
Simplified81.67
[Start]81.67 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]81.67 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]81.67 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]81.66 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]81.66 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]81.66 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]81.66 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]81.66 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]81.66 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]81.67 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in y around -inf 0.51
Simplified0.51
[Start]0.51 | \[ \left(1 + -1 \cdot \frac{\frac{x}{x - 1} - \frac{1}{x - 1}}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
|---|---|
mul-1-neg [=>]0.51 | \[ \left(1 + \color{blue}{\left(-\frac{\frac{x}{x - 1} - \frac{1}{x - 1}}{y}\right)}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
unsub-neg [=>]0.51 | \[ \color{blue}{\left(1 - \frac{\frac{x}{x - 1} - \frac{1}{x - 1}}{y}\right)} - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
sub-neg [=>]0.51 | \[ \left(1 - \frac{\color{blue}{\frac{x}{x - 1} + \left(-\frac{1}{x - 1}\right)}}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
sub-neg [=>]0.51 | \[ \left(1 - \frac{\frac{x}{\color{blue}{x + \left(-1\right)}} + \left(-\frac{1}{x - 1}\right)}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
metadata-eval [=>]0.51 | \[ \left(1 - \frac{\frac{x}{x + \color{blue}{-1}} + \left(-\frac{1}{x - 1}\right)}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
+-commutative [=>]0.51 | \[ \left(1 - \frac{\frac{x}{\color{blue}{-1 + x}} + \left(-\frac{1}{x - 1}\right)}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
distribute-neg-frac [=>]0.51 | \[ \left(1 - \frac{\frac{x}{-1 + x} + \color{blue}{\frac{-1}{x - 1}}}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
metadata-eval [=>]0.51 | \[ \left(1 - \frac{\frac{x}{-1 + x} + \frac{\color{blue}{-1}}{x - 1}}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
sub-neg [=>]0.51 | \[ \left(1 - \frac{\frac{x}{-1 + x} + \frac{-1}{\color{blue}{x + \left(-1\right)}}}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
metadata-eval [=>]0.51 | \[ \left(1 - \frac{\frac{x}{-1 + x} + \frac{-1}{x + \color{blue}{-1}}}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
+-commutative [=>]0.51 | \[ \left(1 - \frac{\frac{x}{-1 + x} + \frac{-1}{\color{blue}{-1 + x}}}{y}\right) - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
if -6.8e5 < y < 0.0800000000000000017Initial program 0.08
Simplified0.05
[Start]0.08 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]0.08 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]0.05 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]0.05 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]0.05 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]0.05 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]0.05 | \[ 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.05 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]0.05 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]0.05 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
if 0.0800000000000000017 < y Initial program 46.79
Simplified46.79
[Start]46.79 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]46.79 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]46.79 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]46.76 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]46.76 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]46.76 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]46.76 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]46.76 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]46.76 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]46.79 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in x around inf 45.81
Simplified45.81
[Start]45.81 | \[ 1 - \mathsf{log1p}\left(-1 \cdot \frac{x}{1 - y}\right)
\] |
|---|---|
mul-1-neg [=>]45.81 | \[ 1 - \mathsf{log1p}\left(\color{blue}{-\frac{x}{1 - y}}\right)
\] |
distribute-neg-frac [=>]45.81 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{-x}{1 - y}}\right)
\] |
Applied egg-rr45.81
Simplified45.81
[Start]45.81 | \[ 1 - \mathsf{log1p}\left(1 + \left(\frac{x}{-1 + y} - 1\right)\right)
\] |
|---|---|
associate-+r- [=>]45.81 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(1 + \frac{x}{-1 + y}\right) - 1}\right)
\] |
+-commutative [=>]45.81 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(\frac{x}{-1 + y} + 1\right)} - 1\right)
\] |
associate--l+ [=>]45.81 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{x}{-1 + y} + \left(1 - 1\right)}\right)
\] |
metadata-eval [=>]45.81 | \[ 1 - \mathsf{log1p}\left(\frac{x}{-1 + y} + \color{blue}{0}\right)
\] |
+-rgt-identity [=>]45.81 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{x}{-1 + y}}\right)
\] |
Taylor expanded in x around inf 3.34
Simplified1.88
[Start]3.34 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log \left(\frac{1}{y - 1}\right)\right)
\] |
|---|---|
sub-neg [=>]3.34 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log \left(\frac{1}{\color{blue}{y + \left(-1\right)}}\right)\right)
\] |
metadata-eval [=>]3.34 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log \left(\frac{1}{y + \color{blue}{-1}}\right)\right)
\] |
+-commutative [<=]3.34 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log \left(\frac{1}{\color{blue}{-1 + y}}\right)\right)
\] |
log-rec [=>]3.34 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \color{blue}{\left(-\log \left(-1 + y\right)\right)}\right)
\] |
sub-neg [<=]3.34 | \[ 1 - \color{blue}{\left(-1 \cdot \log \left(\frac{1}{x}\right) - \log \left(-1 + y\right)\right)}
\] |
mul-1-neg [=>]3.34 | \[ 1 - \left(\color{blue}{\left(-\log \left(\frac{1}{x}\right)\right)} - \log \left(-1 + y\right)\right)
\] |
log-rec [=>]3.34 | \[ 1 - \left(\left(-\color{blue}{\left(-\log x\right)}\right) - \log \left(-1 + y\right)\right)
\] |
remove-double-neg [=>]3.34 | \[ 1 - \left(\color{blue}{\log x} - \log \left(-1 + y\right)\right)
\] |
log-div [<=]1.88 | \[ 1 - \color{blue}{\log \left(\frac{x}{-1 + y}\right)}
\] |
+-commutative [=>]1.88 | \[ 1 - \log \left(\frac{x}{\color{blue}{y + -1}}\right)
\] |
Final simplification0.36
| Alternative 1 | |
|---|---|
| Error | 0.36% |
| Cost | 14084 |
| Alternative 2 | |
|---|---|
| Error | 0.47% |
| Cost | 13444 |
| Alternative 3 | |
|---|---|
| Error | 9.9% |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 9.2% |
| Cost | 7240 |
| Alternative 5 | |
|---|---|
| Error | 9.22% |
| Cost | 7240 |
| Alternative 6 | |
|---|---|
| Error | 18.47% |
| Cost | 7113 |
| Alternative 7 | |
|---|---|
| Error | 11.05% |
| Cost | 7112 |
| Alternative 8 | |
|---|---|
| Error | 26.67% |
| Cost | 7049 |
| Alternative 9 | |
|---|---|
| Error | 27.24% |
| Cost | 6985 |
| Alternative 10 | |
|---|---|
| Error | 36.46% |
| Cost | 6656 |
| Alternative 11 | |
|---|---|
| Error | 54.68% |
| Cost | 448 |
| Alternative 12 | |
|---|---|
| Error | 56.42% |
| Cost | 64 |
herbie shell --seed 2023088
(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))))))