| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 6976 |
\[1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)
\]

(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y) :precision binary64 (- 1.0 (log1p (/ (- y 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) {
return 1.0 - log1p(((y - x) / (1.0 - y)));
}
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) {
return 1.0 - Math.log1p(((y - x) / (1.0 - y)));
}
def code(x, y): return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
def code(x, y): return 1.0 - math.log1p(((y - x) / (1.0 - y)))
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) return Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y)))) 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_] := N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 99.4% |
|---|---|
| Target | 99.8% |
| Herbie | 99.5% |
Initial 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)
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 6976 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 6912 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.9% |
| Cost | 6784 |
| Alternative 4 | |
|---|---|
| Accuracy | 66.2% |
| Cost | 6724 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.1% |
| Cost | 6656 |
| Alternative 6 | |
|---|---|
| Accuracy | 63.7% |
| Cost | 576 |
| Alternative 7 | |
|---|---|
| Accuracy | 63.6% |
| Cost | 192 |
herbie shell --seed 2023277
(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))))))