
(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 96.9%
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 (<= (* a b) -5e+81) (* b a) (if (<= (* a b) 2e-271) (* t z) (if (<= (* a b) 5e-21) (* y x) (* b a)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5e+81) {
tmp = b * a;
} else if ((a * b) <= 2e-271) {
tmp = t * z;
} else if ((a * b) <= 5e-21) {
tmp = y * x;
} 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 ((a * b) <= (-5d+81)) then
tmp = b * a
else if ((a * b) <= 2d-271) then
tmp = t * z
else if ((a * b) <= 5d-21) then
tmp = y * x
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 ((a * b) <= -5e+81) {
tmp = b * a;
} else if ((a * b) <= 2e-271) {
tmp = t * z;
} else if ((a * b) <= 5e-21) {
tmp = y * x;
} else {
tmp = b * a;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -5e+81: tmp = b * a elif (a * b) <= 2e-271: tmp = t * z elif (a * b) <= 5e-21: tmp = y * x else: tmp = b * a return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -5e+81) tmp = Float64(b * a); elseif (Float64(a * b) <= 2e-271) tmp = Float64(t * z); elseif (Float64(a * b) <= 5e-21) tmp = Float64(y * x); else tmp = Float64(b * a); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((a * b) <= -5e+81) tmp = b * a; elseif ((a * b) <= 2e-271) tmp = t * z; elseif ((a * b) <= 5e-21) tmp = y * x; else tmp = b * a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -5e+81], N[(b * a), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e-271], N[(t * z), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e-21], N[(y * x), $MachinePrecision], N[(b * a), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+81}:\\
\;\;\;\;b \cdot a\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-271}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{-21}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;b \cdot a\\
\end{array}
\end{array}
if (*.f64 a b) < -4.9999999999999998e81 or 4.99999999999999973e-21 < (*.f64 a b) Initial program 94.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.7
Applied rewrites85.7%
Taylor expanded in x around 0
Applied rewrites73.5%
if -4.9999999999999998e81 < (*.f64 a b) < 1.99999999999999993e-271Initial program 98.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6458.0
Applied rewrites58.0%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6493.8
Applied rewrites93.8%
Taylor expanded in x around 0
Applied rewrites51.8%
if 1.99999999999999993e-271 < (*.f64 a b) < 4.99999999999999973e-21Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6445.9
Applied rewrites45.9%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6497.6
Applied rewrites97.6%
Taylor expanded in x around 0
Applied rewrites43.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6454.1
Applied rewrites54.1%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -5e+111) (not (<= (* z t) 1e+19))) (fma b a (* 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) <= -5e+111) || !((z * t) <= 1e+19)) {
tmp = fma(b, a, (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) <= -5e+111) || !(Float64(z * t) <= 1e+19)) tmp = fma(b, a, 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], -5e+111], N[Not[LessEqual[N[(z * t), $MachinePrecision], 1e+19]], $MachinePrecision]], N[(b * a + N[(t * z), $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^{+111} \lor \neg \left(z \cdot t \leq 10^{+19}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -4.9999999999999997e111 or 1e19 < (*.f64 z t) Initial program 93.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6481.6
Applied rewrites81.6%
if -4.9999999999999997e111 < (*.f64 z t) < 1e19Initial program 99.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.1
Applied rewrites90.1%
Final simplification86.5%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -2e+146) (not (<= (* x y) 1e+240))) (* y x) (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -2e+146) || !((x * y) <= 1e+240)) {
tmp = y * x;
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -2e+146) || !(Float64(x * y) <= 1e+240)) tmp = Float64(y * x); 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], -2e+146], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e+240]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+146} \lor \neg \left(x \cdot y \leq 10^{+240}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999987e146 or 1.00000000000000001e240 < (*.f64 x y) Initial program 95.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6425.6
Applied rewrites25.6%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.7
Applied rewrites92.7%
Taylor expanded in x around 0
Applied rewrites13.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6484.1
Applied rewrites84.1%
if -1.99999999999999987e146 < (*.f64 x y) < 1.00000000000000001e240Initial program 97.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6483.7
Applied rewrites83.7%
Final simplification83.8%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -5e+81) (fma b a (* y x)) (if (<= (* a b) 5e-21) (fma t z (* y x)) (fma b a (* t z)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5e+81) {
tmp = fma(b, a, (y * x));
} else if ((a * b) <= 5e-21) {
tmp = fma(t, z, (y * x));
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -5e+81) tmp = fma(b, a, Float64(y * x)); elseif (Float64(a * b) <= 5e-21) tmp = fma(t, z, Float64(y * x)); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -5e+81], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e-21], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+81}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -4.9999999999999998e81Initial program 96.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.8
Applied rewrites89.8%
if -4.9999999999999998e81 < (*.f64 a b) < 4.99999999999999973e-21Initial program 99.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6454.4
Applied rewrites54.4%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.9
Applied rewrites94.9%
if 4.99999999999999973e-21 < (*.f64 a b) Initial program 92.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6486.7
Applied rewrites86.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -5e+81) (not (<= (* a b) 5e-27))) (* b a) (* t z)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -5e+81) || !((a * b) <= 5e-27)) {
tmp = b * a;
} else {
tmp = t * z;
}
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 (((a * b) <= (-5d+81)) .or. (.not. ((a * b) <= 5d-27))) then
tmp = b * a
else
tmp = t * z
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 (((a * b) <= -5e+81) || !((a * b) <= 5e-27)) {
tmp = b * a;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -5e+81) or not ((a * b) <= 5e-27): tmp = b * a else: tmp = t * z return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -5e+81) || !(Float64(a * b) <= 5e-27)) tmp = Float64(b * a); else tmp = Float64(t * z); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((a * b) <= -5e+81) || ~(((a * b) <= 5e-27))) tmp = b * a; else tmp = t * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -5e+81], N[Not[LessEqual[N[(a * b), $MachinePrecision], 5e-27]], $MachinePrecision]], N[(b * a), $MachinePrecision], N[(t * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+81} \lor \neg \left(a \cdot b \leq 5 \cdot 10^{-27}\right):\\
\;\;\;\;b \cdot a\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 a b) < -4.9999999999999998e81 or 5.0000000000000002e-27 < (*.f64 a b) Initial program 94.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.9
Applied rewrites85.9%
Taylor expanded in x around 0
Applied rewrites73.0%
if -4.9999999999999998e81 < (*.f64 a b) < 5.0000000000000002e-27Initial program 99.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6454.7
Applied rewrites54.7%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.9
Applied rewrites94.9%
Taylor expanded in x around 0
Applied rewrites49.6%
Final simplification60.9%
(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.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6469.1
Applied rewrites69.1%
Taylor expanded in x around 0
Applied rewrites39.2%
herbie shell --seed 2024324
(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)))