
(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 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.6%
+-commutative97.6%
fma-def99.2%
fma-def99.6%
Simplified99.6%
Final simplification99.6%
(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 a b (* z t)))))
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(a, b, (z * t));
}
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(a, b, Float64(z * t)); 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[(a * b + N[(z * t), $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(a, b, z \cdot t\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 0 33.3%
fma-def66.7%
Simplified66.7%
Final simplification99.2%
(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 97.6%
fma-def98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -3.2e+58)
(* a b)
(if (<= (* a b) -2.2e-162)
(* z t)
(if (<= (* a b) 0.0)
(* x y)
(if (<= (* a b) 8.5e-201)
(* z t)
(if (<= (* a b) 2.8e-39)
(* x y)
(if (<= (* a b) 4e+47) (* z t) (* a b))))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -3.2e+58) {
tmp = a * b;
} else if ((a * b) <= -2.2e-162) {
tmp = z * t;
} else if ((a * b) <= 0.0) {
tmp = x * y;
} else if ((a * b) <= 8.5e-201) {
tmp = z * t;
} else if ((a * b) <= 2.8e-39) {
tmp = x * y;
} else if ((a * b) <= 4e+47) {
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) <= (-3.2d+58)) then
tmp = a * b
else if ((a * b) <= (-2.2d-162)) then
tmp = z * t
else if ((a * b) <= 0.0d0) then
tmp = x * y
else if ((a * b) <= 8.5d-201) then
tmp = z * t
else if ((a * b) <= 2.8d-39) then
tmp = x * y
else if ((a * b) <= 4d+47) 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) <= -3.2e+58) {
tmp = a * b;
} else if ((a * b) <= -2.2e-162) {
tmp = z * t;
} else if ((a * b) <= 0.0) {
tmp = x * y;
} else if ((a * b) <= 8.5e-201) {
tmp = z * t;
} else if ((a * b) <= 2.8e-39) {
tmp = x * y;
} else if ((a * b) <= 4e+47) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -3.2e+58: tmp = a * b elif (a * b) <= -2.2e-162: tmp = z * t elif (a * b) <= 0.0: tmp = x * y elif (a * b) <= 8.5e-201: tmp = z * t elif (a * b) <= 2.8e-39: tmp = x * y elif (a * b) <= 4e+47: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -3.2e+58) tmp = Float64(a * b); elseif (Float64(a * b) <= -2.2e-162) tmp = Float64(z * t); elseif (Float64(a * b) <= 0.0) tmp = Float64(x * y); elseif (Float64(a * b) <= 8.5e-201) tmp = Float64(z * t); elseif (Float64(a * b) <= 2.8e-39) tmp = Float64(x * y); elseif (Float64(a * b) <= 4e+47) 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) <= -3.2e+58) tmp = a * b; elseif ((a * b) <= -2.2e-162) tmp = z * t; elseif ((a * b) <= 0.0) tmp = x * y; elseif ((a * b) <= 8.5e-201) tmp = z * t; elseif ((a * b) <= 2.8e-39) tmp = x * y; elseif ((a * b) <= 4e+47) 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], -3.2e+58], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2.2e-162], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 0.0], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 8.5e-201], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.8e-39], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 4e+47], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -3.2 \cdot 10^{+58}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -2.2 \cdot 10^{-162}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 0:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 8.5 \cdot 10^{-201}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 2.8 \cdot 10^{-39}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{+47}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -3.20000000000000015e58 or 4.0000000000000002e47 < (*.f64 a b) Initial program 95.6%
Taylor expanded in a around inf 69.8%
if -3.20000000000000015e58 < (*.f64 a b) < -2.1999999999999999e-162 or -0.0 < (*.f64 a b) < 8.5000000000000007e-201 or 2.8000000000000001e-39 < (*.f64 a b) < 4.0000000000000002e47Initial program 98.6%
Taylor expanded in z around inf 63.1%
if -2.1999999999999999e-162 < (*.f64 a b) < -0.0 or 8.5000000000000007e-201 < (*.f64 a b) < 2.8000000000000001e-39Initial program 100.0%
Taylor expanded in x around inf 60.1%
Final simplification65.3%
(FPCore (x y z t a b)
:precision binary64
(if (<= y -85000.0)
(* x y)
(if (or (<= y 1.75e+133) (and (not (<= y 1.9e+157)) (<= y 1e+204)))
(+ (* a b) (* z t))
(* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (y <= -85000.0) {
tmp = x * y;
} else if ((y <= 1.75e+133) || (!(y <= 1.9e+157) && (y <= 1e+204))) {
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 (y <= (-85000.0d0)) then
tmp = x * y
else if ((y <= 1.75d+133) .or. (.not. (y <= 1.9d+157)) .and. (y <= 1d+204)) 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 (y <= -85000.0) {
tmp = x * y;
} else if ((y <= 1.75e+133) || (!(y <= 1.9e+157) && (y <= 1e+204))) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if y <= -85000.0: tmp = x * y elif (y <= 1.75e+133) or (not (y <= 1.9e+157) and (y <= 1e+204)): tmp = (a * b) + (z * t) else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (y <= -85000.0) tmp = Float64(x * y); elseif ((y <= 1.75e+133) || (!(y <= 1.9e+157) && (y <= 1e+204))) 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 (y <= -85000.0) tmp = x * y; elseif ((y <= 1.75e+133) || (~((y <= 1.9e+157)) && (y <= 1e+204))) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[y, -85000.0], N[(x * y), $MachinePrecision], If[Or[LessEqual[y, 1.75e+133], And[N[Not[LessEqual[y, 1.9e+157]], $MachinePrecision], LessEqual[y, 1e+204]]], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -85000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{+133} \lor \neg \left(y \leq 1.9 \cdot 10^{+157}\right) \land y \leq 10^{+204}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -85000 or 1.7499999999999999e133 < y < 1.9e157 or 9.99999999999999989e203 < y Initial program 96.0%
Taylor expanded in x around inf 56.2%
if -85000 < y < 1.7499999999999999e133 or 1.9e157 < y < 9.99999999999999989e203Initial program 98.7%
Taylor expanded in x around 0 80.8%
Final simplification71.1%
(FPCore (x y z t a b) :precision binary64 (if (or (<= t -1e-132) (not (<= t 1.2e+111))) (+ (* 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 ((t <= -1e-132) || !(t <= 1.2e+111)) {
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 ((t <= (-1d-132)) .or. (.not. (t <= 1.2d+111))) 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 ((t <= -1e-132) || !(t <= 1.2e+111)) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (t <= -1e-132) or not (t <= 1.2e+111): 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 ((t <= -1e-132) || !(t <= 1.2e+111)) 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 ((t <= -1e-132) || ~((t <= 1.2e+111))) tmp = (a * b) + (z * t); else tmp = (a * b) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[t, -1e-132], N[Not[LessEqual[t, 1.2e+111]], $MachinePrecision]], 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}\;t \leq -1 \cdot 10^{-132} \lor \neg \left(t \leq 1.2 \cdot 10^{+111}\right):\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\end{array}
if t < -9.9999999999999999e-133 or 1.20000000000000003e111 < t Initial program 96.4%
Taylor expanded in x around 0 74.7%
if -9.9999999999999999e-133 < t < 1.20000000000000003e111Initial program 99.1%
Taylor expanded in z around 0 83.9%
Final simplification79.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -8.5e+59) (* a b) (if (<= (* a b) 1.55e+46) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -8.5e+59) {
tmp = a * b;
} else if ((a * b) <= 1.55e+46) {
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) <= (-8.5d+59)) then
tmp = a * b
else if ((a * b) <= 1.55d+46) 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) <= -8.5e+59) {
tmp = a * b;
} else if ((a * b) <= 1.55e+46) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -8.5e+59: tmp = a * b elif (a * b) <= 1.55e+46: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -8.5e+59) tmp = Float64(a * b); elseif (Float64(a * b) <= 1.55e+46) 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) <= -8.5e+59) tmp = a * b; elseif ((a * b) <= 1.55e+46) 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], -8.5e+59], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.55e+46], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -8.5 \cdot 10^{+59}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 1.55 \cdot 10^{+46}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -8.4999999999999999e59 or 1.54999999999999988e46 < (*.f64 a b) Initial program 95.6%
Taylor expanded in a around inf 69.8%
if -8.4999999999999999e59 < (*.f64 a b) < 1.54999999999999988e46Initial program 99.3%
Taylor expanded in z around inf 50.2%
Final simplification58.9%
(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 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 36.9%
Final simplification36.9%
herbie shell --seed 2023268
(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)))