| Alternative 1 | |
|---|---|
| Error | 18.1 |
| Cost | 7620 |
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
:precision binary64
(if (<= y -1.78)
(- 1.0 (log (/ (+ x -1.0) y)))
(if (<= y 0.055)
(- 1.0 (+ y (log1p (- x))))
(- 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 (y <= -1.78) {
tmp = 1.0 - log(((x + -1.0) / y));
} else if (y <= 0.055) {
tmp = 1.0 - (y + log1p(-x));
} 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 (y <= -1.78) {
tmp = 1.0 - Math.log(((x + -1.0) / y));
} else if (y <= 0.055) {
tmp = 1.0 - (y + Math.log1p(-x));
} 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 y <= -1.78: tmp = 1.0 - math.log(((x + -1.0) / y)) elif y <= 0.055: tmp = 1.0 - (y + math.log1p(-x)) 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 (y <= -1.78) tmp = Float64(1.0 - log(Float64(Float64(x + -1.0) / y))); elseif (y <= 0.055) tmp = Float64(1.0 - Float64(y + log1p(Float64(-x)))); else tmp = Float64(1.0 - log(Float64(Float64(-x) / Float64(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[y, -1.78], N[(1.0 - N[Log[N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.055], N[(1.0 - N[(y + N[Log[1 + (-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Log[N[((-x) / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
\mathbf{if}\;y \leq -1.78:\\
\;\;\;\;1 - \log \left(\frac{x + -1}{y}\right)\\
\mathbf{elif}\;y \leq 0.055:\\
\;\;\;\;1 - \left(y + \mathsf{log1p}\left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \log \left(\frac{-x}{1 - y}\right)\\
\end{array}
Results
| Original | 18.6 |
|---|---|
| Target | 0.1 |
| Herbie | 0.7 |
if y < -1.78000000000000003Initial program 50.5
Simplified50.5
[Start]50.5 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]50.5 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]50.5 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]50.5 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]50.5 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]50.5 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]50.5 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]50.5 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]50.5 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]50.5 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in y around inf 64.0
Simplified64.0
[Start]64.0 | \[ 1 - \left(\log \left(\frac{1}{y}\right) + \log \left(x - 1\right)\right)
\] |
|---|---|
+-commutative [=>]64.0 | \[ 1 - \color{blue}{\left(\log \left(x - 1\right) + \log \left(\frac{1}{y}\right)\right)}
\] |
log-rec [=>]64.0 | \[ 1 - \left(\log \left(x - 1\right) + \color{blue}{\left(-\log y\right)}\right)
\] |
unsub-neg [=>]64.0 | \[ 1 - \color{blue}{\left(\log \left(x - 1\right) - \log y\right)}
\] |
sub-neg [=>]64.0 | \[ 1 - \left(\log \color{blue}{\left(x + \left(-1\right)\right)} - \log y\right)
\] |
metadata-eval [=>]64.0 | \[ 1 - \left(\log \left(x + \color{blue}{-1}\right) - \log y\right)
\] |
+-commutative [=>]64.0 | \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right)
\] |
Taylor expanded in y around 0 64.0
Simplified1.0
[Start]64.0 | \[ 1 - \left(\log \left(x - 1\right) - \log y\right)
\] |
|---|---|
sub-neg [=>]64.0 | \[ 1 - \left(\log \color{blue}{\left(x + \left(-1\right)\right)} - \log y\right)
\] |
metadata-eval [=>]64.0 | \[ 1 - \left(\log \left(x + \color{blue}{-1}\right) - \log y\right)
\] |
+-commutative [<=]64.0 | \[ 1 - \left(\log \color{blue}{\left(-1 + x\right)} - \log y\right)
\] |
log-div [<=]1.0 | \[ 1 - \color{blue}{\log \left(\frac{-1 + x}{y}\right)}
\] |
+-commutative [=>]1.0 | \[ 1 - \log \left(\frac{\color{blue}{x + -1}}{y}\right)
\] |
metadata-eval [<=]1.0 | \[ 1 - \log \left(\frac{x + \color{blue}{\left(-1\right)}}{y}\right)
\] |
sub-neg [<=]1.0 | \[ 1 - \log \left(\frac{\color{blue}{x - 1}}{y}\right)
\] |
if -1.78000000000000003 < y < 0.0550000000000000003Initial program 0.0
Simplified0.0
[Start]0.0 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]0.0 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]0.0 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]0.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]0.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]0.0 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]0.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 [=>]0.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]0.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]0.0 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in y around 0 0.4
Simplified0.4
[Start]0.4 | \[ 1 - \left(y \cdot \left(\frac{1}{1 + -1 \cdot x} - \frac{x}{1 + -1 \cdot x}\right) + \log \left(1 + -1 \cdot x\right)\right)
\] |
|---|---|
+-commutative [=>]0.4 | \[ 1 - \color{blue}{\left(\log \left(1 + -1 \cdot x\right) + y \cdot \left(\frac{1}{1 + -1 \cdot x} - \frac{x}{1 + -1 \cdot x}\right)\right)}
\] |
log1p-def [=>]0.4 | \[ 1 - \left(\color{blue}{\mathsf{log1p}\left(-1 \cdot x\right)} + y \cdot \left(\frac{1}{1 + -1 \cdot x} - \frac{x}{1 + -1 \cdot x}\right)\right)
\] |
mul-1-neg [=>]0.4 | \[ 1 - \left(\mathsf{log1p}\left(\color{blue}{-x}\right) + y \cdot \left(\frac{1}{1 + -1 \cdot x} - \frac{x}{1 + -1 \cdot x}\right)\right)
\] |
*-commutative [=>]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \color{blue}{\left(\frac{1}{1 + -1 \cdot x} - \frac{x}{1 + -1 \cdot x}\right) \cdot y}\right)
\] |
mul-1-neg [=>]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \left(\frac{1}{1 + \color{blue}{\left(-x\right)}} - \frac{x}{1 + -1 \cdot x}\right) \cdot y\right)
\] |
sub-neg [<=]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \left(\frac{1}{\color{blue}{1 - x}} - \frac{x}{1 + -1 \cdot x}\right) \cdot y\right)
\] |
mul-1-neg [=>]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \left(\frac{1}{1 - x} - \frac{x}{1 + \color{blue}{\left(-x\right)}}\right) \cdot y\right)
\] |
sub-neg [<=]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \left(\frac{1}{1 - x} - \frac{x}{\color{blue}{1 - x}}\right) \cdot y\right)
\] |
div-sub [<=]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \color{blue}{\frac{1 - x}{1 - x}} \cdot y\right)
\] |
*-inverses [=>]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \color{blue}{1} \cdot y\right)
\] |
metadata-eval [<=]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \color{blue}{\left(--1\right)} \cdot y\right)
\] |
distribute-lft-neg-in [<=]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \color{blue}{\left(--1 \cdot y\right)}\right)
\] |
neg-mul-1 [<=]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \left(-\color{blue}{\left(-y\right)}\right)\right)
\] |
remove-double-neg [=>]0.4 | \[ 1 - \left(\mathsf{log1p}\left(-x\right) + \color{blue}{y}\right)
\] |
if 0.0550000000000000003 < y Initial program 31.2
Simplified31.2
[Start]31.2 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]31.2 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]31.2 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]31.2 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]31.2 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]31.2 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]31.2 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]31.2 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]31.2 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]31.2 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Taylor expanded in x around inf 30.3
Simplified30.3
[Start]30.3 | \[ 1 - \mathsf{log1p}\left(-1 \cdot \frac{x}{1 - y}\right)
\] |
|---|---|
mul-1-neg [=>]30.3 | \[ 1 - \mathsf{log1p}\left(\color{blue}{-\frac{x}{1 - y}}\right)
\] |
distribute-neg-frac [=>]30.3 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{-x}{1 - y}}\right)
\] |
Taylor expanded in x around inf 3.0
Simplified1.7
[Start]3.0 | \[ 1 - \left(\log \left(-\frac{1}{1 - y}\right) + -1 \cdot \log \left(\frac{1}{x}\right)\right)
\] |
|---|---|
+-commutative [=>]3.0 | \[ 1 - \color{blue}{\left(-1 \cdot \log \left(\frac{1}{x}\right) + \log \left(-\frac{1}{1 - y}\right)\right)}
\] |
distribute-neg-frac [=>]3.0 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log \color{blue}{\left(\frac{-1}{1 - y}\right)}\right)
\] |
metadata-eval [=>]3.0 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \log \left(\frac{\color{blue}{-1}}{1 - y}\right)\right)
\] |
log-div [=>]64.0 | \[ 1 - \left(-1 \cdot \log \left(\frac{1}{x}\right) + \color{blue}{\left(\log -1 - \log \left(1 - y\right)\right)}\right)
\] |
associate-+r- [=>]64.0 | \[ 1 - \color{blue}{\left(\left(-1 \cdot \log \left(\frac{1}{x}\right) + \log -1\right) - \log \left(1 - y\right)\right)}
\] |
mul-1-neg [=>]64.0 | \[ 1 - \left(\left(\color{blue}{\left(-\log \left(\frac{1}{x}\right)\right)} + \log -1\right) - \log \left(1 - y\right)\right)
\] |
log-rec [=>]64.0 | \[ 1 - \left(\left(\left(-\color{blue}{\left(-\log x\right)}\right) + \log -1\right) - \log \left(1 - y\right)\right)
\] |
remove-double-neg [=>]64.0 | \[ 1 - \left(\left(\color{blue}{\log x} + \log -1\right) - \log \left(1 - y\right)\right)
\] |
log-prod [<=]63.5 | \[ 1 - \left(\color{blue}{\log \left(x \cdot -1\right)} - \log \left(1 - y\right)\right)
\] |
*-commutative [<=]63.5 | \[ 1 - \left(\log \color{blue}{\left(-1 \cdot x\right)} - \log \left(1 - y\right)\right)
\] |
log-div [<=]1.7 | \[ 1 - \color{blue}{\log \left(\frac{-1 \cdot x}{1 - y}\right)}
\] |
mul-1-neg [=>]1.7 | \[ 1 - \log \left(\frac{\color{blue}{-x}}{1 - y}\right)
\] |
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 18.1 |
| Cost | 7620 |
| Alternative 2 | |
|---|---|
| Error | 18.6 |
| Cost | 7492 |
| Alternative 3 | |
|---|---|
| Error | 0.7 |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Error | 7.0 |
| Cost | 7048 |
| Alternative 5 | |
|---|---|
| Error | 7.4 |
| Cost | 6984 |
| Alternative 6 | |
|---|---|
| Error | 13.3 |
| Cost | 6852 |
| Alternative 7 | |
|---|---|
| Error | 24.0 |
| Cost | 6656 |
| Alternative 8 | |
|---|---|
| Error | 35.2 |
| Cost | 448 |
| Alternative 9 | |
|---|---|
| Error | 36.3 |
| Cost | 64 |
herbie shell --seed 2023031
(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))))))