
(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 z t (fma x y (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(x, y, (a * b)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(x, y, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(x * y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, a \cdot b\right)\right)
\end{array}
Initial program 97.2%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6499.2
Applied rewrites99.2%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma a b (* x y)))) (if (<= (* a b) -2e+61) t_1 (if (<= (* a b) 2e+51) (fma t z (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (x * y));
double tmp;
if ((a * b) <= -2e+61) {
tmp = t_1;
} else if ((a * b) <= 2e+51) {
tmp = fma(t, z, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(x * y)) tmp = 0.0 if (Float64(a * b) <= -2e+61) tmp = t_1; elseif (Float64(a * b) <= 2e+51) tmp = fma(t, z, Float64(x * y)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -2e+61], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 2e+51], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+61}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+51}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -1.9999999999999999e61 or 2e51 < (*.f64 a b) Initial program 96.4%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6486.4
Applied rewrites86.4%
if -1.9999999999999999e61 < (*.f64 a b) < 2e51Initial program 97.9%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6492.9
Applied rewrites92.9%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* x y))))
(if (<= (* x y) -2.2e+153)
t_1
(if (<= (* x y) 1.16e+113) (fma a b (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (x * y));
double tmp;
if ((x * y) <= -2.2e+153) {
tmp = t_1;
} else if ((x * y) <= 1.16e+113) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -2.2e+153) tmp = t_1; elseif (Float64(x * y) <= 1.16e+113) tmp = fma(a, b, Float64(z * t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2.2e+153], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1.16e+113], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -2.2 \cdot 10^{+153}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 1.16 \cdot 10^{+113}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -2.2e153 or 1.1600000000000001e113 < (*.f64 x y) Initial program 91.9%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6491.9
Applied rewrites91.9%
if -2.2e153 < (*.f64 x y) < 1.1600000000000001e113Initial program 99.4%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6488.0
Applied rewrites88.0%
Final simplification89.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -9.5e+158) (* x y) (if (<= (* x y) 3.6e+180) (fma a b (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -9.5e+158) {
tmp = x * y;
} else if ((x * y) <= 3.6e+180) {
tmp = fma(a, b, (z * t));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -9.5e+158) tmp = Float64(x * y); elseif (Float64(x * y) <= 3.6e+180) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -9.5e+158], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 3.6e+180], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -9.5 \cdot 10^{+158}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 3.6 \cdot 10^{+180}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -9.49999999999999913e158 or 3.6000000000000002e180 < (*.f64 x y) Initial program 92.5%
Taylor expanded in x around inf
lower-*.f6485.0
Applied rewrites85.0%
if -9.49999999999999913e158 < (*.f64 x y) < 3.6000000000000002e180Initial program 98.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6486.9
Applied rewrites86.9%
Final simplification86.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -9e+59) (* a b) (if (<= (* a b) 5.4e+51) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -9e+59) {
tmp = a * b;
} else if ((a * b) <= 5.4e+51) {
tmp = z * t;
} 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) <= (-9d+59)) then
tmp = a * b
else if ((a * b) <= 5.4d+51) then
tmp = z * t
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) <= -9e+59) {
tmp = a * b;
} else if ((a * b) <= 5.4e+51) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -9e+59: tmp = a * b elif (a * b) <= 5.4e+51: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -9e+59) tmp = Float64(a * b); elseif (Float64(a * b) <= 5.4e+51) tmp = Float64(z * t); 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) <= -9e+59) tmp = a * b; elseif ((a * b) <= 5.4e+51) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -9e+59], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5.4e+51], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -9 \cdot 10^{+59}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 5.4 \cdot 10^{+51}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -8.99999999999999919e59 or 5.39999999999999983e51 < (*.f64 a b) Initial program 96.4%
Taylor expanded in a around inf
lower-*.f6468.9
Applied rewrites68.9%
if -8.99999999999999919e59 < (*.f64 a b) < 5.39999999999999983e51Initial program 97.9%
Taylor expanded in z around inf
lower-*.f6454.9
Applied rewrites54.9%
Final simplification61.0%
(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 97.2%
Taylor expanded in a around inf
lower-*.f6435.5
Applied rewrites35.5%
herbie shell --seed 2024232
(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)))