
(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 (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.3%
associate-+l+97.3%
fma-def98.0%
fma-def98.4%
Simplified98.4%
Final simplification98.4%
(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 97.3%
+-commutative97.3%
fma-def98.0%
fma-def98.0%
Simplified98.0%
Final simplification98.0%
(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.3%
fma-def97.3%
Simplified97.3%
Final simplification97.3%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -2.2e+86)
(* x y)
(if (<= (* x y) -1.7e-111)
(* z t)
(if (<= (* x y) 7.6e-84)
(* a b)
(if (<= (* x y) 3.9e+36) (* z t) (* x y))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -2.2e+86) {
tmp = x * y;
} else if ((x * y) <= -1.7e-111) {
tmp = z * t;
} else if ((x * y) <= 7.6e-84) {
tmp = a * b;
} else if ((x * y) <= 3.9e+36) {
tmp = 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 ((x * y) <= (-2.2d+86)) then
tmp = x * y
else if ((x * y) <= (-1.7d-111)) then
tmp = z * t
else if ((x * y) <= 7.6d-84) then
tmp = a * b
else if ((x * y) <= 3.9d+36) then
tmp = 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 ((x * y) <= -2.2e+86) {
tmp = x * y;
} else if ((x * y) <= -1.7e-111) {
tmp = z * t;
} else if ((x * y) <= 7.6e-84) {
tmp = a * b;
} else if ((x * y) <= 3.9e+36) {
tmp = z * t;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -2.2e+86: tmp = x * y elif (x * y) <= -1.7e-111: tmp = z * t elif (x * y) <= 7.6e-84: tmp = a * b elif (x * y) <= 3.9e+36: tmp = z * t else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -2.2e+86) tmp = Float64(x * y); elseif (Float64(x * y) <= -1.7e-111) tmp = Float64(z * t); elseif (Float64(x * y) <= 7.6e-84) tmp = Float64(a * b); elseif (Float64(x * y) <= 3.9e+36) tmp = 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 ((x * y) <= -2.2e+86) tmp = x * y; elseif ((x * y) <= -1.7e-111) tmp = z * t; elseif ((x * y) <= 7.6e-84) tmp = a * b; elseif ((x * y) <= 3.9e+36) tmp = z * t; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -2.2e+86], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -1.7e-111], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 7.6e-84], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 3.9e+36], N[(z * t), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2.2 \cdot 10^{+86}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq -1.7 \cdot 10^{-111}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \cdot y \leq 7.6 \cdot 10^{-84}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \cdot y \leq 3.9 \cdot 10^{+36}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -2.20000000000000003e86 or 3.90000000000000021e36 < (*.f64 x y) Initial program 95.0%
Taylor expanded in x around inf 72.2%
if -2.20000000000000003e86 < (*.f64 x y) < -1.69999999999999998e-111 or 7.59999999999999971e-84 < (*.f64 x y) < 3.90000000000000021e36Initial program 96.7%
Taylor expanded in z around inf 61.5%
if -1.69999999999999998e-111 < (*.f64 x y) < 7.59999999999999971e-84Initial program 100.0%
Taylor expanded in a around inf 58.8%
Final simplification64.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -3.2e+52) (not (<= (* x y) 1.7e+91))) (+ (* x y) (* z t)) (+ (* 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+52) || !((x * y) <= 1.7e+91)) {
tmp = (x * y) + (z * t);
} 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+52)) .or. (.not. ((x * y) <= 1.7d+91))) then
tmp = (x * y) + (z * t)
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+52) || !((x * y) <= 1.7e+91)) {
tmp = (x * y) + (z * t);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -3.2e+52) or not ((x * y) <= 1.7e+91): tmp = (x * y) + (z * t) 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+52) || !(Float64(x * y) <= 1.7e+91)) tmp = Float64(Float64(x * y) + Float64(z * t)); 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+52) || ~(((x * y) <= 1.7e+91))) tmp = (x * y) + (z * t); 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+52], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.7e+91]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $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^{+52} \lor \neg \left(x \cdot y \leq 1.7 \cdot 10^{+91}\right):\\
\;\;\;\;x \cdot y + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -3.2e52 or 1.7e91 < (*.f64 x y) Initial program 93.1%
Taylor expanded in a around 0 87.4%
if -3.2e52 < (*.f64 x y) < 1.7e91Initial program 100.0%
Taylor expanded in x around 0 90.9%
Final simplification89.5%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -5.2e+89) (* x y) (if (<= (* x y) 6.6e+156) (+ (* a b) (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -5.2e+89) {
tmp = x * y;
} else if ((x * y) <= 6.6e+156) {
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 ((x * y) <= (-5.2d+89)) then
tmp = x * y
else if ((x * y) <= 6.6d+156) 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 ((x * y) <= -5.2e+89) {
tmp = x * y;
} else if ((x * y) <= 6.6e+156) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -5.2e+89: tmp = x * y elif (x * y) <= 6.6e+156: tmp = (a * b) + (z * t) else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -5.2e+89) tmp = Float64(x * y); elseif (Float64(x * y) <= 6.6e+156) 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 ((x * y) <= -5.2e+89) tmp = x * y; elseif ((x * y) <= 6.6e+156) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -5.2e+89], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 6.6e+156], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5.2 \cdot 10^{+89}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 6.6 \cdot 10^{+156}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -5.2000000000000001e89 or 6.5999999999999997e156 < (*.f64 x y) Initial program 93.7%
Taylor expanded in x around inf 81.4%
if -5.2000000000000001e89 < (*.f64 x y) < 6.5999999999999997e156Initial program 98.9%
Taylor expanded in x around 0 85.5%
Final simplification84.3%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -5.2e+53) (+ (* a b) (* x y)) (if (<= (* x y) 5e+156) (+ (* a b) (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -5.2e+53) {
tmp = (a * b) + (x * y);
} else if ((x * y) <= 5e+156) {
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 ((x * y) <= (-5.2d+53)) then
tmp = (a * b) + (x * y)
else if ((x * y) <= 5d+156) 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 ((x * y) <= -5.2e+53) {
tmp = (a * b) + (x * y);
} else if ((x * y) <= 5e+156) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -5.2e+53: tmp = (a * b) + (x * y) elif (x * y) <= 5e+156: tmp = (a * b) + (z * t) else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -5.2e+53) tmp = Float64(Float64(a * b) + Float64(x * y)); elseif (Float64(x * y) <= 5e+156) 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 ((x * y) <= -5.2e+53) tmp = (a * b) + (x * y); elseif ((x * y) <= 5e+156) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -5.2e+53], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+156], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5.2 \cdot 10^{+53}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+156}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -5.19999999999999996e53Initial program 91.8%
Taylor expanded in z around 0 81.0%
if -5.19999999999999996e53 < (*.f64 x y) < 4.99999999999999992e156Initial program 100.0%
Taylor expanded in x around 0 88.6%
if 4.99999999999999992e156 < (*.f64 x y) Initial program 93.5%
Taylor expanded in x around inf 90.6%
Final simplification87.0%
(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.3%
Final simplification97.3%
(FPCore (x y z t a b) :precision binary64 (if (or (<= a -6.2e+59) (not (<= a 3.4e-145))) (* a b) (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a <= -6.2e+59) || !(a <= 3.4e-145)) {
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 <= (-6.2d+59)) .or. (.not. (a <= 3.4d-145))) 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 <= -6.2e+59) || !(a <= 3.4e-145)) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a <= -6.2e+59) or not (a <= 3.4e-145): tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((a <= -6.2e+59) || !(a <= 3.4e-145)) 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 <= -6.2e+59) || ~((a <= 3.4e-145))) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[a, -6.2e+59], N[Not[LessEqual[a, 3.4e-145]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -6.2 \cdot 10^{+59} \lor \neg \left(a \leq 3.4 \cdot 10^{-145}\right):\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if a < -6.20000000000000029e59 or 3.3999999999999999e-145 < a Initial program 95.8%
Taylor expanded in a around inf 50.2%
if -6.20000000000000029e59 < a < 3.3999999999999999e-145Initial program 99.1%
Taylor expanded in z around inf 44.2%
Final simplification47.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.3%
Taylor expanded in a around inf 34.1%
Final simplification34.1%
herbie shell --seed 2023293
(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)))