
(FPCore (x y z t a b c i) :precision binary64 (+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = (((x * y) + (z * t)) + (a * b)) + (c * i)
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
def code(x, y, z, t, a, b, c, i): return (((x * y) + (z * t)) + (a * b)) + (c * i)
function code(x, y, z, t, a, b, c, i) return Float64(Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) + Float64(c * i)) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = (((x * y) + (z * t)) + (a * b)) + (c * i); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision] + N[(c * i), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b c i) :precision binary64 (+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
real(8) function code(x, y, z, t, a, b, c, i)
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), intent (in) :: c
real(8), intent (in) :: i
code = (((x * y) + (z * t)) + (a * b)) + (c * i)
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
def code(x, y, z, t, a, b, c, i): return (((x * y) + (z * t)) + (a * b)) + (c * i)
function code(x, y, z, t, a, b, c, i) return Float64(Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) + Float64(c * i)) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = (((x * y) + (z * t)) + (a * b)) + (c * i); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision] + N[(c * i), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\end{array}
(FPCore (x y z t a b c i) :precision binary64 (fma z t (fma x y (fma a b (* c i)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return fma(z, t, fma(x, y, fma(a, b, (c * i))));
}
function code(x, y, z, t, a, b, c, i) return fma(z, t, fma(x, y, fma(a, b, Float64(c * i)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(z * t + N[(x * y + N[(a * b + N[(c * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, c \cdot i\right)\right)\right)
\end{array}
Initial program 96.9%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/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 c i)
:precision binary64
(let* ((t_1 (fma i c (* x y))) (t_2 (fma z t (* a b))))
(if (<= (* a b) -5e+82)
t_2
(if (<= (* a b) -1e-305)
t_1
(if (<= (* a b) 2e-141)
(fma i c (* z t))
(if (<= (* a b) 5e-35) t_1 t_2))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(i, c, (x * y));
double t_2 = fma(z, t, (a * b));
double tmp;
if ((a * b) <= -5e+82) {
tmp = t_2;
} else if ((a * b) <= -1e-305) {
tmp = t_1;
} else if ((a * b) <= 2e-141) {
tmp = fma(i, c, (z * t));
} else if ((a * b) <= 5e-35) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(i, c, Float64(x * y)) t_2 = fma(z, t, Float64(a * b)) tmp = 0.0 if (Float64(a * b) <= -5e+82) tmp = t_2; elseif (Float64(a * b) <= -1e-305) tmp = t_1; elseif (Float64(a * b) <= 2e-141) tmp = fma(i, c, Float64(z * t)); elseif (Float64(a * b) <= 5e-35) tmp = t_1; else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(i * c + N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -5e+82], t$95$2, If[LessEqual[N[(a * b), $MachinePrecision], -1e-305], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 2e-141], N[(i * c + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e-35], t$95$1, t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(i, c, x \cdot y\right)\\
t_2 := \mathsf{fma}\left(z, t, a \cdot b\right)\\
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+82}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;a \cdot b \leq -1 \cdot 10^{-305}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-141}:\\
\;\;\;\;\mathsf{fma}\left(i, c, z \cdot t\right)\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{-35}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 a b) < -5.00000000000000015e82 or 4.99999999999999964e-35 < (*.f64 a b) Initial program 93.3%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f6496.6
Applied rewrites96.6%
Taylor expanded in a around inf
lower-*.f6467.7
Applied rewrites67.7%
if -5.00000000000000015e82 < (*.f64 a b) < -9.99999999999999996e-306 or 2.0000000000000001e-141 < (*.f64 a b) < 4.99999999999999964e-35Initial program 97.1%
Taylor expanded in x around inf
lower-*.f6462.8
Applied rewrites62.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6463.3
Applied rewrites63.3%
if -9.99999999999999996e-306 < (*.f64 a b) < 2.0000000000000001e-141Initial program 97.8%
Taylor expanded in a around inf
lower-*.f6435.9
Applied rewrites35.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6435.9
Applied rewrites35.9%
Taylor expanded in z around inf
lower-*.f6468.2
Applied rewrites68.2%
Final simplification66.4%
herbie shell --seed 2024223
(FPCore (x y z t a b c i)
:name "Linear.V4:$cdot from linear-1.19.1.3, C"
:precision binary64
(+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))