| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 7620 |
(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)) (t_1 (/ -1.0 (* y y))))
(if (<= y -290000.0)
(+ (* t_0 (- 1.0 t_1)) (+ x t_1))
(if (<= y 116000000.0) (fma (/ (+ x -1.0) (+ y 1.0)) y 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 t_1 = -1.0 / (y * y);
double tmp;
if (y <= -290000.0) {
tmp = (t_0 * (1.0 - t_1)) + (x + t_1);
} else if (y <= 116000000.0) {
tmp = fma(((x + -1.0) / (y + 1.0)), y, 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) t_1 = Float64(-1.0 / Float64(y * y)) tmp = 0.0 if (y <= -290000.0) tmp = Float64(Float64(t_0 * Float64(1.0 - t_1)) + Float64(x + t_1)); elseif (y <= 116000000.0) tmp = fma(Float64(Float64(x + -1.0) / Float64(y + 1.0)), y, 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]}, Block[{t$95$1 = N[(-1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -290000.0], N[(N[(t$95$0 * N[(1.0 - t$95$1), $MachinePrecision]), $MachinePrecision] + N[(x + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 116000000.0], N[(N[(N[(x + -1.0), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision] * y + 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}\\
t_1 := \frac{-1}{y \cdot y}\\
\mathbf{if}\;y \leq -290000:\\
\;\;\;\;t_0 \cdot \left(1 - t_1\right) + \left(x + t_1\right)\\
\mathbf{elif}\;y \leq 116000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{x + -1}{y + 1}, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + t_0\\
\end{array}
| Original | 22.0 |
|---|---|
| Target | 0.2 |
| Herbie | 0.1 |
if y < -2.9e5Initial program 45.7
Simplified30.7
[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}
\] |
*-lft-identity [<=]45.7 | \[ \color{blue}{1 \cdot \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)} + 1
\] |
associate-/l* [=>]30.7 | \[ 1 \cdot \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\right) + 1
\] |
distribute-neg-frac [=>]30.7 | \[ 1 \cdot \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*r/ [=>]30.7 | \[ \color{blue}{\frac{1 \cdot \left(-\left(1 - x\right)\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*l/ [<=]30.7 | \[ \color{blue}{\frac{1}{\frac{y + 1}{y}} \cdot \left(-\left(1 - x\right)\right)} + 1
\] |
fma-def [=>]30.7 | \[ \color{blue}{\mathsf{fma}\left(\frac{1}{\frac{y + 1}{y}}, -\left(1 - x\right), 1\right)}
\] |
associate-/l* [<=]30.7 | \[ \mathsf{fma}\left(\color{blue}{\frac{1 \cdot y}{y + 1}}, -\left(1 - x\right), 1\right)
\] |
*-lft-identity [=>]30.7 | \[ \mathsf{fma}\left(\frac{\color{blue}{y}}{y + 1}, -\left(1 - x\right), 1\right)
\] |
+-commutative [=>]30.7 | \[ \mathsf{fma}\left(\frac{y}{\color{blue}{1 + y}}, -\left(1 - x\right), 1\right)
\] |
neg-sub0 [=>]30.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right)
\] |
associate--r- [=>]30.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right)
\] |
metadata-eval [=>]30.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{-1} + x, 1\right)
\] |
+-commutative [<=]30.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right)
\] |
Taylor expanded in y around inf 0.0
Simplified0.0
[Start]0.0 | \[ \left(\frac{x}{{y}^{2}} + \left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right)\right) - \frac{1}{{y}^{2}}
\] |
|---|---|
sub-neg [=>]0.0 | \[ \color{blue}{\left(\frac{x}{{y}^{2}} + \left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right)\right) + \left(-\frac{1}{{y}^{2}}\right)}
\] |
+-commutative [=>]0.0 | \[ \color{blue}{\left(\left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right) + \frac{x}{{y}^{2}}\right)} + \left(-\frac{1}{{y}^{2}}\right)
\] |
associate-+l+ [=>]0.0 | \[ \color{blue}{\left(-1 \cdot \frac{x - 1}{y} + \left(-1 \cdot \frac{x - 1}{{y}^{3}} + x\right)\right) + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)}
\] |
associate-+r+ [=>]0.0 | \[ \color{blue}{\left(\left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right) + x\right)} + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)
\] |
associate-+l+ [=>]0.0 | \[ \color{blue}{\left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right) + \left(x + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)\right)}
\] |
Taylor expanded in x around 0 0.1
Simplified0.1
[Start]0.1 | \[ \frac{x + -1}{y} \cdot \left(-1 + \frac{-1}{y \cdot y}\right) + \left(x + \frac{-1}{{y}^{2}}\right)
\] |
|---|---|
unpow2 [=>]0.1 | \[ \frac{x + -1}{y} \cdot \left(-1 + \frac{-1}{y \cdot y}\right) + \left(x + \frac{-1}{\color{blue}{y \cdot y}}\right)
\] |
if -2.9e5 < y < 1.16e8Initial 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}
\] |
neg-mul-1 [=>]0.1 | \[ \color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}} + 1
\] |
associate-*l/ [<=]0.1 | \[ -1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)} + 1
\] |
associate-*r* [=>]0.1 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y} + 1
\] |
fma-def [=>]0.1 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{1 - x}{y + 1}, y, 1\right)}
\] |
associate-*r/ [=>]0.1 | \[ \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{y + 1}}, y, 1\right)
\] |
neg-mul-1 [<=]0.1 | \[ \mathsf{fma}\left(\frac{\color{blue}{-\left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
neg-sub0 [=>]0.1 | \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
associate--r- [=>]0.1 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right)
\] |
metadata-eval [=>]0.1 | \[ \mathsf{fma}\left(\frac{\color{blue}{-1} + x}{y + 1}, y, 1\right)
\] |
+-commutative [<=]0.1 | \[ \mathsf{fma}\left(\frac{\color{blue}{x + -1}}{y + 1}, y, 1\right)
\] |
+-commutative [=>]0.1 | \[ \mathsf{fma}\left(\frac{x + -1}{\color{blue}{1 + y}}, y, 1\right)
\] |
if 1.16e8 < y Initial program 45.5
Simplified29.5
[Start]45.5 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
remove-double-neg [<=]45.5 | \[ 1 - \color{blue}{\left(-\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)\right)}
\] |
neg-mul-1 [=>]45.5 | \[ 1 - \left(-\color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}}\right)
\] |
associate-*l/ [<=]29.5 | \[ 1 - \left(--1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)}\right)
\] |
associate-*r* [=>]29.5 | \[ 1 - \left(-\color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}\right)
\] |
distribute-lft-neg-in [=>]29.5 | \[ 1 - \color{blue}{\left(--1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}
\] |
distribute-lft-neg-in [=>]29.5 | \[ 1 - \color{blue}{\left(\left(--1\right) \cdot \frac{1 - x}{y + 1}\right)} \cdot y
\] |
metadata-eval [=>]29.5 | \[ 1 - \left(\color{blue}{1} \cdot \frac{1 - x}{y + 1}\right) \cdot y
\] |
*-lft-identity [=>]29.5 | \[ 1 - \color{blue}{\frac{1 - x}{y + 1}} \cdot y
\] |
+-commutative [=>]29.5 | \[ 1 - \frac{1 - x}{\color{blue}{1 + y}} \cdot y
\] |
Taylor expanded in y around inf 0.2
Simplified0.2
[Start]0.2 | \[ \left(\frac{1}{y} + x\right) - \frac{x}{y}
\] |
|---|---|
+-commutative [=>]0.2 | \[ \color{blue}{\left(x + \frac{1}{y}\right)} - \frac{x}{y}
\] |
associate--l+ [=>]0.2 | \[ \color{blue}{x + \left(\frac{1}{y} - \frac{x}{y}\right)}
\] |
div-sub [<=]0.2 | \[ x + \color{blue}{\frac{1 - x}{y}}
\] |
sub-neg [=>]0.2 | \[ x + \frac{\color{blue}{1 + \left(-x\right)}}{y}
\] |
mul-1-neg [<=]0.2 | \[ x + \frac{1 + \color{blue}{-1 \cdot x}}{y}
\] |
+-commutative [=>]0.2 | \[ x + \frac{\color{blue}{-1 \cdot x + 1}}{y}
\] |
metadata-eval [<=]0.2 | \[ x + \frac{-1 \cdot x + \color{blue}{-1 \cdot -1}}{y}
\] |
distribute-lft-in [<=]0.2 | \[ x + \frac{\color{blue}{-1 \cdot \left(x + -1\right)}}{y}
\] |
metadata-eval [<=]0.2 | \[ x + \frac{-1 \cdot \left(x + \color{blue}{\left(-1\right)}\right)}{y}
\] |
sub-neg [<=]0.2 | \[ x + \frac{-1 \cdot \color{blue}{\left(x - 1\right)}}{y}
\] |
associate-*r/ [<=]0.2 | \[ x + \color{blue}{-1 \cdot \frac{x - 1}{y}}
\] |
mul-1-neg [=>]0.2 | \[ x + \color{blue}{\left(-\frac{x - 1}{y}\right)}
\] |
unsub-neg [=>]0.2 | \[ \color{blue}{x - \frac{x - 1}{y}}
\] |
sub-neg [=>]0.2 | \[ x - \frac{\color{blue}{x + \left(-1\right)}}{y}
\] |
metadata-eval [=>]0.2 | \[ x - \frac{x + \color{blue}{-1}}{y}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 7620 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 1476 |
| Alternative 3 | |
|---|---|
| Error | 0.1 |
| Cost | 1092 |
| Alternative 4 | |
|---|---|
| Error | 0.1 |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Error | 0.2 |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Error | 8.4 |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 8.3 |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Error | 1.0 |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Error | 16.1 |
| Cost | 585 |
| Alternative 10 | |
|---|---|
| Error | 8.6 |
| Cost | 585 |
| Alternative 11 | |
|---|---|
| Error | 16.3 |
| Cost | 456 |
| Alternative 12 | |
|---|---|
| Error | 16.5 |
| Cost | 328 |
| Alternative 13 | |
|---|---|
| Error | 38.6 |
| Cost | 64 |
herbie shell --seed 2023054
(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))))