
(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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b, c, i)
use fmin_fmax_functions
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}
Herbie found 10 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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b, c, i)
use fmin_fmax_functions
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 i c (fma b a (* y x)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return fma(z, t, fma(i, c, fma(b, a, (y * x))));
}
function code(x, y, z, t, a, b, c, i) return fma(z, t, fma(i, c, fma(b, a, Float64(y * x)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(z * t + N[(i * c + N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(i, c, \mathsf{fma}\left(b, a, y \cdot x\right)\right)\right)
\end{array}
Initial program 95.6%
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
+-commutativeN/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
*-commutativeN/A
remove-double-negN/A
lower-fma.f6497.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6497.8
Applied rewrites97.8%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma a b (fma c i (* x y)))))
(if (<= (* a b) -2e+200)
(fma a b (* t z))
(if (<= (* a b) -2e+68)
t_1
(if (<= (* a b) 2e+28) (fma c i (fma t z (* x y))) t_1)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(a, b, fma(c, i, (x * y)));
double tmp;
if ((a * b) <= -2e+200) {
tmp = fma(a, b, (t * z));
} else if ((a * b) <= -2e+68) {
tmp = t_1;
} else if ((a * b) <= 2e+28) {
tmp = fma(c, i, fma(t, z, (x * y)));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(a, b, fma(c, i, Float64(x * y))) tmp = 0.0 if (Float64(a * b) <= -2e+200) tmp = fma(a, b, Float64(t * z)); elseif (Float64(a * b) <= -2e+68) tmp = t_1; elseif (Float64(a * b) <= 2e+28) tmp = fma(c, i, fma(t, z, Float64(x * y))); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(a * b + N[(c * i + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -2e+200], N[(a * b + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2e+68], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 2e+28], N[(c * i + N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, \mathsf{fma}\left(c, i, x \cdot y\right)\right)\\
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+200}:\\
\;\;\;\;\mathsf{fma}\left(a, b, t \cdot z\right)\\
\mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{+68}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+28}:\\
\;\;\;\;\mathsf{fma}\left(c, i, \mathsf{fma}\left(t, z, x \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 a b) < -1.9999999999999999e200Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
if -1.9999999999999999e200 < (*.f64 a b) < -1.99999999999999991e68 or 1.99999999999999992e28 < (*.f64 a b) Initial program 95.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.9
Applied rewrites74.9%
if -1.99999999999999991e68 < (*.f64 a b) < 1.99999999999999992e28Initial program 95.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.5
Applied rewrites74.5%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma a b (fma c i (* x y)))))
(if (<= (* x y) -2.05e+55)
t_1
(if (<= (* x y) 3.1e+144) (fma a b (fma c i (* t z))) t_1))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(a, b, fma(c, i, (x * y)));
double tmp;
if ((x * y) <= -2.05e+55) {
tmp = t_1;
} else if ((x * y) <= 3.1e+144) {
tmp = fma(a, b, fma(c, i, (t * z)));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(a, b, fma(c, i, Float64(x * y))) tmp = 0.0 if (Float64(x * y) <= -2.05e+55) tmp = t_1; elseif (Float64(x * y) <= 3.1e+144) tmp = fma(a, b, fma(c, i, Float64(t * z))); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(a * b + N[(c * i + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2.05e+55], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 3.1e+144], N[(a * b + N[(c * i + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, \mathsf{fma}\left(c, i, x \cdot y\right)\right)\\
\mathbf{if}\;x \cdot y \leq -2.05 \cdot 10^{+55}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 3.1 \cdot 10^{+144}:\\
\;\;\;\;\mathsf{fma}\left(a, b, \mathsf{fma}\left(c, i, t \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -2.04999999999999991e55 or 3.1000000000000002e144 < (*.f64 x y) Initial program 95.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.9
Applied rewrites74.9%
if -2.04999999999999991e55 < (*.f64 x y) < 3.1000000000000002e144Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* x y) -1.25e+241) (* x y) (if (<= (* x y) 1.65e+180) (fma a b (fma c i (* t z))) (fma a b (* x y)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((x * y) <= -1.25e+241) {
tmp = x * y;
} else if ((x * y) <= 1.65e+180) {
tmp = fma(a, b, fma(c, i, (t * z)));
} else {
tmp = fma(a, b, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(x * y) <= -1.25e+241) tmp = Float64(x * y); elseif (Float64(x * y) <= 1.65e+180) tmp = fma(a, b, fma(c, i, Float64(t * z))); else tmp = fma(a, b, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(x * y), $MachinePrecision], -1.25e+241], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1.65e+180], N[(a * b + N[(c * i + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.25 \cdot 10^{+241}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \cdot y \leq 1.65 \cdot 10^{+180}:\\
\;\;\;\;\mathsf{fma}\left(a, b, \mathsf{fma}\left(c, i, t \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.25000000000000006e241Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in x around inf
lower-*.f6426.7
Applied rewrites26.7%
if -1.25000000000000006e241 < (*.f64 x y) < 1.64999999999999995e180Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
if 1.64999999999999995e180 < (*.f64 x y) Initial program 95.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.9
Applied rewrites74.9%
Taylor expanded in x around 0
lower-*.f6452.6
Applied rewrites52.6%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6451.4
Applied rewrites51.4%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* a b) -2e+192)
(fma a b (* t z))
(if (<= (* a b) -2e+68)
(fma a b (* c i))
(if (<= (* a b) 1e+30) (fma c i (* t z)) (fma a b (* x y))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((a * b) <= -2e+192) {
tmp = fma(a, b, (t * z));
} else if ((a * b) <= -2e+68) {
tmp = fma(a, b, (c * i));
} else if ((a * b) <= 1e+30) {
tmp = fma(c, i, (t * z));
} else {
tmp = fma(a, b, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(a * b) <= -2e+192) tmp = fma(a, b, Float64(t * z)); elseif (Float64(a * b) <= -2e+68) tmp = fma(a, b, Float64(c * i)); elseif (Float64(a * b) <= 1e+30) tmp = fma(c, i, Float64(t * z)); else tmp = fma(a, b, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(a * b), $MachinePrecision], -2e+192], N[(a * b + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2e+68], N[(a * b + N[(c * i), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+30], N[(c * i + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+192}:\\
\;\;\;\;\mathsf{fma}\left(a, b, t \cdot z\right)\\
\mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{+68}:\\
\;\;\;\;\mathsf{fma}\left(a, b, c \cdot i\right)\\
\mathbf{elif}\;a \cdot b \leq 10^{+30}:\\
\;\;\;\;\mathsf{fma}\left(c, i, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -2.00000000000000008e192Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
if -2.00000000000000008e192 < (*.f64 a b) < -1.99999999999999991e68Initial program 95.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.9
Applied rewrites74.9%
Taylor expanded in x around 0
lower-*.f6452.6
Applied rewrites52.6%
if -1.99999999999999991e68 < (*.f64 a b) < 1e30Initial program 95.6%
Taylor expanded in a around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.5
Applied rewrites74.5%
Taylor expanded in x around 0
lower-*.f6452.0
Applied rewrites52.0%
if 1e30 < (*.f64 a b) Initial program 95.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.9
Applied rewrites74.9%
Taylor expanded in x around 0
lower-*.f6452.6
Applied rewrites52.6%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6451.4
Applied rewrites51.4%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma a b (* c i))))
(if (<= (* c i) -2.5e+98)
t_1
(if (<= (* c i) 1.16e+41) (fma a b (* t z)) t_1))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(a, b, (c * i));
double tmp;
if ((c * i) <= -2.5e+98) {
tmp = t_1;
} else if ((c * i) <= 1.16e+41) {
tmp = fma(a, b, (t * z));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(a, b, Float64(c * i)) tmp = 0.0 if (Float64(c * i) <= -2.5e+98) tmp = t_1; elseif (Float64(c * i) <= 1.16e+41) tmp = fma(a, b, Float64(t * z)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(a * b + N[(c * i), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(c * i), $MachinePrecision], -2.5e+98], t$95$1, If[LessEqual[N[(c * i), $MachinePrecision], 1.16e+41], N[(a * b + N[(t * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(a, b, c \cdot i\right)\\
\mathbf{if}\;c \cdot i \leq -2.5 \cdot 10^{+98}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \cdot i \leq 1.16 \cdot 10^{+41}:\\
\;\;\;\;\mathsf{fma}\left(a, b, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 c i) < -2.4999999999999999e98 or 1.16000000000000007e41 < (*.f64 c i) Initial program 95.6%
Taylor expanded in z around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6474.9
Applied rewrites74.9%
Taylor expanded in x around 0
lower-*.f6452.6
Applied rewrites52.6%
if -2.4999999999999999e98 < (*.f64 c i) < 1.16000000000000007e41Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* c i) -4.5e+106) (* c i) (if (<= (* c i) 3.5e+51) (fma a b (* t z)) (* c i))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((c * i) <= -4.5e+106) {
tmp = c * i;
} else if ((c * i) <= 3.5e+51) {
tmp = fma(a, b, (t * z));
} else {
tmp = c * i;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -4.5e+106) tmp = Float64(c * i); elseif (Float64(c * i) <= 3.5e+51) tmp = fma(a, b, Float64(t * z)); else tmp = Float64(c * i); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(c * i), $MachinePrecision], -4.5e+106], N[(c * i), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 3.5e+51], N[(a * b + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(c * i), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -4.5 \cdot 10^{+106}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq 3.5 \cdot 10^{+51}:\\
\;\;\;\;\mathsf{fma}\left(a, b, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;c \cdot i\\
\end{array}
\end{array}
if (*.f64 c i) < -4.4999999999999997e106 or 3.5e51 < (*.f64 c i) Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in z around 0
lower-*.f6428.2
Applied rewrites28.2%
Taylor expanded in c around inf
lower-*.f6427.7
Applied rewrites27.7%
if -4.4999999999999997e106 < (*.f64 c i) < 3.5e51Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* c i) -2.5e+98)
(* c i)
(if (<= (* c i) 5e-199)
(* t z)
(if (<= (* c i) 5.6e-111)
(* a b)
(if (<= (* c i) 1.16e+41) (* t z) (* c i))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((c * i) <= -2.5e+98) {
tmp = c * i;
} else if ((c * i) <= 5e-199) {
tmp = t * z;
} else if ((c * i) <= 5.6e-111) {
tmp = a * b;
} else if ((c * i) <= 1.16e+41) {
tmp = t * z;
} else {
tmp = c * i;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b, c, i)
use fmin_fmax_functions
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 ((c * i) <= (-2.5d+98)) then
tmp = c * i
else if ((c * i) <= 5d-199) then
tmp = t * z
else if ((c * i) <= 5.6d-111) then
tmp = a * b
else if ((c * i) <= 1.16d+41) then
tmp = t * z
else
tmp = c * i
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 ((c * i) <= -2.5e+98) {
tmp = c * i;
} else if ((c * i) <= 5e-199) {
tmp = t * z;
} else if ((c * i) <= 5.6e-111) {
tmp = a * b;
} else if ((c * i) <= 1.16e+41) {
tmp = t * z;
} else {
tmp = c * i;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (c * i) <= -2.5e+98: tmp = c * i elif (c * i) <= 5e-199: tmp = t * z elif (c * i) <= 5.6e-111: tmp = a * b elif (c * i) <= 1.16e+41: tmp = t * z else: tmp = c * i return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -2.5e+98) tmp = Float64(c * i); elseif (Float64(c * i) <= 5e-199) tmp = Float64(t * z); elseif (Float64(c * i) <= 5.6e-111) tmp = Float64(a * b); elseif (Float64(c * i) <= 1.16e+41) tmp = Float64(t * z); else tmp = Float64(c * i); end return tmp end
function tmp_2 = code(x, y, z, t, a, b, c, i) tmp = 0.0; if ((c * i) <= -2.5e+98) tmp = c * i; elseif ((c * i) <= 5e-199) tmp = t * z; elseif ((c * i) <= 5.6e-111) tmp = a * b; elseif ((c * i) <= 1.16e+41) tmp = t * z; else tmp = c * i; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(c * i), $MachinePrecision], -2.5e+98], N[(c * i), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 5e-199], N[(t * z), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 5.6e-111], N[(a * b), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 1.16e+41], N[(t * z), $MachinePrecision], N[(c * i), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -2.5 \cdot 10^{+98}:\\
\;\;\;\;c \cdot i\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{-199}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;c \cdot i \leq 5.6 \cdot 10^{-111}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;c \cdot i \leq 1.16 \cdot 10^{+41}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;c \cdot i\\
\end{array}
\end{array}
if (*.f64 c i) < -2.4999999999999999e98 or 1.16000000000000007e41 < (*.f64 c i) Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in z around 0
lower-*.f6428.2
Applied rewrites28.2%
Taylor expanded in c around inf
lower-*.f6427.7
Applied rewrites27.7%
if -2.4999999999999999e98 < (*.f64 c i) < 4.9999999999999996e-199 or 5.5999999999999999e-111 < (*.f64 c i) < 1.16000000000000007e41Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in z around 0
lower-*.f6428.2
Applied rewrites28.2%
Taylor expanded in z around inf
lower-*.f6427.6
Applied rewrites27.6%
if 4.9999999999999996e-199 < (*.f64 c i) < 5.5999999999999999e-111Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in z around 0
lower-*.f6428.2
Applied rewrites28.2%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* a b) -1.7e+175) (* a b) (if (<= (* a b) 2.5e+43) (* c i) (* 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) <= -1.7e+175) {
tmp = a * b;
} else if ((a * b) <= 2.5e+43) {
tmp = c * i;
} else {
tmp = a * b;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b, c, i)
use fmin_fmax_functions
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) <= (-1.7d+175)) then
tmp = a * b
else if ((a * b) <= 2.5d+43) then
tmp = c * i
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) <= -1.7e+175) {
tmp = a * b;
} else if ((a * b) <= 2.5e+43) {
tmp = c * i;
} else {
tmp = a * b;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (a * b) <= -1.7e+175: tmp = a * b elif (a * b) <= 2.5e+43: tmp = c * i else: tmp = a * b return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(a * b) <= -1.7e+175) tmp = Float64(a * b); elseif (Float64(a * b) <= 2.5e+43) tmp = Float64(c * i); 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) <= -1.7e+175) tmp = a * b; elseif ((a * b) <= 2.5e+43) tmp = c * i; else tmp = a * b; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(a * b), $MachinePrecision], -1.7e+175], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.5e+43], N[(c * i), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.7 \cdot 10^{+175}:\\
\;\;\;\;a \cdot b\\
\mathbf{elif}\;a \cdot b \leq 2.5 \cdot 10^{+43}:\\
\;\;\;\;c \cdot i\\
\mathbf{else}:\\
\;\;\;\;a \cdot b\\
\end{array}
\end{array}
if (*.f64 a b) < -1.70000000000000014e175 or 2.5000000000000002e43 < (*.f64 a b) Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in z around 0
lower-*.f6428.2
Applied rewrites28.2%
if -1.70000000000000014e175 < (*.f64 a b) < 2.5000000000000002e43Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in z around 0
lower-*.f6428.2
Applied rewrites28.2%
Taylor expanded in c around inf
lower-*.f6427.7
Applied rewrites27.7%
(FPCore (x y z t a b c i) :precision binary64 (* a b))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return a * b;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b, c, i)
use fmin_fmax_functions
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 = a * b
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return a * b;
}
def code(x, y, z, t, a, b, c, i): return a * b
function code(x, y, z, t, a, b, c, i) return Float64(a * b) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = a * b; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(a * b), $MachinePrecision]
\begin{array}{l}
\\
a \cdot b
\end{array}
Initial program 95.6%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fma.f64N/A
lower-*.f6476.2
Applied rewrites76.2%
Taylor expanded in c around 0
lower-fma.f64N/A
lower-*.f6452.5
Applied rewrites52.5%
Taylor expanded in z around 0
lower-*.f6428.2
Applied rewrites28.2%
herbie shell --seed 2025155
(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)))