
(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 9 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 z t (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(z, t, (a * b)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(z, t, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
\end{array}
Initial program 98.8%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6499.2
Applied rewrites99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -2900000.0)
(* a b)
(if (<= (* a b) 9e-294)
(* y x)
(if (<= (* a b) 1.75e+93) (* z t) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2900000.0) {
tmp = a * b;
} else if ((a * b) <= 9e-294) {
tmp = y * x;
} else if ((a * b) <= 1.75e+93) {
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) <= (-2900000.0d0)) then
tmp = a * b
else if ((a * b) <= 9d-294) then
tmp = y * x
else if ((a * b) <= 1.75d+93) 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) <= -2900000.0) {
tmp = a * b;
} else if ((a * b) <= 9e-294) {
tmp = y * x;
} else if ((a * b) <= 1.75e+93) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -2900000.0: tmp = a * b elif (a * b) <= 9e-294: tmp = y * x elif (a * b) <= 1.75e+93: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2900000.0) tmp = Float64(a * b); elseif (Float64(a * b) <= 9e-294) tmp = Float64(y * x); elseif (Float64(a * b) <= 1.75e+93) 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) <= -2900000.0) tmp = a * b; elseif ((a * b) <= 9e-294) tmp = y * x; elseif ((a * b) <= 1.75e+93) 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], -2900000.0], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 9e-294], N[(y * x), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.75e+93], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2900000:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 9 \cdot 10^{-294}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;a \cdot b \leq 1.75 \cdot 10^{+93}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -2.9e6 or 1.74999999999999999e93 < (*.f64 a b) Initial program 98.2%
Taylor expanded in a around inf
lower-*.f6471.0
Applied rewrites71.0%
if -2.9e6 < (*.f64 a b) < 8.99999999999999963e-294Initial program 98.6%
Taylor expanded in x around inf
lower-*.f6453.2
Applied rewrites53.2%
if 8.99999999999999963e-294 < (*.f64 a b) < 1.74999999999999999e93Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6453.3
Applied rewrites53.3%
Final simplification61.3%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -2e-32) (fma y x (* a b)) (if (<= (* a b) 5e+86) (fma y x (* z t)) (fma a b (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2e-32) {
tmp = fma(y, x, (a * b));
} else if ((a * b) <= 5e+86) {
tmp = fma(y, x, (z * t));
} else {
tmp = fma(a, b, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2e-32) tmp = fma(y, x, Float64(a * b)); elseif (Float64(a * b) <= 5e+86) tmp = fma(y, x, Float64(z * t)); else tmp = fma(a, b, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -2e-32], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e+86], N[(y * x + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{-32}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -2.00000000000000011e-32Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
lower-*.f6485.8
Applied rewrites85.8%
if -2.00000000000000011e-32 < (*.f64 a b) < 4.9999999999999998e86Initial program 99.2%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
lower-*.f6492.9
Applied rewrites92.9%
if 4.9999999999999998e86 < (*.f64 a b) Initial program 95.2%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6492.5
Applied rewrites92.5%
Final simplification90.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -2e-32) (fma y x (* a b)) (if (<= (* a b) 5e+86) (fma t z (* y x)) (fma a b (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2e-32) {
tmp = fma(y, x, (a * b));
} else if ((a * b) <= 5e+86) {
tmp = fma(t, z, (y * x));
} else {
tmp = fma(a, b, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2e-32) tmp = fma(y, x, Float64(a * b)); elseif (Float64(a * b) <= 5e+86) tmp = fma(t, z, Float64(y * x)); else tmp = fma(a, b, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -2e-32], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e+86], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{-32}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -2.00000000000000011e-32Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
lower-*.f6485.8
Applied rewrites85.8%
if -2.00000000000000011e-32 < (*.f64 a b) < 4.9999999999999998e86Initial program 99.2%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6492.1
Applied rewrites92.1%
if 4.9999999999999998e86 < (*.f64 a b) Initial program 95.2%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6492.5
Applied rewrites92.5%
Final simplification90.2%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma a b (* y x)))) (if (<= (* a b) -2e-32) t_1 (if (<= (* a b) 5e+86) (fma t z (* y x)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (y * x));
double tmp;
if ((a * b) <= -2e-32) {
tmp = t_1;
} else if ((a * b) <= 5e+86) {
tmp = fma(t, z, (y * x));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(y * x)) tmp = 0.0 if (Float64(a * b) <= -2e-32) tmp = t_1; elseif (Float64(a * b) <= 5e+86) tmp = fma(t, z, Float64(y * x)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -2e-32], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 5e+86], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, y \cdot x\right)\\
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{-32}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -2.00000000000000011e-32 or 4.9999999999999998e86 < (*.f64 a b) Initial program 98.4%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6488.0
Applied rewrites88.0%
if -2.00000000000000011e-32 < (*.f64 a b) < 4.9999999999999998e86Initial program 99.2%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6492.1
Applied rewrites92.1%
Final simplification90.2%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* y x))))
(if (<= (* y x) -4.1e+62)
t_1
(if (<= (* y x) 4.4e-52) (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, (y * x));
double tmp;
if ((y * x) <= -4.1e+62) {
tmp = t_1;
} else if ((y * x) <= 4.4e-52) {
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(y * x)) tmp = 0.0 if (Float64(y * x) <= -4.1e+62) tmp = t_1; elseif (Float64(y * x) <= 4.4e-52) 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[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * x), $MachinePrecision], -4.1e+62], t$95$1, If[LessEqual[N[(y * x), $MachinePrecision], 4.4e-52], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, y \cdot x\right)\\
\mathbf{if}\;y \cdot x \leq -4.1 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \cdot x \leq 4.4 \cdot 10^{-52}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -4.09999999999999984e62 or 4.40000000000000018e-52 < (*.f64 x y) Initial program 97.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6483.3
Applied rewrites83.3%
if -4.09999999999999984e62 < (*.f64 x y) < 4.40000000000000018e-52Initial program 100.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6494.1
Applied rewrites94.1%
Final simplification88.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* y x) -3.9e+169) (* y x) (if (<= (* y x) 7.6e+161) (fma a b (* z t)) (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y * x) <= -3.9e+169) {
tmp = y * x;
} else if ((y * x) <= 7.6e+161) {
tmp = fma(a, b, (z * t));
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(y * x) <= -3.9e+169) tmp = Float64(y * x); elseif (Float64(y * x) <= 7.6e+161) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(y * x), $MachinePrecision], -3.9e+169], N[(y * x), $MachinePrecision], If[LessEqual[N[(y * x), $MachinePrecision], 7.6e+161], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -3.9 \cdot 10^{+169}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \cdot x \leq 7.6 \cdot 10^{+161}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -3.89999999999999983e169 or 7.6000000000000005e161 < (*.f64 x y) Initial program 95.6%
Taylor expanded in x around inf
lower-*.f6480.1
Applied rewrites80.1%
if -3.89999999999999983e169 < (*.f64 x y) < 7.6000000000000005e161Initial program 100.0%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6483.2
Applied rewrites83.2%
Final simplification82.4%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -5.2e-53) (* a b) (if (<= (* a b) 1.75e+93) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5.2e-53) {
tmp = a * b;
} else if ((a * b) <= 1.75e+93) {
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) <= (-5.2d-53)) then
tmp = a * b
else if ((a * b) <= 1.75d+93) 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) <= -5.2e-53) {
tmp = a * b;
} else if ((a * b) <= 1.75e+93) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -5.2e-53: tmp = a * b elif (a * b) <= 1.75e+93: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -5.2e-53) tmp = Float64(a * b); elseif (Float64(a * b) <= 1.75e+93) 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) <= -5.2e-53) tmp = a * b; elseif ((a * b) <= 1.75e+93) 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], -5.2e-53], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.75e+93], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5.2 \cdot 10^{-53}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 1.75 \cdot 10^{+93}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -5.19999999999999993e-53 or 1.74999999999999999e93 < (*.f64 a b) Initial program 98.3%
Taylor expanded in a around inf
lower-*.f6468.7
Applied rewrites68.7%
if -5.19999999999999993e-53 < (*.f64 a b) < 1.74999999999999999e93Initial program 99.2%
Taylor expanded in z around inf
lower-*.f6449.9
Applied rewrites49.9%
Final simplification59.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 98.8%
Taylor expanded in a around inf
lower-*.f6437.8
Applied rewrites37.8%
herbie shell --seed 2024233
(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)))