
(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 8 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 98.8%
associate-+l+98.8%
fma-def99.6%
fma-def99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -1.32e+29)
(* a b)
(if (<= (* a b) -8e-204)
(* z t)
(if (<= (* a b) 1.4e-190)
(* x y)
(if (<= (* a b) 1.45e-68)
(* z t)
(if (<= (* a b) 2.45e+61) (* x y) (* a b)))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1.32e+29) {
tmp = a * b;
} else if ((a * b) <= -8e-204) {
tmp = z * t;
} else if ((a * b) <= 1.4e-190) {
tmp = x * y;
} else if ((a * b) <= 1.45e-68) {
tmp = z * t;
} else if ((a * b) <= 2.45e+61) {
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) <= (-1.32d+29)) then
tmp = a * b
else if ((a * b) <= (-8d-204)) then
tmp = z * t
else if ((a * b) <= 1.4d-190) then
tmp = x * y
else if ((a * b) <= 1.45d-68) then
tmp = z * t
else if ((a * b) <= 2.45d+61) 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) <= -1.32e+29) {
tmp = a * b;
} else if ((a * b) <= -8e-204) {
tmp = z * t;
} else if ((a * b) <= 1.4e-190) {
tmp = x * y;
} else if ((a * b) <= 1.45e-68) {
tmp = z * t;
} else if ((a * b) <= 2.45e+61) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1.32e+29: tmp = a * b elif (a * b) <= -8e-204: tmp = z * t elif (a * b) <= 1.4e-190: tmp = x * y elif (a * b) <= 1.45e-68: tmp = z * t elif (a * b) <= 2.45e+61: tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1.32e+29) tmp = Float64(a * b); elseif (Float64(a * b) <= -8e-204) tmp = Float64(z * t); elseif (Float64(a * b) <= 1.4e-190) tmp = Float64(x * y); elseif (Float64(a * b) <= 1.45e-68) tmp = Float64(z * t); elseif (Float64(a * b) <= 2.45e+61) 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) <= -1.32e+29) tmp = a * b; elseif ((a * b) <= -8e-204) tmp = z * t; elseif ((a * b) <= 1.4e-190) tmp = x * y; elseif ((a * b) <= 1.45e-68) tmp = z * t; elseif ((a * b) <= 2.45e+61) 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], -1.32e+29], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -8e-204], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.4e-190], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.45e-68], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.45e+61], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.32 \cdot 10^{+29}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -8 \cdot 10^{-204}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 1.4 \cdot 10^{-190}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 1.45 \cdot 10^{-68}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 2.45 \cdot 10^{+61}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.32e29 or 2.45000000000000013e61 < (*.f64 a b) Initial program 97.5%
Taylor expanded in a around inf 72.6%
if -1.32e29 < (*.f64 a b) < -8.00000000000000001e-204 or 1.40000000000000003e-190 < (*.f64 a b) < 1.45e-68Initial program 99.9%
Taylor expanded in z around inf 69.9%
if -8.00000000000000001e-204 < (*.f64 a b) < 1.40000000000000003e-190 or 1.45e-68 < (*.f64 a b) < 2.45000000000000013e61Initial program 100.0%
Taylor expanded in x around inf 60.5%
Final simplification68.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -4.8e+33) (not (<= (* a b) 5.6e+61))) (+ (* a b) (* z t)) (+ (* z t) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -4.8e+33) || !((a * b) <= 5.6e+61)) {
tmp = (a * b) + (z * t);
} else {
tmp = (z * t) + (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 (((a * b) <= (-4.8d+33)) .or. (.not. ((a * b) <= 5.6d+61))) then
tmp = (a * b) + (z * t)
else
tmp = (z * t) + (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 (((a * b) <= -4.8e+33) || !((a * b) <= 5.6e+61)) {
tmp = (a * b) + (z * t);
} else {
tmp = (z * t) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -4.8e+33) or not ((a * b) <= 5.6e+61): tmp = (a * b) + (z * t) else: tmp = (z * t) + (x * y) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -4.8e+33) || !(Float64(a * b) <= 5.6e+61)) tmp = Float64(Float64(a * b) + Float64(z * t)); else tmp = Float64(Float64(z * t) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((a * b) <= -4.8e+33) || ~(((a * b) <= 5.6e+61))) tmp = (a * b) + (z * t); else tmp = (z * t) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -4.8e+33], N[Not[LessEqual[N[(a * b), $MachinePrecision], 5.6e+61]], $MachinePrecision]], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -4.8 \cdot 10^{+33} \lor \neg \left(a \cdot b \leq 5.6 \cdot 10^{+61}\right):\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;z \cdot t + x \cdot y\\
\end{array}
\end{array}
if (*.f64 a b) < -4.8e33 or 5.6000000000000003e61 < (*.f64 a b) Initial program 97.4%
Taylor expanded in x around 0 91.5%
if -4.8e33 < (*.f64 a b) < 5.6000000000000003e61Initial program 100.0%
Taylor expanded in a around 0 92.6%
Final simplification92.1%
(FPCore (x y z t a b) :precision binary64 (if (or (<= y -1.75e-109) (not (<= y 1.12e+117))) (+ (* 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 ((y <= -1.75e-109) || !(y <= 1.12e+117)) {
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 ((y <= (-1.75d-109)) .or. (.not. (y <= 1.12d+117))) 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 ((y <= -1.75e-109) || !(y <= 1.12e+117)) {
tmp = (a * b) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (y <= -1.75e-109) or not (y <= 1.12e+117): 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 ((y <= -1.75e-109) || !(y <= 1.12e+117)) 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 ((y <= -1.75e-109) || ~((y <= 1.12e+117))) 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[y, -1.75e-109], N[Not[LessEqual[y, 1.12e+117]], $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}\;y \leq -1.75 \cdot 10^{-109} \lor \neg \left(y \leq 1.12 \cdot 10^{+117}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if y < -1.75e-109 or 1.12000000000000002e117 < y Initial program 97.5%
Taylor expanded in z around 0 75.8%
if -1.75e-109 < y < 1.12000000000000002e117Initial program 100.0%
Taylor expanded in x around 0 87.9%
Final simplification82.2%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -5.5e+28) (* a b) (if (<= (* a b) 3.05e+60) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -5.5e+28) {
tmp = a * b;
} else if ((a * b) <= 3.05e+60) {
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.5d+28)) then
tmp = a * b
else if ((a * b) <= 3.05d+60) 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.5e+28) {
tmp = a * b;
} else if ((a * b) <= 3.05e+60) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -5.5e+28: tmp = a * b elif (a * b) <= 3.05e+60: 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.5e+28) tmp = Float64(a * b); elseif (Float64(a * b) <= 3.05e+60) 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.5e+28) tmp = a * b; elseif ((a * b) <= 3.05e+60) 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.5e+28], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 3.05e+60], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5.5 \cdot 10^{+28}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 3.05 \cdot 10^{+60}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -5.5000000000000003e28 or 3.05e60 < (*.f64 a b) Initial program 97.5%
Taylor expanded in a around inf 72.6%
if -5.5000000000000003e28 < (*.f64 a b) < 3.05e60Initial program 100.0%
Taylor expanded in z around inf 50.2%
Final simplification60.5%
(FPCore (x y z t a b) :precision binary64 (if (<= y -3.3e+48) (* x y) (if (<= y 5.2e+148) (+ (* a b) (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (y <= -3.3e+48) {
tmp = x * y;
} else if (y <= 5.2e+148) {
tmp = (a * b) + (z * t);
} 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 (y <= (-3.3d+48)) then
tmp = x * y
else if (y <= 5.2d+148) then
tmp = (a * b) + (z * t)
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 (y <= -3.3e+48) {
tmp = x * y;
} else if (y <= 5.2e+148) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if y <= -3.3e+48: tmp = x * y elif y <= 5.2e+148: tmp = (a * b) + (z * t) else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (y <= -3.3e+48) tmp = Float64(x * y); elseif (y <= 5.2e+148) tmp = Float64(Float64(a * b) + Float64(z * t)); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (y <= -3.3e+48) tmp = x * y; elseif (y <= 5.2e+148) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[y, -3.3e+48], N[(x * y), $MachinePrecision], If[LessEqual[y, 5.2e+148], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+48}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+148}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -3.30000000000000023e48 or 5.2e148 < y Initial program 97.5%
Taylor expanded in x around inf 60.1%
if -3.30000000000000023e48 < y < 5.2e148Initial program 99.4%
Taylor expanded in x around 0 83.1%
Final simplification75.9%
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (+ (* z t) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((z * t) + (x * y));
}
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) + ((z * t) + (x * y))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((z * t) + (x * y));
}
def code(x, y, z, t, a, b): return (a * b) + ((z * t) + (x * y))
function code(x, y, z, t, a, b) return Float64(Float64(a * b) + Float64(Float64(z * t) + Float64(x * y))) end
function tmp = code(x, y, z, t, a, b) tmp = (a * b) + ((z * t) + (x * y)); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + \left(z \cdot t + x \cdot y\right)
\end{array}
Initial program 98.8%
Final simplification98.8%
(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 38.1%
Final simplification38.1%
herbie shell --seed 2023240
(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)))