| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 7492 |

(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.99999998) (- 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.99999998) {
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.99999998) {
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.99999998: 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.99999998) 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.99999998], 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.99999998:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 72.0% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
if (/.f64 (-.f64 x y) (-.f64 1 y)) < 0.999999980000000011Initial program 99.8%
Simplified99.8%
[Start]99.8% | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]99.8% | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]99.8% | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
neg-sub0 [=>]99.8% | \[ 1 - \mathsf{log1p}\left(\color{blue}{0 - \frac{x - y}{1 - y}}\right)
\] |
div-sub [=>]99.8% | \[ 1 - \mathsf{log1p}\left(0 - \color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
associate--r- [=>]99.8% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(0 - \frac{x}{1 - y}\right) + \frac{y}{1 - y}}\right)
\] |
neg-sub0 [<=]99.8% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\frac{x}{1 - y}\right)} + \frac{y}{1 - y}\right)
\] |
+-commutative [=>]99.8% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} + \left(-\frac{x}{1 - y}\right)}\right)
\] |
sub-neg [<=]99.8% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]99.8% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
if 0.999999980000000011 < (/.f64 (-.f64 x y) (-.f64 1 y)) Initial program 4.7%
Simplified4.7%
[Start]4.7% | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]4.7% | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]4.7% | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
neg-sub0 [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{0 - \frac{x - y}{1 - y}}\right)
\] |
div-sub [=>]4.7% | \[ 1 - \mathsf{log1p}\left(0 - \color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
associate--r- [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(0 - \frac{x}{1 - y}\right) + \frac{y}{1 - y}}\right)
\] |
neg-sub0 [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\frac{x}{1 - y}\right)} + \frac{y}{1 - y}\right)
\] |
+-commutative [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} + \left(-\frac{x}{1 - y}\right)}\right)
\] |
sub-neg [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Applied egg-rr6.9%
[Start]4.7% | \[ 1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)
\] |
|---|---|
clear-num [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{1}{\frac{1 - y}{y - x}}}\right)
\] |
associate-/r/ [=>]6.9% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{1}{1 - y} \cdot \left(y - x\right)}\right)
\] |
Taylor expanded in y around inf 4.7%
Simplified4.7%
[Start]4.7% | \[ 1 - \mathsf{log1p}\left(\frac{x}{y} - \left(\frac{1}{y} + 1\right)\right)
\] |
|---|---|
associate--r+ [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(\frac{x}{y} - \frac{1}{y}\right) - 1}\right)
\] |
div-sub [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{x - 1}{y}} - 1\right)
\] |
sub-neg [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{x - 1}{y} + \left(-1\right)}\right)
\] |
sub-neg [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\frac{\color{blue}{x + \left(-1\right)}}{y} + \left(-1\right)\right)
\] |
metadata-eval [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\frac{x + \color{blue}{-1}}{y} + \left(-1\right)\right)
\] |
metadata-eval [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\frac{x + -1}{y} + \color{blue}{-1}\right)
\] |
Applied egg-rr100.0%
[Start]4.7% | \[ 1 - \mathsf{log1p}\left(\frac{x + -1}{y} + -1\right)
\] |
|---|---|
div-inv [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(x + -1\right) \cdot \frac{1}{y}} + -1\right)
\] |
fma-def [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(x + -1, \frac{1}{y}, -1\right)}\right)
\] |
metadata-eval [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\mathsf{fma}\left(x + -1, \frac{1}{y}, \color{blue}{-1}\right)\right)
\] |
fma-neg [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(x + -1\right) \cdot \frac{1}{y} - 1}\right)
\] |
div-inv [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{x + -1}{y}} - 1\right)
\] |
add-exp-log [=>]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{e^{\log \left(\frac{x + -1}{y}\right)}} - 1\right)
\] |
expm1-udef [<=]4.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\log \left(\frac{x + -1}{y}\right)\right)}\right)
\] |
log1p-expm1-u [<=]100.0% | \[ 1 - \color{blue}{\log \left(\frac{x + -1}{y}\right)}
\] |
add-sqr-sqrt [=>]60.0% | \[ 1 - \log \left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}} + -1}{y}\right)
\] |
fma-def [=>]60.0% | \[ 1 - \log \left(\frac{\color{blue}{\mathsf{fma}\left(\sqrt{x}, \sqrt{x}, -1\right)}}{y}\right)
\] |
metadata-eval [<=]60.0% | \[ 1 - \log \left(\frac{\mathsf{fma}\left(\sqrt{x}, \sqrt{x}, \color{blue}{-1}\right)}{y}\right)
\] |
fma-neg [<=]60.0% | \[ 1 - \log \left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x} - 1}}{y}\right)
\] |
add-sqr-sqrt [<=]100.0% | \[ 1 - \log \left(\frac{\color{blue}{x} - 1}{y}\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 7492 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.3% |
| Cost | 7181 |
| Alternative 3 | |
|---|---|
| Accuracy | 82.7% |
| Cost | 7117 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7113 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7113 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.8% |
| Cost | 6852 |
| Alternative 7 | |
|---|---|
| Accuracy | 62.1% |
| Cost | 6720 |
| Alternative 8 | |
|---|---|
| Accuracy | 62.1% |
| Cost | 6656 |
| Alternative 9 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 448 |
| Alternative 10 | |
|---|---|
| Accuracy | 42.4% |
| Cost | 192 |
| Alternative 11 | |
|---|---|
| Accuracy | 42.1% |
| Cost | 64 |
herbie shell --seed 2023165
(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))))))