
(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 10 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 (let* ((t_1 (+ (* z t) (* x y)))) (if (<= t_1 5e+303) (+ (* a b) t_1) (+ (* a b) (* y (+ x (* t (/ z y))))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * t) + (x * y);
double tmp;
if (t_1 <= 5e+303) {
tmp = (a * b) + t_1;
} else {
tmp = (a * b) + (y * (x + (t * (z / 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) :: t_1
real(8) :: tmp
t_1 = (z * t) + (x * y)
if (t_1 <= 5d+303) then
tmp = (a * b) + t_1
else
tmp = (a * b) + (y * (x + (t * (z / y))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * t) + (x * y);
double tmp;
if (t_1 <= 5e+303) {
tmp = (a * b) + t_1;
} else {
tmp = (a * b) + (y * (x + (t * (z / y))));
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (z * t) + (x * y) tmp = 0 if t_1 <= 5e+303: tmp = (a * b) + t_1 else: tmp = (a * b) + (y * (x + (t * (z / y)))) return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(z * t) + Float64(x * y)) tmp = 0.0 if (t_1 <= 5e+303) tmp = Float64(Float64(a * b) + t_1); else tmp = Float64(Float64(a * b) + Float64(y * Float64(x + Float64(t * Float64(z / y))))); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (z * t) + (x * y); tmp = 0.0; if (t_1 <= 5e+303) tmp = (a * b) + t_1; else tmp = (a * b) + (y * (x + (t * (z / y)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e+303], N[(N[(a * b), $MachinePrecision] + t$95$1), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(y * N[(x + N[(t * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot t + x \cdot y\\
\mathbf{if}\;t\_1 \leq 5 \cdot 10^{+303}:\\
\;\;\;\;a \cdot b + t\_1\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + y \cdot \left(x + t \cdot \frac{z}{y}\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z t)) < 4.9999999999999997e303Initial program 100.0%
if 4.9999999999999997e303 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 86.5%
Taylor expanded in y around inf 97.3%
associate-/l*100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t a b) :precision binary64 (fma x y (fma z t (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, fma(z, t, (a * b)));
}
function code(x, y, z, t, a, b) return fma(x, y, fma(z, t, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(x * y + N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
\end{array}
Initial program 98.0%
associate-+l+98.0%
fma-define99.6%
fma-define99.6%
Simplified99.6%
(FPCore (x y z t a b) :precision binary64 (fma a b (fma x y (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(a, b, fma(x, y, (z * t)));
}
function code(x, y, z, t, a, b) return fma(a, b, fma(x, y, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(a * b + N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, b, \mathsf{fma}\left(x, y, z \cdot t\right)\right)
\end{array}
Initial program 98.0%
+-commutative98.0%
fma-define98.0%
fma-define99.6%
Simplified99.6%
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (fma x y (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + fma(x, y, (z * t));
}
function code(x, y, z, t, a, b) return Float64(Float64(a * b) + fma(x, y, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + \mathsf{fma}\left(x, y, z \cdot t\right)
\end{array}
Initial program 98.0%
fma-define99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* z t) -8e+56)
(* z t)
(if (<= (* z t) 3.7e-114)
(* a b)
(if (<= (* z t) 1.2e+101) (* x y) (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -8e+56) {
tmp = z * t;
} else if ((z * t) <= 3.7e-114) {
tmp = a * b;
} else if ((z * t) <= 1.2e+101) {
tmp = x * y;
} else {
tmp = z * t;
}
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 ((z * t) <= (-8d+56)) then
tmp = z * t
else if ((z * t) <= 3.7d-114) then
tmp = a * b
else if ((z * t) <= 1.2d+101) then
tmp = x * y
else
tmp = z * t
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 ((z * t) <= -8e+56) {
tmp = z * t;
} else if ((z * t) <= 3.7e-114) {
tmp = a * b;
} else if ((z * t) <= 1.2e+101) {
tmp = x * y;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -8e+56: tmp = z * t elif (z * t) <= 3.7e-114: tmp = a * b elif (z * t) <= 1.2e+101: tmp = x * y else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -8e+56) tmp = Float64(z * t); elseif (Float64(z * t) <= 3.7e-114) tmp = Float64(a * b); elseif (Float64(z * t) <= 1.2e+101) tmp = Float64(x * y); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((z * t) <= -8e+56) tmp = z * t; elseif ((z * t) <= 3.7e-114) tmp = a * b; elseif ((z * t) <= 1.2e+101) tmp = x * y; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -8e+56], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 3.7e-114], N[(a * b), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1.2e+101], N[(x * y), $MachinePrecision], N[(z * t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -8 \cdot 10^{+56}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 3.7 \cdot 10^{-114}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \cdot t \leq 1.2 \cdot 10^{+101}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -8.00000000000000074e56 or 1.19999999999999994e101 < (*.f64 z t) Initial program 94.3%
Taylor expanded in x around 0 90.2%
Taylor expanded in z around inf 90.2%
Taylor expanded in t around inf 79.0%
if -8.00000000000000074e56 < (*.f64 z t) < 3.69999999999999965e-114Initial program 100.0%
Taylor expanded in a around inf 51.5%
if 3.69999999999999965e-114 < (*.f64 z t) < 1.19999999999999994e101Initial program 100.0%
Taylor expanded in x around inf 76.4%
Taylor expanded in y around inf 67.7%
Taylor expanded in x around inf 53.9%
Final simplification61.4%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (* z t) (* x y)))) (if (<= t_1 INFINITY) (+ (* a b) t_1) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * t) + (x * y);
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = (a * b) + t_1;
} else {
tmp = z * t;
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (z * t) + (x * y);
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = (a * b) + t_1;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (z * t) + (x * y) tmp = 0 if t_1 <= math.inf: tmp = (a * b) + t_1 else: tmp = z * t return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(z * t) + Float64(x * y)) tmp = 0.0 if (t_1 <= Inf) tmp = Float64(Float64(a * b) + t_1); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (z * t) + (x * y); tmp = 0.0; if (t_1 <= Inf) tmp = (a * b) + t_1; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], N[(N[(a * b), $MachinePrecision] + t$95$1), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot t + x \cdot y\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;a \cdot b + t\_1\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z t)) < +inf.0Initial program 100.0%
if +inf.0 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 0.0%
Taylor expanded in x around 0 80.0%
Taylor expanded in z around inf 80.0%
Taylor expanded in t around inf 80.0%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -2e-25) (not (<= (* x y) 5e+110))) (+ (* z t) (* x y)) (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -2e-25) || !((x * y) <= 5e+110)) {
tmp = (z * t) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
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-25)) .or. (.not. ((x * y) <= 5d+110))) then
tmp = (z * t) + (x * y)
else
tmp = (a * b) + (z * t)
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-25) || !((x * y) <= 5e+110)) {
tmp = (z * t) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -2e-25) or not ((x * y) <= 5e+110): tmp = (z * t) + (x * y) else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -2e-25) || !(Float64(x * y) <= 5e+110)) tmp = Float64(Float64(z * t) + Float64(x * y)); else tmp = Float64(Float64(a * b) + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((x * y) <= -2e-25) || ~(((x * y) <= 5e+110))) tmp = (z * t) + (x * y); else tmp = (a * b) + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2e-25], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e+110]], $MachinePrecision]], N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-25} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{+110}\right):\\
\;\;\;\;z \cdot t + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -2.00000000000000008e-25 or 4.99999999999999978e110 < (*.f64 x y) Initial program 95.0%
Taylor expanded in t around inf 78.3%
Taylor expanded in a around 0 73.8%
Taylor expanded in t around 0 85.4%
if -2.00000000000000008e-25 < (*.f64 x y) < 4.99999999999999978e110Initial program 100.0%
Taylor expanded in x around 0 90.7%
Final simplification88.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= x -1.8e+205) (not (<= x 5.2e+19))) (* x y) (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x <= -1.8e+205) || !(x <= 5.2e+19)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
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 <= (-1.8d+205)) .or. (.not. (x <= 5.2d+19))) then
tmp = x * y
else
tmp = (a * b) + (z * t)
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 <= -1.8e+205) || !(x <= 5.2e+19)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x <= -1.8e+205) or not (x <= 5.2e+19): tmp = x * y else: tmp = (a * b) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((x <= -1.8e+205) || !(x <= 5.2e+19)) tmp = Float64(x * y); else tmp = Float64(Float64(a * b) + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x <= -1.8e+205) || ~((x <= 5.2e+19))) tmp = x * y; else tmp = (a * b) + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[x, -1.8e+205], N[Not[LessEqual[x, 5.2e+19]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+205} \lor \neg \left(x \leq 5.2 \cdot 10^{+19}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if x < -1.80000000000000001e205 or 5.2e19 < x Initial program 93.1%
Taylor expanded in x around inf 73.4%
Taylor expanded in y around inf 69.3%
Taylor expanded in x around inf 63.9%
if -1.80000000000000001e205 < x < 5.2e19Initial program 100.0%
Taylor expanded in x around 0 80.0%
Final simplification75.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= x -7e+71) (not (<= x 1.75e-109))) (* x y) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x <= -7e+71) || !(x <= 1.75e-109)) {
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 ((x <= (-7d+71)) .or. (.not. (x <= 1.75d-109))) 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 ((x <= -7e+71) || !(x <= 1.75e-109)) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x <= -7e+71) or not (x <= 1.75e-109): tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((x <= -7e+71) || !(x <= 1.75e-109)) 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 ((x <= -7e+71) || ~((x <= 1.75e-109))) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[x, -7e+71], N[Not[LessEqual[x, 1.75e-109]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+71} \lor \neg \left(x \leq 1.75 \cdot 10^{-109}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if x < -6.9999999999999998e71 or 1.75e-109 < x Initial program 96.0%
Taylor expanded in x around inf 72.2%
Taylor expanded in y around inf 64.7%
Taylor expanded in x around inf 53.2%
if -6.9999999999999998e71 < x < 1.75e-109Initial program 100.0%
Taylor expanded in a around inf 43.9%
Final simplification48.6%
(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.0%
Taylor expanded in a around inf 34.3%
herbie shell --seed 2024123
(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)))