
(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}
Sampling outcomes in binary64 precision:
Herbie found 7 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 (* a (/ d t_0)) -1.0 (* b (/ c t_0)))))
(if (<= c -7.2e+133)
(/ (fma a (/ d c) (- b)) (- c))
(if (<= c -8.2e-85)
t_1
(if (<= c 6.8e-141)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 7.5e+94) t_1 (fma (/ (- a) c) (/ d c) (/ b c))))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = fma((a * (d / t_0)), -1.0, (b * (c / t_0)));
double tmp;
if (c <= -7.2e+133) {
tmp = fma(a, (d / c), -b) / -c;
} else if (c <= -8.2e-85) {
tmp = t_1;
} else if (c <= 6.8e-141) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 7.5e+94) {
tmp = t_1;
} else {
tmp = fma((-a / c), (d / c), (b / c));
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = fma(Float64(a * Float64(d / t_0)), -1.0, Float64(b * Float64(c / t_0))) tmp = 0.0 if (c <= -7.2e+133) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); elseif (c <= -8.2e-85) tmp = t_1; elseif (c <= 6.8e-141) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 7.5e+94) tmp = t_1; else tmp = fma(Float64(Float64(-a) / c), Float64(d / c), Float64(b / c)); 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[(a * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision] * -1.0 + N[(b * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -7.2e+133], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], If[LessEqual[c, -8.2e-85], t$95$1, If[LessEqual[c, 6.8e-141], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 7.5e+94], t$95$1, N[(N[((-a) / c), $MachinePrecision] * N[(d / c), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \mathsf{fma}\left(a \cdot \frac{d}{t\_0}, -1, b \cdot \frac{c}{t\_0}\right)\\
\mathbf{if}\;c \leq -7.2 \cdot 10^{+133}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{elif}\;c \leq -8.2 \cdot 10^{-85}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{-141}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{+94}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)\\
\end{array}
\end{array}
if c < -7.19999999999999956e133Initial program 30.3%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.0
Applied rewrites83.0%
if -7.19999999999999956e133 < c < -8.19999999999999987e-85 or 6.7999999999999997e-141 < c < 7.49999999999999978e94Initial program 77.8%
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 rewrites80.7%
if -8.19999999999999987e-85 < c < 6.7999999999999997e-141Initial program 67.9%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6493.6
Applied rewrites93.6%
if 7.49999999999999978e94 < c Initial program 30.4%
Taylor expanded in d around 0
associate-*r/N/A
associate-*r*N/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
Final simplification87.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
(if (<= c -1.65e+146)
(/ (fma a (/ d c) (- b)) (- c))
(if (<= c -1e-84)
t_0
(if (<= c 8.4e-48)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 6.8e+86) t_0 (fma (/ (- a) c) (/ d c) (/ b c))))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -1.65e+146) {
tmp = fma(a, (d / c), -b) / -c;
} else if (c <= -1e-84) {
tmp = t_0;
} else if (c <= 8.4e-48) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 6.8e+86) {
tmp = t_0;
} else {
tmp = fma((-a / c), (d / c), (b / c));
}
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 (c <= -1.65e+146) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); elseif (c <= -1e-84) tmp = t_0; elseif (c <= 8.4e-48) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 6.8e+86) tmp = t_0; else tmp = fma(Float64(Float64(-a) / c), Float64(d / c), Float64(b / c)); 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[c, -1.65e+146], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], If[LessEqual[c, -1e-84], t$95$0, If[LessEqual[c, 8.4e-48], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.8e+86], t$95$0, N[(N[((-a) / c), $MachinePrecision] * N[(d / c), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -1.65 \cdot 10^{+146}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{elif}\;c \leq -1 \cdot 10^{-84}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 8.4 \cdot 10^{-48}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 6.8 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)\\
\end{array}
\end{array}
if c < -1.65000000000000008e146Initial program 22.6%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6484.1
Applied rewrites84.1%
if -1.65000000000000008e146 < c < -1e-84 or 8.39999999999999954e-48 < c < 6.7999999999999995e86Initial program 78.6%
if -1e-84 < c < 8.39999999999999954e-48Initial program 68.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.2
Applied rewrites91.2%
if 6.7999999999999995e86 < c Initial program 30.4%
Taylor expanded in d around 0
associate-*r/N/A
associate-*r*N/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
Final simplification86.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.6e-32)
(/ (fma a (/ d c) (- b)) (- c))
(if (<= c 3.2e+81)
(/ (fma b (/ c d) (- a)) d)
(fma (/ (- a) c) (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.6e-32) {
tmp = fma(a, (d / c), -b) / -c;
} else if (c <= 3.2e+81) {
tmp = fma(b, (c / d), -a) / d;
} else {
tmp = fma((-a / c), (d / c), (b / c));
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -4.6e-32) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); elseif (c <= 3.2e+81) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); else tmp = fma(Float64(Float64(-a) / c), Float64(d / c), Float64(b / c)); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.6e-32], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], If[LessEqual[c, 3.2e+81], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[((-a) / c), $MachinePrecision] * N[(d / c), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.6 \cdot 10^{-32}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{+81}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-a}{c}, \frac{d}{c}, \frac{b}{c}\right)\\
\end{array}
\end{array}
if c < -4.6000000000000001e-32Initial program 54.9%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6473.5
Applied rewrites73.5%
if -4.6000000000000001e-32 < c < 3.2e81Initial program 71.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6485.3
Applied rewrites85.3%
if 3.2e81 < c Initial program 30.4%
Taylor expanded in d around 0
associate-*r/N/A
associate-*r*N/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
Final simplification83.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -4.6e-32) (not (<= c 2.25e+82))) (/ (fma a (/ d c) (- b)) (- c)) (/ (fma b (/ c d) (- a)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -4.6e-32) || !(c <= 2.25e+82)) {
tmp = fma(a, (d / c), -b) / -c;
} else {
tmp = fma(b, (c / d), -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -4.6e-32) || !(c <= 2.25e+82)) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); else tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.6e-32], N[Not[LessEqual[c, 2.25e+82]], $MachinePrecision]], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.6 \cdot 10^{-32} \lor \neg \left(c \leq 2.25 \cdot 10^{+82}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\end{array}
\end{array}
if c < -4.6000000000000001e-32 or 2.2499999999999998e82 < c Initial program 44.1%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6479.9
Applied rewrites79.9%
if -4.6000000000000001e-32 < c < 2.2499999999999998e82Initial program 71.6%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6485.3
Applied rewrites85.3%
Final simplification83.0%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.25e-32) (not (<= c 1.4e+22))) (/ (fma a (/ d c) (- b)) (- c)) (/ (* (- (* (/ b a) (/ c d)) 1.0) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.25e-32) || !(c <= 1.4e+22)) {
tmp = fma(a, (d / c), -b) / -c;
} else {
tmp = ((((b / a) * (c / d)) - 1.0) * a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.25e-32) || !(c <= 1.4e+22)) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-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[Or[LessEqual[c, -2.25e-32], N[Not[LessEqual[c, 1.4e+22]], $MachinePrecision]], N[(N[(a * N[(d / c), $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}\;c \leq -2.25 \cdot 10^{-32} \lor \neg \left(c \leq 1.4 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{b}{a} \cdot \frac{c}{d} - 1\right) \cdot a}{d}\\
\end{array}
\end{array}
if c < -2.25000000000000002e-32 or 1.4e22 < c Initial program 49.2%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6475.6
Applied rewrites75.6%
if -2.25000000000000002e-32 < c < 1.4e22Initial program 70.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6488.8
Applied rewrites88.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-/.f6484.0
Applied rewrites84.0%
Final simplification79.9%
(FPCore (a b c d) :precision binary64 (if (or (<= d -9.5e+134) (not (<= d 1.12e+170))) (* b (/ (- (/ c d) (pow (/ c d) 3.0)) d)) (/ (fma a (/ d c) (- b)) (- c))))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -9.5e+134) || !(d <= 1.12e+170)) {
tmp = b * (((c / d) - pow((c / d), 3.0)) / d);
} else {
tmp = fma(a, (d / c), -b) / -c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -9.5e+134) || !(d <= 1.12e+170)) tmp = Float64(b * Float64(Float64(Float64(c / d) - (Float64(c / d) ^ 3.0)) / d)); else tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9.5e+134], N[Not[LessEqual[d, 1.12e+170]], $MachinePrecision]], N[(b * N[(N[(N[(c / d), $MachinePrecision] - N[Power[N[(c / d), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.5 \cdot 10^{+134} \lor \neg \left(d \leq 1.12 \cdot 10^{+170}\right):\\
\;\;\;\;b \cdot \frac{\frac{c}{d} - {\left(\frac{c}{d}\right)}^{3}}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\end{array}
\end{array}
if d < -9.5000000000000004e134 or 1.1200000000000001e170 < d Initial program 32.3%
Taylor expanded in d around inf
lower-/.f64N/A
Applied rewrites81.3%
Taylor expanded in b around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lift-/.f64N/A
cube-divN/A
lift-pow.f64N/A
lift-/.f6430.3
Applied rewrites30.3%
if -9.5000000000000004e134 < d < 1.1200000000000001e170Initial program 70.1%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6466.1
Applied rewrites66.1%
Final simplification56.4%
(FPCore (a b c d) :precision binary64 (* b (/ (- (/ c d) (pow (/ c d) 3.0)) d)))
double code(double a, double b, double c, double d) {
return b * (((c / d) - pow((c / d), 3.0)) / 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) - ((c / d) ** 3.0d0)) / d)
end function
public static double code(double a, double b, double c, double d) {
return b * (((c / d) - Math.pow((c / d), 3.0)) / d);
}
def code(a, b, c, d): return b * (((c / d) - math.pow((c / d), 3.0)) / d)
function code(a, b, c, d) return Float64(b * Float64(Float64(Float64(c / d) - (Float64(c / d) ^ 3.0)) / d)) end
function tmp = code(a, b, c, d) tmp = b * (((c / d) - ((c / d) ^ 3.0)) / d); end
code[a_, b_, c_, d_] := N[(b * N[(N[(N[(c / d), $MachinePrecision] - N[Power[N[(c / d), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b \cdot \frac{\frac{c}{d} - {\left(\frac{c}{d}\right)}^{3}}{d}
\end{array}
Initial program 59.9%
Taylor expanded in d around inf
lower-/.f64N/A
Applied rewrites49.1%
Taylor expanded in b around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lift-/.f64N/A
cube-divN/A
lift-pow.f64N/A
lift-/.f6418.0
Applied rewrites18.0%
herbie shell --seed 2025057
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform herbie20 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))