| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 1092 |
(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)))
(if (<= y -220000.0)
(+ (+ x (/ (+ x -1.0) (* y y))) t_0)
(if (<= y 205000000.0) (fma (/ y (+ y 1.0)) (+ x -1.0) 1.0) (+ x t_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;
double tmp;
if (y <= -220000.0) {
tmp = (x + ((x + -1.0) / (y * y))) + t_0;
} else if (y <= 205000000.0) {
tmp = fma((y / (y + 1.0)), (x + -1.0), 1.0);
} else {
tmp = x + t_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) / y) tmp = 0.0 if (y <= -220000.0) tmp = Float64(Float64(x + Float64(Float64(x + -1.0) / Float64(y * y))) + t_0); elseif (y <= 205000000.0) tmp = fma(Float64(y / Float64(y + 1.0)), Float64(x + -1.0), 1.0); else tmp = Float64(x + t_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] / y), $MachinePrecision]}, If[LessEqual[y, -220000.0], N[(N[(x + N[(N[(x + -1.0), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[y, 205000000.0], N[(N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision], N[(x + t$95$0), $MachinePrecision]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{1 - x}{y}\\
\mathbf{if}\;y \leq -220000:\\
\;\;\;\;\left(x + \frac{x + -1}{y \cdot y}\right) + t_0\\
\mathbf{elif}\;y \leq 205000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{y + 1}, x + -1, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + t_0\\
\end{array}
| Original | 22.6 |
|---|---|
| Target | 0.2 |
| Herbie | 0.1 |
if y < -2.2e5Initial program 45.7
Simplified29.4
[Start]45.7 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]45.7 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]45.7 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
neg-mul-1 [=>]45.7 | \[ \color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}} + 1
\] |
associate-*l/ [<=]29.5 | \[ -1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)} + 1
\] |
associate-*r* [=>]29.5 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y} + 1
\] |
fma-def [=>]29.4 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{1 - x}{y + 1}, y, 1\right)}
\] |
associate-*r/ [=>]29.4 | \[ \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{y + 1}}, y, 1\right)
\] |
neg-mul-1 [<=]29.4 | \[ \mathsf{fma}\left(\frac{\color{blue}{-\left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
neg-sub0 [=>]29.4 | \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
associate--r- [=>]29.4 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right)
\] |
metadata-eval [=>]29.4 | \[ \mathsf{fma}\left(\frac{\color{blue}{-1} + x}{y + 1}, y, 1\right)
\] |
+-commutative [<=]29.4 | \[ \mathsf{fma}\left(\frac{\color{blue}{x + -1}}{y + 1}, y, 1\right)
\] |
+-commutative [=>]29.4 | \[ \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(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right)\right) - \frac{x}{y}
\] |
|---|---|
associate--l+ [=>]0.0 | \[ \color{blue}{\frac{1}{y} + \left(\left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right) - \frac{x}{y}\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{\left(\left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right) - \frac{x}{y}\right) + \frac{1}{y}}
\] |
associate-+l- [=>]0.0 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{{y}^{2}} + x\right) - \left(\frac{x}{y} - \frac{1}{y}\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{\left(x + -1 \cdot \frac{1 - x}{{y}^{2}}\right)} - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
associate-*r/ [=>]0.0 | \[ \left(x + \color{blue}{\frac{-1 \cdot \left(1 - x\right)}{{y}^{2}}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
sub-neg [=>]0.0 | \[ \left(x + \frac{-1 \cdot \color{blue}{\left(1 + \left(-x\right)\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-lft-in [=>]0.0 | \[ \left(x + \frac{\color{blue}{-1 \cdot 1 + -1 \cdot \left(-x\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
*-commutative [<=]0.0 | \[ \left(x + \frac{-1 \cdot 1 + \color{blue}{\left(-x\right) \cdot -1}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-lft-neg-in [<=]0.0 | \[ \left(x + \frac{-1 \cdot 1 + \color{blue}{\left(-x \cdot -1\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-rgt-neg-in [=>]0.0 | \[ \left(x + \frac{-1 \cdot 1 + \color{blue}{x \cdot \left(--1\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
metadata-eval [=>]0.0 | \[ \left(x + \frac{-1 \cdot 1 + x \cdot \color{blue}{1}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
distribute-rgt-in [<=]0.0 | \[ \left(x + \frac{\color{blue}{1 \cdot \left(-1 + x\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
+-commutative [<=]0.0 | \[ \left(x + \frac{1 \cdot \color{blue}{\left(x + -1\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
*-lft-identity [=>]0.0 | \[ \left(x + \frac{\color{blue}{x + -1}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
+-commutative [=>]0.0 | \[ \left(x + \frac{\color{blue}{-1 + x}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
unpow2 [=>]0.0 | \[ \left(x + \frac{-1 + x}{\color{blue}{y \cdot y}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
div-sub [<=]0.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \color{blue}{\frac{x - 1}{y}}
\] |
sub-neg [=>]0.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \frac{\color{blue}{x + \left(-1\right)}}{y}
\] |
metadata-eval [=>]0.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \frac{x + \color{blue}{-1}}{y}
\] |
+-commutative [=>]0.0 | \[ \left(x + \frac{-1 + x}{y \cdot y}\right) - \frac{\color{blue}{-1 + x}}{y}
\] |
if -2.2e5 < y < 2.05e8Initial program 0.1
Simplified0.1
[Start]0.1 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]0.1 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]0.1 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
*-lft-identity [<=]0.1 | \[ \color{blue}{1 \cdot \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)} + 1
\] |
associate-/l* [=>]0.2 | \[ 1 \cdot \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\right) + 1
\] |
distribute-neg-frac [=>]0.2 | \[ 1 \cdot \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*r/ [=>]0.2 | \[ \color{blue}{\frac{1 \cdot \left(-\left(1 - x\right)\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*l/ [<=]0.2 | \[ \color{blue}{\frac{1}{\frac{y + 1}{y}} \cdot \left(-\left(1 - x\right)\right)} + 1
\] |
fma-def [=>]0.2 | \[ \color{blue}{\mathsf{fma}\left(\frac{1}{\frac{y + 1}{y}}, -\left(1 - x\right), 1\right)}
\] |
associate-/l* [<=]0.1 | \[ \mathsf{fma}\left(\color{blue}{\frac{1 \cdot y}{y + 1}}, -\left(1 - x\right), 1\right)
\] |
*-lft-identity [=>]0.1 | \[ \mathsf{fma}\left(\frac{\color{blue}{y}}{y + 1}, -\left(1 - x\right), 1\right)
\] |
+-commutative [=>]0.1 | \[ \mathsf{fma}\left(\frac{y}{\color{blue}{1 + y}}, -\left(1 - x\right), 1\right)
\] |
neg-sub0 [=>]0.1 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right)
\] |
associate--r- [=>]0.1 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right)
\] |
metadata-eval [=>]0.1 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{-1} + x, 1\right)
\] |
+-commutative [<=]0.1 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right)
\] |
if 2.05e8 < y Initial program 46.1
Simplified28.9
[Start]46.1 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]46.1 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]46.1 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
*-lft-identity [<=]46.1 | \[ \color{blue}{1 \cdot \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)} + 1
\] |
associate-/l* [=>]28.9 | \[ 1 \cdot \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\right) + 1
\] |
distribute-neg-frac [=>]28.9 | \[ 1 \cdot \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*r/ [=>]28.9 | \[ \color{blue}{\frac{1 \cdot \left(-\left(1 - x\right)\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*l/ [<=]28.9 | \[ \color{blue}{\frac{1}{\frac{y + 1}{y}} \cdot \left(-\left(1 - x\right)\right)} + 1
\] |
fma-def [=>]28.9 | \[ \color{blue}{\mathsf{fma}\left(\frac{1}{\frac{y + 1}{y}}, -\left(1 - x\right), 1\right)}
\] |
associate-/l* [<=]28.9 | \[ \mathsf{fma}\left(\color{blue}{\frac{1 \cdot y}{y + 1}}, -\left(1 - x\right), 1\right)
\] |
*-lft-identity [=>]28.9 | \[ \mathsf{fma}\left(\frac{\color{blue}{y}}{y + 1}, -\left(1 - x\right), 1\right)
\] |
+-commutative [=>]28.9 | \[ \mathsf{fma}\left(\frac{y}{\color{blue}{1 + y}}, -\left(1 - x\right), 1\right)
\] |
neg-sub0 [=>]28.9 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right)
\] |
associate--r- [=>]28.9 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right)
\] |
metadata-eval [=>]28.9 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{-1} + x, 1\right)
\] |
+-commutative [<=]28.9 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right)
\] |
Taylor expanded in y around inf 0.1
Simplified0.1
[Start]0.1 | \[ -1 \cdot \frac{x - 1}{y} + x
\] |
|---|---|
+-commutative [=>]0.1 | \[ \color{blue}{x + -1 \cdot \frac{x - 1}{y}}
\] |
mul-1-neg [=>]0.1 | \[ x + \color{blue}{\left(-\frac{x - 1}{y}\right)}
\] |
unsub-neg [=>]0.1 | \[ \color{blue}{x - \frac{x - 1}{y}}
\] |
sub-neg [=>]0.1 | \[ x - \frac{\color{blue}{x + \left(-1\right)}}{y}
\] |
metadata-eval [=>]0.1 | \[ x - \frac{x + \color{blue}{-1}}{y}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 1092 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 969 |
| Alternative 3 | |
|---|---|
| Error | 0.1 |
| Cost | 969 |
| Alternative 4 | |
|---|---|
| Error | 16.6 |
| Cost | 720 |
| Alternative 5 | |
|---|---|
| Error | 1.1 |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 0.9 |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 8.9 |
| Cost | 585 |
| Alternative 8 | |
|---|---|
| Error | 1.2 |
| Cost | 585 |
| Alternative 9 | |
|---|---|
| Error | 16.5 |
| Cost | 456 |
| Alternative 10 | |
|---|---|
| Error | 16.7 |
| Cost | 328 |
| Alternative 11 | |
|---|---|
| Error | 39.3 |
| Cost | 64 |
herbie shell --seed 2023039
(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))))