
(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 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 96.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 rewrites98.8%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma i c (* z t))))
(if (<= (* a b) -1e+100)
(fma y x (* b a))
(if (<= (* a b) -2e-67)
t_1
(if (<= (* a b) 0.0)
(fma i c (* y x))
(if (<= (* a b) 5000000000.0) t_1 (fma b a (* 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, (z * t));
double tmp;
if ((a * b) <= -1e+100) {
tmp = fma(y, x, (b * a));
} else if ((a * b) <= -2e-67) {
tmp = t_1;
} else if ((a * b) <= 0.0) {
tmp = fma(i, c, (y * x));
} else if ((a * b) <= 5000000000.0) {
tmp = t_1;
} else {
tmp = fma(b, a, (c * i));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(i, c, Float64(z * t)) tmp = 0.0 if (Float64(a * b) <= -1e+100) tmp = fma(y, x, Float64(b * a)); elseif (Float64(a * b) <= -2e-67) tmp = t_1; elseif (Float64(a * b) <= 0.0) tmp = fma(i, c, Float64(y * x)); elseif (Float64(a * b) <= 5000000000.0) tmp = t_1; else tmp = fma(b, a, Float64(c * i)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(i * c + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -1e+100], N[(y * x + N[(b * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2e-67], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 0.0], N[(i * c + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5000000000.0], t$95$1, N[(b * a + N[(c * i), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(i, c, z \cdot t\right)\\
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+100}:\\
\;\;\;\;\mathsf{fma}\left(y, x, b \cdot a\right)\\
\mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-67}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \cdot b \leq 0:\\
\;\;\;\;\mathsf{fma}\left(i, c, y \cdot x\right)\\
\mathbf{elif}\;a \cdot b \leq 5000000000:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, c \cdot i\right)\\
\end{array}
\end{array}
if (*.f64 a b) < -1.00000000000000002e100Initial program 92.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-*.f6490.2
Applied rewrites90.2%
Taylor expanded in c around 0
Applied rewrites82.4%
Applied rewrites84.4%
if -1.00000000000000002e100 < (*.f64 a b) < -1.99999999999999989e-67 or -0.0 < (*.f64 a b) < 5e9Initial program 97.7%
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-*.f6489.8
Applied rewrites89.8%
Taylor expanded in x around 0
Applied rewrites72.6%
if -1.99999999999999989e-67 < (*.f64 a b) < -0.0Initial program 96.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-*.f6474.4
Applied rewrites74.4%
Taylor expanded in c around 0
Applied rewrites44.5%
Taylor expanded in x around 0
Applied rewrites3.8%
Taylor expanded in a around 0
Applied rewrites72.8%
if 5e9 < (*.f64 a b) Initial program 98.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-*.f6495.0
Applied rewrites95.0%
Taylor expanded in x around 0
Applied rewrites84.3%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* z t) -2e+80) (not (<= (* z t) 2e+130))) (fma b a (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) <= -2e+80) || !((z * t) <= 2e+130)) {
tmp = fma(b, a, 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) <= -2e+80) || !(Float64(z * t) <= 2e+130)) tmp = fma(b, a, 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], -2e+80], N[Not[LessEqual[N[(z * t), $MachinePrecision], 2e+130]], $MachinePrecision]], N[(b * a + N[(i * c + N[(t * z), $MachinePrecision]), $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 -2 \cdot 10^{+80} \lor \neg \left(z \cdot t \leq 2 \cdot 10^{+130}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(i, c, t \cdot z\right)\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) < -2e80 or 2.0000000000000001e130 < (*.f64 z t) Initial program 92.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6491.2
Applied rewrites91.2%
if -2e80 < (*.f64 z t) < 2.0000000000000001e130Initial program 98.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-*.f6494.1
Applied rewrites94.1%
Final simplification93.1%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* c i) -1e+47)
(fma b a (fma i c (* t z)))
(if (<= (* c i) 2e+89)
(fma y x (fma a b (* z t)))
(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 ((c * i) <= -1e+47) {
tmp = fma(b, a, fma(i, c, (t * z)));
} else if ((c * i) <= 2e+89) {
tmp = fma(y, x, fma(a, b, (z * t)));
} 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(c * i) <= -1e+47) tmp = fma(b, a, fma(i, c, Float64(t * z))); elseif (Float64(c * i) <= 2e+89) tmp = fma(y, x, fma(a, b, Float64(z * t))); 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[LessEqual[N[(c * i), $MachinePrecision], -1e+47], N[(b * a + N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 2e+89], N[(y * x + N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(i * c + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(i, c, t \cdot z\right)\right)\\
\mathbf{elif}\;c \cdot i \leq 2 \cdot 10^{+89}:\\
\;\;\;\;\mathsf{fma}\left(y, x, \mathsf{fma}\left(a, b, z \cdot t\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(i, c, y \cdot x\right)\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -1e47Initial program 93.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6488.8
Applied rewrites88.8%
if -1e47 < (*.f64 c i) < 1.99999999999999999e89Initial program 97.3%
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 rewrites98.0%
Taylor expanded in c around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6496.1
Applied rewrites96.1%
if 1.99999999999999999e89 < (*.f64 c i) Initial 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-*.f6493.3
Applied rewrites93.3%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* x y) -4e+295) (* y x) (if (<= (* x y) 1e+136) (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) <= -4e+295) {
tmp = y * x;
} else if ((x * y) <= 1e+136) {
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) <= -4e+295) tmp = Float64(y * x); elseif (Float64(x * y) <= 1e+136) 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], -4e+295], N[(y * x), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+136], 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 -4 \cdot 10^{+295}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \cdot y \leq 10^{+136}:\\
\;\;\;\;\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) < -3.9999999999999999e295Initial program 94.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-*.f6494.4
Applied rewrites94.4%
Taylor expanded in c around 0
Applied rewrites94.4%
Taylor expanded in x around 0
Applied rewrites7.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6494.4
Applied rewrites94.4%
if -3.9999999999999999e295 < (*.f64 x y) < 1.00000000000000006e136Initial program 98.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6489.4
Applied rewrites89.4%
if 1.00000000000000006e136 < (*.f64 x y) Initial program 89.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-*.f6485.1
Applied rewrites85.1%
Taylor expanded in c around 0
Applied rewrites77.5%
Applied rewrites80.1%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* c i) -1e+95) (not (<= (* c i) 4e+223))) (* i c) (fma a b (* x y))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double tmp;
if (((c * i) <= -1e+95) || !((c * i) <= 4e+223)) {
tmp = i * c;
} else {
tmp = fma(a, b, (x * y));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(c * i) <= -1e+95) || !(Float64(c * i) <= 4e+223)) tmp = Float64(i * c); else tmp = fma(a, b, Float64(x * y)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(c * i), $MachinePrecision], -1e+95], N[Not[LessEqual[N[(c * i), $MachinePrecision], 4e+223]], $MachinePrecision]], N[(i * c), $MachinePrecision], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+95} \lor \neg \left(c \cdot i \leq 4 \cdot 10^{+223}\right):\\
\;\;\;\;i \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -1.00000000000000002e95 or 4.00000000000000019e223 < (*.f64 c i) Initial program 94.2%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6481.5
Applied rewrites81.5%
if -1.00000000000000002e95 < (*.f64 c i) < 4.00000000000000019e223Initial program 97.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-*.f6473.2
Applied rewrites73.2%
Taylor expanded in c around 0
Applied rewrites65.1%
Final simplification69.5%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* c i) -1e+95) (fma b a (* c i)) (if (<= (* c i) 4e+223) (fma a b (* 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) <= -1e+95) {
tmp = fma(b, a, (c * i));
} else if ((c * i) <= 4e+223) {
tmp = fma(a, b, (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) <= -1e+95) tmp = fma(b, a, Float64(c * i)); elseif (Float64(c * i) <= 4e+223) tmp = fma(a, b, 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], -1e+95], N[(b * a + N[(c * i), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 4e+223], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(i * c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+95}:\\
\;\;\;\;\mathsf{fma}\left(b, a, c \cdot i\right)\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+223}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -1.00000000000000002e95Initial program 92.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-*.f6486.4
Applied rewrites86.4%
Taylor expanded in x around 0
Applied rewrites86.1%
if -1.00000000000000002e95 < (*.f64 c i) < 4.00000000000000019e223Initial program 97.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-*.f6473.2
Applied rewrites73.2%
Taylor expanded in c around 0
Applied rewrites65.1%
if 4.00000000000000019e223 < (*.f64 c i) Initial program 99.9%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6495.5
Applied rewrites95.5%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* c i) -1e+47) (fma i c (* y x)) (if (<= (* c i) 4e+223) (fma a b (* 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) <= -1e+47) {
tmp = fma(i, c, (y * x));
} else if ((c * i) <= 4e+223) {
tmp = fma(a, b, (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) <= -1e+47) tmp = fma(i, c, Float64(y * x)); elseif (Float64(c * i) <= 4e+223) tmp = fma(a, b, 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], -1e+47], N[(i * c + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 4e+223], N[(a * b + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(i * c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(i, c, y \cdot x\right)\\
\mathbf{elif}\;c \cdot i \leq 4 \cdot 10^{+223}:\\
\;\;\;\;\mathsf{fma}\left(a, b, x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -1e47Initial program 93.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-*.f6485.7
Applied rewrites85.7%
Taylor expanded in c around 0
Applied rewrites26.2%
Taylor expanded in x around 0
Applied rewrites14.8%
Taylor expanded in a around 0
Applied rewrites77.8%
if -1e47 < (*.f64 c i) < 4.00000000000000019e223Initial program 97.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-*.f6472.6
Applied rewrites72.6%
Taylor expanded in c around 0
Applied rewrites66.2%
if 4.00000000000000019e223 < (*.f64 c i) Initial program 99.9%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6495.5
Applied rewrites95.5%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* c i) -2e+41) (not (<= (* c i) 4e+223))) (* 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+41) || !((c * i) <= 4e+223)) {
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+41)) .or. (.not. ((c * i) <= 4d+223))) 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+41) || !((c * i) <= 4e+223)) {
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+41) or not ((c * i) <= 4e+223): 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+41) || !(Float64(c * i) <= 4e+223)) 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+41) || ~(((c * i) <= 4e+223))) 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+41], N[Not[LessEqual[N[(c * i), $MachinePrecision], 4e+223]], $MachinePrecision]], N[(i * c), $MachinePrecision], N[(b * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -2 \cdot 10^{+41} \lor \neg \left(c \cdot i \leq 4 \cdot 10^{+223}\right):\\
\;\;\;\;i \cdot c\\
\mathbf{else}:\\
\;\;\;\;b \cdot a\\
\end{array}
\end{array}
if (*.f64 c i) < -2.00000000000000001e41 or 4.00000000000000019e223 < (*.f64 c i) Initial program 95.1%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6473.7
Applied rewrites73.7%
if -2.00000000000000001e41 < (*.f64 c i) < 4.00000000000000019e223Initial program 97.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-*.f6472.3
Applied rewrites72.3%
Taylor expanded in c around 0
Applied rewrites65.8%
Taylor expanded in x around 0
Applied rewrites38.5%
Final simplification49.8%
(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.4
Applied rewrites77.4%
Taylor expanded in c around 0
Applied rewrites52.8%
Taylor expanded in x around 0
Applied rewrites29.9%
herbie shell --seed 2024346
(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)))