
(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}
Sampling outcomes in binary64 precision:
Herbie found 9 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 t z (fma i c (* 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(t, z, fma(i, c, (b * a))));
}
function code(x, y, z, t, a, b, c, i) return fma(y, x, fma(t, z, fma(i, c, Float64(b * a)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(y * x + N[(t * z + N[(i * c + N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(t, z, \mathsf{fma}\left(i, c, b \cdot a\right)\right)\right)
\end{array}
Initial program 97.6%
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
associate--l+N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
lift-*.f64N/A
lower-fma.f64N/A
associate-+r+N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
Applied rewrites99.6%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma i c (* a b))))
(if (<= (* x y) -4e+88)
(fma y x (* a b))
(if (<= (* x y) 5e-319)
t_1
(if (<= (* x y) 1e+40)
(fma i c (* t z))
(if (<= (* x y) 1e+113) t_1 (fma y x (* c i))))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(i, c, (a * b));
double tmp;
if ((x * y) <= -4e+88) {
tmp = fma(y, x, (a * b));
} else if ((x * y) <= 5e-319) {
tmp = t_1;
} else if ((x * y) <= 1e+40) {
tmp = fma(i, c, (t * z));
} else if ((x * y) <= 1e+113) {
tmp = t_1;
} else {
tmp = fma(y, x, (c * i));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(i, c, Float64(a * b)) tmp = 0.0 if (Float64(x * y) <= -4e+88) tmp = fma(y, x, Float64(a * b)); elseif (Float64(x * y) <= 5e-319) tmp = t_1; elseif (Float64(x * y) <= 1e+40) tmp = fma(i, c, Float64(t * z)); elseif (Float64(x * y) <= 1e+113) tmp = t_1; else tmp = fma(y, x, Float64(c * i)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(i * c + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -4e+88], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e-319], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1e+40], N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+113], t$95$1, N[(y * x + N[(c * i), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(i, c, a \cdot b\right)\\
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{+88}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-319}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 10^{+40}:\\
\;\;\;\;\mathsf{fma}\left(i, c, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 10^{+113}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, c \cdot i\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -3.99999999999999984e88Initial program 97.4%
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
associate--l+N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
lift-*.f64N/A
lower-fma.f64N/A
associate-+r+N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites89.3%
if -3.99999999999999984e88 < (*.f64 x y) < 4.9999937e-319 or 1.00000000000000003e40 < (*.f64 x y) < 1e113Initial program 96.7%
Taylor expanded in a around inf
Applied rewrites79.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6480.0
Applied rewrites80.0%
if 4.9999937e-319 < (*.f64 x y) < 1.00000000000000003e40Initial program 100.0%
Taylor expanded in a around inf
Applied rewrites55.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6455.8
Applied rewrites55.8%
Taylor expanded in z around inf
Applied rewrites74.0%
if 1e113 < (*.f64 x y) Initial program 97.4%
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
associate--l+N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
lift-*.f64N/A
lower-fma.f64N/A
associate-+r+N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in c around inf
Applied rewrites84.5%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma i c (* a b))))
(if (<= (* x y) -2e+159)
(* y x)
(if (<= (* x y) 5e-319)
t_1
(if (<= (* x y) 1e+40)
(fma i c (* t z))
(if (<= (* x y) 1e+185) t_1 (* y x)))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(i, c, (a * b));
double tmp;
if ((x * y) <= -2e+159) {
tmp = y * x;
} else if ((x * y) <= 5e-319) {
tmp = t_1;
} else if ((x * y) <= 1e+40) {
tmp = fma(i, c, (t * z));
} else if ((x * y) <= 1e+185) {
tmp = t_1;
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(i, c, Float64(a * b)) tmp = 0.0 if (Float64(x * y) <= -2e+159) tmp = Float64(y * x); elseif (Float64(x * y) <= 5e-319) tmp = t_1; elseif (Float64(x * y) <= 1e+40) tmp = fma(i, c, Float64(t * z)); elseif (Float64(x * y) <= 1e+185) tmp = t_1; else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(i * c + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -2e+159], N[(y * x), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e-319], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1e+40], N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+185], t$95$1, N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(i, c, a \cdot b\right)\\
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+159}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-319}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 10^{+40}:\\
\;\;\;\;\mathsf{fma}\left(i, c, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 10^{+185}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -1.9999999999999999e159 or 9.9999999999999998e184 < (*.f64 x y) Initial program 96.7%
Taylor expanded in x around inf
Applied rewrites83.5%
if -1.9999999999999999e159 < (*.f64 x y) < 4.9999937e-319 or 1.00000000000000003e40 < (*.f64 x y) < 9.9999999999999998e184Initial program 97.1%
Taylor expanded in a around inf
Applied rewrites76.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6476.8
Applied rewrites76.8%
if 4.9999937e-319 < (*.f64 x y) < 1.00000000000000003e40Initial program 100.0%
Taylor expanded in a around inf
Applied rewrites55.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6455.8
Applied rewrites55.8%
Taylor expanded in z around inf
Applied rewrites74.0%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (+ (* x y) (* z t))))
(if (or (<= t_1 -5e+142) (not (<= t_1 1e+185)))
(fma y x (* z t))
(fma i c (* a b)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = (x * y) + (z * t);
double tmp;
if ((t_1 <= -5e+142) || !(t_1 <= 1e+185)) {
tmp = fma(y, x, (z * t));
} else {
tmp = fma(i, c, (a * b));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = Float64(Float64(x * y) + Float64(z * t)) tmp = 0.0 if ((t_1 <= -5e+142) || !(t_1 <= 1e+185)) tmp = fma(y, x, Float64(z * t)); else tmp = fma(i, c, Float64(a * b)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -5e+142], N[Not[LessEqual[t$95$1, 1e+185]], $MachinePrecision]], N[(y * x + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(i * c + N[(a * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+142} \lor \neg \left(t\_1 \leq 10^{+185}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, z \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, a \cdot b\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z t)) < -5.0000000000000001e142 or 9.9999999999999998e184 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 95.5%
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
associate--l+N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
lift-*.f64N/A
lower-fma.f64N/A
associate-+r+N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
Applied rewrites99.1%
Taylor expanded in z around inf
Applied rewrites80.4%
if -5.0000000000000001e142 < (+.f64 (*.f64 x y) (*.f64 z t)) < 9.9999999999999998e184Initial program 99.3%
Taylor expanded in a around inf
Applied rewrites82.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6483.1
Applied rewrites83.1%
Final simplification81.9%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma y x (* a b))))
(if (<= (* x y) -4e+88)
t_1
(if (<= (* x y) 5e-319)
(fma i c (* a b))
(if (<= (* x y) 2e+87) (fma i c (* 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(y, x, (a * b));
double tmp;
if ((x * y) <= -4e+88) {
tmp = t_1;
} else if ((x * y) <= 5e-319) {
tmp = fma(i, c, (a * b));
} else if ((x * y) <= 2e+87) {
tmp = fma(i, c, (t * z));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(y, x, Float64(a * b)) tmp = 0.0 if (Float64(x * y) <= -4e+88) tmp = t_1; elseif (Float64(x * y) <= 5e-319) tmp = fma(i, c, Float64(a * b)); elseif (Float64(x * y) <= 2e+87) tmp = fma(i, c, 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[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -4e+88], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 5e-319], N[(i * c + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e+87], N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, a \cdot b\right)\\
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{+88}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-319}:\\
\;\;\;\;\mathsf{fma}\left(i, c, a \cdot b\right)\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+87}:\\
\;\;\;\;\mathsf{fma}\left(i, c, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 x y) < -3.99999999999999984e88 or 1.9999999999999999e87 < (*.f64 x y) Initial program 97.6%
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
associate--l+N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
lift-*.f64N/A
lower-fma.f64N/A
associate-+r+N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites82.8%
if -3.99999999999999984e88 < (*.f64 x y) < 4.9999937e-319Initial program 96.1%
Taylor expanded in a around inf
Applied rewrites77.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6478.3
Applied rewrites78.3%
if 4.9999937e-319 < (*.f64 x y) < 1.9999999999999999e87Initial program 100.0%
Taylor expanded in a around inf
Applied rewrites62.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6462.4
Applied rewrites62.4%
Taylor expanded in z around inf
Applied rewrites74.1%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* a b) -5e+128) (fma i c (* a b)) (if (<= (* a b) 5e+180) (fma i c (fma t z (* y x))) (fma y x (* 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) <= -5e+128) {
tmp = fma(i, c, (a * b));
} else if ((a * b) <= 5e+180) {
tmp = fma(i, c, fma(t, z, (y * x)));
} else {
tmp = fma(y, x, (a * b));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(a * b) <= -5e+128) tmp = fma(i, c, Float64(a * b)); elseif (Float64(a * b) <= 5e+180) tmp = fma(i, c, fma(t, z, Float64(y * x))); else tmp = fma(y, x, Float64(a * b)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(a * b), $MachinePrecision], -5e+128], N[(i * c + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5e+180], N[(i * c + N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(i, c, a \cdot b\right)\\
\mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{+180}:\\
\;\;\;\;\mathsf{fma}\left(i, c, \mathsf{fma}\left(t, z, y \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -5e128Initial program 92.8%
Taylor expanded in a around inf
Applied rewrites88.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6491.0
Applied rewrites91.0%
if -5e128 < (*.f64 a b) < 4.9999999999999996e180Initial program 99.4%
Taylor expanded in a around 0
Applied rewrites89.9%
if 4.9999999999999996e180 < (*.f64 a b) Initial program 93.5%
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
associate--l+N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
lift-*.f64N/A
lower-fma.f64N/A
associate-+r+N/A
lift-*.f64N/A
remove-double-negN/A
remove-double-negN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
Applied rewrites100.0%
Taylor expanded in a around inf
Applied rewrites90.6%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* x y) -2e+159) (not (<= (* x y) 1e+185))) (* y x) (fma i c (* a b))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if (((x * y) <= -2e+159) || !((x * y) <= 1e+185)) {
tmp = y * x;
} else {
tmp = fma(i, c, (a * b));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(x * y) <= -2e+159) || !(Float64(x * y) <= 1e+185)) tmp = Float64(y * x); else tmp = fma(i, c, Float64(a * b)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2e+159], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e+185]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(i * c + N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+159} \lor \neg \left(x \cdot y \leq 10^{+185}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, a \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.9999999999999999e159 or 9.9999999999999998e184 < (*.f64 x y) Initial program 96.7%
Taylor expanded in x around inf
Applied rewrites83.5%
if -1.9999999999999999e159 < (*.f64 x y) < 9.9999999999999998e184Initial program 97.9%
Taylor expanded in a around inf
Applied rewrites70.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6470.7
Applied rewrites70.7%
Final simplification73.8%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* c i) -2e+47) (not (<= (* c i) 1e+56))) (* i c) (* b a)))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if (((c * i) <= -2e+47) || !((c * i) <= 1e+56)) {
tmp = i * c;
} else {
tmp = b * a;
}
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) <= (-2d+47)) .or. (.not. ((c * i) <= 1d+56))) then
tmp = i * c
else
tmp = b * a
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) <= -2e+47) || !((c * i) <= 1e+56)) {
tmp = i * c;
} else {
tmp = b * a;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if ((c * i) <= -2e+47) or not ((c * i) <= 1e+56): tmp = i * c else: tmp = b * a return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(c * i) <= -2e+47) || !(Float64(c * i) <= 1e+56)) tmp = Float64(i * c); else tmp = Float64(b * a); end return tmp end
function tmp_2 = code(x, y, z, t, a, b, c, i) tmp = 0.0; if (((c * i) <= -2e+47) || ~(((c * i) <= 1e+56))) tmp = i * c; else tmp = b * a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(c * i), $MachinePrecision], -2e+47], N[Not[LessEqual[N[(c * i), $MachinePrecision], 1e+56]], $MachinePrecision]], N[(i * c), $MachinePrecision], N[(b * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -2 \cdot 10^{+47} \lor \neg \left(c \cdot i \leq 10^{+56}\right):\\
\;\;\;\;i \cdot c\\
\mathbf{else}:\\
\;\;\;\;b \cdot a\\
\end{array}
\end{array}
if (*.f64 c i) < -2.0000000000000001e47 or 1.00000000000000009e56 < (*.f64 c i) Initial program 96.4%
Taylor expanded in c around inf
Applied rewrites65.8%
if -2.0000000000000001e47 < (*.f64 c i) < 1.00000000000000009e56Initial program 98.6%
Taylor expanded in a around inf
Applied rewrites42.3%
Final simplification52.5%
(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 97.6%
Taylor expanded in a around inf
Applied rewrites31.0%
herbie shell --seed 2025019
(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)))