
(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 (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(b, a, (x * y)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(b, a, Float64(x * y))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, x \cdot y\right)\right)
\end{array}
Initial program 96.8%
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%
Final simplification99.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e+26) (* x y) (if (<= (* x y) 0.0) (* a b) (if (<= (* x y) 1e+111) (* t z) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2e+26) {
tmp = x * y;
} else if ((x * y) <= 0.0) {
tmp = a * b;
} else if ((x * y) <= 1e+111) {
tmp = t * z;
} else {
tmp = x * y;
}
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 ((x * y) <= (-2d+26)) then
tmp = x * y
else if ((x * y) <= 0.0d0) then
tmp = a * b
else if ((x * y) <= 1d+111) then
tmp = t * z
else
tmp = x * y
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 ((x * y) <= -2e+26) {
tmp = x * y;
} else if ((x * y) <= 0.0) {
tmp = a * b;
} else if ((x * y) <= 1e+111) {
tmp = t * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2e+26: tmp = x * y elif (x * y) <= 0.0: tmp = a * b elif (x * y) <= 1e+111: tmp = t * z else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2e+26) tmp = Float64(x * y); elseif (Float64(x * y) <= 0.0) tmp = Float64(a * b); elseif (Float64(x * y) <= 1e+111) tmp = Float64(t * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * y) <= -2e+26) tmp = x * y; elseif ((x * y) <= 0.0) tmp = a * b; elseif ((x * y) <= 1e+111) tmp = t * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e+26], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 0.0], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+111], N[(t * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+26}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 0:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq 10^{+111}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.0000000000000001e26 or 9.99999999999999957e110 < (*.f64 x y) Initial program 90.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6437.1
Applied rewrites37.1%
Taylor expanded in b around inf
Applied rewrites34.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6470.9
Applied rewrites70.9%
if -2.0000000000000001e26 < (*.f64 x y) < 0.0Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6466.3
Applied rewrites66.3%
Taylor expanded in x around 0
Applied rewrites57.5%
if 0.0 < (*.f64 x y) < 9.99999999999999957e110Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6483.3
Applied rewrites83.3%
Taylor expanded in b around inf
Applied rewrites60.9%
Taylor expanded in z around inf
Applied rewrites52.6%
Final simplification60.3%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b a (* t z))))
(if (<= (* t z) -1e+144)
t_1
(if (<= (* t z) 2e+35) (fma b a (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (t * z));
double tmp;
if ((t * z) <= -1e+144) {
tmp = t_1;
} else if ((t * z) <= 2e+35) {
tmp = fma(b, a, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(t * z)) tmp = 0.0 if (Float64(t * z) <= -1e+144) tmp = t_1; elseif (Float64(t * z) <= 2e+35) tmp = fma(b, a, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t * z), $MachinePrecision], -1e+144], t$95$1, If[LessEqual[N[(t * z), $MachinePrecision], 2e+35], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{if}\;t \cdot z \leq -1 \cdot 10^{+144}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \cdot z \leq 2 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 z t) < -1.00000000000000002e144 or 1.9999999999999999e35 < (*.f64 z t) Initial program 94.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6489.7
Applied rewrites89.7%
if -1.00000000000000002e144 < (*.f64 z t) < 1.9999999999999999e35Initial program 98.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.1
Applied rewrites89.1%
Final simplification89.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e+267) (* x y) (if (<= (* x y) 2e+130) (fma b a (* t z)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2e+267) {
tmp = x * y;
} else if ((x * y) <= 2e+130) {
tmp = fma(b, a, (t * z));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2e+267) tmp = Float64(x * y); elseif (Float64(x * y) <= 2e+130) tmp = fma(b, a, Float64(t * z)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e+267], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+130], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+267}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+130}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1.9999999999999999e267 or 2.0000000000000001e130 < (*.f64 x y) Initial program 84.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6421.1
Applied rewrites21.1%
Taylor expanded in b around inf
Applied rewrites26.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6490.6
Applied rewrites90.6%
if -1.9999999999999999e267 < (*.f64 x y) < 2.0000000000000001e130Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6482.5
Applied rewrites82.5%
Final simplification84.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* t z) -4e+148) (* t z) (if (<= (* t z) 5e-17) (* a b) (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((t * z) <= -4e+148) {
tmp = t * z;
} else if ((t * z) <= 5e-17) {
tmp = a * b;
} 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 ((t * z) <= (-4d+148)) then
tmp = t * z
else if ((t * z) <= 5d-17) then
tmp = a * b
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 ((t * z) <= -4e+148) {
tmp = t * z;
} else if ((t * z) <= 5e-17) {
tmp = a * b;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t * z) <= -4e+148: tmp = t * z elif (t * z) <= 5e-17: tmp = a * b else: tmp = t * z return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(t * z) <= -4e+148) tmp = Float64(t * z); elseif (Float64(t * z) <= 5e-17) tmp = Float64(a * b); else tmp = Float64(t * z); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((t * z) <= -4e+148) tmp = t * z; elseif ((t * z) <= 5e-17) tmp = a * b; else tmp = t * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -4e+148], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 5e-17], N[(a * b), $MachinePrecision], N[(t * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -4 \cdot 10^{+148}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \cdot z \leq 5 \cdot 10^{-17}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if (*.f64 z t) < -4.0000000000000002e148 or 4.9999999999999999e-17 < (*.f64 z t) Initial program 95.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6487.5
Applied rewrites87.5%
Taylor expanded in b around inf
Applied rewrites68.8%
Taylor expanded in z around inf
Applied rewrites71.4%
if -4.0000000000000002e148 < (*.f64 z t) < 4.9999999999999999e-17Initial program 97.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.8
Applied rewrites88.8%
Taylor expanded in x around 0
Applied rewrites47.2%
Final simplification57.7%
(FPCore (x y z t a b) :precision binary64 (fma y x (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(b, a, (t * z)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(b, a, Float64(t * z))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, t \cdot z\right)\right)
\end{array}
Initial program 96.8%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.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 (* t z))
double code(double x, double y, double z, double t, double a, double b) {
return t * z;
}
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 = t * z
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return t * z;
}
def code(x, y, z, t, a, b): return t * z
function code(x, y, z, t, a, b) return Float64(t * z) end
function tmp = code(x, y, z, t, a, b) tmp = t * z; end
code[x_, y_, z_, t_, a_, b_] := N[(t * z), $MachinePrecision]
\begin{array}{l}
\\
t \cdot z
\end{array}
Initial program 96.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6470.0
Applied rewrites70.0%
Taylor expanded in b around inf
Applied rewrites59.3%
Taylor expanded in z around inf
Applied rewrites38.2%
herbie shell --seed 2024294
(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)))