
(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 7 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 (* 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 = 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 = 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 = 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(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 = 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[(x * y), $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}:\\
\;\;\;\;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 57.1%
Taylor expanded in y around inf 71.5%
Final simplification99.2%
(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.2%
associate-+l+97.2%
fma-def97.6%
fma-def98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x y z t a b)
:precision binary64
(if (<= x -4.7e+36)
(* x y)
(if (<= x -1.55e-53)
(* a b)
(if (<= x -2.2e-110)
(* z t)
(if (<= x -1.95e-141)
(* a b)
(if (<= x -8.5e-218) (* z t) (if (<= x 3.7e+15) (* a b) (* x y))))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (x <= -4.7e+36) {
tmp = x * y;
} else if (x <= -1.55e-53) {
tmp = a * b;
} else if (x <= -2.2e-110) {
tmp = z * t;
} else if (x <= -1.95e-141) {
tmp = a * b;
} else if (x <= -8.5e-218) {
tmp = z * t;
} else if (x <= 3.7e+15) {
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 (x <= (-4.7d+36)) then
tmp = x * y
else if (x <= (-1.55d-53)) then
tmp = a * b
else if (x <= (-2.2d-110)) then
tmp = z * t
else if (x <= (-1.95d-141)) then
tmp = a * b
else if (x <= (-8.5d-218)) then
tmp = z * t
else if (x <= 3.7d+15) 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 (x <= -4.7e+36) {
tmp = x * y;
} else if (x <= -1.55e-53) {
tmp = a * b;
} else if (x <= -2.2e-110) {
tmp = z * t;
} else if (x <= -1.95e-141) {
tmp = a * b;
} else if (x <= -8.5e-218) {
tmp = z * t;
} else if (x <= 3.7e+15) {
tmp = a * b;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if x <= -4.7e+36: tmp = x * y elif x <= -1.55e-53: tmp = a * b elif x <= -2.2e-110: tmp = z * t elif x <= -1.95e-141: tmp = a * b elif x <= -8.5e-218: tmp = z * t elif x <= 3.7e+15: tmp = a * b else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (x <= -4.7e+36) tmp = Float64(x * y); elseif (x <= -1.55e-53) tmp = Float64(a * b); elseif (x <= -2.2e-110) tmp = Float64(z * t); elseif (x <= -1.95e-141) tmp = Float64(a * b); elseif (x <= -8.5e-218) tmp = Float64(z * t); elseif (x <= 3.7e+15) 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 (x <= -4.7e+36) tmp = x * y; elseif (x <= -1.55e-53) tmp = a * b; elseif (x <= -2.2e-110) tmp = z * t; elseif (x <= -1.95e-141) tmp = a * b; elseif (x <= -8.5e-218) tmp = z * t; elseif (x <= 3.7e+15) tmp = a * b; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[x, -4.7e+36], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.55e-53], N[(a * b), $MachinePrecision], If[LessEqual[x, -2.2e-110], N[(z * t), $MachinePrecision], If[LessEqual[x, -1.95e-141], N[(a * b), $MachinePrecision], If[LessEqual[x, -8.5e-218], N[(z * t), $MachinePrecision], If[LessEqual[x, 3.7e+15], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{+36}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{-53}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{-110}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \leq -1.95 \cdot 10^{-141}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-218}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{+15}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.69999999999999989e36 or 3.7e15 < x Initial program 94.6%
Taylor expanded in x around inf 73.7%
Taylor expanded in y around inf 64.1%
if -4.69999999999999989e36 < x < -1.55000000000000008e-53 or -2.1999999999999999e-110 < x < -1.9499999999999999e-141 or -8.5000000000000004e-218 < x < 3.7e15Initial program 99.1%
Taylor expanded in a around inf 55.8%
if -1.55000000000000008e-53 < x < -2.1999999999999999e-110 or -1.9499999999999999e-141 < x < -8.5000000000000004e-218Initial program 100.0%
Taylor expanded in x around 0 93.6%
Taylor expanded in t around inf 66.1%
Final simplification60.5%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -1.85e+31) (* a b) (if (<= (* a b) 4.4e-35) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -1.85e+31) {
tmp = a * b;
} else if ((a * b) <= 4.4e-35) {
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) <= (-1.85d+31)) then
tmp = a * b
else if ((a * b) <= 4.4d-35) 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) <= -1.85e+31) {
tmp = a * b;
} else if ((a * b) <= 4.4e-35) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -1.85e+31: tmp = a * b elif (a * b) <= 4.4e-35: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -1.85e+31) tmp = Float64(a * b); elseif (Float64(a * b) <= 4.4e-35) 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) <= -1.85e+31) tmp = a * b; elseif ((a * b) <= 4.4e-35) 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], -1.85e+31], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 4.4e-35], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.85 \cdot 10^{+31}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 4.4 \cdot 10^{-35}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.8499999999999999e31 or 4.39999999999999987e-35 < (*.f64 a b) Initial program 96.1%
Taylor expanded in a around inf 59.8%
if -1.8499999999999999e31 < (*.f64 a b) < 4.39999999999999987e-35Initial program 98.4%
Taylor expanded in x around 0 53.6%
Taylor expanded in t around inf 47.5%
Final simplification53.7%
(FPCore (x y z t a b) :precision binary64 (if (<= y -6.6e-54) (* x y) (if (<= y 5.2e+97) (+ (* a b) (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (y <= -6.6e-54) {
tmp = x * y;
} else if (y <= 5.2e+97) {
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 <= (-6.6d-54)) then
tmp = x * y
else if (y <= 5.2d+97) 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 <= -6.6e-54) {
tmp = x * y;
} else if (y <= 5.2e+97) {
tmp = (a * b) + (z * t);
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if y <= -6.6e-54: tmp = x * y elif y <= 5.2e+97: tmp = (a * b) + (z * t) else: tmp = x * y return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (y <= -6.6e-54) tmp = Float64(x * y); elseif (y <= 5.2e+97) 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 <= -6.6e-54) tmp = x * y; elseif (y <= 5.2e+97) tmp = (a * b) + (z * t); else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[y, -6.6e-54], N[(x * y), $MachinePrecision], If[LessEqual[y, 5.2e+97], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{-54}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+97}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -6.59999999999999986e-54 or 5.2e97 < y Initial program 94.2%
Taylor expanded in x around inf 78.3%
Taylor expanded in y around inf 58.2%
if -6.59999999999999986e-54 < y < 5.2e97Initial program 100.0%
Taylor expanded in x around 0 86.4%
Final simplification73.1%
(FPCore (x y z t a b) :precision binary64 (if (<= y -6.6e-54) (* x y) (if (<= y 7.2e+96) (+ (* 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 (y <= -6.6e-54) {
tmp = x * y;
} else if (y <= 7.2e+96) {
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 (y <= (-6.6d-54)) then
tmp = x * y
else if (y <= 7.2d+96) 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 (y <= -6.6e-54) {
tmp = x * y;
} else if (y <= 7.2e+96) {
tmp = (a * b) + (z * t);
} else {
tmp = (a * b) + (x * y);
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if y <= -6.6e-54: tmp = x * y elif y <= 7.2e+96: 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 (y <= -6.6e-54) tmp = Float64(x * y); elseif (y <= 7.2e+96) 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 (y <= -6.6e-54) tmp = x * y; elseif (y <= 7.2e+96) tmp = (a * b) + (z * t); else tmp = (a * b) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[y, -6.6e-54], N[(x * y), $MachinePrecision], If[LessEqual[y, 7.2e+96], 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}\;y \leq -6.6 \cdot 10^{-54}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+96}:\\
\;\;\;\;a \cdot b + z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\
\end{array}
\end{array}
if y < -6.59999999999999986e-54Initial program 96.1%
Taylor expanded in x around inf 78.2%
Taylor expanded in y around inf 61.9%
if -6.59999999999999986e-54 < y < 7.20000000000000026e96Initial program 100.0%
Taylor expanded in x around 0 86.4%
if 7.20000000000000026e96 < y Initial program 90.9%
Taylor expanded in x around inf 78.4%
Final simplification77.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.2%
Taylor expanded in a around inf 34.7%
Final simplification34.7%
herbie shell --seed 2023195
(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)))