
(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 10 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 (let* ((t_1 (+ (* a b) (+ (* z t) (* x y))))) (if (<= t_1 INFINITY) t_1 (fma b a (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((z * t) + (x * y));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = fma(b, a, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(Float64(z * t) + Float64(x * y))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = fma(b, a, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + \left(z \cdot t + x \cdot y\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\
\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 x around inf 60.0%
+-commutative60.0%
*-commutative60.0%
fma-define80.0%
Applied egg-rr80.0%
Final simplification99.6%
(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.0%
associate-+l+98.0%
fma-define98.4%
fma-define98.8%
Simplified98.8%
Final simplification98.8%
(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.0%
+-commutative98.0%
fma-define98.4%
fma-define98.4%
Simplified98.4%
Final simplification98.4%
(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 98.0%
fma-define98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x y z t a b) :precision binary64 (fma a b (+ (* z t) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(a, b, ((z * t) + (x * y)));
}
function code(x, y, z, t, a, b) return fma(a, b, Float64(Float64(z * t) + Float64(x * y))) end
code[x_, y_, z_, t_, a_, b_] := N[(a * b + N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, b, z \cdot t + x \cdot y\right)
\end{array}
Initial program 98.0%
+-commutative98.0%
fma-define98.4%
fma-define98.4%
Simplified98.4%
fma-define98.4%
+-commutative98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (x y z t a b)
:precision binary64
(if (or (<= (* x y) -3.2e+190)
(not
(or (<= (* x y) -2e+143)
(and (not (<= (* x y) -3.8e+118)) (<= (* x y) 2.1e+160)))))
(* 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.2e+190) || !(((x * y) <= -2e+143) || (!((x * y) <= -3.8e+118) && ((x * y) <= 2.1e+160)))) {
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.2d+190)) .or. (.not. ((x * y) <= (-2d+143)) .or. (.not. ((x * y) <= (-3.8d+118))) .and. ((x * y) <= 2.1d+160))) 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.2e+190) || !(((x * y) <= -2e+143) || (!((x * y) <= -3.8e+118) && ((x * y) <= 2.1e+160)))) {
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.2e+190) or not (((x * y) <= -2e+143) or (not ((x * y) <= -3.8e+118) and ((x * y) <= 2.1e+160))): 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.2e+190) || !((Float64(x * y) <= -2e+143) || (!(Float64(x * y) <= -3.8e+118) && (Float64(x * y) <= 2.1e+160)))) 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.2e+190) || ~((((x * y) <= -2e+143) || (~(((x * y) <= -3.8e+118)) && ((x * y) <= 2.1e+160))))) 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.2e+190], N[Not[Or[LessEqual[N[(x * y), $MachinePrecision], -2e+143], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -3.8e+118]], $MachinePrecision], LessEqual[N[(x * y), $MachinePrecision], 2.1e+160]]]], $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.2 \cdot 10^{+190} \lor \neg \left(x \cdot y \leq -2 \cdot 10^{+143} \lor \neg \left(x \cdot y \leq -3.8 \cdot 10^{+118}\right) \land x \cdot y \leq 2.1 \cdot 10^{+160}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -3.2000000000000001e190 or -2e143 < (*.f64 x y) < -3.80000000000000016e118 or 2.09999999999999997e160 < (*.f64 x y) Initial program 93.6%
Taylor expanded in x around inf 93.8%
+-commutative93.8%
*-commutative93.8%
fma-define95.1%
Applied egg-rr95.1%
Taylor expanded in b around 0 86.4%
if -3.2000000000000001e190 < (*.f64 x y) < -2e143 or -3.80000000000000016e118 < (*.f64 x y) < 2.09999999999999997e160Initial program 100.0%
Taylor expanded in x around 0 85.6%
Final simplification85.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (* a b) (* z t))) (t_2 (+ (* a b) (* x y))))
(if (<= (* x y) -1.45e+190)
t_2
(if (<= (* x y) -2.8e+145)
t_1
(if (<= (* x y) -3.2e+118)
(* x y)
(if (<= (* x y) 5.9e-36) t_1 t_2))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + (z * t);
double t_2 = (a * b) + (x * y);
double tmp;
if ((x * y) <= -1.45e+190) {
tmp = t_2;
} else if ((x * y) <= -2.8e+145) {
tmp = t_1;
} else if ((x * y) <= -3.2e+118) {
tmp = x * y;
} else if ((x * y) <= 5.9e-36) {
tmp = t_1;
} else {
tmp = t_2;
}
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (a * b) + (z * t)
t_2 = (a * b) + (x * y)
if ((x * y) <= (-1.45d+190)) then
tmp = t_2
else if ((x * y) <= (-2.8d+145)) then
tmp = t_1
else if ((x * y) <= (-3.2d+118)) then
tmp = x * y
else if ((x * y) <= 5.9d-36) then
tmp = t_1
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + (z * t);
double t_2 = (a * b) + (x * y);
double tmp;
if ((x * y) <= -1.45e+190) {
tmp = t_2;
} else if ((x * y) <= -2.8e+145) {
tmp = t_1;
} else if ((x * y) <= -3.2e+118) {
tmp = x * y;
} else if ((x * y) <= 5.9e-36) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (a * b) + (z * t) t_2 = (a * b) + (x * y) tmp = 0 if (x * y) <= -1.45e+190: tmp = t_2 elif (x * y) <= -2.8e+145: tmp = t_1 elif (x * y) <= -3.2e+118: tmp = x * y elif (x * y) <= 5.9e-36: tmp = t_1 else: tmp = t_2 return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(z * t)) t_2 = Float64(Float64(a * b) + Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -1.45e+190) tmp = t_2; elseif (Float64(x * y) <= -2.8e+145) tmp = t_1; elseif (Float64(x * y) <= -3.2e+118) tmp = Float64(x * y); elseif (Float64(x * y) <= 5.9e-36) tmp = t_1; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (a * b) + (z * t); t_2 = (a * b) + (x * y); tmp = 0.0; if ((x * y) <= -1.45e+190) tmp = t_2; elseif ((x * y) <= -2.8e+145) tmp = t_1; elseif ((x * y) <= -3.2e+118) tmp = x * y; elseif ((x * y) <= 5.9e-36) tmp = t_1; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1.45e+190], t$95$2, If[LessEqual[N[(x * y), $MachinePrecision], -2.8e+145], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], -3.2e+118], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5.9e-36], t$95$1, t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
\mathbf{if}\;x \cdot y \leq -1.45 \cdot 10^{+190}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \cdot y \leq -2.8 \cdot 10^{+145}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq -3.2 \cdot 10^{+118}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 5.9 \cdot 10^{-36}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 x y) < -1.44999999999999995e190 or 5.89999999999999995e-36 < (*.f64 x y) Initial program 95.3%
Taylor expanded in x around inf 89.1%
if -1.44999999999999995e190 < (*.f64 x y) < -2.7999999999999999e145 or -3.20000000000000016e118 < (*.f64 x y) < 5.89999999999999995e-36Initial program 100.0%
Taylor expanded in x around 0 88.8%
if -2.7999999999999999e145 < (*.f64 x y) < -3.20000000000000016e118Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
*-commutative100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in b around 0 100.0%
Final simplification89.2%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (+ (* a b) (+ (* z t) (* x y))))) (if (<= t_1 INFINITY) t_1 (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((z * t) + (x * y));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = x * y;
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((z * t) + (x * y));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (a * b) + ((z * t) + (x * y)) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = x * y return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(Float64(z * t) + Float64(x * y))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (a * b) + ((z * t) + (x * y)); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + \left(z \cdot t + x \cdot y\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\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 x around inf 60.0%
+-commutative60.0%
*-commutative60.0%
fma-define80.0%
Applied egg-rr80.0%
Taylor expanded in b around 0 80.0%
Final simplification99.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* a b) -1.7e+88) (not (<= (* a b) 0.029))) (* a b) (* x y)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((a * b) <= -1.7e+88) || !((a * b) <= 0.029)) {
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.7d+88)) .or. (.not. ((a * b) <= 0.029d0))) 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.7e+88) || !((a * b) <= 0.029)) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((a * b) <= -1.7e+88) or not ((a * b) <= 0.029): 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.7e+88) || !(Float64(a * b) <= 0.029)) 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.7e+88) || ~(((a * b) <= 0.029))) 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.7e+88], N[Not[LessEqual[N[(a * b), $MachinePrecision], 0.029]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.7 \cdot 10^{+88} \lor \neg \left(a \cdot b \leq 0.029\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 a b) < -1.70000000000000002e88 or 0.0290000000000000015 < (*.f64 a b) Initial program 97.3%
Taylor expanded in a around inf 63.9%
if -1.70000000000000002e88 < (*.f64 a b) < 0.0290000000000000015Initial program 98.6%
Taylor expanded in x around inf 60.4%
+-commutative60.4%
*-commutative60.4%
fma-define60.4%
Applied egg-rr60.4%
Taylor expanded in b around 0 52.9%
Final simplification57.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.0%
Taylor expanded in a around inf 33.6%
Final simplification33.6%
herbie shell --seed 2024045
(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)))