
(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 6 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 b a (fma t z (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(b, a, fma(t, z, (y * x)));
}
function code(x, y, z, t, a, b) return fma(b, a, fma(t, z, Float64(y * x))) end
code[x_, y_, z_, t_, a_, b_] := N[(b * a + N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b, a, \mathsf{fma}\left(t, z, y \cdot x\right)\right)
\end{array}
Initial program 96.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6497.3
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.0
Applied rewrites98.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -1.5e+94) (not (<= (* x y) 1e+37))) (fma y x (* b a)) (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -1.5e+94) || !((x * y) <= 1e+37)) {
tmp = fma(y, x, (b * a));
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -1.5e+94) || !(Float64(x * y) <= 1e+37)) tmp = fma(y, x, Float64(b * a)); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -1.5e+94], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e+37]], $MachinePrecision]], N[(y * x + N[(b * a), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.5 \cdot 10^{+94} \lor \neg \left(x \cdot y \leq 10^{+37}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, b \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.5e94 or 9.99999999999999954e36 < (*.f64 x y) Initial program 91.7%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.9
Applied rewrites85.9%
if -1.5e94 < (*.f64 x y) < 9.99999999999999954e36Initial program 99.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-*.f6490.4
Applied rewrites90.4%
Final simplification88.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -5e-19) (not (<= (* z t) 5e+22))) (fma t z (* b a)) (fma y x (* b a))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((z * t) <= -5e-19) || !((z * t) <= 5e+22)) {
tmp = fma(t, z, (b * a));
} else {
tmp = fma(y, x, (b * a));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(z * t) <= -5e-19) || !(Float64(z * t) <= 5e+22)) tmp = fma(t, z, Float64(b * a)); else tmp = fma(y, x, Float64(b * a)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -5e-19], N[Not[LessEqual[N[(z * t), $MachinePrecision], 5e+22]], $MachinePrecision]], N[(t * z + N[(b * a), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(b * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{-19} \lor \neg \left(z \cdot t \leq 5 \cdot 10^{+22}\right):\\
\;\;\;\;\mathsf{fma}\left(t, z, b \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, b \cdot a\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -5.0000000000000004e-19 or 4.9999999999999996e22 < (*.f64 z t) Initial program 95.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.0
Applied rewrites85.0%
if -5.0000000000000004e-19 < (*.f64 z t) < 4.9999999999999996e22Initial program 97.6%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.0
Applied rewrites92.0%
Final simplification88.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -5e-19) (not (<= (* z t) 5e+22))) (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) <= -5e-19) || !((z * t) <= 5e+22)) {
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) <= -5e-19) || !(Float64(z * t) <= 5e+22)) 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], -5e-19], N[Not[LessEqual[N[(z * t), $MachinePrecision], 5e+22]], $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 -5 \cdot 10^{-19} \lor \neg \left(z \cdot t \leq 5 \cdot 10^{+22}\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) < -5.0000000000000004e-19 or 4.9999999999999996e22 < (*.f64 z t) Initial program 95.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.0
Applied rewrites85.0%
if -5.0000000000000004e-19 < (*.f64 z t) < 4.9999999999999996e22Initial program 97.6%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.0
Applied rewrites92.0%
Applied rewrites91.2%
Final simplification88.1%
(FPCore (x y z t a b) :precision binary64 (fma b a (* y x)))
double code(double x, double y, double z, double t, double a, double b) {
return fma(b, a, (y * x));
}
function code(x, y, z, t, a, b) return fma(b, a, Float64(y * x)) end
code[x_, y_, z_, t_, a_, b_] := N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b, a, y \cdot x\right)
\end{array}
Initial program 96.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6464.8
Applied rewrites64.8%
Applied rewrites64.0%
(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 96.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6464.8
Applied rewrites64.8%
Taylor expanded in x around 0
Applied rewrites35.2%
herbie shell --seed 2024339
(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)))