
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
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), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
real(8) function code(x, y, z, t, a, b)
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), intent (in) :: b
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
(FPCore (x y z t a b) :precision binary64 (fma z t (fma b a (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(b, a, (y * x)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(b, a, Float64(y * x))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, y \cdot x\right)\right)
\end{array}
Initial program 98.4%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -2e+134) (not (<= (* z t) 1e+83))) (fma t z (* b a)) (fma b a (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((z * t) <= -2e+134) || !((z * t) <= 1e+83)) {
tmp = fma(t, z, (b * a));
} else {
tmp = fma(b, a, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(z * t) <= -2e+134) || !(Float64(z * t) <= 1e+83)) tmp = fma(t, z, Float64(b * a)); else tmp = fma(b, a, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -2e+134], N[Not[LessEqual[N[(z * t), $MachinePrecision], 1e+83]], $MachinePrecision]], N[(t * z + N[(b * a), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+134} \lor \neg \left(z \cdot t \leq 10^{+83}\right):\\
\;\;\;\;\mathsf{fma}\left(t, z, b \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -1.99999999999999984e134 or 1.00000000000000003e83 < (*.f64 z t) Initial program 96.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.1
Applied rewrites90.1%
if -1.99999999999999984e134 < (*.f64 z t) < 1.00000000000000003e83Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.9
Applied rewrites89.9%
Applied rewrites89.3%
Final simplification89.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -2e+182) (not (<= (* z t) 1e+83))) (* t z) (fma b a (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((z * t) <= -2e+182) || !((z * t) <= 1e+83)) {
tmp = t * z;
} else {
tmp = fma(b, a, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(z * t) <= -2e+182) || !(Float64(z * t) <= 1e+83)) tmp = Float64(t * z); else tmp = fma(b, a, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -2e+182], N[Not[LessEqual[N[(z * t), $MachinePrecision], 1e+83]], $MachinePrecision]], N[(t * z), $MachinePrecision], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+182} \lor \neg \left(z \cdot t \leq 10^{+83}\right):\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -2.0000000000000001e182 or 1.00000000000000003e83 < (*.f64 z t) Initial program 96.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.9
Applied rewrites89.9%
Taylor expanded in z around inf
lower-*.f6480.0
Applied rewrites80.0%
if -2.0000000000000001e182 < (*.f64 z t) < 1.00000000000000003e83Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.9
Applied rewrites88.9%
Applied rewrites88.3%
Final simplification85.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -2e+182) (not (<= (* z t) 2e+27))) (* t z) (* b a)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((z * t) <= -2e+182) || !((z * t) <= 2e+27)) {
tmp = t * z;
} else {
tmp = b * a;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
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), intent (in) :: b
real(8) :: tmp
if (((z * t) <= (-2d+182)) .or. (.not. ((z * t) <= 2d+27))) then
tmp = t * z
else
tmp = b * a
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((z * t) <= -2e+182) || !((z * t) <= 2e+27)) {
tmp = t * z;
} else {
tmp = b * a;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((z * t) <= -2e+182) or not ((z * t) <= 2e+27): tmp = t * z else: tmp = b * a return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(z * t) <= -2e+182) || !(Float64(z * t) <= 2e+27)) tmp = Float64(t * z); else tmp = Float64(b * a); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((z * t) <= -2e+182) || ~(((z * t) <= 2e+27))) tmp = t * z; else tmp = b * a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -2e+182], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e+27]], $MachinePrecision]], N[(t * z), $MachinePrecision], N[(b * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+182} \lor \neg \left(z \cdot t \leq 2 \cdot 10^{+27}\right):\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;b \cdot a\\
\end{array}
\end{array}
if (*.f64 z t) < -2.0000000000000001e182 or 2e27 < (*.f64 z t) Initial program 96.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.7
Applied rewrites86.7%
Taylor expanded in z around inf
lower-*.f6476.7
Applied rewrites76.7%
if -2.0000000000000001e182 < (*.f64 z t) < 2e27Initial program 99.4%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.6
Applied rewrites90.6%
Taylor expanded in x around 0
Applied rewrites48.5%
Final simplification58.7%
(FPCore (x y z t a b) :precision binary64 (if (<= z -15000000000000.0) (fma t z (* b a)) (if (<= z 3.1e-98) (fma y x (* b a)) (fma t z (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (z <= -15000000000000.0) {
tmp = fma(t, z, (b * a));
} else if (z <= 3.1e-98) {
tmp = fma(y, x, (b * a));
} else {
tmp = fma(t, z, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (z <= -15000000000000.0) tmp = fma(t, z, Float64(b * a)); elseif (z <= 3.1e-98) tmp = fma(y, x, Float64(b * a)); else tmp = fma(t, z, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[z, -15000000000000.0], N[(t * z + N[(b * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.1e-98], N[(y * x + N[(b * a), $MachinePrecision]), $MachinePrecision], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -15000000000000:\\
\;\;\;\;\mathsf{fma}\left(t, z, b \cdot a\right)\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{-98}:\\
\;\;\;\;\mathsf{fma}\left(y, x, b \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\end{array}
\end{array}
if z < -1.5e13Initial program 96.6%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.1
Applied rewrites87.1%
if -1.5e13 < z < 3.1e-98Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.7
Applied rewrites91.7%
if 3.1e-98 < z Initial program 97.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6469.7
Applied rewrites69.7%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
lower-fma.f64N/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f6479.3
Applied rewrites79.3%
(FPCore (x y z t a b) :precision binary64 (if (<= z -15000000000000.0) (fma t z (* b a)) (if (<= z 3.1e-98) (fma b a (* y x)) (fma t z (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (z <= -15000000000000.0) {
tmp = fma(t, z, (b * a));
} else if (z <= 3.1e-98) {
tmp = fma(b, a, (y * x));
} else {
tmp = fma(t, z, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (z <= -15000000000000.0) tmp = fma(t, z, Float64(b * a)); elseif (z <= 3.1e-98) tmp = fma(b, a, Float64(y * x)); else tmp = fma(t, z, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[z, -15000000000000.0], N[(t * z + N[(b * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.1e-98], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -15000000000000:\\
\;\;\;\;\mathsf{fma}\left(t, z, b \cdot a\right)\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{-98}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\end{array}
\end{array}
if z < -1.5e13Initial program 96.6%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.1
Applied rewrites87.1%
if -1.5e13 < z < 3.1e-98Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.7
Applied rewrites91.7%
Applied rewrites91.7%
if 3.1e-98 < z Initial program 97.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6469.7
Applied rewrites69.7%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
lower-fma.f64N/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f6479.3
Applied rewrites79.3%
(FPCore (x y z t a b) :precision binary64 (* b a))
double code(double x, double y, double z, double t, double a, double b) {
return b * a;
}
real(8) function code(x, y, z, t, a, b)
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), intent (in) :: b
code = b * a
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return b * a;
}
def code(x, y, z, t, a, b): return b * a
function code(x, y, z, t, a, b) return Float64(b * a) end
function tmp = code(x, y, z, t, a, b) tmp = b * a; end
code[x_, y_, z_, t_, a_, b_] := N[(b * a), $MachinePrecision]
\begin{array}{l}
\\
b \cdot a
\end{array}
Initial program 98.4%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6468.0
Applied rewrites68.0%
Taylor expanded in x around 0
Applied rewrites35.9%
herbie shell --seed 2024337
(FPCore (x y z t a b)
:name "Linear.V3:$cdot from linear-1.19.1.3, B"
:precision binary64
(+ (+ (* x y) (* z t)) (* a b)))