| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 7112 |
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y) :precision binary64 (if (<= (/ (- x y) (- 1.0 y)) 0.02) (- 1.0 (log1p (/ (- y x) (- 1.0 y)))) (- 1.0 (log (/ (+ x -1.0) 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 (((x - y) / (1.0 - y)) <= 0.02) {
tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - log(((x + -1.0) / 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 (((x - y) / (1.0 - y)) <= 0.02) {
tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
} else {
tmp = 1.0 - Math.log(((x + -1.0) / 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 ((x - y) / (1.0 - y)) <= 0.02: tmp = 1.0 - math.log1p(((y - x) / (1.0 - y))) else: tmp = 1.0 - math.log(((x + -1.0) / 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 (Float64(Float64(x - y) / Float64(1.0 - y)) <= 0.02) tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y)))); else tmp = Float64(1.0 - log(Float64(Float64(x + -1.0) / 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[N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 0.02], 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[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;\frac{x - y}{1 - y} \leq 0.02:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\
\end{array}
Results
| Original | 71.3% |
|---|---|
| Target | 99.8% |
| Herbie | 99.5% |
if (/.f64 (-.f64 x y) (-.f64 1 y)) < 0.0200000000000000004Initial program 100.0%
Simplified100.0%
[Start]100.0 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]100.0 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]100.0 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]100.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]100.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]100.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]100.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]100.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]100.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]100.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
if 0.0200000000000000004 < (/.f64 (-.f64 x y) (-.f64 1 y)) Initial program 5.3%
Simplified5.3%
[Start]5.3 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]5.3 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]5.3 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]5.4 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]5.4 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]5.4 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]5.4 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]5.4 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]5.4 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]5.3 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in y around inf 16.8%
Simplified16.8%
[Start]16.8 | \[ 1 - \left(\log \left(\frac{1}{y}\right) + \log \left(x - 1\right)\right)
\] |
|---|---|
+-commutative [=>]16.8 | \[ 1 - \color{blue}{\left(\log \left(x - 1\right) + \log \left(\frac{1}{y}\right)\right)}
\] |
log-rec [=>]16.8 | \[ 1 - \left(\log \left(x - 1\right) + \color{blue}{\left(-\log y\right)}\right)
\] |
unsub-neg [=>]16.8 | \[ 1 - \color{blue}{\left(\log \left(x - 1\right) - \log y\right)}
\] |
sub-neg [=>]16.8 | \[ 1 - \left(\log \color{blue}{\left(x + \left(-1\right)\right)} - \log y\right)
\] |
metadata-eval [=>]16.8 | \[ 1 - \left(\log \left(x + \color{blue}{-1}\right) - \log y\right)
\] |
+-commutative [=>]16.8 | \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right)
\] |
Taylor expanded in y around 0 16.8%
Simplified98.4%
[Start]16.8 | \[ 1 - \left(\log \left(x - 1\right) - \log y\right)
\] |
|---|---|
sub-neg [=>]16.8 | \[ 1 - \left(\log \color{blue}{\left(x + \left(-1\right)\right)} - \log y\right)
\] |
metadata-eval [=>]16.8 | \[ 1 - \left(\log \left(x + \color{blue}{-1}\right) - \log y\right)
\] |
+-commutative [<=]16.8 | \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right)
\] |
log-div [<=]98.4 | \[ 1 - \color{blue}{\log \left(\frac{-1 + x}{y}\right)}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 7112 |
| Alternative 2 | |
|---|---|
| Accuracy | 89.3% |
| Cost | 7048 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7048 |
| Alternative 4 | |
|---|---|
| Accuracy | 88.6% |
| Cost | 6984 |
| Alternative 5 | |
|---|---|
| Accuracy | 59.4% |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.5% |
| Cost | 6788 |
| Alternative 7 | |
|---|---|
| Accuracy | 42.8% |
| Cost | 64 |
herbie shell --seed 2023138
(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))))))