
(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 11 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 97.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.f6498.8
Applied rewrites98.8%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* z t) -1e+103)
(* z t)
(if (<= (* z t) -1e-227)
(* c i)
(if (<= (* z t) 4e-259)
(* x y)
(if (<= (* z t) 1e-106)
(* a b)
(if (<= (* z t) 5e+78) (* c i) (* z t)))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((z * t) <= -1e+103) {
tmp = z * t;
} else if ((z * t) <= -1e-227) {
tmp = c * i;
} else if ((z * t) <= 4e-259) {
tmp = x * y;
} else if ((z * t) <= 1e-106) {
tmp = a * b;
} else if ((z * t) <= 5e+78) {
tmp = c * i;
} else {
tmp = z * t;
}
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 ((z * t) <= (-1d+103)) then
tmp = z * t
else if ((z * t) <= (-1d-227)) then
tmp = c * i
else if ((z * t) <= 4d-259) then
tmp = x * y
else if ((z * t) <= 1d-106) then
tmp = a * b
else if ((z * t) <= 5d+78) then
tmp = c * i
else
tmp = z * t
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 ((z * t) <= -1e+103) {
tmp = z * t;
} else if ((z * t) <= -1e-227) {
tmp = c * i;
} else if ((z * t) <= 4e-259) {
tmp = x * y;
} else if ((z * t) <= 1e-106) {
tmp = a * b;
} else if ((z * t) <= 5e+78) {
tmp = c * i;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (z * t) <= -1e+103: tmp = z * t elif (z * t) <= -1e-227: tmp = c * i elif (z * t) <= 4e-259: tmp = x * y elif (z * t) <= 1e-106: tmp = a * b elif (z * t) <= 5e+78: tmp = c * i else: tmp = z * t return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(z * t) <= -1e+103) tmp = Float64(z * t); elseif (Float64(z * t) <= -1e-227) tmp = Float64(c * i); elseif (Float64(z * t) <= 4e-259) tmp = Float64(x * y); elseif (Float64(z * t) <= 1e-106) tmp = Float64(a * b); elseif (Float64(z * t) <= 5e+78) tmp = Float64(c * i); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b, c, i) tmp = 0.0; if ((z * t) <= -1e+103) tmp = z * t; elseif ((z * t) <= -1e-227) tmp = c * i; elseif ((z * t) <= 4e-259) tmp = x * y; elseif ((z * t) <= 1e-106) tmp = a * b; elseif ((z * t) <= 5e+78) tmp = c * i; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(z * t), $MachinePrecision], -1e+103], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], -1e-227], N[(c * i), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 4e-259], N[(x * y), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1e-106], N[(a * b), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+78], N[(c * i), $MachinePrecision], N[(z * t), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+103}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq -1 \cdot 10^{-227}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{-259}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \cdot t \leq 10^{-106}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+78}:\\
\;\;\;\;c \cdot i\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -1e103 or 4.99999999999999984e78 < (*.f64 z t) Initial program 92.7%
Taylor expanded in z around inf
lower-*.f6460.9
Applied rewrites60.9%
if -1e103 < (*.f64 z t) < -9.99999999999999945e-228 or 9.99999999999999941e-107 < (*.f64 z t) < 4.99999999999999984e78Initial program 97.8%
Taylor expanded in c around inf
lower-*.f6431.2
Applied rewrites31.2%
if -9.99999999999999945e-228 < (*.f64 z t) < 4.0000000000000003e-259Initial program 97.6%
Taylor expanded in x around inf
lower-*.f6435.7
Applied rewrites35.7%
if 4.0000000000000003e-259 < (*.f64 z t) < 9.99999999999999941e-107Initial program 98.3%
Taylor expanded in a around inf
lower-*.f6432.3
Applied rewrites32.3%
Final simplification42.7%
herbie shell --seed 2024228
(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)))