| Alternative 1 | |
|---|---|
| Error | 0.27% |
| Cost | 969 |
(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 -2450000.0)
(+ (+ x (/ -1.0 (* y y))) t_0)
(if (<= y 205000000.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 tmp;
if (y <= -2450000.0) {
tmp = (x + (-1.0 / (y * y))) + t_0;
} else if (y <= 205000000.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) tmp = 0.0 if (y <= -2450000.0) tmp = Float64(Float64(x + Float64(-1.0 / Float64(y * y))) + t_0); elseif (y <= 205000000.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]}, If[LessEqual[y, -2450000.0], N[(N[(x + N[(-1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[y, 205000000.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}\\
\mathbf{if}\;y \leq -2450000:\\
\;\;\;\;\left(x + \frac{-1}{y \cdot y}\right) + t_0\\
\mathbf{elif}\;y \leq 205000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{x + -1}{y + 1}, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + t_0\\
\end{array}
| Original | 35.34% |
|---|---|
| Target | 0.38% |
| Herbie | 0.18% |
if y < -2.45e6Initial program 71.31
Simplified44.56
[Start]71.31 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
remove-double-neg [<=]71.31 | \[ 1 - \color{blue}{\left(-\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)\right)}
\] |
distribute-neg-frac [=>]71.31 | \[ 1 - \left(-\color{blue}{\frac{-\left(1 - x\right) \cdot y}{y + 1}}\right)
\] |
distribute-rgt-neg-in [=>]71.31 | \[ 1 - \left(-\frac{\color{blue}{\left(1 - x\right) \cdot \left(-y\right)}}{y + 1}\right)
\] |
associate-/l* [=>]44.56 | \[ 1 - \left(-\color{blue}{\frac{1 - x}{\frac{y + 1}{-y}}}\right)
\] |
distribute-frac-neg [<=]44.56 | \[ 1 - \color{blue}{\frac{-\left(1 - x\right)}{\frac{y + 1}{-y}}}
\] |
/-rgt-identity [<=]44.56 | \[ 1 - \frac{\color{blue}{\frac{-\left(1 - x\right)}{1}}}{\frac{y + 1}{-y}}
\] |
neg-mul-1 [=>]44.56 | \[ 1 - \frac{\frac{\color{blue}{-1 \cdot \left(1 - x\right)}}{1}}{\frac{y + 1}{-y}}
\] |
*-commutative [=>]44.56 | \[ 1 - \frac{\frac{\color{blue}{\left(1 - x\right) \cdot -1}}{1}}{\frac{y + 1}{-y}}
\] |
associate-/l* [=>]44.56 | \[ 1 - \frac{\color{blue}{\frac{1 - x}{\frac{1}{-1}}}}{\frac{y + 1}{-y}}
\] |
metadata-eval [=>]44.56 | \[ 1 - \frac{\frac{1 - x}{\color{blue}{-1}}}{\frac{y + 1}{-y}}
\] |
associate-/r* [<=]44.56 | \[ 1 - \color{blue}{\frac{1 - x}{-1 \cdot \frac{y + 1}{-y}}}
\] |
mul-1-neg [=>]44.56 | \[ 1 - \frac{1 - x}{\color{blue}{-\frac{y + 1}{-y}}}
\] |
*-rgt-identity [<=]44.56 | \[ 1 - \frac{1 - x}{-\color{blue}{\frac{y + 1}{-y} \cdot 1}}
\] |
mul-1-neg [<=]44.56 | \[ 1 - \frac{1 - x}{-\frac{y + 1}{\color{blue}{-1 \cdot y}} \cdot 1}
\] |
associate-*l/ [=>]44.56 | \[ 1 - \frac{1 - x}{-\color{blue}{\frac{\left(y + 1\right) \cdot 1}{-1 \cdot y}}}
\] |
*-commutative [=>]44.56 | \[ 1 - \frac{1 - x}{-\frac{\color{blue}{1 \cdot \left(y + 1\right)}}{-1 \cdot y}}
\] |
times-frac [=>]44.56 | \[ 1 - \frac{1 - x}{-\color{blue}{\frac{1}{-1} \cdot \frac{y + 1}{y}}}
\] |
metadata-eval [=>]44.56 | \[ 1 - \frac{1 - x}{-\color{blue}{-1} \cdot \frac{y + 1}{y}}
\] |
mul-1-neg [=>]44.56 | \[ 1 - \frac{1 - x}{-\color{blue}{\left(-\frac{y + 1}{y}\right)}}
\] |
remove-double-neg [=>]44.56 | \[ 1 - \frac{1 - x}{\color{blue}{\frac{y + 1}{y}}}
\] |
Taylor expanded in y around inf 0.03
Simplified0.03
[Start]0.03 | \[ \left(\frac{1}{y} + \left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} + x\right)\right) - \frac{x}{y}
\] |
|---|---|
associate--l+ [=>]0.03 | \[ \color{blue}{\frac{1}{y} + \left(\left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} + x\right) - \frac{x}{y}\right)}
\] |
+-commutative [=>]0.03 | \[ \color{blue}{\left(\left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} + x\right) - \frac{x}{y}\right) + \frac{1}{y}}
\] |
associate-+l- [=>]0.03 | \[ \color{blue}{\left(-1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}} + x\right) - \left(\frac{x}{y} - \frac{1}{y}\right)}
\] |
+-commutative [=>]0.03 | \[ \color{blue}{\left(x + -1 \cdot \frac{1 + -1 \cdot x}{{y}^{2}}\right)} - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
mul-1-neg [=>]0.03 | \[ \left(x + \color{blue}{\left(-\frac{1 + -1 \cdot x}{{y}^{2}}\right)}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
unsub-neg [=>]0.03 | \[ \color{blue}{\left(x - \frac{1 + -1 \cdot x}{{y}^{2}}\right)} - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
mul-1-neg [=>]0.03 | \[ \left(x - \frac{1 + \color{blue}{\left(-x\right)}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
sub-neg [<=]0.03 | \[ \left(x - \frac{\color{blue}{1 - x}}{{y}^{2}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
unpow2 [=>]0.03 | \[ \left(x - \frac{1 - x}{\color{blue}{y \cdot y}}\right) - \left(\frac{x}{y} - \frac{1}{y}\right)
\] |
div-sub [<=]0.03 | \[ \left(x - \frac{1 - x}{y \cdot y}\right) - \color{blue}{\frac{x - 1}{y}}
\] |
sub-neg [=>]0.03 | \[ \left(x - \frac{1 - x}{y \cdot y}\right) - \frac{\color{blue}{x + \left(-1\right)}}{y}
\] |
metadata-eval [=>]0.03 | \[ \left(x - \frac{1 - x}{y \cdot y}\right) - \frac{x + \color{blue}{-1}}{y}
\] |
Taylor expanded in x around 0 0.04
Simplified0.04
[Start]0.04 | \[ \left(x - \frac{1}{{y}^{2}}\right) - \frac{x + -1}{y}
\] |
|---|---|
unpow2 [=>]0.04 | \[ \left(x - \frac{1}{\color{blue}{y \cdot y}}\right) - \frac{x + -1}{y}
\] |
if -2.45e6 < y < 2.05e8Initial program 0.23
Simplified0.22
[Start]0.23 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
sub-neg [=>]0.23 | \[ \color{blue}{1 + \left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)}
\] |
+-commutative [=>]0.23 | \[ \color{blue}{\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right) + 1}
\] |
neg-mul-1 [=>]0.23 | \[ \color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}} + 1
\] |
associate-*l/ [<=]0.24 | \[ -1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)} + 1
\] |
associate-*r* [=>]0.24 | \[ \color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y} + 1
\] |
fma-def [=>]0.22 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{1 - x}{y + 1}, y, 1\right)}
\] |
associate-*r/ [=>]0.22 | \[ \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot \left(1 - x\right)}{y + 1}}, y, 1\right)
\] |
neg-mul-1 [<=]0.22 | \[ \mathsf{fma}\left(\frac{\color{blue}{-\left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
neg-sub0 [=>]0.22 | \[ \mathsf{fma}\left(\frac{\color{blue}{0 - \left(1 - x\right)}}{y + 1}, y, 1\right)
\] |
associate--r- [=>]0.22 | \[ \mathsf{fma}\left(\frac{\color{blue}{\left(0 - 1\right) + x}}{y + 1}, y, 1\right)
\] |
metadata-eval [=>]0.22 | \[ \mathsf{fma}\left(\frac{\color{blue}{-1} + x}{y + 1}, y, 1\right)
\] |
+-commutative [<=]0.22 | \[ \mathsf{fma}\left(\frac{\color{blue}{x + -1}}{y + 1}, y, 1\right)
\] |
+-commutative [=>]0.22 | \[ \mathsf{fma}\left(\frac{x + -1}{\color{blue}{1 + y}}, y, 1\right)
\] |
if 2.05e8 < y Initial program 72.75
Simplified46.02
[Start]72.75 | \[ 1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\] |
|---|---|
remove-double-neg [<=]72.75 | \[ 1 - \color{blue}{\left(-\left(-\frac{\left(1 - x\right) \cdot y}{y + 1}\right)\right)}
\] |
neg-mul-1 [=>]72.75 | \[ 1 - \left(-\color{blue}{-1 \cdot \frac{\left(1 - x\right) \cdot y}{y + 1}}\right)
\] |
associate-*l/ [<=]46.02 | \[ 1 - \left(--1 \cdot \color{blue}{\left(\frac{1 - x}{y + 1} \cdot y\right)}\right)
\] |
associate-*r* [=>]46.02 | \[ 1 - \left(-\color{blue}{\left(-1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}\right)
\] |
distribute-lft-neg-in [=>]46.02 | \[ 1 - \color{blue}{\left(--1 \cdot \frac{1 - x}{y + 1}\right) \cdot y}
\] |
distribute-lft-neg-in [=>]46.02 | \[ 1 - \color{blue}{\left(\left(--1\right) \cdot \frac{1 - x}{y + 1}\right)} \cdot y
\] |
metadata-eval [=>]46.02 | \[ 1 - \left(\color{blue}{1} \cdot \frac{1 - x}{y + 1}\right) \cdot y
\] |
*-lft-identity [=>]46.02 | \[ 1 - \color{blue}{\frac{1 - x}{y + 1}} \cdot y
\] |
+-commutative [=>]46.02 | \[ 1 - \frac{1 - x}{\color{blue}{1 + y}} \cdot y
\] |
Taylor expanded in y around inf 0.23
Simplified0.23
[Start]0.23 | \[ \left(\frac{1}{y} + x\right) - \frac{x}{y}
\] |
|---|---|
associate--l+ [=>]0.23 | \[ \color{blue}{\frac{1}{y} + \left(x - \frac{x}{y}\right)}
\] |
+-commutative [=>]0.23 | \[ \color{blue}{\left(x - \frac{x}{y}\right) + \frac{1}{y}}
\] |
associate-+l- [=>]0.23 | \[ \color{blue}{x - \left(\frac{x}{y} - \frac{1}{y}\right)}
\] |
div-sub [<=]0.23 | \[ x - \color{blue}{\frac{x - 1}{y}}
\] |
unsub-neg [<=]0.23 | \[ \color{blue}{x + \left(-\frac{x - 1}{y}\right)}
\] |
mul-1-neg [<=]0.23 | \[ x + \color{blue}{-1 \cdot \frac{x - 1}{y}}
\] |
associate-*r/ [=>]0.23 | \[ x + \color{blue}{\frac{-1 \cdot \left(x - 1\right)}{y}}
\] |
sub-neg [=>]0.23 | \[ x + \frac{-1 \cdot \color{blue}{\left(x + \left(-1\right)\right)}}{y}
\] |
metadata-eval [=>]0.23 | \[ x + \frac{-1 \cdot \left(x + \color{blue}{-1}\right)}{y}
\] |
distribute-lft-in [=>]0.23 | \[ x + \frac{\color{blue}{-1 \cdot x + -1 \cdot -1}}{y}
\] |
metadata-eval [=>]0.23 | \[ x + \frac{-1 \cdot x + \color{blue}{1}}{y}
\] |
+-commutative [<=]0.23 | \[ x + \frac{\color{blue}{1 + -1 \cdot x}}{y}
\] |
mul-1-neg [=>]0.23 | \[ x + \frac{1 + \color{blue}{\left(-x\right)}}{y}
\] |
sub-neg [<=]0.23 | \[ x + \frac{\color{blue}{1 - x}}{y}
\] |
Final simplification0.18
| Alternative 1 | |
|---|---|
| Error | 0.27% |
| Cost | 969 |
| Alternative 2 | |
|---|---|
| Error | 0.19% |
| Cost | 968 |
| Alternative 3 | |
|---|---|
| Error | 26.13% |
| Cost | 844 |
| Alternative 4 | |
|---|---|
| Error | 26.36% |
| Cost | 716 |
| Alternative 5 | |
|---|---|
| Error | 13.77% |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 1.49% |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 26.51% |
| Cost | 460 |
| Alternative 8 | |
|---|---|
| Error | 25.73% |
| Cost | 328 |
| Alternative 9 | |
|---|---|
| Error | 61.3% |
| Cost | 64 |
herbie shell --seed 2023090
(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))))