| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 1352 |
(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) (+ 1.0 y))))
(if (<= t_0 5e-24)
(+ 1.0 (* y (/ (+ x -1.0) (+ 1.0 y))))
(if (<= t_0 1.1)
(+ x (+ (/ (+ 1.0 (/ 1.0 (* y y))) y) (/ -1.0 (* y y))))
(fma (/ y (+ 1.0 y)) (+ x -1.0) 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) / (1.0 + y);
double tmp;
if (t_0 <= 5e-24) {
tmp = 1.0 + (y * ((x + -1.0) / (1.0 + y)));
} else if (t_0 <= 1.1) {
tmp = x + (((1.0 + (1.0 / (y * y))) / y) + (-1.0 / (y * y)));
} else {
tmp = fma((y / (1.0 + y)), (x + -1.0), 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(Float64(1.0 - x) * y) / Float64(1.0 + y)) tmp = 0.0 if (t_0 <= 5e-24) tmp = Float64(1.0 + Float64(y * Float64(Float64(x + -1.0) / Float64(1.0 + y)))); elseif (t_0 <= 1.1) tmp = Float64(x + Float64(Float64(Float64(1.0 + Float64(1.0 / Float64(y * y))) / y) + Float64(-1.0 / Float64(y * y)))); else tmp = fma(Float64(y / Float64(1.0 + y)), Float64(x + -1.0), 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[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e-24], N[(1.0 + N[(y * N[(N[(x + -1.0), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1.1], N[(x + N[(N[(N[(1.0 + N[(1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + N[(-1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision] * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]]]]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
t_0 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{-24}:\\
\;\;\;\;1 + y \cdot \frac{x + -1}{1 + y}\\
\mathbf{elif}\;t_0 \leq 1.1:\\
\;\;\;\;x + \left(\frac{1 + \frac{1}{y \cdot y}}{y} + \frac{-1}{y \cdot y}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{1 + y}, x + -1, 1\right)\\
\end{array}
| Original | 22.6 |
|---|---|
| Target | 0.2 |
| Herbie | 1.3 |
if (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 4.9999999999999998e-24Initial program 7.5
Simplified0.0
[Start]7.5 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
remove-double-neg [<=]7.5 | \[ 1 - \color{blue}{\left(-\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)\right)}
\] |
neg-mul-1 [=>]7.5 | \[ 1 - \left(-\color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}}\right)
\] |
associate-*l/ [<=]0.0 | \[ 1 - \left(--1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)}\right)
\] |
associate-*r* [=>]0.0 | \[ 1 - \left(-\color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}\right)
\] |
distribute-lft-neg-in [=>]0.0 | \[ 1 - \color{blue}{\left(--1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}
\] |
distribute-lft-neg-in [=>]0.0 | \[ 1 - \color{blue}{\left(\left(--1\right) \cdot \frac{1 - x}{y + 1}\right)} \cdot y
\] |
metadata-eval [=>]0.0 | \[ 1 - \left(\color{blue}{1} \cdot \frac{1 - x}{y + 1}\right) \cdot y
\] |
*-lft-identity [=>]0.0 | \[ 1 - \color{blue}{\frac{1 - x}{y + 1}} \cdot y
\] |
+-commutative [=>]0.0 | \[ 1 - \frac{1 - x}{\color{blue}{1 + y}} \cdot y
\] |
if 4.9999999999999998e-24 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) < 1.1000000000000001Initial program 53.7
Simplified53.7
[Start]53.7 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]53.7 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]53.7 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
*-lft-identity [<=]53.7 | \[ \color{blue}{1 \cdot \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)} + 1
\] |
associate-/l* [=>]53.8 | \[ 1 \cdot \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\right) + 1
\] |
distribute-neg-frac [=>]53.8 | \[ 1 \cdot \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*r/ [=>]53.8 | \[ \color{blue}{\frac{1 \cdot \left(-\left(1 - x\right)\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*l/ [<=]53.8 | \[ \color{blue}{\frac{1}{\frac{y + 1}{y}} \cdot \left(-\left(1 - x\right)\right)} + 1
\] |
fma-def [=>]53.8 | \[ \color{blue}{\mathsf{fma}\left(\frac{1}{\frac{y + 1}{y}}, -\left(1 - x\right), 1\right)}
\] |
associate-/l* [<=]53.7 | \[ \mathsf{fma}\left(\color{blue}{\frac{1 \cdot y}{y + 1}}, -\left(1 - x\right), 1\right)
\] |
*-lft-identity [=>]53.7 | \[ \mathsf{fma}\left(\frac{\color{blue}{y}}{y + 1}, -\left(1 - x\right), 1\right)
\] |
+-commutative [=>]53.7 | \[ \mathsf{fma}\left(\frac{y}{\color{blue}{1 + y}}, -\left(1 - x\right), 1\right)
\] |
neg-sub0 [=>]53.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right)
\] |
associate--r- [=>]53.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right)
\] |
metadata-eval [=>]53.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{-1} + x, 1\right)
\] |
+-commutative [<=]53.7 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right)
\] |
Taylor expanded in y around inf 4.5
Simplified4.5
[Start]4.5 | \[ \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 [=>]4.5 | \[ \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 [=>]4.5 | \[ \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+ [=>]4.5 | \[ \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+ [=>]4.5 | \[ \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)
\] |
+-commutative [=>]4.5 | \[ \color{blue}{\left(x + \left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right)\right)} + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)
\] |
associate-+l+ [=>]4.5 | \[ \color{blue}{x + \left(\left(-1 \cdot \frac{x - 1}{y} + -1 \cdot \frac{x - 1}{{y}^{3}}\right) + \left(\frac{x}{{y}^{2}} + \left(-\frac{1}{{y}^{2}}\right)\right)\right)}
\] |
Taylor expanded in x around 0 4.6
Simplified4.6
[Start]4.6 | \[ x + \left(\frac{1 + \frac{1}{{y}^{2}}}{y} + \frac{x + -1}{y \cdot y}\right)
\] |
|---|---|
unpow2 [=>]4.6 | \[ x + \left(\frac{1 + \frac{1}{\color{blue}{y \cdot y}}}{y} + \frac{x + -1}{y \cdot y}\right)
\] |
Taylor expanded in x around 0 4.6
Simplified4.6
[Start]4.6 | \[ x + \left(\frac{1 + \frac{1}{y \cdot y}}{y} + \frac{-1}{{y}^{2}}\right)
\] |
|---|---|
unpow2 [=>]4.6 | \[ x + \left(\frac{1 + \frac{1}{y \cdot y}}{y} + \frac{-1}{\color{blue}{y \cdot y}}\right)
\] |
if 1.1000000000000001 < (/.f64 (*.f64 (-.f64 1 x) y) (+.f64 y 1)) Initial program 21.8
Simplified0.0
[Start]21.8 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]21.8 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]21.8 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
*-lft-identity [<=]21.8 | \[ \color{blue}{1 \cdot \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)} + 1
\] |
associate-/l* [=>]0.1 | \[ 1 \cdot \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\right) + 1
\] |
distribute-neg-frac [=>]0.1 | \[ 1 \cdot \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*r/ [=>]0.1 | \[ \color{blue}{\frac{1 \cdot \left(-\left(1 - x\right)\right)}{\frac{y + 1}{y}}} + 1
\] |
associate-*l/ [<=]0.1 | \[ \color{blue}{\frac{1}{\frac{y + 1}{y}} \cdot \left(-\left(1 - x\right)\right)} + 1
\] |
fma-def [=>]0.1 | \[ \color{blue}{\mathsf{fma}\left(\frac{1}{\frac{y + 1}{y}}, -\left(1 - x\right), 1\right)}
\] |
associate-/l* [<=]0.0 | \[ \mathsf{fma}\left(\color{blue}{\frac{1 \cdot y}{y + 1}}, -\left(1 - x\right), 1\right)
\] |
*-lft-identity [=>]0.0 | \[ \mathsf{fma}\left(\frac{\color{blue}{y}}{y + 1}, -\left(1 - x\right), 1\right)
\] |
+-commutative [=>]0.0 | \[ \mathsf{fma}\left(\frac{y}{\color{blue}{1 + y}}, -\left(1 - x\right), 1\right)
\] |
neg-sub0 [=>]0.0 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{0 - \left(1 - x\right)}, 1\right)
\] |
associate--r- [=>]0.0 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{\left(0 - 1\right) + x}, 1\right)
\] |
metadata-eval [=>]0.0 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{-1} + x, 1\right)
\] |
+-commutative [<=]0.0 | \[ \mathsf{fma}\left(\frac{y}{1 + y}, \color{blue}{x + -1}, 1\right)
\] |
Final simplification1.3
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 1352 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 1225 |
| Alternative 3 | |
|---|---|
| Error | 0.2 |
| Cost | 969 |
| Alternative 4 | |
|---|---|
| Error | 0.3 |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Error | 18.0 |
| Cost | 720 |
| Alternative 6 | |
|---|---|
| Error | 1.2 |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 8.9 |
| 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.0 |
| Cost | 64 |
herbie shell --seed 2023066
(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))))