| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 1993 |
(FPCore (x y) :precision binary64 (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (+ -1.0 x) (* y y))))
(if (or (<= y -13200.0) (not (<= y 14200.0)))
(+ (+ t_0 (- x (* t_0 (/ 1.0 y)))) (/ (- 1.0 x) y))
(fma (/ (+ -1.0 x) (+ y 1.0)) y 1.0))))double code(double x, double y) {
return 1.0 - (((1.0 - x) * y) / (y + 1.0));
}
double code(double x, double y) {
double t_0 = (-1.0 + x) / (y * y);
double tmp;
if ((y <= -13200.0) || !(y <= 14200.0)) {
tmp = (t_0 + (x - (t_0 * (1.0 / y)))) + ((1.0 - x) / y);
} else {
tmp = fma(((-1.0 + x) / (y + 1.0)), y, 1.0);
}
return tmp;
}
function code(x, y) return Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0))) end
function code(x, y) t_0 = Float64(Float64(-1.0 + x) / Float64(y * y)) tmp = 0.0 if ((y <= -13200.0) || !(y <= 14200.0)) tmp = Float64(Float64(t_0 + Float64(x - Float64(t_0 * Float64(1.0 / y)))) + Float64(Float64(1.0 - x) / y)); else tmp = fma(Float64(Float64(-1.0 + x) / Float64(y + 1.0)), y, 1.0); end return tmp end
code[x_, y_] := N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(-1.0 + x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[y, -13200.0], N[Not[LessEqual[y, 14200.0]], $MachinePrecision]], N[(N[(t$95$0 + N[(x - N[(t$95$0 * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 + x), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision] * y + 1.0), $MachinePrecision]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{-1 + x}{y \cdot y}\\
\mathbf{if}\;y \leq -13200 \lor \neg \left(y \leq 14200\right):\\
\;\;\;\;\left(t_0 + \left(x - t_0 \cdot \frac{1}{y}\right)\right) + \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1 + x}{y + 1}, y, 1\right)\\
\end{array}
| Original | 22.4 |
|---|---|
| Target | 0.2 |
| Herbie | 0.0 |
if y < -13200 or 14200 < y Initial program 45.4
Simplified29.3
[Start]45.4 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]45.4 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]45.4 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
neg-mul-1 [=>]45.4 | \[ \color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}} + 1
\] |
associate-*l/ [<=]29.3 | \[ -1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)} + 1
\] |
associate-*r* [=>]29.3 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y} + 1
\] |
fma-def [=>]29.3 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{1 - x}{y + 1}, y, 1\right)}
\] |
associate-*r/ [=>]29.3 | \[ \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{y + 1}}, y, 1\right)
\] |
neg-mul-1 [<=]29.3 | \[ \mathsf{fma}\left(\frac{\color{blue}{-\left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
neg-sub0 [=>]29.3 | \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
associate--r- [=>]29.3 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right)
\] |
metadata-eval [=>]29.3 | \[ \mathsf{fma}\left(\frac{\color{blue}{-1} + x}{y + 1}, y, 1\right)
\] |
+-commutative [<=]29.3 | \[ \mathsf{fma}\left(\frac{\color{blue}{x + -1}}{y + 1}, y, 1\right)
\] |
+-commutative [=>]29.3 | \[ \mathsf{fma}\left(\frac{x + -1}{\color{blue}{1 + y}}, y, 1\right)
\] |
Taylor expanded in y around -inf 0.0
Simplified0.0
[Start]0.0 | \[ \left(\frac{1}{y} + \left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right)\right) - \left(\frac{x}{{y}^{3}} + \frac{x}{y}\right)
\] |
|---|---|
associate--l+ [=>]0.0 | \[ \color{blue}{\frac{1}{y} + \left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \left(\frac{x}{{y}^{3}} + \frac{x}{y}\right)\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{\left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \left(\frac{x}{{y}^{3}} + \frac{x}{y}\right)\right) + \frac{1}{y}}
\] |
associate--r+ [=>]0.0 | \[ \color{blue}{\left(\left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \frac{x}{{y}^{3}}\right) - \frac{x}{y}\right)} + \frac{1}{y}
\] |
associate-+l- [=>]0.0 | \[ \color{blue}{\left(\left(\frac{1}{{y}^{3}} + \left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \frac{x}{{y}^{3}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)}
\] |
Applied egg-rr0.0
if -13200 < y < 14200Initial program 0.0
Simplified0.0
[Start]0.0 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]0.0 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
neg-mul-1 [=>]0.0 | \[ \color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}} + 1
\] |
associate-*l/ [<=]0.0 | \[ -1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)} + 1
\] |
associate-*r* [=>]0.0 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y} + 1
\] |
fma-def [=>]0.0 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{1 - x}{y + 1}, y, 1\right)}
\] |
associate-*r/ [=>]0.0 | \[ \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{y + 1}}, y, 1\right)
\] |
neg-mul-1 [<=]0.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{-\left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
neg-sub0 [=>]0.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
associate--r- [=>]0.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right)
\] |
metadata-eval [=>]0.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{-1} + x}{y + 1}, y, 1\right)
\] |
+-commutative [<=]0.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{x + -1}}{y + 1}, y, 1\right)
\] |
+-commutative [=>]0.0 | \[ \mathsf{fma}\left(\frac{x + -1}{\color{blue}{1 + y}}, y, 1\right)
\] |
Final simplification0.0
| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 1993 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 1092 |
| Alternative 3 | |
|---|---|
| Error | 0.2 |
| Cost | 968 |
| Alternative 4 | |
|---|---|
| Error | 1.1 |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Error | 1.0 |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 16.4 |
| Cost | 588 |
| Alternative 7 | |
|---|---|
| Error | 8.8 |
| Cost | 585 |
| Alternative 8 | |
|---|---|
| Error | 1.3 |
| Cost | 585 |
| Alternative 9 | |
|---|---|
| Error | 16.3 |
| Cost | 456 |
| Alternative 10 | |
|---|---|
| Error | 16.5 |
| Cost | 328 |
| Alternative 11 | |
|---|---|
| Error | 39.2 |
| Cost | 64 |
herbie shell --seed 2023237
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, D"
:precision binary64
:herbie-target
(if (< y -3693.8482788297247) (- (/ 1.0 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) (- (/ 1.0 y) (- (/ x y) x))))
(- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))