| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 7241 |
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
:precision binary64
(if (or (<= y -3500000000.0) (not (<= y 7.2e+14)))
(- 1.0 (log (/ (+ -1.0 x) y)))
(-
1.0
(log1p
(*
(/ (+ (* y (- 1.0 y)) (* x (+ y -1.0))) (* (- 1.0 y) (- 1.0 (* y y))))
(+ 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 <= -3500000000.0) || !(y <= 7.2e+14)) {
tmp = 1.0 - log(((-1.0 + x) / y));
} else {
tmp = 1.0 - log1p(((((y * (1.0 - y)) + (x * (y + -1.0))) / ((1.0 - y) * (1.0 - (y * y)))) * (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 <= -3500000000.0) || !(y <= 7.2e+14)) {
tmp = 1.0 - Math.log(((-1.0 + x) / y));
} else {
tmp = 1.0 - Math.log1p(((((y * (1.0 - y)) + (x * (y + -1.0))) / ((1.0 - y) * (1.0 - (y * y)))) * (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 <= -3500000000.0) or not (y <= 7.2e+14): tmp = 1.0 - math.log(((-1.0 + x) / y)) else: tmp = 1.0 - math.log1p(((((y * (1.0 - y)) + (x * (y + -1.0))) / ((1.0 - y) * (1.0 - (y * y)))) * (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 <= -3500000000.0) || !(y <= 7.2e+14)) tmp = Float64(1.0 - log(Float64(Float64(-1.0 + x) / y))); else tmp = Float64(1.0 - log1p(Float64(Float64(Float64(Float64(y * Float64(1.0 - y)) + Float64(x * Float64(y + -1.0))) / Float64(Float64(1.0 - y) * Float64(1.0 - Float64(y * y)))) * 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[Or[LessEqual[y, -3500000000.0], N[Not[LessEqual[y, 7.2e+14]], $MachinePrecision]], N[(1.0 - N[Log[N[(N[(-1.0 + x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Log[1 + N[(N[(N[(N[(y * N[(1.0 - y), $MachinePrecision]), $MachinePrecision] + N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - y), $MachinePrecision] * N[(1.0 - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 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 -3500000000 \lor \neg \left(y \leq 7.2 \cdot 10^{+14}\right):\\
\;\;\;\;1 - \log \left(\frac{-1 + x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y \cdot \left(1 - y\right) + x \cdot \left(y + -1\right)}{\left(1 - y\right) \cdot \left(1 - y \cdot y\right)} \cdot \left(y + 1\right)\right)\\
\end{array}
Results
| Original | 70.8% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
if y < -3.5e9 or 7.2e14 < y Initial program 27.0%
Simplified27.0%
[Start]27.0 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]27.0 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]27.0 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]27.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]27.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]27.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]27.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 [=>]27.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]27.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]27.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in y around inf 25.1%
Simplified25.1%
[Start]25.1 | \[ 1 - \left(\log \left(\frac{1}{y}\right) + \log \left(x - 1\right)\right)
\] |
|---|---|
+-commutative [=>]25.1 | \[ 1 - \color{blue}{\left(\log \left(x - 1\right) + \log \left(\frac{1}{y}\right)\right)}
\] |
log-rec [=>]25.1 | \[ 1 - \left(\log \left(x - 1\right) + \color{blue}{\left(-\log y\right)}\right)
\] |
unsub-neg [=>]25.1 | \[ 1 - \color{blue}{\left(\log \left(x - 1\right) - \log y\right)}
\] |
sub-neg [=>]25.1 | \[ 1 - \left(\log \color{blue}{\left(x + \left(-1\right)\right)} - \log y\right)
\] |
metadata-eval [=>]25.1 | \[ 1 - \left(\log \left(x + \color{blue}{-1}\right) - \log y\right)
\] |
+-commutative [=>]25.1 | \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right)
\] |
Taylor expanded in y around 0 25.1%
Simplified99.9%
[Start]25.1 | \[ 1 - \left(\log \left(x - 1\right) - \log y\right)
\] |
|---|---|
sub-neg [=>]25.1 | \[ 1 - \left(\log \color{blue}{\left(x + \left(-1\right)\right)} - \log y\right)
\] |
metadata-eval [=>]25.1 | \[ 1 - \left(\log \left(x + \color{blue}{-1}\right) - \log y\right)
\] |
+-commutative [<=]25.1 | \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right)
\] |
log-div [<=]99.9 | \[ 1 - \color{blue}{\log \left(\frac{-1 + x}{y}\right)}
\] |
if -3.5e9 < y < 7.2e14Initial 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)}
\] |
div-sub [=>]99.8 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]99.8 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]99.8 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]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)
\] |
Applied egg-rr99.8%
[Start]99.8 | \[ 1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)
\] |
|---|---|
div-sub [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
frac-sub [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y \cdot \left(1 - y\right) - \left(1 - y\right) \cdot x}{\left(1 - y\right) \cdot \left(1 - y\right)}}\right)
\] |
flip-- [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\frac{y \cdot \left(1 - y\right) - \left(1 - y\right) \cdot x}{\left(1 - y\right) \cdot \color{blue}{\frac{1 \cdot 1 - y \cdot y}{1 + y}}}\right)
\] |
associate-*r/ [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\frac{y \cdot \left(1 - y\right) - \left(1 - y\right) \cdot x}{\color{blue}{\frac{\left(1 - y\right) \cdot \left(1 \cdot 1 - y \cdot y\right)}{1 + y}}}\right)
\] |
associate-/r/ [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y \cdot \left(1 - y\right) - \left(1 - y\right) \cdot x}{\left(1 - y\right) \cdot \left(1 \cdot 1 - y \cdot y\right)} \cdot \left(1 + y\right)}\right)
\] |
*-commutative [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\frac{y \cdot \left(1 - y\right) - \color{blue}{x \cdot \left(1 - y\right)}}{\left(1 - y\right) \cdot \left(1 \cdot 1 - y \cdot y\right)} \cdot \left(1 + y\right)\right)
\] |
metadata-eval [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\frac{y \cdot \left(1 - y\right) - x \cdot \left(1 - y\right)}{\left(1 - y\right) \cdot \left(\color{blue}{1} - y \cdot y\right)} \cdot \left(1 + y\right)\right)
\] |
+-commutative [=>]99.8 | \[ 1 - \mathsf{log1p}\left(\frac{y \cdot \left(1 - y\right) - x \cdot \left(1 - y\right)}{\left(1 - y\right) \cdot \left(1 - y \cdot y\right)} \cdot \color{blue}{\left(y + 1\right)}\right)
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 7241 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 7113 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 7048 |
| Alternative 5 | |
|---|---|
| Accuracy | 84.5% |
| Cost | 6984 |
| Alternative 6 | |
|---|---|
| Accuracy | 59.4% |
| Cost | 6788 |
| Alternative 7 | |
|---|---|
| Accuracy | 78.6% |
| Cost | 6788 |
| Alternative 8 | |
|---|---|
| Accuracy | 42.3% |
| Cost | 64 |
herbie shell --seed 2023137
(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))))))