
(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 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b c i) :precision binary64 (+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b, c, i)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: i
code = (((x * y) + (z * t)) + (a * b)) + (c * i)
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return (((x * y) + (z * t)) + (a * b)) + (c * i);
}
def code(x, y, z, t, a, b, c, i): return (((x * y) + (z * t)) + (a * b)) + (c * i)
function code(x, y, z, t, a, b, c, i) return Float64(Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) + Float64(c * i)) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = (((x * y) + (z * t)) + (a * b)) + (c * i); end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision] + N[(c * i), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i
\end{array}
(FPCore (x y z t a b c i) :precision binary64 (let* ((t_1 (+ (+ (+ (* x y) (* z t)) (* a b)) (* c i)))) (if (<= t_1 INFINITY) t_1 (fma i c (* t z)))))
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)) + (a * b)) + (c * i);
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = fma(i, c, (t * z));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = Float64(Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) + Float64(c * i)) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = fma(i, c, Float64(t * z)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision] + N[(c * i), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\left(x \cdot y + z \cdot t\right) + a \cdot b\right) + c \cdot i\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, t \cdot z\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) (*.f64 c i)) < +inf.0Initial program 100.0%
if +inf.0 < (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) (*.f64 c i)) Initial program 0.0%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6450.0
Applied rewrites50.0%
Taylor expanded in x around 0
lift-*.f6458.3
Applied rewrites58.3%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* c i) -1e+230)
(* i c)
(if (<= (* c i) -5e+164)
(* b a)
(if (<= (* c i) 5000000.0)
(* t z)
(if (<= (* c i) 1e+131) (* y x) (* 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+230) {
tmp = i * c;
} else if ((c * i) <= -5e+164) {
tmp = b * a;
} else if ((c * i) <= 5000000.0) {
tmp = t * z;
} else if ((c * i) <= 1e+131) {
tmp = y * x;
} 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) <= (-1d+230)) then
tmp = i * c
else if ((c * i) <= (-5d+164)) then
tmp = b * a
else if ((c * i) <= 5000000.0d0) then
tmp = t * z
else if ((c * i) <= 1d+131) then
tmp = y * x
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) <= -1e+230) {
tmp = i * c;
} else if ((c * i) <= -5e+164) {
tmp = b * a;
} else if ((c * i) <= 5000000.0) {
tmp = t * z;
} else if ((c * i) <= 1e+131) {
tmp = y * x;
} else {
tmp = i * c;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (c * i) <= -1e+230: tmp = i * c elif (c * i) <= -5e+164: tmp = b * a elif (c * i) <= 5000000.0: tmp = t * z elif (c * i) <= 1e+131: tmp = y * x else: tmp = i * c return tmp
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -1e+230) tmp = Float64(i * c); elseif (Float64(c * i) <= -5e+164) tmp = Float64(b * a); elseif (Float64(c * i) <= 5000000.0) tmp = Float64(t * z); elseif (Float64(c * i) <= 1e+131) tmp = Float64(y * x); 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) <= -1e+230) tmp = i * c; elseif ((c * i) <= -5e+164) tmp = b * a; elseif ((c * i) <= 5000000.0) tmp = t * z; elseif ((c * i) <= 1e+131) tmp = y * x; else tmp = i * c; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[LessEqual[N[(c * i), $MachinePrecision], -1e+230], N[(i * c), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], -5e+164], N[(b * a), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 5000000.0], N[(t * z), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 1e+131], N[(y * x), $MachinePrecision], N[(i * c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+230}:\\
\;\;\;\;i \cdot c\\
\mathbf{elif}\;c \cdot i \leq -5 \cdot 10^{+164}:\\
\;\;\;\;b \cdot a\\
\mathbf{elif}\;c \cdot i \leq 5000000:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;c \cdot i \leq 10^{+131}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -1.0000000000000001e230 or 9.9999999999999991e130 < (*.f64 c i) Initial program 88.7%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6478.3
Applied rewrites78.3%
if -1.0000000000000001e230 < (*.f64 c i) < -4.9999999999999995e164Initial program 100.0%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6459.8
Applied rewrites59.8%
if -4.9999999999999995e164 < (*.f64 c i) < 5e6Initial program 97.3%
Taylor expanded in z around inf
lower-*.f6444.4
Applied rewrites44.4%
if 5e6 < (*.f64 c i) < 9.9999999999999991e130Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6456.0
Applied rewrites56.0%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (+ (* x y) (* z t))))
(if (or (<= t_1 -1e+157) (not (<= t_1 2e+107)))
(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+157) || !(t_1 <= 2e+107)) {
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+157) || !(t_1 <= 2e+107)) 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+157], N[Not[LessEqual[t$95$1, 2e+107]], $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^{+157} \lor \neg \left(t\_1 \leq 2 \cdot 10^{+107}\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.99999999999999983e156 or 1.9999999999999999e107 < (+.f64 (*.f64 x y) (*.f64 z t)) Initial program 92.6%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6488.9
Applied rewrites88.9%
Taylor expanded in c around 0
lower-fma.f64N/A
*-commutativeN/A
lift-*.f6478.5
Applied rewrites78.5%
if -9.99999999999999983e156 < (+.f64 (*.f64 x y) (*.f64 z t)) < 1.9999999999999999e107Initial program 99.1%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6476.8
Applied rewrites76.8%
lift-+.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6476.8
Applied rewrites76.8%
Final simplification77.8%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma i c (* t z))))
(if (<= (* c i) -1e+230)
t_1
(if (<= (* c i) -2e+176)
(fma b a (* y x))
(if (<= (* c i) 1e+131) (fma t z (* y x)) t_1)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(i, c, (t * z));
double tmp;
if ((c * i) <= -1e+230) {
tmp = t_1;
} else if ((c * i) <= -2e+176) {
tmp = fma(b, a, (y * x));
} else if ((c * i) <= 1e+131) {
tmp = fma(t, z, (y * x));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(i, c, Float64(t * z)) tmp = 0.0 if (Float64(c * i) <= -1e+230) tmp = t_1; elseif (Float64(c * i) <= -2e+176) tmp = fma(b, a, Float64(y * x)); elseif (Float64(c * i) <= 1e+131) tmp = fma(t, z, Float64(y * x)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(i * c + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(c * i), $MachinePrecision], -1e+230], t$95$1, If[LessEqual[N[(c * i), $MachinePrecision], -2e+176], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 1e+131], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(i, c, t \cdot z\right)\\
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+230}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \cdot i \leq -2 \cdot 10^{+176}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{elif}\;c \cdot i \leq 10^{+131}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 c i) < -1.0000000000000001e230 or 9.9999999999999991e130 < (*.f64 c i) Initial program 88.7%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6484.8
Applied rewrites84.8%
Taylor expanded in x around 0
lift-*.f6483.4
Applied rewrites83.4%
if -1.0000000000000001e230 < (*.f64 c i) < -2e176Initial program 100.0%
Taylor expanded in c around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
*-commutativeN/A
lift-*.f6490.6
Applied rewrites90.6%
if -2e176 < (*.f64 c i) < 9.9999999999999991e130Initial program 97.7%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6478.9
Applied rewrites78.9%
Taylor expanded in c around 0
lower-fma.f64N/A
*-commutativeN/A
lift-*.f6471.0
Applied rewrites71.0%
(FPCore (x y z t a b c i)
:precision binary64
(if (<= (* c i) -1e+230)
(* i c)
(if (<= (* c i) -2e+176)
(fma b a (* y x))
(if (<= (* c i) 1e+139) (fma t z (* y x)) (* 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+230) {
tmp = i * c;
} else if ((c * i) <= -2e+176) {
tmp = fma(b, a, (y * x));
} else if ((c * i) <= 1e+139) {
tmp = fma(t, z, (y * x));
} else {
tmp = i * c;
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if (Float64(c * i) <= -1e+230) tmp = Float64(i * c); elseif (Float64(c * i) <= -2e+176) tmp = fma(b, a, Float64(y * x)); elseif (Float64(c * i) <= 1e+139) tmp = fma(t, z, Float64(y * x)); 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+230], N[(i * c), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], -2e+176], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 1e+139], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(i * c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+230}:\\
\;\;\;\;i \cdot c\\
\mathbf{elif}\;c \cdot i \leq -2 \cdot 10^{+176}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
\mathbf{elif}\;c \cdot i \leq 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -1.0000000000000001e230 or 1.00000000000000003e139 < (*.f64 c i) Initial program 88.6%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6479.3
Applied rewrites79.3%
if -1.0000000000000001e230 < (*.f64 c i) < -2e176Initial program 100.0%
Taylor expanded in c around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
*-commutativeN/A
lift-*.f6490.6
Applied rewrites90.6%
if -2e176 < (*.f64 c i) < 1.00000000000000003e139Initial program 97.7%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6478.5
Applied rewrites78.5%
Taylor expanded in c around 0
lower-fma.f64N/A
*-commutativeN/A
lift-*.f6470.6
Applied rewrites70.6%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* c i) -1e+230) (not (<= (* c i) 1e+131))) (fma i c (* b a)) (fma b a (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 (((c * i) <= -1e+230) || !((c * i) <= 1e+131)) {
tmp = fma(i, c, (b * a));
} else {
tmp = fma(b, a, fma(t, z, (y * x)));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(c * i) <= -1e+230) || !(Float64(c * i) <= 1e+131)) tmp = fma(i, c, Float64(b * a)); else tmp = fma(b, a, fma(t, z, Float64(y * x))); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(c * i), $MachinePrecision], -1e+230], N[Not[LessEqual[N[(c * i), $MachinePrecision], 1e+131]], $MachinePrecision]], N[(i * c + N[(b * a), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+230} \lor \neg \left(c \cdot i \leq 10^{+131}\right):\\
\;\;\;\;\mathsf{fma}\left(i, c, b \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b, a, \mathsf{fma}\left(t, z, y \cdot x\right)\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -1.0000000000000001e230 or 9.9999999999999991e130 < (*.f64 c i) Initial program 88.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6486.5
Applied rewrites86.5%
lift-+.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6487.9
Applied rewrites87.9%
if -1.0000000000000001e230 < (*.f64 c i) < 9.9999999999999991e130Initial program 97.8%
Taylor expanded in c around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6491.1
Applied rewrites91.1%
Final simplification90.2%
(FPCore (x y z t a b c i)
:precision binary64
(let* ((t_1 (fma t z (* y x))))
(if (<= (* c i) -1e+230)
(fma i c (* b a))
(if (<= (* c i) 5e+64) (fma b a t_1) (fma i c t_1)))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
double t_1 = fma(t, z, (y * x));
double tmp;
if ((c * i) <= -1e+230) {
tmp = fma(i, c, (b * a));
} else if ((c * i) <= 5e+64) {
tmp = fma(b, a, t_1);
} else {
tmp = fma(i, c, t_1);
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) t_1 = fma(t, z, Float64(y * x)) tmp = 0.0 if (Float64(c * i) <= -1e+230) tmp = fma(i, c, Float64(b * a)); elseif (Float64(c * i) <= 5e+64) tmp = fma(b, a, t_1); else tmp = fma(i, c, t_1); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(c * i), $MachinePrecision], -1e+230], N[(i * c + N[(b * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 5e+64], N[(b * a + t$95$1), $MachinePrecision], N[(i * c + t$95$1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(t, z, y \cdot x\right)\\
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+230}:\\
\;\;\;\;\mathsf{fma}\left(i, c, b \cdot a\right)\\
\mathbf{elif}\;c \cdot i \leq 5 \cdot 10^{+64}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t\_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(i, c, t\_1\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -1.0000000000000001e230Initial program 89.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6487.0
Applied rewrites87.0%
lift-+.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6487.0
Applied rewrites87.0%
if -1.0000000000000001e230 < (*.f64 c i) < 5e64Initial program 97.7%
Taylor expanded in c around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6492.7
Applied rewrites92.7%
if 5e64 < (*.f64 c i) Initial program 90.7%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6487.4
Applied rewrites87.4%
(FPCore (x y z t a b c i) :precision binary64 (if (<= (* c i) -1e+230) (* i c) (if (<= (* c i) -5e+164) (* b a) (if (<= (* c i) 1e+78) (* 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) <= -1e+230) {
tmp = i * c;
} else if ((c * i) <= -5e+164) {
tmp = b * a;
} else if ((c * i) <= 1e+78) {
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) <= (-1d+230)) then
tmp = i * c
else if ((c * i) <= (-5d+164)) then
tmp = b * a
else if ((c * i) <= 1d+78) 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) <= -1e+230) {
tmp = i * c;
} else if ((c * i) <= -5e+164) {
tmp = b * a;
} else if ((c * i) <= 1e+78) {
tmp = t * z;
} else {
tmp = i * c;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if (c * i) <= -1e+230: tmp = i * c elif (c * i) <= -5e+164: tmp = b * a elif (c * i) <= 1e+78: 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) <= -1e+230) tmp = Float64(i * c); elseif (Float64(c * i) <= -5e+164) tmp = Float64(b * a); elseif (Float64(c * i) <= 1e+78) 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) <= -1e+230) tmp = i * c; elseif ((c * i) <= -5e+164) tmp = b * a; elseif ((c * i) <= 1e+78) 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], -1e+230], N[(i * c), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], -5e+164], N[(b * a), $MachinePrecision], If[LessEqual[N[(c * i), $MachinePrecision], 1e+78], N[(t * z), $MachinePrecision], N[(i * c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+230}:\\
\;\;\;\;i \cdot c\\
\mathbf{elif}\;c \cdot i \leq -5 \cdot 10^{+164}:\\
\;\;\;\;b \cdot a\\
\mathbf{elif}\;c \cdot i \leq 10^{+78}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;i \cdot c\\
\end{array}
\end{array}
if (*.f64 c i) < -1.0000000000000001e230 or 1.00000000000000001e78 < (*.f64 c i) Initial program 90.2%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6472.9
Applied rewrites72.9%
if -1.0000000000000001e230 < (*.f64 c i) < -4.9999999999999995e164Initial program 100.0%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6459.8
Applied rewrites59.8%
if -4.9999999999999995e164 < (*.f64 c i) < 1.00000000000000001e78Initial program 97.5%
Taylor expanded in z around inf
lower-*.f6442.8
Applied rewrites42.8%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* c i) -1e+228) (not (<= (* c i) 1e+139))) (* 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 (((c * i) <= -1e+228) || !((c * i) <= 1e+139)) {
tmp = i * c;
} else {
tmp = fma(t, z, (y * x));
}
return tmp;
}
function code(x, y, z, t, a, b, c, i) tmp = 0.0 if ((Float64(c * i) <= -1e+228) || !(Float64(c * i) <= 1e+139)) tmp = Float64(i * c); else tmp = fma(t, z, Float64(y * x)); end return tmp end
code[x_, y_, z_, t_, a_, b_, c_, i_] := If[Or[LessEqual[N[(c * i), $MachinePrecision], -1e+228], N[Not[LessEqual[N[(c * i), $MachinePrecision], 1e+139]], $MachinePrecision]], N[(i * c), $MachinePrecision], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+228} \lor \neg \left(c \cdot i \leq 10^{+139}\right):\\
\;\;\;\;i \cdot c\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 c i) < -9.9999999999999992e227 or 1.00000000000000003e139 < (*.f64 c i) Initial program 88.7%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6478.3
Applied rewrites78.3%
if -9.9999999999999992e227 < (*.f64 c i) < 1.00000000000000003e139Initial program 97.8%
Taylor expanded in a around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6476.4
Applied rewrites76.4%
Taylor expanded in c around 0
lower-fma.f64N/A
*-commutativeN/A
lift-*.f6468.8
Applied rewrites68.8%
Final simplification71.4%
(FPCore (x y z t a b c i) :precision binary64 (if (or (<= (* c i) -1e+230) (not (<= (* c i) 1e+78))) (* 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) <= -1e+230) || !((c * i) <= 1e+78)) {
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) <= (-1d+230)) .or. (.not. ((c * i) <= 1d+78))) 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) <= -1e+230) || !((c * i) <= 1e+78)) {
tmp = i * c;
} else {
tmp = b * a;
}
return tmp;
}
def code(x, y, z, t, a, b, c, i): tmp = 0 if ((c * i) <= -1e+230) or not ((c * i) <= 1e+78): 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) <= -1e+230) || !(Float64(c * i) <= 1e+78)) 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) <= -1e+230) || ~(((c * i) <= 1e+78))) 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], -1e+230], N[Not[LessEqual[N[(c * i), $MachinePrecision], 1e+78]], $MachinePrecision]], N[(i * c), $MachinePrecision], N[(b * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \cdot i \leq -1 \cdot 10^{+230} \lor \neg \left(c \cdot i \leq 10^{+78}\right):\\
\;\;\;\;i \cdot c\\
\mathbf{else}:\\
\;\;\;\;b \cdot a\\
\end{array}
\end{array}
if (*.f64 c i) < -1.0000000000000001e230 or 1.00000000000000001e78 < (*.f64 c i) Initial program 90.2%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f6472.9
Applied rewrites72.9%
if -1.0000000000000001e230 < (*.f64 c i) < 1.00000000000000001e78Initial program 97.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6427.0
Applied rewrites27.0%
Final simplification41.7%
(FPCore (x y z t a b c i) :precision binary64 (* b a))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return b * a;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t, a, b, c, i)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: i
code = b * a
end function
public static double code(double x, double y, double z, double t, double a, double b, double c, double i) {
return b * a;
}
def code(x, y, z, t, a, b, c, i): return b * a
function code(x, y, z, t, a, b, c, i) return Float64(b * a) end
function tmp = code(x, y, z, t, a, b, c, i) tmp = b * a; end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(b * a), $MachinePrecision]
\begin{array}{l}
\\
b \cdot a
\end{array}
Initial program 95.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6422.9
Applied rewrites22.9%
herbie shell --seed 2025043
(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)))