
(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 8 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) (+ (* x y) (* z t))))) (if (<= t_1 INFINITY) t_1 (+ (* a b) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (a * b) + ((x * y) + (z * t));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = (a * b) + (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) + ((x * y) + (z * t));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = (a * b) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): t_1 = (a * b) + ((x * y) + (z * t)) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = (a * b) + (x * y) return tmp
function code(x, y, z, t, a, b) t_1 = Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(Float64(a * b) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (a * b) + ((x * y) + (z * t)); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = (a * b) + (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[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := a \cdot b + \left(x \cdot y + z \cdot t\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + 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 66.7%
Final simplification99.2%
(FPCore (x y z t a b) :precision binary64 (fma x y (fma a b (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(x, y, fma(a, b, (z * t)));
}
function code(x, y, z, t, a, b) return fma(x, y, fma(a, b, Float64(z * t))) end
code[x_, y_, z_, t_, a_, b_] := N[(x * y + N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)
\end{array}
Initial program 97.6%
associate-+l+97.6%
fma-def98.0%
+-commutative98.0%
fma-def98.4%
Simplified98.4%
Final simplification98.4%
(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 (or (<= (* x y) -3.5e+114) (not (<= (* x y) 1.8e+142))) (* 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.5e+114) || !((x * y) <= 1.8e+142)) {
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.5d+114)) .or. (.not. ((x * y) <= 1.8d+142))) 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.5e+114) || !((x * y) <= 1.8e+142)) {
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.5e+114) or not ((x * y) <= 1.8e+142): 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.5e+114) || !(Float64(x * y) <= 1.8e+142)) 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.5e+114) || ~(((x * y) <= 1.8e+142))) 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.5e+114], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.8e+142]], $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.5 \cdot 10^{+114} \lor \neg \left(x \cdot y \leq 1.8 \cdot 10^{+142}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -3.5000000000000001e114 or 1.8000000000000001e142 < (*.f64 x y) Initial program 94.9%
Taylor expanded in x around inf 89.3%
Taylor expanded in x around inf 76.5%
if -3.5000000000000001e114 < (*.f64 x y) < 1.8000000000000001e142Initial program 98.9%
Taylor expanded in x around 0 88.4%
Final simplification84.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -5.2e+65) (not (<= (* x y) 9.6e+142))) (+ (* a b) (* 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) <= -5.2e+65) || !((x * y) <= 9.6e+142)) {
tmp = (a * b) + (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) <= (-5.2d+65)) .or. (.not. ((x * y) <= 9.6d+142))) then
tmp = (a * b) + (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) <= -5.2e+65) || !((x * y) <= 9.6e+142)) {
tmp = (a * b) + (x * y);
} else {
tmp = (a * b) + (z * t);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((x * y) <= -5.2e+65) or not ((x * y) <= 9.6e+142): tmp = (a * b) + (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) <= -5.2e+65) || !(Float64(x * y) <= 9.6e+142)) tmp = Float64(Float64(a * b) + 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) <= -5.2e+65) || ~(((x * y) <= 9.6e+142))) tmp = (a * b) + (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], -5.2e+65], N[Not[LessEqual[N[(x * y), $MachinePrecision], 9.6e+142]], $MachinePrecision]], N[(N[(a * b), $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 -5.2 \cdot 10^{+65} \lor \neg \left(x \cdot y \leq 9.6 \cdot 10^{+142}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if (*.f64 x y) < -5.20000000000000005e65 or 9.5999999999999996e142 < (*.f64 x y) Initial program 95.0%
Taylor expanded in x around inf 89.7%
if -5.20000000000000005e65 < (*.f64 x y) < 9.5999999999999996e142Initial program 98.8%
Taylor expanded in x around 0 88.8%
Final simplification89.1%
(FPCore (x y z t a b) :precision binary64 (if (<= t -5e-78) (* z t) (if (<= t -2.5e-289) (* x y) (if (<= t 3.6e+109) (* a b) (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (t <= -5e-78) {
tmp = z * t;
} else if (t <= -2.5e-289) {
tmp = x * y;
} else if (t <= 3.6e+109) {
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 (t <= (-5d-78)) then
tmp = z * t
else if (t <= (-2.5d-289)) then
tmp = x * y
else if (t <= 3.6d+109) 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 (t <= -5e-78) {
tmp = z * t;
} else if (t <= -2.5e-289) {
tmp = x * y;
} else if (t <= 3.6e+109) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if t <= -5e-78: tmp = z * t elif t <= -2.5e-289: tmp = x * y elif t <= 3.6e+109: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (t <= -5e-78) tmp = Float64(z * t); elseif (t <= -2.5e-289) tmp = Float64(x * y); elseif (t <= 3.6e+109) 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 (t <= -5e-78) tmp = z * t; elseif (t <= -2.5e-289) tmp = x * y; elseif (t <= 3.6e+109) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[t, -5e-78], N[(z * t), $MachinePrecision], If[LessEqual[t, -2.5e-289], N[(x * y), $MachinePrecision], If[LessEqual[t, 3.6e+109], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5 \cdot 10^{-78}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;t \leq -2.5 \cdot 10^{-289}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;t \leq 3.6 \cdot 10^{+109}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if t < -4.9999999999999996e-78 or 3.6e109 < t Initial program 95.1%
Taylor expanded in x around 0 80.7%
+-commutative80.7%
*-commutative80.7%
fma-def81.5%
Simplified81.5%
Taylor expanded in z around inf 56.4%
if -4.9999999999999996e-78 < t < -2.50000000000000014e-289Initial program 100.0%
Taylor expanded in x around inf 96.9%
Taylor expanded in x around inf 47.7%
if -2.50000000000000014e-289 < t < 3.6e109Initial program 100.0%
Taylor expanded in a around inf 44.3%
Final simplification50.7%
(FPCore (x y z t a b) :precision binary64 (if (or (<= z -2.5e+37) (not (<= z 1.06e-67))) (* z t) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z <= -2.5e+37) || !(z <= 1.06e-67)) {
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 ((z <= (-2.5d+37)) .or. (.not. (z <= 1.06d-67))) 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 ((z <= -2.5e+37) || !(z <= 1.06e-67)) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z <= -2.5e+37) or not (z <= 1.06e-67): tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((z <= -2.5e+37) || !(z <= 1.06e-67)) 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 ((z <= -2.5e+37) || ~((z <= 1.06e-67))) tmp = z * t; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[z, -2.5e+37], N[Not[LessEqual[z, 1.06e-67]], $MachinePrecision]], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{+37} \lor \neg \left(z \leq 1.06 \cdot 10^{-67}\right):\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if z < -2.49999999999999994e37 or 1.06e-67 < z Initial program 94.9%
Taylor expanded in x around 0 75.4%
+-commutative75.4%
*-commutative75.4%
fma-def76.2%
Simplified76.2%
Taylor expanded in z around inf 51.9%
if -2.49999999999999994e37 < z < 1.06e-67Initial program 100.0%
Taylor expanded in a around inf 47.0%
Final simplification49.3%
(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 37.8%
Final simplification37.8%
herbie shell --seed 2024031
(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)))