
(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 (+ (+ (* 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}
Initial program 98.4%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* x y))))
(if (<= (* x y) -1.56e+86)
t_1
(if (<= (* x y) 2.3e+57)
(fma a b (* z t))
(if (<= (* x y) 1.45e+155) t_1 (fma t z (* x y)))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(a, b, (x * y));
double tmp;
if ((x * y) <= -1.56e+86) {
tmp = t_1;
} else if ((x * y) <= 2.3e+57) {
tmp = fma(a, b, (z * t));
} else if ((x * y) <= 1.45e+155) {
tmp = t_1;
} else {
tmp = fma(t, z, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -1.56e+86) tmp = t_1; elseif (Float64(x * y) <= 2.3e+57) tmp = fma(a, b, Float64(z * t)); elseif (Float64(x * y) <= 1.45e+155) tmp = t_1; else tmp = fma(t, z, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1.56e+86], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 2.3e+57], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.45e+155], t$95$1, N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -1.56 \cdot 10^{+86}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 2.3 \cdot 10^{+57}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{elif}\;x \cdot y \leq 1.45 \cdot 10^{+155}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.56000000000000013e86 or 2.2999999999999999e57 < (*.f64 x y) < 1.45e155Initial program 97.2%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6482.6
Applied rewrites82.6%
if -1.56000000000000013e86 < (*.f64 x y) < 2.2999999999999999e57Initial program 99.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6487.4
Applied rewrites87.4%
if 1.45e155 < (*.f64 x y) Initial program 94.5%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6488.0
Applied rewrites88.0%
Final simplification86.3%
herbie shell --seed 2024229
(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)))