
(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 (fma y x (fma z t (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(z, t, (a * b)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(z, t, Float64(a * b))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(z, t, a \cdot b\right)\right)
\end{array}
Initial program 98.8%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -2e+163) (* z t) (if (<= (* z t) 5e-171) (* y x) (if (<= (* z t) 4e+15) (* a b) (* z t)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -2e+163) {
tmp = z * t;
} else if ((z * t) <= 5e-171) {
tmp = y * x;
} else if ((z * t) <= 4e+15) {
tmp = a * b;
} else {
tmp = z * t;
}
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 ((z * t) <= (-2d+163)) then
tmp = z * t
else if ((z * t) <= 5d-171) then
tmp = y * x
else if ((z * t) <= 4d+15) then
tmp = a * b
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 tmp;
if ((z * t) <= -2e+163) {
tmp = z * t;
} else if ((z * t) <= 5e-171) {
tmp = y * x;
} else if ((z * t) <= 4e+15) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -2e+163: tmp = z * t elif (z * t) <= 5e-171: tmp = y * x elif (z * t) <= 4e+15: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -2e+163) tmp = Float64(z * t); elseif (Float64(z * t) <= 5e-171) tmp = Float64(y * x); elseif (Float64(z * t) <= 4e+15) tmp = Float64(a * b); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((z * t) <= -2e+163) tmp = z * t; elseif ((z * t) <= 5e-171) tmp = y * x; elseif ((z * t) <= 4e+15) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -2e+163], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e-171], N[(y * x), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 4e+15], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+163}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{-171}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+15}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -1.9999999999999999e163 or 4e15 < (*.f64 z t) Initial program 98.9%
Taylor expanded in z around inf
lower-*.f6474.9
Applied rewrites74.9%
if -1.9999999999999999e163 < (*.f64 z t) < 4.99999999999999992e-171Initial program 99.3%
Taylor expanded in x around inf
lower-*.f6451.5
Applied rewrites51.5%
if 4.99999999999999992e-171 < (*.f64 z t) < 4e15Initial program 96.8%
Taylor expanded in a around inf
lower-*.f6460.9
Applied rewrites60.9%
Final simplification60.9%
(FPCore (x y z t a b) :precision binary64 (if (<= (* y x) -5e+67) (fma y x (* z t)) (if (<= (* y x) 4e+15) (fma a b (* z t)) (fma t z (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y * x) <= -5e+67) {
tmp = fma(y, x, (z * t));
} else if ((y * x) <= 4e+15) {
tmp = fma(a, b, (z * t));
} else {
tmp = fma(t, z, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(y * x) <= -5e+67) tmp = fma(y, x, Float64(z * t)); elseif (Float64(y * x) <= 4e+15) tmp = fma(a, b, Float64(z * t)); else tmp = fma(t, z, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(y * x), $MachinePrecision], -5e+67], N[(y * x + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * x), $MachinePrecision], 4e+15], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -5 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\mathbf{elif}\;y \cdot x \leq 4 \cdot 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -4.99999999999999976e67Initial program 96.3%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
lower-*.f6484.3
Applied rewrites84.3%
if -4.99999999999999976e67 < (*.f64 x y) < 4e15Initial program 99.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6488.0
Applied rewrites88.0%
if 4e15 < (*.f64 x y) Initial program 100.0%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6486.7
Applied rewrites86.7%
Final simplification86.9%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma t z (* y x))))
(if (<= (* y x) -1.86e+67)
t_1
(if (<= (* y x) 6.8e+15) (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(t, z, (y * x));
double tmp;
if ((y * x) <= -1.86e+67) {
tmp = t_1;
} else if ((y * x) <= 6.8e+15) {
tmp = fma(a, b, (z * t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(t, z, Float64(y * x)) tmp = 0.0 if (Float64(y * x) <= -1.86e+67) tmp = t_1; elseif (Float64(y * x) <= 6.8e+15) 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[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * x), $MachinePrecision], -1.86e+67], t$95$1, If[LessEqual[N[(y * x), $MachinePrecision], 6.8e+15], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{if}\;y \cdot x \leq -1.86 \cdot 10^{+67}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \cdot x \leq 6.8 \cdot 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -1.86000000000000004e67 or 6.8e15 < (*.f64 x y) Initial program 98.2%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-*.f6485.5
Applied rewrites85.5%
if -1.86000000000000004e67 < (*.f64 x y) < 6.8e15Initial program 99.3%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6488.0
Applied rewrites88.0%
Final simplification86.9%
(FPCore (x y z t a b) :precision binary64 (if (<= (* y x) -3.7e+230) (* y x) (if (<= (* y x) 4e+217) (fma a b (* z t)) (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((y * x) <= -3.7e+230) {
tmp = y * x;
} else if ((y * x) <= 4e+217) {
tmp = fma(a, b, (z * t));
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(y * x) <= -3.7e+230) tmp = Float64(y * x); elseif (Float64(y * x) <= 4e+217) tmp = fma(a, b, Float64(z * t)); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(y * x), $MachinePrecision], -3.7e+230], N[(y * x), $MachinePrecision], If[LessEqual[N[(y * x), $MachinePrecision], 4e+217], N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -3.7 \cdot 10^{+230}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \cdot x \leq 4 \cdot 10^{+217}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -3.69999999999999992e230 or 3.99999999999999984e217 < (*.f64 x y) Initial program 96.1%
Taylor expanded in x around inf
lower-*.f6486.6
Applied rewrites86.6%
if -3.69999999999999992e230 < (*.f64 x y) < 3.99999999999999984e217Initial program 99.5%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-*.f6479.1
Applied rewrites79.1%
Final simplification80.6%
(FPCore (x y z t a b) :precision binary64 (if (<= (* z t) -1.15e+162) (* z t) (if (<= (* z t) 4e+15) (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((z * t) <= -1.15e+162) {
tmp = z * t;
} else if ((z * t) <= 4e+15) {
tmp = a * b;
} else {
tmp = z * t;
}
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 ((z * t) <= (-1.15d+162)) then
tmp = z * t
else if ((z * t) <= 4d+15) then
tmp = a * b
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 tmp;
if ((z * t) <= -1.15e+162) {
tmp = z * t;
} else if ((z * t) <= 4e+15) {
tmp = a * b;
} else {
tmp = z * t;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (z * t) <= -1.15e+162: tmp = z * t elif (z * t) <= 4e+15: tmp = a * b else: tmp = z * t return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(z * t) <= -1.15e+162) tmp = Float64(z * t); elseif (Float64(z * t) <= 4e+15) tmp = Float64(a * b); else tmp = Float64(z * t); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((z * t) <= -1.15e+162) tmp = z * t; elseif ((z * t) <= 4e+15) tmp = a * b; else tmp = z * t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(z * t), $MachinePrecision], -1.15e+162], N[(z * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 4e+15], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1.15 \cdot 10^{+162}:\\
\;\;\;\;z \cdot t\\
\mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+15}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;z \cdot t\\
\end{array}
\end{array}
if (*.f64 z t) < -1.14999999999999997e162 or 4e15 < (*.f64 z t) Initial program 98.9%
Taylor expanded in z around inf
lower-*.f6474.2
Applied rewrites74.2%
if -1.14999999999999997e162 < (*.f64 z t) < 4e15Initial program 98.8%
Taylor expanded in a around inf
lower-*.f6449.0
Applied rewrites49.0%
Final simplification58.0%
(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 98.8%
Taylor expanded in a around inf
lower-*.f6438.2
Applied rewrites38.2%
herbie shell --seed 2024219
(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)))