
(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 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.8%
+-commutative98.8%
fma-define99.2%
fma-define99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (+ (fma x y (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, (z * t)) + (a * b);
}
function code(x, y, z, t, a, b) return Float64(fma(x, y, Float64(z * t)) + Float64(a * b)) end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z \cdot t\right) + a \cdot b
\end{array}
Initial program 98.8%
fma-define99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -1.55e-20)
(* a b)
(if (<= (* a b) 2.6e-261)
(* x y)
(if (<= (* a b) 5.6e-159)
(* z t)
(if (<= (* a b) 14500000000000.0) (* x y) (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1.55e-20) {
tmp = a * b;
} else if ((a * b) <= 2.6e-261) {
tmp = x * y;
} else if ((a * b) <= 5.6e-159) {
tmp = z * t;
} else if ((a * b) <= 14500000000000.0) {
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.55d-20)) then
tmp = a * b
else if ((a * b) <= 2.6d-261) then
tmp = x * y
else if ((a * b) <= 5.6d-159) then
tmp = z * t
else if ((a * b) <= 14500000000000.0d0) 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.55e-20) {
tmp = a * b;
} else if ((a * b) <= 2.6e-261) {
tmp = x * y;
} else if ((a * b) <= 5.6e-159) {
tmp = z * t;
} else if ((a * b) <= 14500000000000.0) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1.55e-20: tmp = a * b elif (a * b) <= 2.6e-261: tmp = x * y elif (a * b) <= 5.6e-159: tmp = z * t elif (a * b) <= 14500000000000.0: 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.55e-20) tmp = Float64(a * b); elseif (Float64(a * b) <= 2.6e-261) tmp = Float64(x * y); elseif (Float64(a * b) <= 5.6e-159) tmp = Float64(z * t); elseif (Float64(a * b) <= 14500000000000.0) 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.55e-20) tmp = a * b; elseif ((a * b) <= 2.6e-261) tmp = x * y; elseif ((a * b) <= 5.6e-159) tmp = z * t; elseif ((a * b) <= 14500000000000.0) 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.55e-20], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.6e-261], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5.6e-159], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 14500000000000.0], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.55 \cdot 10^{-20}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 2.6 \cdot 10^{-261}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 5.6 \cdot 10^{-159}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 14500000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.55e-20 or 1.45e13 < (*.f64 a b) Initial program 98.3%
Taylor expanded in a around inf 66.6%
if -1.55e-20 < (*.f64 a b) < 2.6000000000000001e-261 or 5.6000000000000004e-159 < (*.f64 a b) < 1.45e13Initial program 99.1%
Taylor expanded in x around inf 64.1%
Taylor expanded in y around inf 64.1%
associate-/l*62.8%
Simplified62.8%
Taylor expanded in x around inf 59.7%
if 2.6000000000000001e-261 < (*.f64 a b) < 5.6000000000000004e-159Initial program 100.0%
Taylor expanded in x around 0 69.1%
Taylor expanded in z around inf 69.1%
Taylor expanded in t around inf 69.0%
Final simplification63.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -2e-9) (not (<= (* a b) 5000000000000.0))) (+ (* z t) (* a b)) (+ (* z t) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -2e-9) || !((a * b) <= 5000000000000.0)) {
tmp = (z * t) + (a * b);
} 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) <= (-2d-9)) .or. (.not. ((a * b) <= 5000000000000.0d0))) then
tmp = (z * t) + (a * b)
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) <= -2e-9) || !((a * b) <= 5000000000000.0)) {
tmp = (z * t) + (a * b);
} else {
tmp = (z * t) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -2e-9) or not ((a * b) <= 5000000000000.0): tmp = (z * t) + (a * b) else: tmp = (z * t) + (x * y) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -2e-9) || !(Float64(a * b) <= 5000000000000.0)) tmp = Float64(Float64(z * t) + Float64(a * b)); 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) <= -2e-9) || ~(((a * b) <= 5000000000000.0))) tmp = (z * t) + (a * b); 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], -2e-9], N[Not[LessEqual[N[(a * b), $MachinePrecision], 5000000000000.0]], $MachinePrecision]], N[(N[(z * t), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{-9} \lor \neg \left(a \cdot b \leq 5000000000000\right):\\
\;\;\;\;z \cdot t + a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t + x \cdot y\\
\end{array}
\end{array}
if (*.f64 a b) < -2.00000000000000012e-9 or 5e12 < (*.f64 a b) Initial program 98.3%
Taylor expanded in x around 0 84.8%
if -2.00000000000000012e-9 < (*.f64 a b) < 5e12Initial program 99.2%
Taylor expanded in y around inf 93.1%
Taylor expanded in a around 0 88.7%
Taylor expanded in y around 0 94.9%
Final simplification90.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -1.55e-20) (not (<= (* a b) 14500000000000.0))) (* a b) (* x y)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -1.55e-20) || !((a * b) <= 14500000000000.0)) {
tmp = a * b;
} 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 (((a * b) <= (-1.55d-20)) .or. (.not. ((a * b) <= 14500000000000.0d0))) then
tmp = a * b
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 (((a * b) <= -1.55e-20) || !((a * b) <= 14500000000000.0)) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -1.55e-20) or not ((a * b) <= 14500000000000.0): tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -1.55e-20) || !(Float64(a * b) <= 14500000000000.0)) tmp = Float64(a * b); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((a * b) <= -1.55e-20) || ~(((a * b) <= 14500000000000.0))) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -1.55e-20], N[Not[LessEqual[N[(a * b), $MachinePrecision], 14500000000000.0]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.55 \cdot 10^{-20} \lor \neg \left(a \cdot b \leq 14500000000000\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 a b) < -1.55e-20 or 1.45e13 < (*.f64 a b) Initial program 98.3%
Taylor expanded in a around inf 66.6%
if -1.55e-20 < (*.f64 a b) < 1.45e13Initial program 99.2%
Taylor expanded in x around inf 59.7%
Taylor expanded in y around inf 59.7%
associate-/l*58.6%
Simplified58.6%
Taylor expanded in x around inf 55.9%
Final simplification61.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= y -1.4e+62) (not (<= y 1.9e+131))) (* x y) (+ (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y <= -1.4e+62) || !(y <= 1.9e+131)) {
tmp = x * y;
} else {
tmp = (z * t) + (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 ((y <= (-1.4d+62)) .or. (.not. (y <= 1.9d+131))) then
tmp = x * y
else
tmp = (z * t) + (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 ((y <= -1.4e+62) || !(y <= 1.9e+131)) {
tmp = x * y;
} else {
tmp = (z * t) + (a * b);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (y <= -1.4e+62) or not (y <= 1.9e+131): tmp = x * y else: tmp = (z * t) + (a * b) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((y <= -1.4e+62) || !(y <= 1.9e+131)) tmp = Float64(x * y); else tmp = Float64(Float64(z * t) + Float64(a * b)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((y <= -1.4e+62) || ~((y <= 1.9e+131))) tmp = x * y; else tmp = (z * t) + (a * b); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[y, -1.4e+62], N[Not[LessEqual[y, 1.9e+131]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(z * t), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+62} \lor \neg \left(y \leq 1.9 \cdot 10^{+131}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot t + a \cdot b\\
\end{array}
\end{array}
if y < -1.40000000000000007e62 or 1.9000000000000002e131 < y Initial program 97.7%
Taylor expanded in x around inf 81.5%
Taylor expanded in y around inf 81.5%
associate-/l*81.9%
Simplified81.9%
Taylor expanded in x around inf 60.9%
if -1.40000000000000007e62 < y < 1.9000000000000002e131Initial program 99.4%
Taylor expanded in x around 0 73.8%
Final simplification69.4%
(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 34.6%
Final simplification34.6%
herbie shell --seed 2024085
(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)))