
(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 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 y x (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(z, t, fma(y, x, fma(i, c, (b * a))));
}
function code(x, y, z, t, a, b, c, i) return fma(z, t, fma(y, x, fma(i, c, Float64(b * a)))) end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(z * t + N[(y * x + N[(i * c + N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(y, x, \mathsf{fma}\left(i, c, b \cdot a\right)\right)\right)
\end{array}
Initial program 96.5%
lift-+.f64N/A
lift-*.f64N/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
associate-+l+N/A
lift-*.f64N/A
remove-double-negN/A
lift-*.f64N/A
associate-+r+N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
Applied rewrites98.0%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* c i) -2e+172)
(* i c)
(if (<= (* c i) 2e-199)
(* t z)
(if (<= (* c i) 100000000000.0)
(* b a)
(if (<= (* c i) 2e+49) (* t z) (* 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+172) {
tmp = i * c;
} else if ((c * i) <= 2e-199) {
tmp = t * z;
} else if ((c * i) <= 100000000000.0) {
tmp = b * a;
} else if ((c * i) <= 2e+49) {
tmp = t * z;
} 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) <= (-2d+172)) then
tmp = i * c
else if ((c * i) <= 2d-199) then
tmp = t * z
else if ((c * i) <= 100000000000.0d0) then
tmp = b * a
else if ((c * i) <= 2d+49) then
tmp = t * z
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) <= -2e+172) {
tmp = i * c;
} else if ((c * i) <= 2e-199) {
tmp = t * z;
} else if ((c * i) <= 100000000000.0) {
tmp = b * a;
} else if ((c * i) <= 2e+49) {
tmp = t * z;
} else {
tmp = i * c;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (c * i) <= -2e+172: tmp = i * c elif (c * i) <= 2e-199: tmp = t * z elif (c * i) <= 100000000000.0: tmp = b * a elif (c * i) <= 2e+49: tmp = t * z else: tmp = i * c return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -2e+172) tmp = Float64(i * c); elseif (Float64(c * i) <= 2e-199) tmp = Float64(t * z); elseif (Float64(c * i) <= 100000000000.0) tmp = Float64(b * a); elseif (Float64(c * i) <= 2e+49) tmp = Float64(t * z); 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) <= -2e+172) tmp = i * c; elseif ((c * i) <= 2e-199) tmp = t * z; elseif ((c * i) <= 100000000000.0) tmp = b * a; elseif ((c * i) <= 2e+49) tmp = t * z; else tmp = i * c; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(c * i), $MachinePrecision], -2e+172], N[(i * c), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 2e-199], N[(t * z), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 100000000000.0], N[(b * a), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 2e+49], N[(t * z), $MachinePrecision], N[(i * c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -2 \cdot 10^{+172}:\\
\;\;\;\;i \cdot c\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{-199}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;c \cdot i \leq 100000000000:\\
\;\;\;\;b \cdot a\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+49}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -2.0000000000000002e172 or 1.99999999999999989e49 < (*.f64 c i) Initial program 93.7%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6467.3
Applied rewrites67.3%
if -2.0000000000000002e172 < (*.f64 c i) < 1.99999999999999996e-199 or 1e11 < (*.f64 c i) < 1.99999999999999989e49Initial program 98.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6466.6
Applied rewrites66.6%
Taylor expanded in c around 0
Applied rewrites61.2%
Taylor expanded in x around 0
Applied rewrites24.9%
Taylor expanded in z around inf
lower-*.f6436.3
Applied rewrites36.3%
if 1.99999999999999996e-199 < (*.f64 c i) < 1e11Initial program 97.2%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.0
Applied rewrites84.0%
Taylor expanded in c around 0
Applied rewrites82.6%
Taylor expanded in x around 0
Applied rewrites44.4%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (+ (* x y) (* z t))))
(if (or (<= t_1 -1e+147) (not (<= t_1 1e+98)))
(fma t z (* y x))
(fma i c (* b a)))))
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 <= -1e+147) || !(t_1 <= 1e+98)) {
tmp = fma(t, z, (y * x));
} else {
tmp = fma(i, c, (b * a));
}
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 <= -1e+147) || !(t_1 <= 1e+98)) tmp = fma(t, z, Float64(y * x)); else tmp = fma(i, c, Float64(b * a)); 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, -1e+147], N[Not[LessEqual[t$95$1, 1e+98]], $MachinePrecision]], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(i * c + N[(b * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+147} \lor \neg \left(t\_1 \leq 10^{+98}\right):\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, b \cdot a\right)\\
\end{array}
\end{array}
if (+.f64 (*.f64 x y) (*.f64 z t)) < -9.9999999999999998e146 or 9.99999999999999998e97 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 93.5%
Taylor expanded in a around 0
*-lft-identityN/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.1
Applied rewrites90.1%
Taylor expanded in x around 0
Applied rewrites50.0%
Taylor expanded in z around 0
Applied rewrites56.8%
Taylor expanded in c around 0
Applied rewrites81.0%
if -9.9999999999999998e146 < (+.f64 (*.f64 x y) (*.f64 z t)) < 9.99999999999999998e97Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.4
Applied rewrites91.4%
Taylor expanded in x around 0
Applied rewrites78.9%
Final simplification80.0%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* a b) -5e+126) (not (<= (* a b) 1e+98))) (fma b a (fma i c (* y x))) (fma i c (fma t z (* y x)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if (((a * b) <= -5e+126) || !((a * b) <= 1e+98)) {
tmp = fma(b, a, fma(i, c, (y * x)));
} else {
tmp = fma(i, c, fma(t, z, (y * x)));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(a * b) <= -5e+126) || !(Float64(a * b) <= 1e+98)) tmp = fma(b, a, fma(i, c, Float64(y * x))); else tmp = fma(i, c, fma(t, z, Float64(y * x))); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -5e+126], N[Not[LessEqual[N[(a * b), $MachinePrecision], 1e+98]], $MachinePrecision]], N[(b * a + N[(i * c + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(i * c + N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+126} \lor \neg \left(a \cdot b \leq 10^{+98}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(i, c, y \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, \mathsf{fma}\left(t, z, y \cdot x\right)\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -4.99999999999999977e126 or 9.99999999999999998e97 < (*.f64 a b) Initial program 96.1%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.3
Applied rewrites91.3%
if -4.99999999999999977e126 < (*.f64 a b) < 9.99999999999999998e97Initial program 96.6%
Taylor expanded in a around 0
*-lft-identityN/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6495.1
Applied rewrites95.1%
Final simplification93.9%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* z t) -4e+155) (not (<= (* z t) 2e+181))) (fma i c (* t z)) (fma b a (fma 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 (((z * t) <= -4e+155) || !((z * t) <= 2e+181)) {
tmp = fma(i, c, (t * z));
} else {
tmp = fma(b, a, fma(i, c, (y * x)));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(z * t) <= -4e+155) || !(Float64(z * t) <= 2e+181)) tmp = fma(i, c, Float64(t * z)); else tmp = fma(b, a, fma(i, c, Float64(y * x))); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -4e+155], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e+181]], $MachinePrecision]], N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(i * c + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+155} \lor \neg \left(z \cdot t \leq 2 \cdot 10^{+181}\right):\\
\;\;\;\;\mathsf{fma}\left(i, c, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(i, c, y \cdot x\right)\right)\\
\end{array}
\end{array}
if (*.f64 z t) < -4.00000000000000003e155 or 1.9999999999999998e181 < (*.f64 z t) Initial program 89.2%
Taylor expanded in a around 0
*-lft-identityN/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6494.0
Applied rewrites94.0%
Taylor expanded in x around 0
Applied rewrites89.0%
if -4.00000000000000003e155 < (*.f64 z t) < 1.9999999999999998e181Initial program 98.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.7
Applied rewrites92.7%
Final simplification91.7%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* x y) -1e+75) (not (<= (* x y) 1e+90))) (fma b a (* y x)) (fma 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 (((x * y) <= -1e+75) || !((x * y) <= 1e+90)) {
tmp = fma(b, a, (y * x));
} else {
tmp = fma(i, c, (b * a));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(x * y) <= -1e+75) || !(Float64(x * y) <= 1e+90)) tmp = fma(b, a, Float64(y * x)); else tmp = fma(i, c, Float64(b * a)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -1e+75], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e+90]], $MachinePrecision]], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(i * c + N[(b * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+75} \lor \neg \left(x \cdot y \leq 10^{+90}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, b \cdot a\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -9.99999999999999927e74 or 9.99999999999999966e89 < (*.f64 x y) Initial program 94.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.7
Applied rewrites84.7%
Taylor expanded in c around 0
Applied rewrites79.5%
if -9.99999999999999927e74 < (*.f64 x y) < 9.99999999999999966e89Initial program 97.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6472.7
Applied rewrites72.7%
Taylor expanded in x around 0
Applied rewrites66.5%
Final simplification71.4%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* c i) -1e+167) (not (<= (* c i) 5e+145))) (* 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) {
double tmp;
if (((c * i) <= -1e+167) || !((c * i) <= 5e+145)) {
tmp = i * c;
} else {
tmp = fma(b, a, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(c * i) <= -1e+167) || !(Float64(c * i) <= 5e+145)) tmp = Float64(i * c); else tmp = fma(b, a, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(c * i), $MachinePrecision], -1e+167], N[Not[LessEqual[N[(c * i), $MachinePrecision], 5e+145]], $MachinePrecision]], N[(i * c), $MachinePrecision], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+167} \lor \neg \left(c \cdot i \leq 5 \cdot 10^{+145}\right):\\
\;\;\;\;i \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -1e167 or 4.99999999999999967e145 < (*.f64 c i) Initial program 93.7%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6474.2
Applied rewrites74.2%
if -1e167 < (*.f64 c i) < 4.99999999999999967e145Initial program 97.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6473.2
Applied rewrites73.2%
Taylor expanded in c around 0
Applied rewrites66.4%
Final simplification68.8%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* a b) -1e+80) (fma b a (* y x)) (if (<= (* a b) 2e+103) (fma i c (* y x)) (fma 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 ((a * b) <= -1e+80) {
tmp = fma(b, a, (y * x));
} else if ((a * b) <= 2e+103) {
tmp = fma(i, c, (y * x));
} else {
tmp = fma(i, c, (b * a));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(a * b) <= -1e+80) tmp = fma(b, a, Float64(y * x)); elseif (Float64(a * b) <= 2e+103) tmp = fma(i, c, Float64(y * x)); else tmp = fma(i, c, Float64(b * a)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(a * b), $MachinePrecision], -1e+80], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e+103], N[(i * c + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(i * c + N[(b * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+80}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(i, c, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, b \cdot a\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -1e80Initial program 97.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.0
Applied rewrites87.0%
Taylor expanded in c around 0
Applied rewrites76.3%
if -1e80 < (*.f64 a b) < 2e103Initial program 96.5%
Taylor expanded in a around 0
*-lft-identityN/A
metadata-evalN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6496.1
Applied rewrites96.1%
Taylor expanded in x around 0
Applied rewrites62.4%
Taylor expanded in z around 0
Applied rewrites69.4%
if 2e103 < (*.f64 a b) Initial program 94.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.4
Applied rewrites89.4%
Taylor expanded in x around 0
Applied rewrites84.1%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* a b) -5e+77) (not (<= (* a b) 1e+108))) (* 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 (((a * b) <= -5e+77) || !((a * b) <= 1e+108)) {
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 (((a * b) <= (-5d+77)) .or. (.not. ((a * b) <= 1d+108))) 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 (((a * b) <= -5e+77) || !((a * b) <= 1e+108)) {
tmp = b * a;
} else {
tmp = i * c;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if ((a * b) <= -5e+77) or not ((a * b) <= 1e+108): tmp = b * a else: tmp = i * c return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(a * b) <= -5e+77) || !(Float64(a * b) <= 1e+108)) 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 (((a * b) <= -5e+77) || ~(((a * b) <= 1e+108))) tmp = b * a; else tmp = i * c; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -5e+77], N[Not[LessEqual[N[(a * b), $MachinePrecision], 1e+108]], $MachinePrecision]], N[(b * a), $MachinePrecision], N[(i * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+77} \lor \neg \left(a \cdot b \leq 10^{+108}\right):\\
\;\;\;\;b \cdot a\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 a b) < -5.00000000000000004e77 or 1e108 < (*.f64 a b) Initial program 96.3%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.1
Applied rewrites88.1%
Taylor expanded in c around 0
Applied rewrites77.5%
Taylor expanded in x around 0
Applied rewrites60.4%
if -5.00000000000000004e77 < (*.f64 a b) < 1e108Initial program 96.5%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6436.1
Applied rewrites36.1%
Final simplification43.9%
(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 96.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6477.2
Applied rewrites77.2%
Taylor expanded in c around 0
Applied rewrites50.6%
Taylor expanded in x around 0
Applied rewrites22.6%
herbie shell --seed 2024364
(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)))