
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (fma c c (* d d)))))
(if (<= d -6.9e+103)
(fma (/ a d) (/ c d) (/ b d))
(if (<= d -3.95e-144)
t_0
(if (<= d 2e-162)
(-
(/
(fma
(/
(fma
d
b
(- (/ (fma b (/ (pow d 3.0) c) (* 1.0 (* (* d d) a))) c)))
c)
-1.0
(- a))
c))
(if (<= d 2.2e+179)
t_0
(/ (+ (fma (/ c d) a (- (* b (pow (/ c d) 2.0)))) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / fma(c, c, (d * d));
double tmp;
if (d <= -6.9e+103) {
tmp = fma((a / d), (c / d), (b / d));
} else if (d <= -3.95e-144) {
tmp = t_0;
} else if (d <= 2e-162) {
tmp = -(fma((fma(d, b, -(fma(b, (pow(d, 3.0) / c), (1.0 * ((d * d) * a))) / c)) / c), -1.0, -a) / c);
} else if (d <= 2.2e+179) {
tmp = t_0;
} else {
tmp = (fma((c / d), a, -(b * pow((c / d), 2.0))) + b) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / fma(c, c, Float64(d * d))) tmp = 0.0 if (d <= -6.9e+103) tmp = fma(Float64(a / d), Float64(c / d), Float64(b / d)); elseif (d <= -3.95e-144) tmp = t_0; elseif (d <= 2e-162) tmp = Float64(-Float64(fma(Float64(fma(d, b, Float64(-Float64(fma(b, Float64((d ^ 3.0) / c), Float64(1.0 * Float64(Float64(d * d) * a))) / c))) / c), -1.0, Float64(-a)) / c)); elseif (d <= 2.2e+179) tmp = t_0; else tmp = Float64(Float64(fma(Float64(c / d), a, Float64(-Float64(b * (Float64(c / d) ^ 2.0)))) + b) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.9e+103], N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.95e-144], t$95$0, If[LessEqual[d, 2e-162], (-N[(N[(N[(N[(d * b + (-N[(N[(b * N[(N[Power[d, 3.0], $MachinePrecision] / c), $MachinePrecision] + N[(1.0 * N[(N[(d * d), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision])), $MachinePrecision] / c), $MachinePrecision] * -1.0 + (-a)), $MachinePrecision] / c), $MachinePrecision]), If[LessEqual[d, 2.2e+179], t$95$0, N[(N[(N[(N[(c / d), $MachinePrecision] * a + (-N[(b * N[Power[N[(c / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision])), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{if}\;d \leq -6.9 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{elif}\;d \leq -3.95 \cdot 10^{-144}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2 \cdot 10^{-162}:\\
\;\;\;\;-\frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(d, b, -\frac{\mathsf{fma}\left(b, \frac{{d}^{3}}{c}, 1 \cdot \left(\left(d \cdot d\right) \cdot a\right)\right)}{c}\right)}{c}, -1, -a\right)}{c}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+179}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, -b \cdot {\left(\frac{c}{d}\right)}^{2}\right) + b}{d}\\
\end{array}
\end{array}
if d < -6.8999999999999999e103Initial program 36.8%
Taylor expanded in c around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6484.1
Applied rewrites84.1%
if -6.8999999999999999e103 < d < -3.95000000000000026e-144 or 1.99999999999999991e-162 < d < 2.2e179Initial program 72.7%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6472.7
Applied rewrites72.7%
if -3.95000000000000026e-144 < d < 1.99999999999999991e-162Initial program 72.1%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
Applied rewrites93.3%
if 2.2e179 < d Initial program 31.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6491.2
Applied rewrites91.2%
Taylor expanded in d around inf
lower-/.f64N/A
Applied rewrites90.8%
(FPCore (a b c d)
:precision binary64
(if (<= d -3.2e-10)
(fma (/ a d) (/ c d) (/ b d))
(if (<= d 2.15e-162)
(/ (fma b (/ d c) a) c)
(if (<= d 2.2e+179)
(/ (+ (* a c) (* b d)) (fma c c (* d d)))
(/ (+ (fma (/ c d) a (- (* b (pow (/ c d) 2.0)))) b) d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -3.2e-10) {
tmp = fma((a / d), (c / d), (b / d));
} else if (d <= 2.15e-162) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 2.2e+179) {
tmp = ((a * c) + (b * d)) / fma(c, c, (d * d));
} else {
tmp = (fma((c / d), a, -(b * pow((c / d), 2.0))) + b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -3.2e-10) tmp = fma(Float64(a / d), Float64(c / d), Float64(b / d)); elseif (d <= 2.15e-162) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 2.2e+179) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / fma(c, c, Float64(d * d))); else tmp = Float64(Float64(fma(Float64(c / d), a, Float64(-Float64(b * (Float64(c / d) ^ 2.0)))) + b) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.2e-10], N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.15e-162], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.2e+179], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(c / d), $MachinePrecision] * a + (-N[(b * N[Power[N[(c / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision])), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{-162}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 2.2 \cdot 10^{+179}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, -b \cdot {\left(\frac{c}{d}\right)}^{2}\right) + b}{d}\\
\end{array}
\end{array}
if d < -3.19999999999999981e-10Initial program 49.8%
Taylor expanded in c around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
if -3.19999999999999981e-10 < d < 2.14999999999999998e-162Initial program 73.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.2
Applied rewrites86.2%
if 2.14999999999999998e-162 < d < 2.2e179Initial program 70.3%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6470.3
Applied rewrites70.3%
if 2.2e179 < d Initial program 31.8%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6491.2
Applied rewrites91.2%
Taylor expanded in d around inf
lower-/.f64N/A
Applied rewrites90.8%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma (/ a d) (/ c d) (/ b d))))
(if (<= d -3.2e-10)
t_0
(if (<= d 2.15e-162)
(/ (fma b (/ d c) a) c)
(if (<= d 3e+153) (/ (+ (* a c) (* b d)) (fma c c (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), (c / d), (b / d));
double tmp;
if (d <= -3.2e-10) {
tmp = t_0;
} else if (d <= 2.15e-162) {
tmp = fma(b, (d / c), a) / c;
} else if (d <= 3e+153) {
tmp = ((a * c) + (b * d)) / fma(c, c, (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(a / d), Float64(c / d), Float64(b / d)) tmp = 0.0 if (d <= -3.2e-10) tmp = t_0; elseif (d <= 2.15e-162) tmp = Float64(fma(b, Float64(d / c), a) / c); elseif (d <= 3e+153) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / fma(c, c, Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.2e-10], t$95$0, If[LessEqual[d, 2.15e-162], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3e+153], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -3.2 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.15 \cdot 10^{-162}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{elif}\;d \leq 3 \cdot 10^{+153}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.19999999999999981e-10 or 3.00000000000000019e153 < d Initial program 43.2%
Taylor expanded in c around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6480.4
Applied rewrites80.4%
if -3.19999999999999981e-10 < d < 2.14999999999999998e-162Initial program 73.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.2
Applied rewrites86.2%
if 2.14999999999999998e-162 < d < 3.00000000000000019e153Initial program 74.4%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6474.4
Applied rewrites74.4%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (fma (/ a d) (/ c d) (/ b d)))) (if (<= d -3.2e-10) t_0 (if (<= d 1.2e-20) (/ (fma b (/ d c) a) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), (c / d), (b / d));
double tmp;
if (d <= -3.2e-10) {
tmp = t_0;
} else if (d <= 1.2e-20) {
tmp = fma(b, (d / c), a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(a / d), Float64(c / d), Float64(b / d)) tmp = 0.0 if (d <= -3.2e-10) tmp = t_0; elseif (d <= 1.2e-20) tmp = Float64(fma(b, Float64(d / c), a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.2e-10], t$95$0, If[LessEqual[d, 1.2e-20], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -3.2 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.2 \cdot 10^{-20}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.19999999999999981e-10 or 1.19999999999999996e-20 < d Initial program 50.3%
Taylor expanded in c around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6475.2
Applied rewrites75.2%
if -3.19999999999999981e-10 < d < 1.19999999999999996e-20Initial program 75.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.7
Applied rewrites82.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma b (/ d c) a) c)))
(if (<= c -2.05e+129)
t_0
(if (<= c 130000000.0) (/ (fma a (/ c d) b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -2.05e+129) {
tmp = t_0;
} else if (c <= 130000000.0) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -2.05e+129) tmp = t_0; elseif (c <= 130000000.0) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.05e+129], t$95$0, If[LessEqual[c, 130000000.0], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -2.05 \cdot 10^{+129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 130000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -2.0500000000000001e129 or 1.3e8 < c Initial program 43.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6480.7
Applied rewrites80.7%
if -2.0500000000000001e129 < c < 1.3e8Initial program 73.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6473.6
Applied rewrites73.6%
(FPCore (a b c d) :precision binary64 (if (<= c -3e+188) (/ a c) (if (<= c 4e+99) (/ (fma a (/ c d) b) d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e+188) {
tmp = a / c;
} else if (c <= 4e+99) {
tmp = fma(a, (c / d), b) / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3e+188) tmp = Float64(a / c); elseif (c <= 4e+99) tmp = Float64(fma(a, Float64(c / d), b) / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e+188], N[(a / c), $MachinePrecision], If[LessEqual[c, 4e+99], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{+188}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{+99}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3.0000000000000001e188 or 3.9999999999999999e99 < c Initial program 36.6%
Taylor expanded in c around inf
lower-/.f6478.2
Applied rewrites78.2%
if -3.0000000000000001e188 < c < 3.9999999999999999e99Initial program 71.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6467.5
Applied rewrites67.5%
(FPCore (a b c d) :precision binary64 (if (<= d -6.5e-11) (/ b d) (if (<= d 1.26e-20) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.5e-11) {
tmp = b / d;
} else if (d <= 1.26e-20) {
tmp = a / c;
} else {
tmp = b / d;
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-6.5d-11)) then
tmp = b / d
else if (d <= 1.26d-20) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -6.5e-11) {
tmp = b / d;
} else if (d <= 1.26e-20) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -6.5e-11: tmp = b / d elif d <= 1.26e-20: tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -6.5e-11) tmp = Float64(b / d); elseif (d <= 1.26e-20) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -6.5e-11) tmp = b / d; elseif (d <= 1.26e-20) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -6.5e-11], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.26e-20], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.5 \cdot 10^{-11}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 1.26 \cdot 10^{-20}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -6.49999999999999953e-11 or 1.26e-20 < d Initial program 50.3%
Taylor expanded in c around 0
lower-/.f6463.3
Applied rewrites63.3%
if -6.49999999999999953e-11 < d < 1.26e-20Initial program 75.0%
Taylor expanded in c around inf
lower-/.f6465.4
Applied rewrites65.4%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 62.3%
Taylor expanded in c around inf
lower-/.f6443.7
Applied rewrites43.7%
herbie shell --seed 2025101
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))