(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
↓
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (* x y) (* z t))))
(if (<= t_1 -2e+210)
(- (/ x (/ a y)) (/ z (/ a t)))
(if (<= t_1 5e+185)
(- (/ (* x y) a) (/ (* z t) a))
(fma -1.0 (/ t (/ a z)) (/ y (/ a x)))))))
double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
↓
double code(double x, double y, double z, double t, double a) {
double t_1 = (x * y) - (z * t);
double tmp;
if (t_1 <= -2e+210) {
tmp = (x / (a / y)) - (z / (a / t));
} else if (t_1 <= 5e+185) {
tmp = ((x * y) / a) - ((z * t) / a);
} else {
tmp = fma(-1.0, (t / (a / z)), (y / (a / x)));
}
return tmp;
}
function code(x, y, z, t, a)
return Float64(Float64(Float64(x * y) - Float64(z * t)) / a)
end
↓
function code(x, y, z, t, a)
t_1 = Float64(Float64(x * y) - Float64(z * t))
tmp = 0.0
if (t_1 <= -2e+210)
tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t)));
elseif (t_1 <= 5e+185)
tmp = Float64(Float64(Float64(x * y) / a) - Float64(Float64(z * t) / a));
else
tmp = fma(-1.0, Float64(t / Float64(a / z)), Float64(y / Float64(a / x)));
end
return tmp
end
(fma.f64 -1 (/.f64 t (/.f64 a z)) (/.f64 y (/.f64 a x))): 0 points increase in error, 0 points decrease in error
(fma.f64 -1 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 t z) a)) (/.f64 y (/.f64 a x))): 39 points increase in error, 31 points decrease in error
(fma.f64 -1 (/.f64 (*.f64 t z) a) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) a))): 33 points increase in error, 25 points decrease in error
(Rewrite<= fma-def_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 t z) a)) (/.f64 (*.f64 y x) a))): 0 points increase in error, 0 points decrease in error
(Rewrite=> +-commutative_binary64 (+.f64 (/.f64 (*.f64 y x) a) (*.f64 -1 (/.f64 (*.f64 t z) a)))): 0 points increase in error, 0 points decrease in error
(+.f64 (/.f64 (*.f64 y x) a) (Rewrite=> mul-1-neg_binary64 (neg.f64 (/.f64 (*.f64 t z) a)))): 0 points increase in error, 0 points decrease in error
(Rewrite=> unsub-neg_binary64 (-.f64 (/.f64 (*.f64 y x) a) (/.f64 (*.f64 t z) a))): 0 points increase in error, 0 points decrease in error
(Rewrite<= div-sub_binary64 (/.f64 (-.f64 (*.f64 y x) (*.f64 t z)) a)): 2 points increase in error, 2 points decrease in error
Recombined 3 regimes into one program.
Final simplification0.9
\[\leadsto \begin{array}{l}
\mathbf{if}\;x \cdot y - z \cdot t \leq -2 \cdot 10^{+210}:\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\
\mathbf{elif}\;x \cdot y - z \cdot t \leq 5 \cdot 10^{+185}:\\
\;\;\;\;\frac{x \cdot y}{a} - \frac{z \cdot t}{a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{t}{\frac{a}{z}}, \frac{y}{\frac{a}{x}}\right)\\
\end{array}
\]
Alternatives
Alternative 1
Error
0.7
Cost
1736
\[\begin{array}{l}
t_1 := x \cdot \frac{y}{a} - \frac{t}{\frac{a}{z}}\\
t_2 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+223}:\\
\;\;\;\;\frac{t_2}{a}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\]
herbie shell --seed 2022308
(FPCore (x y z t a)
:name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
:precision binary64
:herbie-target
(if (< z -2.468684968699548e+170) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z))))
(/ (- (* x y) (* z t)) a))