| 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.999999998) (- 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.999999998) {
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.999999998) {
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.999999998: 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.999999998) 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.999999998], 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.999999998:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 72.3% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
if (/.f64 (-.f64 x y) (-.f64 1 y)) < 0.999999997999999946Initial program 99.6%
Simplified99.7%
[Start]99.6% | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]99.6% | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]99.7% | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
neg-sub0 [=>]99.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{0 - \frac{x - y}{1 - y}}\right)
\] |
div-sub [=>]99.7% | \[ 1 - \mathsf{log1p}\left(0 - \color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
associate--r- [=>]99.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(0 - \frac{x}{1 - y}\right) + \frac{y}{1 - y}}\right)
\] |
neg-sub0 [<=]99.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\frac{x}{1 - y}\right)} + \frac{y}{1 - y}\right)
\] |
+-commutative [=>]99.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} + \left(-\frac{x}{1 - y}\right)}\right)
\] |
sub-neg [<=]99.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]99.7% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
if 0.999999997999999946 < (/.f64 (-.f64 x y) (-.f64 1 y)) Initial program 4.1%
Simplified4.1%
[Start]4.1% | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]4.1% | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]4.1% | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
neg-sub0 [=>]4.1% | \[ 1 - \mathsf{log1p}\left(\color{blue}{0 - \frac{x - y}{1 - y}}\right)
\] |
div-sub [=>]4.2% | \[ 1 - \mathsf{log1p}\left(0 - \color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
associate--r- [=>]4.2% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(0 - \frac{x}{1 - y}\right) + \frac{y}{1 - y}}\right)
\] |
neg-sub0 [<=]4.2% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\frac{x}{1 - y}\right)} + \frac{y}{1 - y}\right)
\] |
+-commutative [=>]4.2% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} + \left(-\frac{x}{1 - y}\right)}\right)
\] |
sub-neg [<=]4.2% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]4.1% | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in y around -inf 85.8%
Simplified85.8%
[Start]85.8% | \[ 1 - \left(\log \left(-1 \cdot \left(x - 1\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
|---|---|
sub-neg [=>]85.8% | \[ 1 - \left(\log \left(-1 \cdot \color{blue}{\left(x + \left(-1\right)\right)}\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
metadata-eval [=>]85.8% | \[ 1 - \left(\log \left(-1 \cdot \left(x + \color{blue}{-1}\right)\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
distribute-lft-in [=>]85.8% | \[ 1 - \left(\log \color{blue}{\left(-1 \cdot x + -1 \cdot -1\right)} + \log \left(\frac{-1}{y}\right)\right)
\] |
metadata-eval [=>]85.8% | \[ 1 - \left(\log \left(-1 \cdot x + \color{blue}{1}\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
+-commutative [<=]85.8% | \[ 1 - \left(\log \color{blue}{\left(1 + -1 \cdot x\right)} + \log \left(\frac{-1}{y}\right)\right)
\] |
log1p-def [=>]85.8% | \[ 1 - \left(\color{blue}{\mathsf{log1p}\left(-1 \cdot x\right)} + \log \left(\frac{-1}{y}\right)\right)
\] |
mul-1-neg [=>]85.8% | \[ 1 - \left(\mathsf{log1p}\left(\color{blue}{-x}\right) + \log \left(\frac{-1}{y}\right)\right)
\] |
Taylor expanded in y around 0 0.0%
Simplified99.9%
[Start]0.0% | \[ 1 - \left(\log -1 + \left(\log \left(1 - x\right) + -1 \cdot \log y\right)\right)
\] |
|---|---|
neg-mul-1 [<=]0.0% | \[ 1 - \left(\log -1 + \left(\log \left(1 - x\right) + \color{blue}{\left(-\log y\right)}\right)\right)
\] |
log-rec [<=]0.0% | \[ 1 - \left(\log -1 + \left(\log \left(1 - x\right) + \color{blue}{\log \left(\frac{1}{y}\right)}\right)\right)
\] |
+-commutative [=>]0.0% | \[ 1 - \left(\log -1 + \color{blue}{\left(\log \left(\frac{1}{y}\right) + \log \left(1 - x\right)\right)}\right)
\] |
associate-+r+ [=>]0.0% | \[ 1 - \color{blue}{\left(\left(\log -1 + \log \left(\frac{1}{y}\right)\right) + \log \left(1 - x\right)\right)}
\] |
log-rec [=>]0.0% | \[ 1 - \left(\left(\log -1 + \color{blue}{\left(-\log y\right)}\right) + \log \left(1 - x\right)\right)
\] |
sub-neg [<=]0.0% | \[ 1 - \left(\color{blue}{\left(\log -1 - \log y\right)} + \log \left(1 - x\right)\right)
\] |
log-div [<=]85.8% | \[ 1 - \left(\color{blue}{\log \left(\frac{-1}{y}\right)} + \log \left(1 - x\right)\right)
\] |
log-prod [<=]99.9% | \[ 1 - \color{blue}{\log \left(\frac{-1}{y} \cdot \left(1 - x\right)\right)}
\] |
associate-*l/ [=>]99.9% | \[ 1 - \log \color{blue}{\left(\frac{-1 \cdot \left(1 - x\right)}{y}\right)}
\] |
mul-1-neg [=>]99.9% | \[ 1 - \log \left(\frac{\color{blue}{-\left(1 - x\right)}}{y}\right)
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 7492 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 7177 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Accuracy | 79.7% |
| Cost | 6916 |
| Alternative 5 | |
|---|---|
| Accuracy | 79.1% |
| Cost | 6852 |
| Alternative 6 | |
|---|---|
| Accuracy | 62.5% |
| Cost | 6656 |
| Alternative 7 | |
|---|---|
| Accuracy | 5.6% |
| Cost | 704 |
herbie shell --seed 2023263
(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))))))