| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 6848 |
\[\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)
\]
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t) :precision binary64 (if (<= (/ x y) 4e+170) (fma (/ x y) (- z t) t) (/ 1.0 (/ 1.0 (fma x (/ (- z t) y) t)))))
double code(double x, double y, double z, double t) {
return ((x / y) * (z - t)) + t;
}
double code(double x, double y, double z, double t) {
double tmp;
if ((x / y) <= 4e+170) {
tmp = fma((x / y), (z - t), t);
} else {
tmp = 1.0 / (1.0 / fma(x, ((z - t) / y), t));
}
return tmp;
}
function code(x, y, z, t) return Float64(Float64(Float64(x / y) * Float64(z - t)) + t) end
function code(x, y, z, t) tmp = 0.0 if (Float64(x / y) <= 4e+170) tmp = fma(Float64(x / y), Float64(z - t), t); else tmp = Float64(1.0 / Float64(1.0 / fma(x, Float64(Float64(z - t) / y), t))); end return tmp end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(x / y), $MachinePrecision], 4e+170], N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision] + t), $MachinePrecision], N[(1.0 / N[(1.0 / N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;\frac{x}{y} \leq 4 \cdot 10^{+170}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)}}\\
\end{array}
| Original | 1.8 |
|---|---|
| Target | 2.0 |
| Herbie | 1.4 |
if (/.f64 x y) < 4.00000000000000014e170Initial program 1.3
Simplified1.3
[Start]1.3 | \[ \frac{x}{y} \cdot \left(z - t\right) + t
\] |
|---|---|
fma-def [=>]1.3 | \[ \color{blue}{\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)}
\] |
if 4.00000000000000014e170 < (/.f64 x y) Initial program 14.8
Simplified3.1
[Start]14.8 | \[ \frac{x}{y} \cdot \left(z - t\right) + t
\] |
|---|---|
associate-*l/ [=>]2.0 | \[ \color{blue}{\frac{x \cdot \left(z - t\right)}{y}} + t
\] |
associate-*r/ [<=]3.1 | \[ \color{blue}{x \cdot \frac{z - t}{y}} + t
\] |
fma-def [=>]3.1 | \[ \color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)}
\] |
Applied egg-rr54.4
Applied egg-rr3.2
Simplified3.2
[Start]3.2 | \[ {\left(\frac{1}{t + x \cdot \frac{z - t}{y}}\right)}^{-1}
\] |
|---|---|
unpow-1 [=>]3.2 | \[ \color{blue}{\frac{1}{\frac{1}{t + x \cdot \frac{z - t}{y}}}}
\] |
+-commutative [<=]3.2 | \[ \frac{1}{\frac{1}{\color{blue}{x \cdot \frac{z - t}{y} + t}}}
\] |
fma-def [=>]3.2 | \[ \frac{1}{\frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)}}}
\] |
Final simplification1.4
| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 6848 |
| Alternative 2 | |
|---|---|
| Error | 22.9 |
| Cost | 1424 |
| Alternative 3 | |
|---|---|
| Error | 22.9 |
| Cost | 1424 |
| Alternative 4 | |
|---|---|
| Error | 4.7 |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Error | 22.9 |
| Cost | 841 |
| Alternative 6 | |
|---|---|
| Error | 22.4 |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Error | 7.9 |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Error | 20.8 |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Error | 1.8 |
| Cost | 576 |
| Alternative 10 | |
|---|---|
| Error | 31.5 |
| Cost | 64 |
herbie shell --seed 2023018
(FPCore (x y z t)
:name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
:precision binary64
:herbie-target
(if (< z 2.759456554562692e-282) (+ (* (/ x y) (- z t)) t) (if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) (+ (* (/ x y) (- z t)) t)))
(+ (* (/ x y) (- z t)) t))