
(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 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 96.5%
associate-+l+96.5%
fma-define98.4%
fma-define99.2%
Simplified99.2%
Final simplification99.2%
(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 96.5%
+-commutative96.5%
fma-define96.9%
fma-define97.7%
Simplified97.7%
Final simplification97.7%
(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 96.5%
fma-define97.3%
Simplified97.3%
Final simplification97.3%
(FPCore (x y z t a b)
:precision binary64
(if (<= z -1.8e+110)
(* z t)
(if (<= z -3.2e-242)
(* a b)
(if (<= z -4.8e-278)
(* x y)
(if (<= z 2.1e-277)
(* a b)
(if (<= z 3.4e-219) (* x y) (if (<= z 3.2e-147) (* a b) (* z t))))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (z <= -1.8e+110) {
tmp = z * t;
} else if (z <= -3.2e-242) {
tmp = a * b;
} else if (z <= -4.8e-278) {
tmp = x * y;
} else if (z <= 2.1e-277) {
tmp = a * b;
} else if (z <= 3.4e-219) {
tmp = x * y;
} else if (z <= 3.2e-147) {
tmp = a * b;
} 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 <= (-1.8d+110)) then
tmp = z * t
else if (z <= (-3.2d-242)) then
tmp = a * b
else if (z <= (-4.8d-278)) then
tmp = x * y
else if (z <= 2.1d-277) then
tmp = a * b
else if (z <= 3.4d-219) then
tmp = x * y
else if (z <= 3.2d-147) then
tmp = a * b
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 <= -1.8e+110) {
tmp = z * t;
} else if (z <= -3.2e-242) {
tmp = a * b;
} else if (z <= -4.8e-278) {
tmp = x * y;
} else if (z <= 2.1e-277) {
tmp = a * b;
} else if (z <= 3.4e-219) {
tmp = x * y;
} else if (z <= 3.2e-147) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if z <= -1.8e+110: tmp = z * t elif z <= -3.2e-242: tmp = a * b elif z <= -4.8e-278: tmp = x * y elif z <= 2.1e-277: tmp = a * b elif z <= 3.4e-219: tmp = x * y elif z <= 3.2e-147: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (z <= -1.8e+110) tmp = Float64(z * t); elseif (z <= -3.2e-242) tmp = Float64(a * b); elseif (z <= -4.8e-278) tmp = Float64(x * y); elseif (z <= 2.1e-277) tmp = Float64(a * b); elseif (z <= 3.4e-219) tmp = Float64(x * y); elseif (z <= 3.2e-147) tmp = Float64(a * b); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (z <= -1.8e+110) tmp = z * t; elseif (z <= -3.2e-242) tmp = a * b; elseif (z <= -4.8e-278) tmp = x * y; elseif (z <= 2.1e-277) tmp = a * b; elseif (z <= 3.4e-219) tmp = x * y; elseif (z <= 3.2e-147) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[z, -1.8e+110], N[(z * t), $MachinePrecision], If[LessEqual[z, -3.2e-242], N[(a * b), $MachinePrecision], If[LessEqual[z, -4.8e-278], N[(x * y), $MachinePrecision], If[LessEqual[z, 2.1e-277], N[(a * b), $MachinePrecision], If[LessEqual[z, 3.4e-219], N[(x * y), $MachinePrecision], If[LessEqual[z, 3.2e-147], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+110}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-242}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{-278}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-277}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-219}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{-147}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if z < -1.7999999999999998e110 or 3.19999999999999979e-147 < z Initial program 94.8%
Taylor expanded in z around inf 56.9%
if -1.7999999999999998e110 < z < -3.19999999999999999e-242 or -4.8e-278 < z < 2.09999999999999995e-277 or 3.3999999999999999e-219 < z < 3.19999999999999979e-147Initial program 97.8%
Taylor expanded in a around inf 52.8%
if -3.19999999999999999e-242 < z < -4.8e-278 or 2.09999999999999995e-277 < z < 3.3999999999999999e-219Initial program 100.0%
Taylor expanded in x around inf 61.2%
Final simplification56.0%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (* a b) (+ (* x y) (* z t))))) (if (<= t_1 INFINITY) t_1 (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((x * y) + (z * t));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = a * b;
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((x * y) + (z * t));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (a * b) + ((x * y) + (z * t)) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = a * b return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (a * b) + ((x * y) + (z * t)); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) < +inf.0Initial program 100.0%
if +inf.0 < (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) Initial program 0.0%
Taylor expanded in a around inf 56.0%
Final simplification98.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -3.4e+161) (not (<= (* x y) 5.1e+150))) (* 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) <= -3.4e+161) || !((x * y) <= 5.1e+150)) {
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 * y) <= (-3.4d+161)) .or. (.not. ((x * y) <= 5.1d+150))) 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 * y) <= -3.4e+161) || !((x * y) <= 5.1e+150)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -3.4e+161) or not ((x * y) <= 5.1e+150): tmp = 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) <= -3.4e+161) || !(Float64(x * y) <= 5.1e+150)) 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 * y) <= -3.4e+161) || ~(((x * y) <= 5.1e+150))) tmp = 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], -3.4e+161], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5.1e+150]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.4 \cdot 10^{+161} \lor \neg \left(x \cdot y \leq 5.1 \cdot 10^{+150}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -3.39999999999999993e161 or 5.1000000000000001e150 < (*.f64 x y) Initial program 88.4%
Taylor expanded in x around inf 77.4%
if -3.39999999999999993e161 < (*.f64 x y) < 5.1000000000000001e150Initial program 99.5%
Taylor expanded in x around 0 87.5%
Final simplification84.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -1.76e+50) (not (<= (* x y) 3.7e+85))) (+ (* a b) (* 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) <= -1.76e+50) || !((x * y) <= 3.7e+85)) {
tmp = (a * b) + (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) <= (-1.76d+50)) .or. (.not. ((x * y) <= 3.7d+85))) then
tmp = (a * b) + (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) <= -1.76e+50) || !((x * y) <= 3.7e+85)) {
tmp = (a * b) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -1.76e+50) or not ((x * y) <= 3.7e+85): tmp = (a * b) + (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) <= -1.76e+50) || !(Float64(x * y) <= 3.7e+85)) tmp = Float64(Float64(a * b) + 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) <= -1.76e+50) || ~(((x * y) <= 3.7e+85))) tmp = (a * b) + (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], -1.76e+50], N[Not[LessEqual[N[(x * y), $MachinePrecision], 3.7e+85]], $MachinePrecision]], N[(N[(a * b), $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 -1.76 \cdot 10^{+50} \lor \neg \left(x \cdot y \leq 3.7 \cdot 10^{+85}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -1.7600000000000001e50 or 3.7000000000000002e85 < (*.f64 x y) Initial program 91.6%
Taylor expanded in z around 0 84.4%
if -1.7600000000000001e50 < (*.f64 x y) < 3.7000000000000002e85Initial program 99.4%
Taylor expanded in x around 0 92.1%
Final simplification89.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -8.8e+111) (not (<= z 3.2e-147))) (* z t) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -8.8e+111) || !(z <= 3.2e-147)) {
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 ((z <= (-8.8d+111)) .or. (.not. (z <= 3.2d-147))) 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 ((z <= -8.8e+111) || !(z <= 3.2e-147)) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z <= -8.8e+111) or not (z <= 3.2e-147): tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -8.8e+111) || !(z <= 3.2e-147)) 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 ((z <= -8.8e+111) || ~((z <= 3.2e-147))) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -8.8e+111], N[Not[LessEqual[z, 3.2e-147]], $MachinePrecision]], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.8 \cdot 10^{+111} \lor \neg \left(z \leq 3.2 \cdot 10^{-147}\right):\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if z < -8.79999999999999994e111 or 3.19999999999999979e-147 < z Initial program 94.8%
Taylor expanded in z around inf 56.9%
if -8.79999999999999994e111 < z < 3.19999999999999979e-147Initial program 98.3%
Taylor expanded in a around inf 48.5%
Final simplification52.9%
(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.5%
Taylor expanded in a around inf 37.6%
Final simplification37.6%
herbie shell --seed 2024053
(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)))