
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c)))
(t_1
(/ (+ (fma (/ c d) b (* a (pow (* (/ c d) -1.0) 2.0))) (* -1.0 a)) d))
(t_2 (fma (* a (/ d t_0)) -1.0 (* b (/ c t_0)))))
(if (<= d -1.18e+154)
t_1
(if (<= d -3.15e-96)
t_2
(if (<= d 2.7e-140)
(/ (fma (/ (* d a) c) -1.0 b) c)
(if (<= d 2.3e+175) t_2 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = (fma((c / d), b, (a * pow(((c / d) * -1.0), 2.0))) + (-1.0 * a)) / d;
double t_2 = fma((a * (d / t_0)), -1.0, (b * (c / t_0)));
double tmp;
if (d <= -1.18e+154) {
tmp = t_1;
} else if (d <= -3.15e-96) {
tmp = t_2;
} else if (d <= 2.7e-140) {
tmp = fma(((d * a) / c), -1.0, b) / c;
} else if (d <= 2.3e+175) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(fma(Float64(c / d), b, Float64(a * (Float64(Float64(c / d) * -1.0) ^ 2.0))) + Float64(-1.0 * a)) / d) t_2 = fma(Float64(a * Float64(d / t_0)), -1.0, Float64(b * Float64(c / t_0))) tmp = 0.0 if (d <= -1.18e+154) tmp = t_1; elseif (d <= -3.15e-96) tmp = t_2; elseif (d <= 2.7e-140) tmp = Float64(fma(Float64(Float64(d * a) / c), -1.0, b) / c); elseif (d <= 2.3e+175) tmp = t_2; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[(c / d), $MachinePrecision] * b + N[(a * N[Power[N[(N[(c / d), $MachinePrecision] * -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision] * -1.0 + N[(b * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.18e+154], t$95$1, If[LessEqual[d, -3.15e-96], t$95$2, If[LessEqual[d, 2.7e-140], N[(N[(N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision] * -1.0 + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.3e+175], t$95$2, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{\mathsf{fma}\left(\frac{c}{d}, b, a \cdot {\left(\frac{c}{d} \cdot -1\right)}^{2}\right) + -1 \cdot a}{d}\\
t_2 := \mathsf{fma}\left(a \cdot \frac{d}{t\_0}, -1, b \cdot \frac{c}{t\_0}\right)\\
\mathbf{if}\;d \leq -1.18 \cdot 10^{+154}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -3.15 \cdot 10^{-96}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{-140}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d \cdot a}{c}, -1, b\right)}{c}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{+175}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -1.18000000000000004e154 or 2.3e175 < d Initial program 32.7%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6483.7
Applied rewrites83.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6479.9
Applied rewrites79.9%
Taylor expanded in d around inf
lower-/.f64N/A
Applied rewrites89.4%
if -1.18000000000000004e154 < d < -3.1499999999999998e-96 or 2.7e-140 < d < 2.3e175Initial program 73.1%
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
pow2N/A
pow2N/A
div-add-revN/A
associate-*r/N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites79.3%
if -3.1499999999999998e-96 < d < 2.7e-140Initial program 71.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6490.7
Applied rewrites90.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
(if (<= d -5.7e+113)
(/ (fma b (/ c d) (* -1.0 a)) d)
(if (<= d -1.15e-92)
t_0
(if (<= d 2.7e-140)
(/ (fma (/ (* d a) c) -1.0 b) c)
(if (<= d 2.7e+159)
t_0
(/
(+ (fma (/ c d) b (* a (pow (* (/ c d) -1.0) 2.0))) (* -1.0 a))
d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -5.7e+113) {
tmp = fma(b, (c / d), (-1.0 * a)) / d;
} else if (d <= -1.15e-92) {
tmp = t_0;
} else if (d <= 2.7e-140) {
tmp = fma(((d * a) / c), -1.0, b) / c;
} else if (d <= 2.7e+159) {
tmp = t_0;
} else {
tmp = (fma((c / d), b, (a * pow(((c / d) * -1.0), 2.0))) + (-1.0 * a)) / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -5.7e+113) tmp = Float64(fma(b, Float64(c / d), Float64(-1.0 * a)) / d); elseif (d <= -1.15e-92) tmp = t_0; elseif (d <= 2.7e-140) tmp = Float64(fma(Float64(Float64(d * a) / c), -1.0, b) / c); elseif (d <= 2.7e+159) tmp = t_0; else tmp = Float64(Float64(fma(Float64(c / d), b, Float64(a * (Float64(Float64(c / d) * -1.0) ^ 2.0))) + Float64(-1.0 * a)) / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.7e+113], N[(N[(b * N[(c / d), $MachinePrecision] + N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.15e-92], t$95$0, If[LessEqual[d, 2.7e-140], N[(N[(N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision] * -1.0 + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.7e+159], t$95$0, N[(N[(N[(N[(c / d), $MachinePrecision] * b + N[(a * N[Power[N[(N[(c / d), $MachinePrecision] * -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -5.7 \cdot 10^{+113}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -1 \cdot a\right)}{d}\\
\mathbf{elif}\;d \leq -1.15 \cdot 10^{-92}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{-140}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d \cdot a}{c}, -1, b\right)}{c}\\
\mathbf{elif}\;d \leq 2.7 \cdot 10^{+159}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, a \cdot {\left(\frac{c}{d} \cdot -1\right)}^{2}\right) + -1 \cdot a}{d}\\
\end{array}
\end{array}
if d < -5.6999999999999998e113Initial program 39.5%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6481.4
Applied rewrites81.4%
lift-fma.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6486.3
Applied rewrites86.3%
if -5.6999999999999998e113 < d < -1.15000000000000008e-92 or 2.7e-140 < d < 2.70000000000000008e159Initial program 74.6%
if -1.15000000000000008e-92 < d < 2.7e-140Initial program 72.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6490.6
Applied rewrites90.6%
if 2.70000000000000008e159 < d Initial program 32.8%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6483.1
Applied rewrites83.1%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
Taylor expanded in d around inf
lower-/.f64N/A
Applied rewrites88.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (* a (/ d c)) -1.0 b) c)))
(if (<= c -350000000.0)
t_0
(if (<= c 7e-41) (/ (fma b (/ c d) (* -1.0 a)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a * (d / c)), -1.0, b) / c;
double tmp;
if (c <= -350000000.0) {
tmp = t_0;
} else if (c <= 7e-41) {
tmp = fma(b, (c / d), (-1.0 * a)) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a * Float64(d / c)), -1.0, b) / c) tmp = 0.0 if (c <= -350000000.0) tmp = t_0; elseif (c <= 7e-41) tmp = Float64(fma(b, Float64(c / d), Float64(-1.0 * a)) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision] * -1.0 + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -350000000.0], t$95$0, If[LessEqual[c, 7e-41], N[(N[(b * N[(c / d), $MachinePrecision] + N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(a \cdot \frac{d}{c}, -1, b\right)}{c}\\
\mathbf{if}\;c \leq -350000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 7 \cdot 10^{-41}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -1 \cdot a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.5e8 or 6.9999999999999999e-41 < c Initial program 53.3%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6470.6
Applied rewrites70.6%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6474.0
Applied rewrites74.0%
if -3.5e8 < c < 6.9999999999999999e-41Initial program 74.3%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6481.5
Applied rewrites81.5%
lift-fma.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6481.4
Applied rewrites81.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0
(/
(+
(fma (* b (pow (* (/ d c) -1.0) 2.0)) -1.0 (* (/ (* d a) c) -1.0))
b)
c)))
(if (<= c -350000000.0)
t_0
(if (<= c 12.6) (/ (fma b (/ c d) (* -1.0 a)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (fma((b * pow(((d / c) * -1.0), 2.0)), -1.0, (((d * a) / c) * -1.0)) + b) / c;
double tmp;
if (c <= -350000000.0) {
tmp = t_0;
} else if (c <= 12.6) {
tmp = fma(b, (c / d), (-1.0 * a)) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(fma(Float64(b * (Float64(Float64(d / c) * -1.0) ^ 2.0)), -1.0, Float64(Float64(Float64(d * a) / c) * -1.0)) + b) / c) tmp = 0.0 if (c <= -350000000.0) tmp = t_0; elseif (c <= 12.6) tmp = Float64(fma(b, Float64(c / d), Float64(-1.0 * a)) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(b * N[Power[N[(N[(d / c), $MachinePrecision] * -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * -1.0 + N[(N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision] * -1.0), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -350000000.0], t$95$0, If[LessEqual[c, 12.6], N[(N[(b * N[(c / d), $MachinePrecision] + N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b \cdot {\left(\frac{d}{c} \cdot -1\right)}^{2}, -1, \frac{d \cdot a}{c} \cdot -1\right) + b}{c}\\
\mathbf{if}\;c \leq -350000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 12.6:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -1 \cdot a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.5e8 or 12.5999999999999996 < c Initial program 51.7%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6424.0
Applied rewrites24.0%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6424.8
Applied rewrites24.8%
Taylor expanded in c around inf
lower-/.f64N/A
Applied rewrites71.6%
if -3.5e8 < c < 12.5999999999999996Initial program 74.6%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6480.2
Applied rewrites80.2%
lift-fma.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6480.1
Applied rewrites80.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0
(/
(+
(fma (* b (pow (* (/ d c) -1.0) 2.0)) -1.0 (* (/ (* d a) c) -1.0))
b)
c)))
(if (<= c -350000000.0)
t_0
(if (<= c 12.6) (/ (fma -1.0 a (/ (* c b) d)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (fma((b * pow(((d / c) * -1.0), 2.0)), -1.0, (((d * a) / c) * -1.0)) + b) / c;
double tmp;
if (c <= -350000000.0) {
tmp = t_0;
} else if (c <= 12.6) {
tmp = fma(-1.0, a, ((c * b) / d)) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(fma(Float64(b * (Float64(Float64(d / c) * -1.0) ^ 2.0)), -1.0, Float64(Float64(Float64(d * a) / c) * -1.0)) + b) / c) tmp = 0.0 if (c <= -350000000.0) tmp = t_0; elseif (c <= 12.6) tmp = Float64(fma(-1.0, a, Float64(Float64(c * b) / d)) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(b * N[Power[N[(N[(d / c), $MachinePrecision] * -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * -1.0 + N[(N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision] * -1.0), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -350000000.0], t$95$0, If[LessEqual[c, 12.6], N[(N[(-1.0 * a + N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b \cdot {\left(\frac{d}{c} \cdot -1\right)}^{2}, -1, \frac{d \cdot a}{c} \cdot -1\right) + b}{c}\\
\mathbf{if}\;c \leq -350000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 12.6:\\
\;\;\;\;\frac{\mathsf{fma}\left(-1, a, \frac{c \cdot b}{d}\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.5e8 or 12.5999999999999996 < c Initial program 51.7%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6424.0
Applied rewrites24.0%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6424.8
Applied rewrites24.8%
Taylor expanded in c around inf
lower-/.f64N/A
Applied rewrites71.6%
if -3.5e8 < c < 12.5999999999999996Initial program 74.6%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6480.2
Applied rewrites80.2%
(FPCore (a b c d)
:precision binary64
(let* ((t_0
(/
(+ (fma (/ c d) b (* a (pow (* (/ c d) -1.0) 2.0))) (* -1.0 a))
d)))
(if (<= d -6.5e+49)
t_0
(if (<= d 2.3e+62)
(/
(+
(fma (* b (pow (* (/ d c) -1.0) 2.0)) -1.0 (* (/ (* d a) c) -1.0))
b)
c)
t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (fma((c / d), b, (a * pow(((c / d) * -1.0), 2.0))) + (-1.0 * a)) / d;
double tmp;
if (d <= -6.5e+49) {
tmp = t_0;
} else if (d <= 2.3e+62) {
tmp = (fma((b * pow(((d / c) * -1.0), 2.0)), -1.0, (((d * a) / c) * -1.0)) + b) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(fma(Float64(c / d), b, Float64(a * (Float64(Float64(c / d) * -1.0) ^ 2.0))) + Float64(-1.0 * a)) / d) tmp = 0.0 if (d <= -6.5e+49) tmp = t_0; elseif (d <= 2.3e+62) tmp = Float64(Float64(fma(Float64(b * (Float64(Float64(d / c) * -1.0) ^ 2.0)), -1.0, Float64(Float64(Float64(d * a) / c) * -1.0)) + b) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(c / d), $MachinePrecision] * b + N[(a * N[Power[N[(N[(c / d), $MachinePrecision] * -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -6.5e+49], t$95$0, If[LessEqual[d, 2.3e+62], N[(N[(N[(N[(b * N[Power[N[(N[(d / c), $MachinePrecision] * -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * -1.0 + N[(N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision] * -1.0), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{c}{d}, b, a \cdot {\left(\frac{c}{d} \cdot -1\right)}^{2}\right) + -1 \cdot a}{d}\\
\mathbf{if}\;d \leq -6.5 \cdot 10^{+49}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{+62}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b \cdot {\left(\frac{d}{c} \cdot -1\right)}^{2}, -1, \frac{d \cdot a}{c} \cdot -1\right) + b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.5000000000000005e49 or 2.29999999999999984e62 < d Initial program 46.5%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6477.1
Applied rewrites77.1%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6472.2
Applied rewrites72.2%
Taylor expanded in d around inf
lower-/.f64N/A
Applied rewrites80.3%
if -6.5000000000000005e49 < d < 2.29999999999999984e62Initial program 75.3%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6435.7
Applied rewrites35.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6433.0
Applied rewrites33.0%
Taylor expanded in c around inf
lower-/.f64N/A
Applied rewrites72.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.02e+48)
(/ (* (- (* b (/ c (* d a))) 1.0) a) d)
(if (<= d 2.3e+62)
(/
(+ (fma (* b (pow (* (/ d c) -1.0) 2.0)) -1.0 (* (/ (* d a) c) -1.0)) b)
c)
(/ (* (- (* (/ b a) (/ c d)) 1.0) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.02e+48) {
tmp = (((b * (c / (d * a))) - 1.0) * a) / d;
} else if (d <= 2.3e+62) {
tmp = (fma((b * pow(((d / c) * -1.0), 2.0)), -1.0, (((d * a) / c) * -1.0)) + b) / c;
} else {
tmp = ((((b / a) * (c / d)) - 1.0) * a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.02e+48) tmp = Float64(Float64(Float64(Float64(b * Float64(c / Float64(d * a))) - 1.0) * a) / d); elseif (d <= 2.3e+62) tmp = Float64(Float64(fma(Float64(b * (Float64(Float64(d / c) * -1.0) ^ 2.0)), -1.0, Float64(Float64(Float64(d * a) / c) * -1.0)) + b) / c); else tmp = Float64(Float64(Float64(Float64(Float64(b / a) * Float64(c / d)) - 1.0) * a) / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.02e+48], N[(N[(N[(N[(b * N[(c / N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.3e+62], N[(N[(N[(N[(b * N[Power[N[(N[(d / c), $MachinePrecision] * -1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * -1.0 + N[(N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision] * -1.0), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(N[(b / a), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+48}:\\
\;\;\;\;\frac{\left(b \cdot \frac{c}{d \cdot a} - 1\right) \cdot a}{d}\\
\mathbf{elif}\;d \leq 2.3 \cdot 10^{+62}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b \cdot {\left(\frac{d}{c} \cdot -1\right)}^{2}, -1, \frac{d \cdot a}{c} \cdot -1\right) + b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{b}{a} \cdot \frac{c}{d} - 1\right) \cdot a}{d}\\
\end{array}
\end{array}
if d < -1.02e48Initial program 47.9%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6477.0
Applied rewrites77.0%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lift-*.f6478.6
Applied rewrites78.6%
if -1.02e48 < d < 2.29999999999999984e62Initial program 75.3%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6435.6
Applied rewrites35.6%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6433.0
Applied rewrites33.0%
Taylor expanded in c around inf
lower-/.f64N/A
Applied rewrites73.0%
if 2.29999999999999984e62 < d Initial program 45.3%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6477.0
Applied rewrites77.0%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6472.5
Applied rewrites72.5%
(FPCore (a b c d) :precision binary64 (/ (* (- (* b (/ c (* d a))) 1.0) a) d))
double code(double a, double b, double c, double d) {
return (((b * (c / (d * a))) - 1.0) * a) / 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 = (((b * (c / (d * a))) - 1.0d0) * a) / d
end function
public static double code(double a, double b, double c, double d) {
return (((b * (c / (d * a))) - 1.0) * a) / d;
}
def code(a, b, c, d): return (((b * (c / (d * a))) - 1.0) * a) / d
function code(a, b, c, d) return Float64(Float64(Float64(Float64(b * Float64(c / Float64(d * a))) - 1.0) * a) / d) end
function tmp = code(a, b, c, d) tmp = (((b * (c / (d * a))) - 1.0) * a) / d; end
code[a_, b_, c_, d_] := N[(N[(N[(N[(b * N[(c / N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * a), $MachinePrecision] / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(b \cdot \frac{c}{d \cdot a} - 1\right) \cdot a}{d}
\end{array}
Initial program 63.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6452.7
Applied rewrites52.7%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6449.2
Applied rewrites49.2%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lift-*.f6451.8
Applied rewrites51.8%
herbie shell --seed 2025093
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))