
(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 98.0%
associate-+l+98.0%
fma-def98.4%
fma-def98.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-def98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y z t a b)
:precision binary64
(if (<= y -16000.0)
(* x y)
(if (or (<= y 8.5e+91) (and (not (<= y 1.5e+134)) (<= y 3.2e+142)))
(+ (* a b) (* z t))
(* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (y <= -16000.0) {
tmp = x * y;
} else if ((y <= 8.5e+91) || (!(y <= 1.5e+134) && (y <= 3.2e+142))) {
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 <= (-16000.0d0)) then
tmp = x * y
else if ((y <= 8.5d+91) .or. (.not. (y <= 1.5d+134)) .and. (y <= 3.2d+142)) 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 <= -16000.0) {
tmp = x * y;
} else if ((y <= 8.5e+91) || (!(y <= 1.5e+134) && (y <= 3.2e+142))) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if y <= -16000.0: tmp = x * y elif (y <= 8.5e+91) or (not (y <= 1.5e+134) and (y <= 3.2e+142)): tmp = (a * b) + (z * t) else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (y <= -16000.0) tmp = Float64(x * y); elseif ((y <= 8.5e+91) || (!(y <= 1.5e+134) && (y <= 3.2e+142))) 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 <= -16000.0) tmp = x * y; elseif ((y <= 8.5e+91) || (~((y <= 1.5e+134)) && (y <= 3.2e+142))) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[y, -16000.0], N[(x * y), $MachinePrecision], If[Or[LessEqual[y, 8.5e+91], And[N[Not[LessEqual[y, 1.5e+134]], $MachinePrecision], LessEqual[y, 3.2e+142]]], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+91} \lor \neg \left(y \leq 1.5 \cdot 10^{+134}\right) \land y \leq 3.2 \cdot 10^{+142}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -16000 or 8.4999999999999995e91 < y < 1.49999999999999998e134 or 3.20000000000000005e142 < y Initial program 96.3%
Taylor expanded in x around inf 70.1%
if -16000 < y < 8.4999999999999995e91 or 1.49999999999999998e134 < y < 3.20000000000000005e142Initial program 99.3%
Taylor expanded in x around 0 84.5%
Final simplification78.5%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* a b) -2.05e+90)
(* a b)
(if (<= (* a b) -6.2e-288)
(* z t)
(if (<= (* a b) 5.8e-37) (* x y) (* a b)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -2.05e+90) {
tmp = a * b;
} else if ((a * b) <= -6.2e-288) {
tmp = z * t;
} else if ((a * b) <= 5.8e-37) {
tmp = x * y;
} 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) <= (-2.05d+90)) then
tmp = a * b
else if ((a * b) <= (-6.2d-288)) then
tmp = z * t
else if ((a * b) <= 5.8d-37) then
tmp = x * y
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) <= -2.05e+90) {
tmp = a * b;
} else if ((a * b) <= -6.2e-288) {
tmp = z * t;
} else if ((a * b) <= 5.8e-37) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -2.05e+90: tmp = a * b elif (a * b) <= -6.2e-288: tmp = z * t elif (a * b) <= 5.8e-37: tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -2.05e+90) tmp = Float64(a * b); elseif (Float64(a * b) <= -6.2e-288) tmp = Float64(z * t); elseif (Float64(a * b) <= 5.8e-37) tmp = Float64(x * y); 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) <= -2.05e+90) tmp = a * b; elseif ((a * b) <= -6.2e-288) tmp = z * t; elseif ((a * b) <= 5.8e-37) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -2.05e+90], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -6.2e-288], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5.8e-37], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2.05 \cdot 10^{+90}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -6.2 \cdot 10^{-288}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;a \cdot b \leq 5.8 \cdot 10^{-37}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -2.05000000000000021e90 or 5.80000000000000009e-37 < (*.f64 a b) Initial program 96.4%
Taylor expanded in a around inf 64.9%
if -2.05000000000000021e90 < (*.f64 a b) < -6.19999999999999967e-288Initial program 100.0%
Taylor expanded in z around inf 51.6%
if -6.19999999999999967e-288 < (*.f64 a b) < 5.80000000000000009e-37Initial program 98.8%
Taylor expanded in x around inf 59.0%
Final simplification59.8%
(FPCore (x y z t a b) :precision binary64 (if (or (<= x -3200000000.0) (not (<= x 3.5e-115))) (+ (* 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 <= -3200000000.0) || !(x <= 3.5e-115)) {
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 <= (-3200000000.0d0)) .or. (.not. (x <= 3.5d-115))) 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 <= -3200000000.0) || !(x <= 3.5e-115)) {
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 <= -3200000000.0) or not (x <= 3.5e-115): 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 ((x <= -3200000000.0) || !(x <= 3.5e-115)) 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 <= -3200000000.0) || ~((x <= 3.5e-115))) 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[x, -3200000000.0], N[Not[LessEqual[x, 3.5e-115]], $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 \leq -3200000000 \lor \neg \left(x \leq 3.5 \cdot 10^{-115}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\end{array}
\end{array}
if x < -3.2e9 or 3.5000000000000002e-115 < x Initial program 96.7%
Taylor expanded in z around 0 81.9%
if -3.2e9 < x < 3.5000000000000002e-115Initial program 100.0%
Taylor expanded in x around 0 87.2%
Final simplification84.1%
(FPCore (x y z t a b) :precision binary64 (if (<= t -1.3e-66) (+ (* a b) (* z t)) (if (<= t 2.8e+72) (+ (* a b) (* x y)) (+ (* z t) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (t <= -1.3e-66) {
tmp = (a * b) + (z * t);
} else if (t <= 2.8e+72) {
tmp = (a * b) + (x * y);
} else {
tmp = (z * t) + (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 <= (-1.3d-66)) then
tmp = (a * b) + (z * t)
else if (t <= 2.8d+72) then
tmp = (a * b) + (x * y)
else
tmp = (z * t) + (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 <= -1.3e-66) {
tmp = (a * b) + (z * t);
} else if (t <= 2.8e+72) {
tmp = (a * b) + (x * y);
} else {
tmp = (z * t) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if t <= -1.3e-66: tmp = (a * b) + (z * t) elif t <= 2.8e+72: tmp = (a * b) + (x * y) else: tmp = (z * t) + (x * y) return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (t <= -1.3e-66) tmp = Float64(Float64(a * b) + Float64(z * t)); elseif (t <= 2.8e+72) tmp = Float64(Float64(a * b) + Float64(x * y)); else tmp = Float64(Float64(z * t) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (t <= -1.3e-66) tmp = (a * b) + (z * t); elseif (t <= 2.8e+72) tmp = (a * b) + (x * y); else tmp = (z * t) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[t, -1.3e-66], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 2.8e+72], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.3 \cdot 10^{-66}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{elif}\;t \leq 2.8 \cdot 10^{+72}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot t + x \cdot y\\
\end{array}
\end{array}
if t < -1.2999999999999999e-66Initial program 94.6%
Taylor expanded in x around 0 73.7%
if -1.2999999999999999e-66 < t < 2.7999999999999999e72Initial program 100.0%
Taylor expanded in z around 0 88.2%
if 2.7999999999999999e72 < t Initial program 97.6%
Taylor expanded in a around 0 89.7%
Final simplification84.3%
(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 98.0%
Final simplification98.0%
(FPCore (x y z t a b) :precision binary64 (if (<= t -4.9e-85) (* z t) (if (<= t 2.8e+72) (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (t <= -4.9e-85) {
tmp = z * t;
} else if (t <= 2.8e+72) {
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 <= (-4.9d-85)) then
tmp = z * t
else if (t <= 2.8d+72) 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 <= -4.9e-85) {
tmp = z * t;
} else if (t <= 2.8e+72) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if t <= -4.9e-85: tmp = z * t elif t <= 2.8e+72: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (t <= -4.9e-85) tmp = Float64(z * t); elseif (t <= 2.8e+72) 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 <= -4.9e-85) tmp = z * t; elseif (t <= 2.8e+72) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[t, -4.9e-85], N[(z * t), $MachinePrecision], If[LessEqual[t, 2.8e+72], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.9 \cdot 10^{-85}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;t \leq 2.8 \cdot 10^{+72}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if t < -4.90000000000000015e-85 or 2.7999999999999999e72 < t Initial program 95.9%
Taylor expanded in z around inf 53.6%
if -4.90000000000000015e-85 < t < 2.7999999999999999e72Initial program 100.0%
Taylor expanded in a around inf 43.2%
Final simplification48.2%
(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.7%
Final simplification33.7%
herbie shell --seed 2023278
(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)))