
(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 16 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 i c (fma y x (fma b a (* z t)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return fma(i, c, fma(y, x, fma(b, a, (z * t))));
}
function code(x, y, z, t, a, b, c, i) return fma(i, c, fma(y, x, fma(b, a, Float64(z * t)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(i * c + N[(y * x + N[(b * a + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(i, c, \mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, z \cdot t\right)\right)\right)
\end{array}
Initial program 96.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.0
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* a b) -2e+127)
(* a b)
(if (<= (* a b) -1e-204)
(* x y)
(if (<= (* a b) 2e-87)
(* c i)
(if (<= (* a b) 3.48e+154) (* x y) (* a b))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((a * b) <= -2e+127) {
tmp = a * b;
} else if ((a * b) <= -1e-204) {
tmp = x * y;
} else if ((a * b) <= 2e-87) {
tmp = c * i;
} else if ((a * b) <= 3.48e+154) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
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
real(8) :: tmp
if ((a * b) <= (-2d+127)) then
tmp = a * b
else if ((a * b) <= (-1d-204)) then
tmp = x * y
else if ((a * b) <= 2d-87) then
tmp = c * i
else if ((a * b) <= 3.48d+154) 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 c, double i) {
double tmp;
if ((a * b) <= -2e+127) {
tmp = a * b;
} else if ((a * b) <= -1e-204) {
tmp = x * y;
} else if ((a * b) <= 2e-87) {
tmp = c * i;
} else if ((a * b) <= 3.48e+154) {
tmp = x * y;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (a * b) <= -2e+127: tmp = a * b elif (a * b) <= -1e-204: tmp = x * y elif (a * b) <= 2e-87: tmp = c * i elif (a * b) <= 3.48e+154: tmp = x * y else: tmp = a * b return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(a * b) <= -2e+127) tmp = Float64(a * b); elseif (Float64(a * b) <= -1e-204) tmp = Float64(x * y); elseif (Float64(a * b) <= 2e-87) tmp = Float64(c * i); elseif (Float64(a * b) <= 3.48e+154) tmp = Float64(x * y); else tmp = Float64(a * b); end return tmp end
function tmp_2 = code(x, y, z, t, a, b, c, i) tmp = 0.0; if ((a * b) <= -2e+127) tmp = a * b; elseif ((a * b) <= -1e-204) tmp = x * y; elseif ((a * b) <= 2e-87) tmp = c * i; elseif ((a * b) <= 3.48e+154) tmp = x * y; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(a * b), $MachinePrecision], -2e+127], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -1e-204], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e-87], N[(c * i), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 3.48e+154], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+127}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq -1 \cdot 10^{-204}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-87}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;a \cdot b \leq 3.48 \cdot 10^{+154}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.99999999999999991e127 or 3.47999999999999987e154 < (*.f64 a b) Initial program 90.9%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6467.1
Applied rewrites67.1%
if -1.99999999999999991e127 < (*.f64 a b) < -1e-204 or 2.00000000000000004e-87 < (*.f64 a b) < 3.47999999999999987e154Initial program 97.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6430.7
Applied rewrites30.7%
if -1e-204 < (*.f64 a b) < 2.00000000000000004e-87Initial program 97.6%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6435.4
Applied rewrites35.4%
Final simplification43.3%
herbie shell --seed 2024230
(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)))