
(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 99.2%
associate-+l+99.2%
fma-define99.2%
fma-define100.0%
Simplified100.0%
(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 99.2%
+-commutative99.2%
fma-define99.2%
fma-define99.2%
Simplified99.2%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* z t) -1.75e+62)
(* z t)
(if (<= (* z t) -4.1e-196)
(* x y)
(if (<= (* z t) 7e+22) (* a b) (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1.75e+62) {
tmp = z * t;
} else if ((z * t) <= -4.1e-196) {
tmp = x * y;
} else if ((z * t) <= 7e+22) {
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 * t) <= (-1.75d+62)) then
tmp = z * t
else if ((z * t) <= (-4.1d-196)) then
tmp = x * y
else if ((z * t) <= 7d+22) 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 * t) <= -1.75e+62) {
tmp = z * t;
} else if ((z * t) <= -4.1e-196) {
tmp = x * y;
} else if ((z * t) <= 7e+22) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -1.75e+62: tmp = z * t elif (z * t) <= -4.1e-196: tmp = x * y elif (z * t) <= 7e+22: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1.75e+62) tmp = Float64(z * t); elseif (Float64(z * t) <= -4.1e-196) tmp = Float64(x * y); elseif (Float64(z * t) <= 7e+22) 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 * t) <= -1.75e+62) tmp = z * t; elseif ((z * t) <= -4.1e-196) tmp = x * y; elseif ((z * t) <= 7e+22) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -1.75e+62], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], -4.1e-196], N[(x * y), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 7e+22], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1.75 \cdot 10^{+62}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq -4.1 \cdot 10^{-196}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \cdot t \leq 7 \cdot 10^{+22}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -1.74999999999999992e62 or 7e22 < (*.f64 z t) Initial program 98.3%
Taylor expanded in z around inf 95.9%
Taylor expanded in a around 0 83.6%
Taylor expanded in t around inf 73.8%
if -1.74999999999999992e62 < (*.f64 z t) < -4.10000000000000021e-196Initial program 100.0%
+-commutative100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in t around inf 84.5%
Taylor expanded in x around inf 57.6%
if -4.10000000000000021e-196 < (*.f64 z t) < 7e22Initial program 100.0%
+-commutative100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in a around inf 53.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -6.8e+68) (not (<= (* x y) 1.25e+42))) (+ (* 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) <= -6.8e+68) || !((x * y) <= 1.25e+42)) {
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) <= (-6.8d+68)) .or. (.not. ((x * y) <= 1.25d+42))) 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) <= -6.8e+68) || !((x * y) <= 1.25e+42)) {
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) <= -6.8e+68) or not ((x * y) <= 1.25e+42): 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) <= -6.8e+68) || !(Float64(x * y) <= 1.25e+42)) 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) <= -6.8e+68) || ~(((x * y) <= 1.25e+42))) 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], -6.8e+68], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.25e+42]], $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 -6.8 \cdot 10^{+68} \lor \neg \left(x \cdot y \leq 1.25 \cdot 10^{+42}\right):\\
\;\;\;\;z \cdot t + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -6.8000000000000003e68 or 1.25000000000000002e42 < (*.f64 x y) Initial program 100.0%
Taylor expanded in z around inf 78.6%
Taylor expanded in a around 0 71.2%
Taylor expanded in z around 0 90.1%
if -6.8000000000000003e68 < (*.f64 x y) < 1.25000000000000002e42Initial program 98.7%
+-commutative98.7%
fma-define98.7%
fma-define98.7%
Simplified98.7%
Taylor expanded in x around 0 90.3%
Final simplification90.2%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -3.3e+132) (not (<= (* x y) 5.6e+110))) (* 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.3e+132) || !((x * y) <= 5.6e+110)) {
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.3d+132)) .or. (.not. ((x * y) <= 5.6d+110))) 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.3e+132) || !((x * y) <= 5.6e+110)) {
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.3e+132) or not ((x * y) <= 5.6e+110): 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.3e+132) || !(Float64(x * y) <= 5.6e+110)) 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.3e+132) || ~(((x * y) <= 5.6e+110))) 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.3e+132], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5.6e+110]], $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.3 \cdot 10^{+132} \lor \neg \left(x \cdot y \leq 5.6 \cdot 10^{+110}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -3.3000000000000003e132 or 5.59999999999999973e110 < (*.f64 x y) Initial program 100.0%
+-commutative100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in t around inf 75.8%
Taylor expanded in x around inf 79.7%
if -3.3000000000000003e132 < (*.f64 x y) < 5.59999999999999973e110Initial program 98.9%
+-commutative98.9%
fma-define98.9%
fma-define98.9%
Simplified98.9%
Taylor expanded in x around 0 85.5%
Final simplification83.9%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -3.6e+65) (+ (* z t) (* x y)) (if (<= (* x y) 5.2e+46) (+ (* a b) (* z t)) (+ (* a b) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -3.6e+65) {
tmp = (z * t) + (x * y);
} else if ((x * y) <= 5.2e+46) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (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 ((x * y) <= (-3.6d+65)) then
tmp = (z * t) + (x * y)
else if ((x * y) <= 5.2d+46) then
tmp = (a * b) + (z * t)
else
tmp = (a * b) + (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 ((x * y) <= -3.6e+65) {
tmp = (z * t) + (x * y);
} else if ((x * y) <= 5.2e+46) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -3.6e+65: tmp = (z * t) + (x * y) elif (x * y) <= 5.2e+46: tmp = (a * b) + (z * t) else: tmp = (a * b) + (x * y) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -3.6e+65) tmp = Float64(Float64(z * t) + Float64(x * y)); elseif (Float64(x * y) <= 5.2e+46) tmp = Float64(Float64(a * b) + Float64(z * t)); else tmp = Float64(Float64(a * b) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * y) <= -3.6e+65) tmp = (z * t) + (x * y); elseif ((x * y) <= 5.2e+46) tmp = (a * b) + (z * t); else tmp = (a * b) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -3.6e+65], N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5.2e+46], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.6 \cdot 10^{+65}:\\
\;\;\;\;z \cdot t + x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 5.2 \cdot 10^{+46}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -3.59999999999999978e65Initial program 99.9%
Taylor expanded in z around inf 76.3%
Taylor expanded in a around 0 74.2%
Taylor expanded in z around 0 94.7%
if -3.59999999999999978e65 < (*.f64 x y) < 5.20000000000000027e46Initial program 98.7%
+-commutative98.7%
fma-define98.7%
fma-define98.7%
Simplified98.7%
Taylor expanded in x around 0 90.4%
if 5.20000000000000027e46 < (*.f64 x y) Initial program 100.0%
Taylor expanded in x around inf 85.7%
Final simplification90.4%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -3.7e+65) (not (<= (* x y) 3.4e+39))) (* x y) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -3.7e+65) || !((x * y) <= 3.4e+39)) {
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 * y) <= (-3.7d+65)) .or. (.not. ((x * y) <= 3.4d+39))) 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 * y) <= -3.7e+65) || !((x * y) <= 3.4e+39)) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -3.7e+65) or not ((x * y) <= 3.4e+39): tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -3.7e+65) || !(Float64(x * y) <= 3.4e+39)) 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 * y) <= -3.7e+65) || ~(((x * y) <= 3.4e+39))) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -3.7e+65], N[Not[LessEqual[N[(x * y), $MachinePrecision], 3.4e+39]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.7 \cdot 10^{+65} \lor \neg \left(x \cdot y \leq 3.4 \cdot 10^{+39}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 x y) < -3.69999999999999995e65 or 3.3999999999999999e39 < (*.f64 x y) Initial program 100.0%
+-commutative100.0%
fma-define100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in t around inf 78.5%
Taylor expanded in x around inf 70.2%
if -3.69999999999999995e65 < (*.f64 x y) < 3.3999999999999999e39Initial program 98.7%
+-commutative98.7%
fma-define98.7%
fma-define98.7%
Simplified98.7%
Taylor expanded in a around inf 43.7%
Final simplification53.8%
(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 99.2%
Final simplification99.2%
(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 99.2%
+-commutative99.2%
fma-define99.2%
fma-define99.2%
Simplified99.2%
Taylor expanded in a around inf 32.2%
herbie shell --seed 2024139
(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)))