
(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 6 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 z t (fma x y (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(x, y, (a * b)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(x, y, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(x * y + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, a \cdot b\right)\right)
\end{array}
Initial program 97.2%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6498.0
Applied rewrites98.0%
(FPCore (x y z t a b) :precision binary64 (let* ((t_1 (fma a b (* x y)))) (if (<= (* a b) -1e+24) t_1 (if (<= (* a b) 4e+47) (fma t z (* x y)) t_1))))
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 ((a * b) <= -1e+24) {
tmp = t_1;
} else if ((a * b) <= 4e+47) {
tmp = fma(t, z, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(a, b, Float64(x * y)) tmp = 0.0 if (Float64(a * b) <= -1e+24) tmp = t_1; elseif (Float64(a * b) <= 4e+47) tmp = fma(t, z, Float64(x * y)); else tmp = t_1; 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[(a * b), $MachinePrecision], -1e+24], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 4e+47], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+24}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -9.9999999999999998e23 or 4.0000000000000002e47 < (*.f64 a b) Initial program 94.9%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6487.6
Applied rewrites87.6%
if -9.9999999999999998e23 < (*.f64 a b) < 4.0000000000000002e47Initial program 99.2%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6493.2
Applied rewrites93.2%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma a b (* x y))))
(if (<= (* x y) -1e+54)
t_1
(if (<= (* x y) 1.3e+181) (fma a b (* z t)) t_1))))
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) <= -1e+54) {
tmp = t_1;
} else if ((x * y) <= 1.3e+181) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
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) <= -1e+54) tmp = t_1; elseif (Float64(x * y) <= 1.3e+181) tmp = fma(a, b, Float64(z * t)); else tmp = t_1; 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], -1e+54], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1.3e+181], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+54}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 1.3 \cdot 10^{+181}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -1.0000000000000001e54 or 1.3e181 < (*.f64 x y) Initial program 94.5%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-*.f6484.5
Applied rewrites84.5%
if -1.0000000000000001e54 < (*.f64 x y) < 1.3e181Initial program 98.8%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6488.5
Applied rewrites88.5%
Final simplification87.1%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -3.8e+166) (* x y) (if (<= (* x y) 9.6e+188) (fma a b (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -3.8e+166) {
tmp = x * y;
} else if ((x * y) <= 9.6e+188) {
tmp = fma(a, b, (z * t));
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -3.8e+166) tmp = Float64(x * y); elseif (Float64(x * y) <= 9.6e+188) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -3.8e+166], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 9.6e+188], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.8 \cdot 10^{+166}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 9.6 \cdot 10^{+188}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -3.80000000000000007e166 or 9.5999999999999997e188 < (*.f64 x y) Initial program 93.0%
Taylor expanded in x around inf
lower-*.f6482.6
Applied rewrites82.6%
if -3.80000000000000007e166 < (*.f64 x y) < 9.5999999999999997e188Initial program 98.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6485.5
Applied rewrites85.5%
Final simplification84.7%
(FPCore (x y z t a b) :precision binary64 (if (<= (* a b) -4.5e+22) (* a b) (if (<= (* a b) 4.5e+27) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((a * b) <= -4.5e+22) {
tmp = a * b;
} else if ((a * b) <= 4.5e+27) {
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) <= (-4.5d+22)) then
tmp = a * b
else if ((a * b) <= 4.5d+27) 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) <= -4.5e+22) {
tmp = a * b;
} else if ((a * b) <= 4.5e+27) {
tmp = z * t;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (a * b) <= -4.5e+22: tmp = a * b elif (a * b) <= 4.5e+27: tmp = z * t else: tmp = a * b return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(a * b) <= -4.5e+22) tmp = Float64(a * b); elseif (Float64(a * b) <= 4.5e+27) 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) <= -4.5e+22) tmp = a * b; elseif ((a * b) <= 4.5e+27) 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], -4.5e+22], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 4.5e+27], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -4.5 \cdot 10^{+22}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 4.5 \cdot 10^{+27}:\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -4.4999999999999998e22 or 4.4999999999999999e27 < (*.f64 a b) Initial program 95.0%
Taylor expanded in a around inf
lower-*.f6468.0
Applied rewrites68.0%
if -4.4999999999999998e22 < (*.f64 a b) < 4.4999999999999999e27Initial program 99.2%
Taylor expanded in z around inf
lower-*.f6451.9
Applied rewrites51.9%
Final simplification59.5%
(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
lower-*.f6436.1
Applied rewrites36.1%
herbie shell --seed 2024220
(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)))