| Alternative 1 | |
|---|---|
| Error | 0.2% |
| Cost | 13449 |
(FPCore (x y) :precision binary64 (- 1.0 (log (- 1.0 (/ (- x y) (- 1.0 y))))))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ x -1.0) y)))
(if (<= y -750000.0)
(log (/ E (+ (/ t_0 y) t_0)))
(if (<= y 54000000000000.0)
(- 1.0 (log1p (/ (- y x) (- 1.0 y))))
(log (/ (* y E) (+ x -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 t_0 = (x + -1.0) / y;
double tmp;
if (y <= -750000.0) {
tmp = log((((double) M_E) / ((t_0 / y) + t_0)));
} else if (y <= 54000000000000.0) {
tmp = 1.0 - log1p(((y - x) / (1.0 - y)));
} else {
tmp = log(((y * ((double) M_E)) / (x + -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 t_0 = (x + -1.0) / y;
double tmp;
if (y <= -750000.0) {
tmp = Math.log((Math.E / ((t_0 / y) + t_0)));
} else if (y <= 54000000000000.0) {
tmp = 1.0 - Math.log1p(((y - x) / (1.0 - y)));
} else {
tmp = Math.log(((y * Math.E) / (x + -1.0)));
}
return tmp;
}
def code(x, y): return 1.0 - math.log((1.0 - ((x - y) / (1.0 - y))))
def code(x, y): t_0 = (x + -1.0) / y tmp = 0 if y <= -750000.0: tmp = math.log((math.e / ((t_0 / y) + t_0))) elif y <= 54000000000000.0: tmp = 1.0 - math.log1p(((y - x) / (1.0 - y))) else: tmp = math.log(((y * math.e) / (x + -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) t_0 = Float64(Float64(x + -1.0) / y) tmp = 0.0 if (y <= -750000.0) tmp = log(Float64(exp(1) / Float64(Float64(t_0 / y) + t_0))); elseif (y <= 54000000000000.0) tmp = Float64(1.0 - log1p(Float64(Float64(y - x) / Float64(1.0 - y)))); else tmp = log(Float64(Float64(y * exp(1)) / Float64(x + -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_] := Block[{t$95$0 = N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[y, -750000.0], N[Log[N[(E / N[(N[(t$95$0 / y), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[y, 54000000000000.0], N[(1.0 - N[Log[1 + N[(N[(y - x), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Log[N[(N[(y * E), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\begin{array}{l}
t_0 := \frac{x + -1}{y}\\
\mathbf{if}\;y \leq -750000:\\
\;\;\;\;\log \left(\frac{e}{\frac{t_0}{y} + t_0}\right)\\
\mathbf{elif}\;y \leq 54000000000000:\\
\;\;\;\;1 - \mathsf{log1p}\left(\frac{y - x}{1 - y}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{y \cdot e}{x + -1}\right)\\
\end{array}
Results
| Original | 28.1% |
|---|---|
| Target | 0.17% |
| Herbie | 0.09% |
if y < -7.5e5Initial program 81.45
Simplified81.45
[Start]81.45 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]81.45 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]81.45 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]81.42 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]81.42 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]81.42 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]81.42 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]81.42 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]81.42 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]81.45 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Applied egg-rr81.44
Taylor expanded in y around -inf 0.13
Simplified0.13
[Start]0.13 | \[ \log \left(\frac{e}{\left(\frac{x}{y} + -1 \cdot \frac{1 - x}{{y}^{2}}\right) - \frac{1}{y}}\right)
\] |
|---|---|
+-commutative [=>]0.13 | \[ \log \left(\frac{e}{\color{blue}{\left(-1 \cdot \frac{1 - x}{{y}^{2}} + \frac{x}{y}\right)} - \frac{1}{y}}\right)
\] |
associate--l+ [=>]0.13 | \[ \log \left(\frac{e}{\color{blue}{-1 \cdot \frac{1 - x}{{y}^{2}} + \left(\frac{x}{y} - \frac{1}{y}\right)}}\right)
\] |
associate-*r/ [=>]0.13 | \[ \log \left(\frac{e}{\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{{y}^{2}}} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
unpow2 [=>]0.13 | \[ \log \left(\frac{e}{\frac{-1 \cdot \left(1 - x\right)}{\color{blue}{y \cdot y}} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
associate-/r* [=>]0.13 | \[ \log \left(\frac{e}{\color{blue}{\frac{\frac{-1 \cdot \left(1 - x\right)}{y}}{y}} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
sub-neg [=>]0.13 | \[ \log \left(\frac{e}{\frac{\frac{-1 \cdot \color{blue}{\left(1 + \left(-x\right)\right)}}{y}}{y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
mul-1-neg [<=]0.13 | \[ \log \left(\frac{e}{\frac{\frac{-1 \cdot \left(1 + \color{blue}{-1 \cdot x}\right)}{y}}{y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
associate-*r/ [<=]0.13 | \[ \log \left(\frac{e}{\frac{\color{blue}{-1 \cdot \frac{1 + -1 \cdot x}{y}}}{y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
mul-1-neg [=>]0.13 | \[ \log \left(\frac{e}{\frac{\color{blue}{-\frac{1 + -1 \cdot x}{y}}}{y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
distribute-neg-frac [=>]0.13 | \[ \log \left(\frac{e}{\frac{\color{blue}{\frac{-\left(1 + -1 \cdot x\right)}{y}}}{y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
mul-1-neg [=>]0.13 | \[ \log \left(\frac{e}{\frac{\frac{-\left(1 + \color{blue}{\left(-x\right)}\right)}{y}}{y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
sub-neg [<=]0.13 | \[ \log \left(\frac{e}{\frac{\frac{-\color{blue}{\left(1 - x\right)}}{y}}{y} + \left(\frac{x}{y} - \frac{1}{y}\right)}\right)
\] |
div-sub [<=]0.13 | \[ \log \left(\frac{e}{\frac{\frac{-\left(1 - x\right)}{y}}{y} + \color{blue}{\frac{x - 1}{y}}}\right)
\] |
sub-neg [=>]0.13 | \[ \log \left(\frac{e}{\frac{\frac{-\left(1 - x\right)}{y}}{y} + \frac{\color{blue}{x + \left(-1\right)}}{y}}\right)
\] |
metadata-eval [=>]0.13 | \[ \log \left(\frac{e}{\frac{\frac{-\left(1 - x\right)}{y}}{y} + \frac{x + \color{blue}{-1}}{y}}\right)
\] |
if -7.5e5 < y < 5.4e13Initial program 0.08
Simplified0.04
[Start]0.08 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]0.08 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]0.04 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]0.04 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]0.04 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]0.04 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]0.04 | \[ 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.04 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]0.04 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]0.04 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
if 5.4e13 < y Initial program 46.89
Simplified46.89
[Start]46.89 | \[ 1 - \log \left(1 - \frac{x - y}{1 - y}\right)
\] |
|---|---|
sub-neg [=>]46.89 | \[ 1 - \log \color{blue}{\left(1 + \left(-\frac{x - y}{1 - y}\right)\right)}
\] |
log1p-def [=>]46.89 | \[ 1 - \color{blue}{\mathsf{log1p}\left(-\frac{x - y}{1 - y}\right)}
\] |
div-sub [=>]46.85 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} - \frac{y}{1 - y}\right)}\right)
\] |
sub-neg [=>]46.85 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\frac{x}{1 - y} + \left(-\frac{y}{1 - y}\right)\right)}\right)
\] |
+-commutative [=>]46.85 | \[ 1 - \mathsf{log1p}\left(-\color{blue}{\left(\left(-\frac{y}{1 - y}\right) + \frac{x}{1 - y}\right)}\right)
\] |
distribute-neg-in [=>]46.85 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\left(-\left(-\frac{y}{1 - y}\right)\right) + \left(-\frac{x}{1 - y}\right)}\right)
\] |
remove-double-neg [=>]46.85 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y}} + \left(-\frac{x}{1 - y}\right)\right)
\] |
sub-neg [<=]46.85 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y}{1 - y} - \frac{x}{1 - y}}\right)
\] |
div-sub [<=]46.89 | \[ 1 - \mathsf{log1p}\left(\color{blue}{\frac{y - x}{1 - y}}\right)
\] |
Applied egg-rr46.89
Taylor expanded in y around -inf 0.26
Final simplification0.09
| Alternative 1 | |
|---|---|
| Error | 0.2% |
| Cost | 13449 |
| Alternative 2 | |
|---|---|
| Error | 9.15% |
| Cost | 7492 |
| Alternative 3 | |
|---|---|
| Error | 9.11% |
| Cost | 7240 |
| Alternative 4 | |
|---|---|
| Error | 10.22% |
| Cost | 7112 |
| Alternative 5 | |
|---|---|
| Error | 14.68% |
| Cost | 7048 |
| Alternative 6 | |
|---|---|
| Error | 15.3% |
| Cost | 6984 |
| Alternative 7 | |
|---|---|
| Error | 20.93% |
| Cost | 6852 |
| Alternative 8 | |
|---|---|
| Error | 37.01% |
| Cost | 6656 |
| Alternative 9 | |
|---|---|
| Error | 54.81% |
| Cost | 448 |
| Alternative 10 | |
|---|---|
| Error | 56.26% |
| Cost | 192 |
| Alternative 11 | |
|---|---|
| Error | 56.45% |
| Cost | 64 |
herbie shell --seed 2023089
(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))))))