
(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 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);
}
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 y x (fma z t (fma c i (* b a)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return fma(y, x, fma(z, t, fma(c, i, (b * a))));
}
function code(x, y, z, t, a, b, c, i) return fma(y, x, fma(z, t, fma(c, i, Float64(b * a)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(y * x + N[(z * t + N[(c * i + N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(z, t, \mathsf{fma}\left(c, i, b \cdot a\right)\right)\right)
\end{array}
Initial program 95.7%
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6496.7
Applied rewrites96.7%
lift-+.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.1
Applied rewrites97.1%
lift-+.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.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 z t (* x y))) (t_2 (+ (* x y) (* z t))))
(if (<= t_2 -5e+103)
t_1
(if (<= t_2 1e+110)
(fma b a (* c i))
(if (<= t_2 1e+275) (fma i c (* 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(z, t, (x * y));
double t_2 = (x * y) + (z * t);
double tmp;
if (t_2 <= -5e+103) {
tmp = t_1;
} else if (t_2 <= 1e+110) {
tmp = fma(b, a, (c * i));
} else if (t_2 <= 1e+275) {
tmp = fma(i, c, (x * y));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(z, t, Float64(x * y)) t_2 = Float64(Float64(x * y) + Float64(z * t)) tmp = 0.0 if (t_2 <= -5e+103) tmp = t_1; elseif (t_2 <= 1e+110) tmp = fma(b, a, Float64(c * i)); elseif (t_2 <= 1e+275) tmp = fma(i, c, 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[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+103], t$95$1, If[LessEqual[t$95$2, 1e+110], N[(b * a + N[(c * i), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+275], N[(i * c + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, t, x \cdot y\right)\\
t_2 := x \cdot y + z \cdot t\\
\mathbf{if}\;t\_2 \leq -5 \cdot 10^{+103}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 10^{+110}:\\
\;\;\;\;\mathsf{fma}\left(b, a, c \cdot i\right)\\
\mathbf{elif}\;t\_2 \leq 10^{+275}:\\
\;\;\;\;\mathsf{fma}\left(i, c, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z t)) < -5e103 or 9.9999999999999996e274 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 90.9%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.9
Applied rewrites87.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6479.6
Applied rewrites79.6%
if -5e103 < (+.f64 (*.f64 x y) (*.f64 z t)) < 1e110Initial program 99.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6488.0
Applied rewrites88.0%
Taylor expanded in z around 0
lower-*.f6477.9
Applied rewrites77.9%
if 1e110 < (+.f64 (*.f64 x y) (*.f64 z t)) < 9.9999999999999996e274Initial program 99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6449.3
Applied rewrites49.3%
lift-+.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6449.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6449.3
Applied rewrites49.3%
(FPCore (x y z t a b c i) :precision binary64 (let* ((t_1 (fma z t (* x y))) (t_2 (+ (* x y) (* z t)))) (if (<= t_2 -5e+103) t_1 (if (<= t_2 2e+131) (fma b a (* c i)) t_1))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(z, t, (x * y));
double t_2 = (x * y) + (z * t);
double tmp;
if (t_2 <= -5e+103) {
tmp = t_1;
} else if (t_2 <= 2e+131) {
tmp = fma(b, a, (c * i));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(z, t, Float64(x * y)) t_2 = Float64(Float64(x * y) + Float64(z * t)) tmp = 0.0 if (t_2 <= -5e+103) tmp = t_1; elseif (t_2 <= 2e+131) tmp = fma(b, a, Float64(c * i)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+103], t$95$1, If[LessEqual[t$95$2, 2e+131], N[(b * a + N[(c * i), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, t, x \cdot y\right)\\
t_2 := x \cdot y + z \cdot t\\
\mathbf{if}\;t\_2 \leq -5 \cdot 10^{+103}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{+131}:\\
\;\;\;\;\mathsf{fma}\left(b, a, c \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z t)) < -5e103 or 1.9999999999999998e131 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 92.8%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.3
Applied rewrites86.3%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6475.6
Applied rewrites75.6%
if -5e103 < (+.f64 (*.f64 x y) (*.f64 z t)) < 1.9999999999999998e131Initial program 99.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6487.7
Applied rewrites87.7%
Taylor expanded in z around 0
lower-*.f6477.2
Applied rewrites77.2%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma t z (* y x))))
(if (<= (* c i) -5e+18)
(fma y x (fma z t (* i c)))
(if (<= (* c i) 5e+36) (fma b a t_1) (fma i c t_1)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(t, z, (y * x));
double tmp;
if ((c * i) <= -5e+18) {
tmp = fma(y, x, fma(z, t, (i * c)));
} else if ((c * i) <= 5e+36) {
tmp = fma(b, a, t_1);
} else {
tmp = fma(i, c, t_1);
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(t, z, Float64(y * x)) tmp = 0.0 if (Float64(c * i) <= -5e+18) tmp = fma(y, x, fma(z, t, Float64(i * c))); elseif (Float64(c * i) <= 5e+36) tmp = fma(b, a, t_1); else tmp = fma(i, c, t_1); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(c * i), $MachinePrecision], -5e+18], N[(y * x + N[(z * t + N[(i * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 5e+36], N[(b * a + t$95$1), $MachinePrecision], N[(i * c + t$95$1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+18}:\\
\;\;\;\;\mathsf{fma}\left(y, x, \mathsf{fma}\left(z, t, i \cdot c\right)\right)\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t\_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, t\_1\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -5e18Initial program 93.9%
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6494.7
Applied rewrites94.7%
lift-+.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6495.7
Applied rewrites95.7%
lift-+.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6497.0
Applied rewrites97.0%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
if -5e18 < (*.f64 c i) < 4.99999999999999977e36Initial program 97.4%
Taylor expanded in c around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.1
Applied rewrites94.1%
if 4.99999999999999977e36 < (*.f64 c i) Initial program 93.5%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
(FPCore (x y z t a b c i) :precision binary64 (let* ((t_1 (fma t z (* y x))) (t_2 (fma i c t_1))) (if (<= (* c i) -5e+18) t_2 (if (<= (* c i) 5e+36) (fma b a 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(t, z, (y * x));
double t_2 = fma(i, c, t_1);
double tmp;
if ((c * i) <= -5e+18) {
tmp = t_2;
} else if ((c * i) <= 5e+36) {
tmp = fma(b, a, t_1);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(t, z, Float64(y * x)) t_2 = fma(i, c, t_1) tmp = 0.0 if (Float64(c * i) <= -5e+18) tmp = t_2; elseif (Float64(c * i) <= 5e+36) tmp = fma(b, a, t_1); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(i * c + t$95$1), $MachinePrecision]}, If[LessEqual[N[(c * i), $MachinePrecision], -5e+18], t$95$2, If[LessEqual[N[(c * i), $MachinePrecision], 5e+36], N[(b * a + t$95$1), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, y \cdot x\right)\\
t_2 := \mathsf{fma}\left(i, c, t\_1\right)\\
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+18}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t\_1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 c i) < -5e18 or 4.99999999999999977e36 < (*.f64 c i) Initial program 93.7%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6482.5
Applied rewrites82.5%
if -5e18 < (*.f64 c i) < 4.99999999999999977e36Initial program 97.4%
Taylor expanded in c around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.1
Applied rewrites94.1%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* c i) -2e+294) (fma b a (fma i c (* t z))) (if (<= (* c i) 4e+101) (fma b a (fma t z (* y x))) (fma y x (* 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) <= -2e+294) {
tmp = fma(b, a, fma(i, c, (t * z)));
} else if ((c * i) <= 4e+101) {
tmp = fma(b, a, fma(t, z, (y * x)));
} else {
tmp = fma(y, x, (c * i));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -2e+294) tmp = fma(b, a, fma(i, c, Float64(t * z))); elseif (Float64(c * i) <= 4e+101) tmp = fma(b, a, fma(t, z, Float64(y * x))); else tmp = fma(y, x, Float64(c * i)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(c * i), $MachinePrecision], -2e+294], N[(b * a + N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 4e+101], N[(b * a + N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(c * i), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -2 \cdot 10^{+294}:\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(i, c, t \cdot z\right)\right)\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+101}:\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(t, z, y \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, c \cdot i\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -2.00000000000000013e294Initial program 84.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6492.0
Applied rewrites92.0%
if -2.00000000000000013e294 < (*.f64 c i) < 3.9999999999999999e101Initial program 97.5%
Taylor expanded in c around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.4
Applied rewrites86.4%
if 3.9999999999999999e101 < (*.f64 c i) Initial program 92.4%
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6493.3
Applied rewrites93.3%
lift-+.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6494.2
Applied rewrites94.2%
Taylor expanded in c around inf
lower-*.f6473.0
Applied rewrites73.0%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* x y) -5e+103) (fma z t (* x y)) (if (<= (* x y) 2e+183) (fma b a (fma i c (* t z))) (fma y x (* b a)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((x * y) <= -5e+103) {
tmp = fma(z, t, (x * y));
} else if ((x * y) <= 2e+183) {
tmp = fma(b, a, fma(i, c, (t * z)));
} else {
tmp = fma(y, x, (b * a));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(x * y) <= -5e+103) tmp = fma(z, t, Float64(x * y)); elseif (Float64(x * y) <= 2e+183) tmp = fma(b, a, fma(i, c, Float64(t * z))); else tmp = fma(y, x, Float64(b * a)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e+103], N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+183], N[(b * a + N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(b * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(z, t, x \cdot y\right)\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+183}:\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(i, c, t \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, b \cdot a\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -5e103Initial program 91.7%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.2
Applied rewrites86.2%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6474.9
Applied rewrites74.9%
if -5e103 < (*.f64 x y) < 1.99999999999999989e183Initial program 97.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6489.6
Applied rewrites89.6%
if 1.99999999999999989e183 < (*.f64 x y) Initial program 89.2%
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-+l+N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6491.8
Applied rewrites91.8%
lift-+.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6493.6
Applied rewrites93.6%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6479.3
Applied rewrites79.3%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* x y) -5e+103) (* y x) (if (<= (* x y) -5e-189) (* b a) (if (<= (* x y) 5e+137) (* i c) (* y x)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((x * y) <= -5e+103) {
tmp = y * x;
} else if ((x * y) <= -5e-189) {
tmp = b * a;
} else if ((x * y) <= 5e+137) {
tmp = i * c;
} else {
tmp = y * x;
}
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 ((x * y) <= (-5d+103)) then
tmp = y * x
else if ((x * y) <= (-5d-189)) then
tmp = b * a
else if ((x * y) <= 5d+137) then
tmp = i * c
else
tmp = y * x
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 ((x * y) <= -5e+103) {
tmp = y * x;
} else if ((x * y) <= -5e-189) {
tmp = b * a;
} else if ((x * y) <= 5e+137) {
tmp = i * c;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (x * y) <= -5e+103: tmp = y * x elif (x * y) <= -5e-189: tmp = b * a elif (x * y) <= 5e+137: tmp = i * c else: tmp = y * x return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(x * y) <= -5e+103) tmp = Float64(y * x); elseif (Float64(x * y) <= -5e-189) tmp = Float64(b * a); elseif (Float64(x * y) <= 5e+137) tmp = Float64(i * c); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z, t, a, b, c, i) tmp = 0.0; if ((x * y) <= -5e+103) tmp = y * x; elseif ((x * y) <= -5e-189) tmp = b * a; elseif ((x * y) <= 5e+137) tmp = i * c; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e+103], N[(y * x), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -5e-189], N[(b * a), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+137], N[(i * c), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+103}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \cdot y \leq -5 \cdot 10^{-189}:\\
\;\;\;\;b \cdot a\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+137}:\\
\;\;\;\;i \cdot c\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -5e103 or 5.0000000000000002e137 < (*.f64 x y) Initial program 91.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6464.4
Applied rewrites64.4%
if -5e103 < (*.f64 x y) < -4.9999999999999997e-189Initial program 97.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6430.6
Applied rewrites30.6%
if -4.9999999999999997e-189 < (*.f64 x y) < 5.0000000000000002e137Initial program 97.9%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6433.9
Applied rewrites33.9%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* c i) -2e+294) (* i c) (if (<= (* c i) 4e+106) (fma z t (* x y)) (* i c))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((c * i) <= -2e+294) {
tmp = i * c;
} else if ((c * i) <= 4e+106) {
tmp = fma(z, t, (x * y));
} else {
tmp = i * c;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -2e+294) tmp = Float64(i * c); elseif (Float64(c * i) <= 4e+106) tmp = fma(z, t, Float64(x * y)); else tmp = Float64(i * c); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(c * i), $MachinePrecision], -2e+294], N[(i * c), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 4e+106], N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(i * c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -2 \cdot 10^{+294}:\\
\;\;\;\;i \cdot c\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+106}:\\
\;\;\;\;\mathsf{fma}\left(z, t, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -2.00000000000000013e294 or 4.00000000000000036e106 < (*.f64 c i) Initial program 90.1%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6470.1
Applied rewrites70.1%
if -2.00000000000000013e294 < (*.f64 c i) < 4.00000000000000036e106Initial program 97.5%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6472.2
Applied rewrites72.2%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6459.8
Applied rewrites59.8%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* c i) -5e+18) (* i c) (if (<= (* c i) 5e+72) (* b a) (* i c))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if ((c * i) <= -5e+18) {
tmp = i * c;
} else if ((c * i) <= 5e+72) {
tmp = b * a;
} else {
tmp = i * c;
}
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) <= (-5d+18)) then
tmp = i * c
else if ((c * i) <= 5d+72) then
tmp = b * a
else
tmp = i * c
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) <= -5e+18) {
tmp = i * c;
} else if ((c * i) <= 5e+72) {
tmp = b * a;
} else {
tmp = i * c;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (c * i) <= -5e+18: tmp = i * c elif (c * i) <= 5e+72: tmp = b * a else: tmp = i * c return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -5e+18) tmp = Float64(i * c); elseif (Float64(c * i) <= 5e+72) tmp = Float64(b * a); else tmp = Float64(i * c); end return tmp end
function tmp_2 = code(x, y, z, t, a, b, c, i) tmp = 0.0; if ((c * i) <= -5e+18) tmp = i * c; elseif ((c * i) <= 5e+72) tmp = b * a; else tmp = i * c; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(c * i), $MachinePrecision], -5e+18], N[(i * c), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 5e+72], N[(b * a), $MachinePrecision], N[(i * c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -5 \cdot 10^{+18}:\\
\;\;\;\;i \cdot c\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{+72}:\\
\;\;\;\;b \cdot a\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -5e18 or 4.99999999999999992e72 < (*.f64 c i) Initial program 93.4%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6454.3
Applied rewrites54.3%
if -5e18 < (*.f64 c i) < 4.99999999999999992e72Initial program 97.5%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6432.6
Applied rewrites32.6%
(FPCore (x y z t a b c i) :precision binary64 (* b a))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return b * a;
}
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 = b * a
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return b * a;
}
def code(x, y, z, t, a, b, c, i): return b * a
function code(x, y, z, t, a, b, c, i) return Float64(b * a) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = b * a; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(b * a), $MachinePrecision]
\begin{array}{l}
\\
b \cdot a
\end{array}
Initial program 95.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6427.0
Applied rewrites27.0%
herbie shell --seed 2025093
(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)))