
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = ((x * y) - (z * t)) / a
end function
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a): return ((x * y) - (z * t)) / a
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(z * t)) / a) end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - (z * t)) / a; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = ((x * y) - (z * t)) / a
end function
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a): return ((x * y) - (z * t)) / a
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(z * t)) / a) end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - (z * t)) / a; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}
(FPCore (x y z t a) :precision binary64 (if (or (<= (* z t) (- INFINITY)) (not (<= (* z t) 1e+262))) (* (- z) (/ t a)) (/ (fma y x (* (- z) t)) a)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (((z * t) <= -((double) INFINITY)) || !((z * t) <= 1e+262)) {
tmp = -z * (t / a);
} else {
tmp = fma(y, x, (-z * t)) / a;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((Float64(z * t) <= Float64(-Inf)) || !(Float64(z * t) <= 1e+262)) tmp = Float64(Float64(-z) * Float64(t / a)); else tmp = Float64(fma(y, x, Float64(Float64(-z) * t)) / a); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(z * t), $MachinePrecision], 1e+262]], $MachinePrecision]], N[((-z) * N[(t / a), $MachinePrecision]), $MachinePrecision], N[(N[(y * x + N[((-z) * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty \lor \neg \left(z \cdot t \leq 10^{+262}\right):\\
\;\;\;\;\left(-z\right) \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, \left(-z\right) \cdot t\right)}{a}\\
\end{array}
\end{array}
if (*.f64 z t) < -inf.0 or 1e262 < (*.f64 z t) Initial program 56.6%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6497.3
Applied rewrites97.3%
if -inf.0 < (*.f64 z t) < 1e262Initial program 97.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6497.8
Applied rewrites97.8%
Final simplification97.7%
(FPCore (x y z t a) :precision binary64 (if (or (<= (* z t) (- INFINITY)) (not (<= (* z t) 1e+262))) (* (- z) (/ t a)) (/ (- (* x y) (* z t)) a)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (((z * t) <= -((double) INFINITY)) || !((z * t) <= 1e+262)) {
tmp = -z * (t / a);
} else {
tmp = ((x * y) - (z * t)) / a;
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (((z * t) <= -Double.POSITIVE_INFINITY) || !((z * t) <= 1e+262)) {
tmp = -z * (t / a);
} else {
tmp = ((x * y) - (z * t)) / a;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if ((z * t) <= -math.inf) or not ((z * t) <= 1e+262): tmp = -z * (t / a) else: tmp = ((x * y) - (z * t)) / a return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((Float64(z * t) <= Float64(-Inf)) || !(Float64(z * t) <= 1e+262)) tmp = Float64(Float64(-z) * Float64(t / a)); else tmp = Float64(Float64(Float64(x * y) - Float64(z * t)) / a); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (((z * t) <= -Inf) || ~(((z * t) <= 1e+262))) tmp = -z * (t / a); else tmp = ((x * y) - (z * t)) / a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(z * t), $MachinePrecision], 1e+262]], $MachinePrecision]], N[((-z) * N[(t / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty \lor \neg \left(z \cdot t \leq 10^{+262}\right):\\
\;\;\;\;\left(-z\right) \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\
\end{array}
\end{array}
if (*.f64 z t) < -inf.0 or 1e262 < (*.f64 z t) Initial program 56.6%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6497.3
Applied rewrites97.3%
if -inf.0 < (*.f64 z t) < 1e262Initial program 97.8%
Final simplification97.7%
(FPCore (x y z t a) :precision binary64 (if (<= a 7.5e-8) (/ (- (* x y) (* z t)) a) (fma (/ y a) x (* (- t) (/ z a)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= 7.5e-8) {
tmp = ((x * y) - (z * t)) / a;
} else {
tmp = fma((y / a), x, (-t * (z / a)));
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= 7.5e-8) tmp = Float64(Float64(Float64(x * y) - Float64(z * t)) / a); else tmp = fma(Float64(y / a), x, Float64(Float64(-t) * Float64(z / a))); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, 7.5e-8], N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * x + N[((-t) * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.5 \cdot 10^{-8}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, x, \left(-t\right) \cdot \frac{z}{a}\right)\\
\end{array}
\end{array}
if a < 7.4999999999999997e-8Initial program 92.3%
if 7.4999999999999997e-8 < a Initial program 88.9%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-/.f6492.8
Applied rewrites92.8%
(FPCore (x y z t a) :precision binary64 (if (or (<= (* z t) -4e-62) (not (<= (* z t) 2e+18))) (* (- z) (/ t a)) (/ (* x y) a)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (((z * t) <= -4e-62) || !((z * t) <= 2e+18)) {
tmp = -z * (t / a);
} else {
tmp = (x * y) / a;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (((z * t) <= (-4d-62)) .or. (.not. ((z * t) <= 2d+18))) then
tmp = -z * (t / a)
else
tmp = (x * y) / a
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (((z * t) <= -4e-62) || !((z * t) <= 2e+18)) {
tmp = -z * (t / a);
} else {
tmp = (x * y) / a;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if ((z * t) <= -4e-62) or not ((z * t) <= 2e+18): tmp = -z * (t / a) else: tmp = (x * y) / a return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((Float64(z * t) <= -4e-62) || !(Float64(z * t) <= 2e+18)) tmp = Float64(Float64(-z) * Float64(t / a)); else tmp = Float64(Float64(x * y) / a); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (((z * t) <= -4e-62) || ~(((z * t) <= 2e+18))) tmp = -z * (t / a); else tmp = (x * y) / a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -4e-62], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e+18]], $MachinePrecision]], N[((-z) * N[(t / a), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{-62} \lor \neg \left(z \cdot t \leq 2 \cdot 10^{+18}\right):\\
\;\;\;\;\left(-z\right) \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{a}\\
\end{array}
\end{array}
if (*.f64 z t) < -4.0000000000000002e-62 or 2e18 < (*.f64 z t) Initial program 87.1%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6475.7
Applied rewrites75.7%
if -4.0000000000000002e-62 < (*.f64 z t) < 2e18Initial program 96.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6496.8
Applied rewrites96.8%
Taylor expanded in x around inf
lower-*.f6483.2
Applied rewrites83.2%
Final simplification79.1%
(FPCore (x y z t a) :precision binary64 (if (<= (* z t) -4e-62) (* (- z) (/ t a)) (if (<= (* z t) 2e+18) (/ (* x y) a) (* (/ (- z) a) t))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z * t) <= -4e-62) {
tmp = -z * (t / a);
} else if ((z * t) <= 2e+18) {
tmp = (x * y) / a;
} else {
tmp = (-z / a) * t;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if ((z * t) <= (-4d-62)) then
tmp = -z * (t / a)
else if ((z * t) <= 2d+18) then
tmp = (x * y) / a
else
tmp = (-z / a) * t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z * t) <= -4e-62) {
tmp = -z * (t / a);
} else if ((z * t) <= 2e+18) {
tmp = (x * y) / a;
} else {
tmp = (-z / a) * t;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (z * t) <= -4e-62: tmp = -z * (t / a) elif (z * t) <= 2e+18: tmp = (x * y) / a else: tmp = (-z / a) * t return tmp
function code(x, y, z, t, a) tmp = 0.0 if (Float64(z * t) <= -4e-62) tmp = Float64(Float64(-z) * Float64(t / a)); elseif (Float64(z * t) <= 2e+18) tmp = Float64(Float64(x * y) / a); else tmp = Float64(Float64(Float64(-z) / a) * t); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((z * t) <= -4e-62) tmp = -z * (t / a); elseif ((z * t) <= 2e+18) tmp = (x * y) / a; else tmp = (-z / a) * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[N[(z * t), $MachinePrecision], -4e-62], N[((-z) * N[(t / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+18], N[(N[(x * y), $MachinePrecision] / a), $MachinePrecision], N[(N[((-z) / a), $MachinePrecision] * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{-62}:\\
\;\;\;\;\left(-z\right) \cdot \frac{t}{a}\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+18}:\\
\;\;\;\;\frac{x \cdot y}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-z}{a} \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -4.0000000000000002e-62Initial program 87.0%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6475.0
Applied rewrites75.0%
if -4.0000000000000002e-62 < (*.f64 z t) < 2e18Initial program 96.8%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6496.8
Applied rewrites96.8%
Taylor expanded in x around inf
lower-*.f6483.2
Applied rewrites83.2%
if 2e18 < (*.f64 z t) Initial program 87.2%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6476.6
Applied rewrites76.6%
Applied rewrites76.6%
(FPCore (x y z t a) :precision binary64 (* (/ x a) y))
double code(double x, double y, double z, double t, double a) {
return (x / a) * y;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (x / a) * y
end function
public static double code(double x, double y, double z, double t, double a) {
return (x / a) * y;
}
def code(x, y, z, t, a): return (x / a) * y
function code(x, y, z, t, a) return Float64(Float64(x / a) * y) end
function tmp = code(x, y, z, t, a) tmp = (x / a) * y; end
code[x_, y_, z_, t_, a_] := N[(N[(x / a), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{a} \cdot y
\end{array}
Initial program 91.5%
Taylor expanded in x around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6450.1
Applied rewrites50.1%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (* (/ y a) x) (* (/ t a) z))))
(if (< z -2.468684968699548e+170)
t_1
(if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = ((y / a) * x) - ((t / a) * z);
double tmp;
if (z < -2.468684968699548e+170) {
tmp = t_1;
} else if (z < 6.309831121978371e-71) {
tmp = ((x * y) - (z * t)) / a;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: t_1
real(8) :: tmp
t_1 = ((y / a) * x) - ((t / a) * z)
if (z < (-2.468684968699548d+170)) then
tmp = t_1
else if (z < 6.309831121978371d-71) then
tmp = ((x * y) - (z * t)) / a
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = ((y / a) * x) - ((t / a) * z);
double tmp;
if (z < -2.468684968699548e+170) {
tmp = t_1;
} else if (z < 6.309831121978371e-71) {
tmp = ((x * y) - (z * t)) / a;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = ((y / a) * x) - ((t / a) * z) tmp = 0 if z < -2.468684968699548e+170: tmp = t_1 elif z < 6.309831121978371e-71: tmp = ((x * y) - (z * t)) / a else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(Float64(y / a) * x) - Float64(Float64(t / a) * z)) tmp = 0.0 if (z < -2.468684968699548e+170) tmp = t_1; elseif (z < 6.309831121978371e-71) tmp = Float64(Float64(Float64(x * y) - Float64(z * t)) / a); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = ((y / a) * x) - ((t / a) * z); tmp = 0.0; if (z < -2.468684968699548e+170) tmp = t_1; elseif (z < 6.309831121978371e-71) tmp = ((x * y) - (z * t)) / a; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(N[(y / a), $MachinePrecision] * x), $MachinePrecision] - N[(N[(t / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -2.468684968699548e+170], t$95$1, If[Less[z, 6.309831121978371e-71], N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\
\mathbf{if}\;z < -2.468684968699548 \cdot 10^{+170}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z < 6.309831121978371 \cdot 10^{-71}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2024338
(FPCore (x y z t a)
:name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
:precision binary64
:alt
(! :herbie-platform default (if (< z -246868496869954800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6309831121978371/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z)))))
(/ (- (* x y) (* z t)) a))