
(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 98.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.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e+28) (* x y) (if (<= (* x y) 5e-210) (* t z) (if (<= (* x y) 5e+107) (* a b) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2e+28) {
tmp = x * y;
} else if ((x * y) <= 5e-210) {
tmp = t * z;
} else if ((x * y) <= 5e+107) {
tmp = a * b;
} 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+28)) then
tmp = x * y
else if ((x * y) <= 5d-210) then
tmp = t * z
else if ((x * y) <= 5d+107) then
tmp = a * b
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+28) {
tmp = x * y;
} else if ((x * y) <= 5e-210) {
tmp = t * z;
} else if ((x * y) <= 5e+107) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2e+28: tmp = x * y elif (x * y) <= 5e-210: tmp = t * z elif (x * y) <= 5e+107: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2e+28) tmp = Float64(x * y); elseif (Float64(x * y) <= 5e-210) tmp = Float64(t * z); elseif (Float64(x * y) <= 5e+107) tmp = Float64(a * b); 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+28) tmp = x * y; elseif ((x * y) <= 5e-210) tmp = t * z; elseif ((x * y) <= 5e+107) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e+28], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e-210], N[(t * z), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+107], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+28}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-210}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+107}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999992e28 or 5.0000000000000002e107 < (*.f64 x y) Initial program 98.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6472.2
Applied rewrites72.2%
if -1.99999999999999992e28 < (*.f64 x y) < 5.0000000000000002e-210Initial program 99.0%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6456.6
Applied rewrites56.6%
if 5.0000000000000002e-210 < (*.f64 x y) < 5.0000000000000002e107Initial program 98.3%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6458.7
Applied rewrites58.7%
Final simplification63.1%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma z t (* x y)))) (if (<= (* x y) -5e+23) t_1 (if (<= (* x y) 5e+70) (fma b a (* t z)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(z, t, (x * y));
double tmp;
if ((x * y) <= -5e+23) {
tmp = t_1;
} else if ((x * y) <= 5e+70) {
tmp = fma(b, a, (t * z));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(z, t, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -5e+23) tmp = t_1; elseif (Float64(x * y) <= 5e+70) tmp = fma(b, a, Float64(t * z)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -5e+23], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 5e+70], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, t, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+70}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999999e23 or 5.0000000000000002e70 < (*.f64 x y) Initial program 98.1%
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.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f6489.9
Applied rewrites89.9%
if -4.9999999999999999e23 < (*.f64 x y) < 5.0000000000000002e70Initial program 99.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.5
Applied rewrites91.5%
Final simplification90.8%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma y x (* t z)))) (if (<= (* x y) -5e+23) t_1 (if (<= (* x y) 5e+70) (fma b a (* t z)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(y, x, (t * z));
double tmp;
if ((x * y) <= -5e+23) {
tmp = t_1;
} else if ((x * y) <= 5e+70) {
tmp = fma(b, a, (t * z));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(y, x, Float64(t * z)) tmp = 0.0 if (Float64(x * y) <= -5e+23) tmp = t_1; elseif (Float64(x * y) <= 5e+70) tmp = fma(b, a, Float64(t * z)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -5e+23], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 5e+70], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+23}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+70}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999999e23 or 5.0000000000000002e70 < (*.f64 x y) Initial program 98.1%
Taylor expanded in b around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.9
Applied rewrites88.9%
if -4.9999999999999999e23 < (*.f64 x y) < 5.0000000000000002e70Initial program 99.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.5
Applied rewrites91.5%
Final simplification90.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -2e+140) (* x y) (if (<= (* x y) 2e+134) (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+140) {
tmp = x * y;
} else if ((x * y) <= 2e+134) {
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+140) tmp = Float64(x * y); elseif (Float64(x * y) <= 2e+134) 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+140], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+134], 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^{+140}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+134}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.00000000000000012e140 or 1.99999999999999984e134 < (*.f64 x y) Initial program 98.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6478.9
Applied rewrites78.9%
if -2.00000000000000012e140 < (*.f64 x y) < 1.99999999999999984e134Initial program 98.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6485.9
Applied rewrites85.9%
Final simplification83.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1e+22) (* x y) (if (<= (* x y) 5e+107) (* a b) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1e+22) {
tmp = x * y;
} else if ((x * y) <= 5e+107) {
tmp = a * b;
} 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) <= (-1d+22)) then
tmp = x * y
else if ((x * y) <= 5d+107) then
tmp = a * b
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) <= -1e+22) {
tmp = x * y;
} else if ((x * y) <= 5e+107) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -1e+22: tmp = x * y elif (x * y) <= 5e+107: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1e+22) tmp = Float64(x * y); elseif (Float64(x * y) <= 5e+107) tmp = Float64(a * b); 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) <= -1e+22) tmp = x * y; elseif ((x * y) <= 5e+107) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -1e+22], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+107], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+22}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+107}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -1e22 or 5.0000000000000002e107 < (*.f64 x y) Initial program 99.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6470.6
Applied rewrites70.6%
if -1e22 < (*.f64 x y) < 5.0000000000000002e107Initial program 98.7%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6448.8
Applied rewrites48.8%
Final simplification57.4%
(FPCore (x y z t a b) :precision binary64 (* a b))
double code(double x, double y, double z, double t, double a, double b) {
return 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 = a * b
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return a * b;
}
def code(x, y, z, t, a, b): return a * b
function code(x, y, z, t, a, b) return Float64(a * b) end
function tmp = code(x, y, z, t, a, b) tmp = a * b; end
code[x_, y_, z_, t_, a_, b_] := N[(a * b), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b
\end{array}
Initial program 98.8%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6436.3
Applied rewrites36.3%
Final simplification36.3%
herbie shell --seed 2024277
(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)))