
(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 97.6%
associate-+l+97.6%
fma-define98.8%
fma-define99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (fma b a (fma x y (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(b, a, fma(x, y, (z * t)));
}
function code(x, y, z, t, a, b) return fma(b, a, fma(x, y, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(b * a + N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b, a, \mathsf{fma}\left(x, y, z \cdot t\right)\right)
\end{array}
Initial program 97.6%
+-commutative97.6%
*-commutative97.6%
fma-define98.0%
fma-define99.2%
Applied egg-rr99.2%
Final simplification99.2%
(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 97.6%
fma-define98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -3600000000000.0)
(* a b)
(if (<= (* a b) -2.6e-56)
(* z t)
(if (<= (* a b) -7.8e-60)
(* a b)
(if (<= (* a b) 0.0)
(* x y)
(if (<= (* a b) 1.8e-110)
(* z t)
(if (<= (* a b) 2.1e-52)
(* x y)
(if (<= (* a b) 2.3e+177) (* z t) (* a b)))))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -3600000000000.0) {
tmp = a * b;
} else if ((a * b) <= -2.6e-56) {
tmp = z * t;
} else if ((a * b) <= -7.8e-60) {
tmp = a * b;
} else if ((a * b) <= 0.0) {
tmp = x * y;
} else if ((a * b) <= 1.8e-110) {
tmp = z * t;
} else if ((a * b) <= 2.1e-52) {
tmp = x * y;
} else if ((a * b) <= 2.3e+177) {
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) <= (-3600000000000.0d0)) then
tmp = a * b
else if ((a * b) <= (-2.6d-56)) then
tmp = z * t
else if ((a * b) <= (-7.8d-60)) then
tmp = a * b
else if ((a * b) <= 0.0d0) then
tmp = x * y
else if ((a * b) <= 1.8d-110) then
tmp = z * t
else if ((a * b) <= 2.1d-52) then
tmp = x * y
else if ((a * b) <= 2.3d+177) 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) <= -3600000000000.0) {
tmp = a * b;
} else if ((a * b) <= -2.6e-56) {
tmp = z * t;
} else if ((a * b) <= -7.8e-60) {
tmp = a * b;
} else if ((a * b) <= 0.0) {
tmp = x * y;
} else if ((a * b) <= 1.8e-110) {
tmp = z * t;
} else if ((a * b) <= 2.1e-52) {
tmp = x * y;
} else if ((a * b) <= 2.3e+177) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -3600000000000.0: tmp = a * b elif (a * b) <= -2.6e-56: tmp = z * t elif (a * b) <= -7.8e-60: tmp = a * b elif (a * b) <= 0.0: tmp = x * y elif (a * b) <= 1.8e-110: tmp = z * t elif (a * b) <= 2.1e-52: tmp = x * y elif (a * b) <= 2.3e+177: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -3600000000000.0) tmp = Float64(a * b); elseif (Float64(a * b) <= -2.6e-56) tmp = Float64(z * t); elseif (Float64(a * b) <= -7.8e-60) tmp = Float64(a * b); elseif (Float64(a * b) <= 0.0) tmp = Float64(x * y); elseif (Float64(a * b) <= 1.8e-110) tmp = Float64(z * t); elseif (Float64(a * b) <= 2.1e-52) tmp = Float64(x * y); elseif (Float64(a * b) <= 2.3e+177) 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) <= -3600000000000.0) tmp = a * b; elseif ((a * b) <= -2.6e-56) tmp = z * t; elseif ((a * b) <= -7.8e-60) tmp = a * b; elseif ((a * b) <= 0.0) tmp = x * y; elseif ((a * b) <= 1.8e-110) tmp = z * t; elseif ((a * b) <= 2.1e-52) tmp = x * y; elseif ((a * b) <= 2.3e+177) 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], -3600000000000.0], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2.6e-56], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -7.8e-60], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 0.0], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.8e-110], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.1e-52], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.3e+177], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -3600000000000:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -2.6 \cdot 10^{-56}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq -7.8 \cdot 10^{-60}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 0:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 1.8 \cdot 10^{-110}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 2.1 \cdot 10^{-52}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 2.3 \cdot 10^{+177}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -3.6e12 or -2.59999999999999997e-56 < (*.f64 a b) < -7.8000000000000004e-60 or 2.2999999999999999e177 < (*.f64 a b) Initial program 96.0%
Taylor expanded in a around inf 71.2%
if -3.6e12 < (*.f64 a b) < -2.59999999999999997e-56 or 0.0 < (*.f64 a b) < 1.79999999999999997e-110 or 2.0999999999999999e-52 < (*.f64 a b) < 2.2999999999999999e177Initial program 97.5%
+-commutative97.5%
*-commutative97.5%
fma-define97.5%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 61.0%
if -7.8000000000000004e-60 < (*.f64 a b) < 0.0 or 1.79999999999999997e-110 < (*.f64 a b) < 2.0999999999999999e-52Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
fma-define100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 63.4%
Final simplification65.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -1.06e+114) (not (<= (* x y) 6.8e+209))) (* 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.06e+114) || !((x * y) <= 6.8e+209)) {
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) <= (-1.06d+114)) .or. (.not. ((x * y) <= 6.8d+209))) 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) <= -1.06e+114) || !((x * y) <= 6.8e+209)) {
tmp = x * y;
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -1.06e+114) or not ((x * y) <= 6.8e+209): 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) <= -1.06e+114) || !(Float64(x * y) <= 6.8e+209)) 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) <= -1.06e+114) || ~(((x * y) <= 6.8e+209))) 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], -1.06e+114], N[Not[LessEqual[N[(x * y), $MachinePrecision], 6.8e+209]], $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 -1.06 \cdot 10^{+114} \lor \neg \left(x \cdot y \leq 6.8 \cdot 10^{+209}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -1.05999999999999993e114 or 6.7999999999999993e209 < (*.f64 x y) Initial program 91.3%
+-commutative91.3%
*-commutative91.3%
fma-define92.8%
fma-define97.1%
Applied egg-rr97.1%
Taylor expanded in x around inf 81.6%
if -1.05999999999999993e114 < (*.f64 x y) < 6.7999999999999993e209Initial program 100.0%
Taylor expanded in x around 0 83.7%
Final simplification83.1%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -1.95e+42) (not (<= (* a b) 1.2e+31))) (+ (* a b) (* z t)) (+ (* x y) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -1.95e+42) || !((a * b) <= 1.2e+31)) {
tmp = (a * b) + (z * t);
} else {
tmp = (x * y) + (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 (((a * b) <= (-1.95d+42)) .or. (.not. ((a * b) <= 1.2d+31))) then
tmp = (a * b) + (z * t)
else
tmp = (x * y) + (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 (((a * b) <= -1.95e+42) || !((a * b) <= 1.2e+31)) {
tmp = (a * b) + (z * t);
} else {
tmp = (x * y) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -1.95e+42) or not ((a * b) <= 1.2e+31): tmp = (a * b) + (z * t) else: tmp = (x * y) + (z * t) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -1.95e+42) || !(Float64(a * b) <= 1.2e+31)) tmp = Float64(Float64(a * b) + Float64(z * t)); else tmp = Float64(Float64(x * y) + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((a * b) <= -1.95e+42) || ~(((a * b) <= 1.2e+31))) tmp = (a * b) + (z * t); else tmp = (x * y) + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -1.95e+42], N[Not[LessEqual[N[(a * b), $MachinePrecision], 1.2e+31]], $MachinePrecision]], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.95 \cdot 10^{+42} \lor \neg \left(a \cdot b \leq 1.2 \cdot 10^{+31}\right):\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y + z \cdot t\\
\end{array}
\end{array}
if (*.f64 a b) < -1.94999999999999985e42 or 1.19999999999999991e31 < (*.f64 a b) Initial program 96.5%
Taylor expanded in x around 0 85.3%
if -1.94999999999999985e42 < (*.f64 a b) < 1.19999999999999991e31Initial program 98.6%
+-commutative98.6%
*-commutative98.6%
fma-define98.6%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in b around 0 88.2%
Final simplification86.9%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -8.5e+15) (not (<= (* a b) 2.3e+177))) (* a b) (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -8.5e+15) || !((a * b) <= 2.3e+177)) {
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 (((a * b) <= (-8.5d+15)) .or. (.not. ((a * b) <= 2.3d+177))) 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 (((a * b) <= -8.5e+15) || !((a * b) <= 2.3e+177)) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -8.5e+15) or not ((a * b) <= 2.3e+177): tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(a * b) <= -8.5e+15) || !(Float64(a * b) <= 2.3e+177)) 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 (((a * b) <= -8.5e+15) || ~(((a * b) <= 2.3e+177))) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -8.5e+15], N[Not[LessEqual[N[(a * b), $MachinePrecision], 2.3e+177]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -8.5 \cdot 10^{+15} \lor \neg \left(a \cdot b \leq 2.3 \cdot 10^{+177}\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 a b) < -8.5e15 or 2.2999999999999999e177 < (*.f64 a b) Initial program 95.9%
Taylor expanded in a around inf 71.0%
if -8.5e15 < (*.f64 a b) < 2.2999999999999999e177Initial program 98.7%
+-commutative98.7%
*-commutative98.7%
fma-define98.7%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 48.1%
Final simplification56.8%
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (+ (* x y) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((x * y) + (z * t));
}
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) + ((x * y) + (z * t))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (a * b) + ((x * y) + (z * t));
}
def code(x, y, z, t, a, b): return (a * b) + ((x * y) + (z * t))
function code(x, y, z, t, a, b) return Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t))) end
function tmp = code(x, y, z, t, a, b) tmp = (a * b) + ((x * y) + (z * t)); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b + \left(x \cdot y + z \cdot t\right)
\end{array}
Initial program 97.6%
Final simplification97.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 97.6%
Taylor expanded in a around inf 34.6%
Final simplification34.6%
herbie shell --seed 2024046
(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)))