
(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 y x (fma b a (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(b, a, (z * t)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(b, a, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, z \cdot t\right)\right)
\end{array}
Initial program 96.9%
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.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -5e+249)
(* x y)
(if (<= (* x y) -2e-81)
(* a b)
(if (<= (* x y) 4e-171)
(* z t)
(if (<= (* x y) 5e+47) (* a b) (* x y))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -5e+249) {
tmp = x * y;
} else if ((x * y) <= -2e-81) {
tmp = a * b;
} else if ((x * y) <= 4e-171) {
tmp = z * t;
} else if ((x * y) <= 5e+47) {
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) <= (-5d+249)) then
tmp = x * y
else if ((x * y) <= (-2d-81)) then
tmp = a * b
else if ((x * y) <= 4d-171) then
tmp = z * t
else if ((x * y) <= 5d+47) 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) <= -5e+249) {
tmp = x * y;
} else if ((x * y) <= -2e-81) {
tmp = a * b;
} else if ((x * y) <= 4e-171) {
tmp = z * t;
} else if ((x * y) <= 5e+47) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -5e+249: tmp = x * y elif (x * y) <= -2e-81: tmp = a * b elif (x * y) <= 4e-171: tmp = z * t elif (x * y) <= 5e+47: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -5e+249) tmp = Float64(x * y); elseif (Float64(x * y) <= -2e-81) tmp = Float64(a * b); elseif (Float64(x * y) <= 4e-171) tmp = Float64(z * t); elseif (Float64(x * y) <= 5e+47) 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) <= -5e+249) tmp = x * y; elseif ((x * y) <= -2e-81) tmp = a * b; elseif ((x * y) <= 4e-171) tmp = z * t; elseif ((x * y) <= 5e+47) 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], -5e+249], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -2e-81], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4e-171], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+47], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+249}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq -2 \cdot 10^{-81}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{-171}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+47}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999996e249 or 5.00000000000000022e47 < (*.f64 x y) Initial program 91.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6482.1
Applied rewrites82.1%
if -4.9999999999999996e249 < (*.f64 x y) < -1.9999999999999999e-81 or 3.9999999999999999e-171 < (*.f64 x y) < 5.00000000000000022e47Initial program 100.0%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6453.3
Applied rewrites53.3%
if -1.9999999999999999e-81 < (*.f64 x y) < 3.9999999999999999e-171Initial program 97.7%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6462.3
Applied rewrites62.3%
Final simplification64.7%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma y x (* a b)))) (if (<= (* x y) -2e-57) t_1 (if (<= (* x y) 5e+47) (fma b a (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(y, x, (a * b));
double tmp;
if ((x * y) <= -2e-57) {
tmp = t_1;
} else if ((x * y) <= 5e+47) {
tmp = fma(b, a, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(y, x, Float64(a * b)) tmp = 0.0 if (Float64(x * y) <= -2e-57) tmp = t_1; elseif (Float64(x * y) <= 5e+47) tmp = fma(b, a, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2e-57], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 5e+47], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-57}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999991e-57 or 5.00000000000000022e47 < (*.f64 x y) Initial program 94.9%
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.f6496.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6496.6
Applied rewrites96.6%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6490.9
Applied rewrites90.9%
if -1.99999999999999991e-57 < (*.f64 x y) < 5.00000000000000022e47Initial program 98.5%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.3
Applied rewrites91.3%
Final simplification91.1%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma b a (* x y)))) (if (<= (* x y) -2e-57) t_1 (if (<= (* x y) 5e+47) (fma b a (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, a, (x * y));
double tmp;
if ((x * y) <= -2e-57) {
tmp = t_1;
} else if ((x * y) <= 5e+47) {
tmp = fma(b, a, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, a, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -2e-57) tmp = t_1; elseif (Float64(x * y) <= 5e+47) tmp = fma(b, a, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2e-57], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 5e+47], N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-57}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(b, a, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -1.99999999999999991e-57 or 5.00000000000000022e47 < (*.f64 x y) Initial program 94.9%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.0
Applied rewrites90.0%
if -1.99999999999999991e-57 < (*.f64 x y) < 5.00000000000000022e47Initial program 98.5%
Taylor expanded in y around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.3
Applied rewrites91.3%
Final simplification90.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -2.5e+166) (* z t) (if (<= (* z t) 4e+192) (fma b a (* x y)) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -2.5e+166) {
tmp = z * t;
} else if ((z * t) <= 4e+192) {
tmp = fma(b, a, (x * y));
} else {
tmp = z * t;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -2.5e+166) tmp = Float64(z * t); elseif (Float64(z * t) <= 4e+192) tmp = fma(b, a, Float64(x * y)); else tmp = Float64(z * t); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -2.5e+166], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 4e+192], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2.5 \cdot 10^{+166}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+192}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -2.5000000000000001e166 or 4.00000000000000016e192 < (*.f64 z t) Initial program 89.2%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f6477.1
Applied rewrites77.1%
if -2.5000000000000001e166 < (*.f64 z t) < 4.00000000000000016e192Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.9
Applied rewrites84.9%
Final simplification82.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -2e+155) (* a b) (if (<= (* a b) 2e+73) (* x y) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2e+155) {
tmp = a * b;
} else if ((a * b) <= 2e+73) {
tmp = x * y;
} else {
tmp = a * b;
}
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) <= (-2d+155)) then
tmp = a * b
else if ((a * b) <= 2d+73) then
tmp = x * y
else
tmp = a * b
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) <= -2e+155) {
tmp = a * b;
} else if ((a * b) <= 2e+73) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -2e+155: tmp = a * b elif (a * b) <= 2e+73: tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2e+155) tmp = Float64(a * b); elseif (Float64(a * b) <= 2e+73) tmp = Float64(x * y); else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((a * b) <= -2e+155) tmp = a * b; elseif ((a * b) <= 2e+73) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -2e+155], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e+73], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+155}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+73}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -2.00000000000000001e155 or 1.99999999999999997e73 < (*.f64 a b) Initial program 94.4%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6474.3
Applied rewrites74.3%
if -2.00000000000000001e155 < (*.f64 a b) < 1.99999999999999997e73Initial program 98.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6448.8
Applied rewrites48.8%
Final simplification57.7%
(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 96.9%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f6436.3
Applied rewrites36.3%
Final simplification36.3%
herbie shell --seed 2024268
(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)))