
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b)
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
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b)
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
code = ((x * y) + (z * t)) + (a * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((x * y) + (z * t)) + (a * b);
}
def code(x, y, z, t, a, b): return ((x * y) + (z * t)) + (a * b)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) end
function tmp = code(x, y, z, t, a, b) tmp = ((x * y) + (z * t)) + (a * b); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}
(FPCore (x y z t a b) :precision binary64 (fma z t (fma b a (* y x))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(z, t, fma(b, a, (y * x)));
}
function code(x, y, z, t, a, b) return fma(z, t, fma(b, a, Float64(y * x))) end
code[x_, y_, z_, t_, a_, b_] := N[(z * t + N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, y \cdot x\right)\right)
\end{array}
Initial program 96.4%
+-commutativeN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
(FPCore (x y z t a b)
:precision binary64
(if (<= (* x y) -1e+83)
(* y x)
(if (<= (* x y) -9e-274)
(* b a)
(if (<= (* x y) 1e-62) (* t z) (if (<= (* x y) 5e+99) (* b a) (* y x))))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1e+83) {
tmp = y * x;
} else if ((x * y) <= -9e-274) {
tmp = b * a;
} else if ((x * y) <= 1e-62) {
tmp = t * z;
} else if ((x * y) <= 5e+99) {
tmp = b * a;
} else {
tmp = y * x;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b)
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) :: tmp
if ((x * y) <= (-1d+83)) then
tmp = y * x
else if ((x * y) <= (-9d-274)) then
tmp = b * a
else if ((x * y) <= 1d-62) then
tmp = t * z
else if ((x * y) <= 5d+99) then
tmp = b * a
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1e+83) {
tmp = y * x;
} else if ((x * y) <= -9e-274) {
tmp = b * a;
} else if ((x * y) <= 1e-62) {
tmp = t * z;
} else if ((x * y) <= 5e+99) {
tmp = b * a;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if (x * y) <= -1e+83: tmp = y * x elif (x * y) <= -9e-274: tmp = b * a elif (x * y) <= 1e-62: tmp = t * z elif (x * y) <= 5e+99: tmp = b * a else: tmp = y * x return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1e+83) tmp = Float64(y * x); elseif (Float64(x * y) <= -9e-274) tmp = Float64(b * a); elseif (Float64(x * y) <= 1e-62) tmp = Float64(t * z); elseif (Float64(x * y) <= 5e+99) tmp = Float64(b * a); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if ((x * y) <= -1e+83) tmp = y * x; elseif ((x * y) <= -9e-274) tmp = b * a; elseif ((x * y) <= 1e-62) tmp = t * z; elseif ((x * y) <= 5e+99) tmp = b * a; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -1e+83], N[(y * x), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -9e-274], N[(b * a), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e-62], N[(t * z), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+99], N[(b * a), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+83}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \cdot y \leq -9 \cdot 10^{-274}:\\
\;\;\;\;b \cdot a\\
\mathbf{elif}\;x \cdot y \leq 10^{-62}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+99}:\\
\;\;\;\;b \cdot a\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 x y) < -1.00000000000000003e83 or 5.00000000000000008e99 < (*.f64 x y) Initial program 92.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6477.6
Applied rewrites77.6%
if -1.00000000000000003e83 < (*.f64 x y) < -8.99999999999999982e-274 or 1e-62 < (*.f64 x y) < 5.00000000000000008e99Initial program 97.9%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6452.0
Applied rewrites52.0%
if -8.99999999999999982e-274 < (*.f64 x y) < 1e-62Initial program 99.9%
Taylor expanded in z around inf
lower-*.f6464.6
Applied rewrites64.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -1e+83) (not (<= (* x y) 5e+114))) (fma b a (* y x)) (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -1e+83) || !((x * y) <= 5e+114)) {
tmp = fma(b, a, (y * x));
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -1e+83) || !(Float64(x * y) <= 5e+114)) tmp = fma(b, a, Float64(y * x)); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -1e+83], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e+114]], $MachinePrecision]], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+83} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{+114}\right):\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.00000000000000003e83 or 5.0000000000000001e114 < (*.f64 x y) Initial program 92.4%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6490.8
Applied rewrites90.8%
if -1.00000000000000003e83 < (*.f64 x y) < 5.0000000000000001e114Initial program 98.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6488.9
Applied rewrites88.9%
Final simplification89.6%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* x y) -5e+146) (not (<= (* x y) 1e+140))) (* y x) (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((x * y) <= -5e+146) || !((x * y) <= 1e+140)) {
tmp = y * x;
} else {
tmp = fma(b, a, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(x * y) <= -5e+146) || !(Float64(x * y) <= 1e+140)) tmp = Float64(y * x); else tmp = fma(b, a, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -5e+146], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e+140]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+146} \lor \neg \left(x \cdot y \leq 10^{+140}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999999e146 or 1.00000000000000006e140 < (*.f64 x y) Initial program 90.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6488.3
Applied rewrites88.3%
if -4.9999999999999999e146 < (*.f64 x y) < 1.00000000000000006e140Initial program 98.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6486.3
Applied rewrites86.3%
Final simplification86.9%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -0.2) (fma y x (* t z)) (if (<= (* x y) 5e+114) (fma z t (* a b)) (fma b a (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -0.2) {
tmp = fma(y, x, (t * z));
} else if ((x * y) <= 5e+114) {
tmp = fma(z, t, (a * b));
} else {
tmp = fma(b, a, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -0.2) tmp = fma(y, x, Float64(t * z)); elseif (Float64(x * y) <= 5e+114) tmp = fma(z, t, Float64(a * b)); else tmp = fma(b, a, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -0.2], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+114], N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -0.2:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+114}:\\
\;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -0.20000000000000001Initial program 96.9%
associate-+l+N/A
*-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
lower-*.f6480.5
Applied rewrites80.5%
if -0.20000000000000001 < (*.f64 x y) < 5.0000000000000001e114Initial program 99.3%
+-commutativeN/A
*-commutativeN/A
associate-+l+N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-*.f6492.7
Applied rewrites92.7%
if 5.0000000000000001e114 < (*.f64 x y) Initial program 87.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.0
Applied rewrites98.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1e+83) (fma y x (* t z)) (if (<= (* x y) 5e+114) (fma b a (* t z)) (fma b a (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1e+83) {
tmp = fma(y, x, (t * z));
} else if ((x * y) <= 5e+114) {
tmp = fma(b, a, (t * z));
} else {
tmp = fma(b, a, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1e+83) tmp = fma(y, x, Float64(t * z)); elseif (Float64(x * y) <= 5e+114) tmp = fma(b, a, Float64(t * z)); else tmp = fma(b, a, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -1e+83], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+114], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+114}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.00000000000000003e83Initial program 97.7%
associate-+l+N/A
*-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
lower-*.f6486.5
Applied rewrites86.5%
if -1.00000000000000003e83 < (*.f64 x y) < 5.0000000000000001e114Initial program 98.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6488.9
Applied rewrites88.9%
if 5.0000000000000001e114 < (*.f64 x y) Initial program 87.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.0
Applied rewrites98.0%
(FPCore (x y z t a b) :precision binary64 (if (<= (* x y) -1e+83) (fma t z (* y x)) (if (<= (* x y) 5e+114) (fma b a (* t z)) (fma b a (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if ((x * y) <= -1e+83) {
tmp = fma(t, z, (y * x));
} else if ((x * y) <= 5e+114) {
tmp = fma(b, a, (t * z));
} else {
tmp = fma(b, a, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b) tmp = 0.0 if (Float64(x * y) <= -1e+83) tmp = fma(t, z, Float64(y * x)); elseif (Float64(x * y) <= 5e+114) tmp = fma(b, a, Float64(t * z)); else tmp = fma(b, a, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -1e+83], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+114], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+83}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+114}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 x y) < -1.00000000000000003e83Initial program 97.7%
Taylor expanded in a around 0
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6486.4
Applied rewrites86.4%
if -1.00000000000000003e83 < (*.f64 x y) < 5.0000000000000001e114Initial program 98.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6488.9
Applied rewrites88.9%
if 5.0000000000000001e114 < (*.f64 x y) Initial program 87.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.0
Applied rewrites98.0%
(FPCore (x y z t a b) :precision binary64 (if (or (<= (* z t) -1e+36) (not (<= (* z t) 20000.0))) (* t z) (* b a)))
double code(double x, double y, double z, double t, double a, double b) {
double tmp;
if (((z * t) <= -1e+36) || !((z * t) <= 20000.0)) {
tmp = t * z;
} 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)
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) :: tmp
if (((z * t) <= (-1d+36)) .or. (.not. ((z * t) <= 20000.0d0))) then
tmp = t * z
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 tmp;
if (((z * t) <= -1e+36) || !((z * t) <= 20000.0)) {
tmp = t * z;
} else {
tmp = b * a;
}
return tmp;
}
def code(x, y, z, t, a, b): tmp = 0 if ((z * t) <= -1e+36) or not ((z * t) <= 20000.0): tmp = t * z else: tmp = b * a return tmp
function code(x, y, z, t, a, b) tmp = 0.0 if ((Float64(z * t) <= -1e+36) || !(Float64(z * t) <= 20000.0)) tmp = Float64(t * z); else tmp = Float64(b * a); end return tmp end
function tmp_2 = code(x, y, z, t, a, b) tmp = 0.0; if (((z * t) <= -1e+36) || ~(((z * t) <= 20000.0))) tmp = t * z; else tmp = b * a; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(z * t), $MachinePrecision], -1e+36], N[Not[LessEqual[N[(z * t), $MachinePrecision], 20000.0]], $MachinePrecision]], N[(t * z), $MachinePrecision], N[(b * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+36} \lor \neg \left(z \cdot t \leq 20000\right):\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;b \cdot a\\
\end{array}
\end{array}
if (*.f64 z t) < -1.00000000000000004e36 or 2e4 < (*.f64 z t) Initial program 95.9%
Taylor expanded in z around inf
lower-*.f6461.5
Applied rewrites61.5%
if -1.00000000000000004e36 < (*.f64 z t) < 2e4Initial program 96.9%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6448.6
Applied rewrites48.6%
Final simplification54.8%
(FPCore (x y z t a b) :precision binary64 (fma y x (fma b a (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
return fma(y, x, fma(b, a, (t * z)));
}
function code(x, y, z, t, a, b) return fma(y, x, fma(b, a, Float64(t * z))) end
code[x_, y_, z_, t_, a_, b_] := N[(y * x + N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, t \cdot z\right)\right)
\end{array}
Initial program 96.4%
associate-+l+N/A
*-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6497.7
Applied rewrites97.7%
(FPCore (x y z t a b) :precision binary64 (* b a))
double code(double x, double y, double z, double t, double a, double b) {
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)
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
code = b * a
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return b * a;
}
def code(x, y, z, t, a, b): return b * a
function code(x, y, z, t, a, b) return Float64(b * a) end
function tmp = code(x, y, z, t, a, b) tmp = b * a; end
code[x_, y_, z_, t_, a_, b_] := N[(b * a), $MachinePrecision]
\begin{array}{l}
\\
b \cdot a
\end{array}
Initial program 96.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6434.5
Applied rewrites34.5%
herbie shell --seed 2025044
(FPCore (x y z t a b)
:name "Linear.V3:$cdot from linear-1.19.1.3, B"
:precision binary64
(+ (+ (* x y) (* z t)) (* a b)))