
(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 (/ (- b (* d (/ a c))) c)))
(if (<= c -6e+52)
t_0
(if (<= c -3.8e-137)
(* (/ (fma b (/ c a) (- d)) (fma d d (* c c))) a)
(if (<= c 6e-161)
(/ (- (/ (* c b) d) a) d)
(if (<= c 3.65e+59)
(/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6e+52) {
tmp = t_0;
} else if (c <= -3.8e-137) {
tmp = (fma(b, (c / a), -d) / fma(d, d, (c * c))) * a;
} else if (c <= 6e-161) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 3.65e+59) {
tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -6e+52) tmp = t_0; elseif (c <= -3.8e-137) tmp = Float64(Float64(fma(b, Float64(c / a), Float64(-d)) / fma(d, d, Float64(c * c))) * a); elseif (c <= 6e-161) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); elseif (c <= 3.65e+59) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6e+52], t$95$0, If[LessEqual[c, -3.8e-137], N[(N[(N[(b * N[(c / a), $MachinePrecision] + (-d)), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], If[LessEqual[c, 6e-161], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.65e+59], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -6 \cdot 10^{+52}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -3.8 \cdot 10^{-137}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{a}, -d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\
\mathbf{elif}\;c \leq 6 \cdot 10^{-161}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 3.65 \cdot 10^{+59}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6e52 or 3.6500000000000001e59 < c Initial program 37.6%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6480.3
Applied rewrites80.3%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6485.8
Applied rewrites85.8%
if -6e52 < c < -3.79999999999999999e-137Initial program 85.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites88.3%
if -3.79999999999999999e-137 < c < 5.99999999999999977e-161Initial program 69.4%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6496.0
Applied rewrites96.0%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6496.0
Applied rewrites96.0%
if 5.99999999999999977e-161 < c < 3.6500000000000001e59Initial program 83.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(t_1 (/ (- b (* d (/ a c))) c)))
(if (<= c -6e+52)
t_1
(if (<= c -2.9e-137)
t_0
(if (<= c 6e-161)
(/ (- (/ (* c b) d) a) d)
(if (<= c 3.65e+59) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6e+52) {
tmp = t_1;
} else if (c <= -2.9e-137) {
tmp = t_0;
} else if (c <= 6e-161) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 3.65e+59) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
t_1 = (b - (d * (a / c))) / c
if (c <= (-6d+52)) then
tmp = t_1
else if (c <= (-2.9d-137)) then
tmp = t_0
else if (c <= 6d-161) then
tmp = (((c * b) / d) - a) / d
else if (c <= 3.65d+59) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double t_1 = (b - (d * (a / c))) / c;
double tmp;
if (c <= -6e+52) {
tmp = t_1;
} else if (c <= -2.9e-137) {
tmp = t_0;
} else if (c <= 6e-161) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 3.65e+59) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)) t_1 = (b - (d * (a / c))) / c tmp = 0 if c <= -6e+52: tmp = t_1 elif c <= -2.9e-137: tmp = t_0 elif c <= 6e-161: tmp = (((c * b) / d) - a) / d elif c <= 3.65e+59: tmp = t_0 else: tmp = t_1 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))) t_1 = Float64(Float64(b - Float64(d * Float64(a / c))) / c) tmp = 0.0 if (c <= -6e+52) tmp = t_1; elseif (c <= -2.9e-137) tmp = t_0; elseif (c <= 6e-161) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); elseif (c <= 3.65e+59) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d)); t_1 = (b - (d * (a / c))) / c; tmp = 0.0; if (c <= -6e+52) tmp = t_1; elseif (c <= -2.9e-137) tmp = t_0; elseif (c <= 6e-161) tmp = (((c * b) / d) - a) / d; elseif (c <= 3.65e+59) tmp = t_0; else tmp = t_1; end tmp_2 = 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]}, Block[{t$95$1 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6e+52], t$95$1, If[LessEqual[c, -2.9e-137], t$95$0, If[LessEqual[c, 6e-161], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.65e+59], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -6 \cdot 10^{+52}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -2.9 \cdot 10^{-137}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 6 \cdot 10^{-161}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 3.65 \cdot 10^{+59}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -6e52 or 3.6500000000000001e59 < c Initial program 37.6%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6480.3
Applied rewrites80.3%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6485.8
Applied rewrites85.8%
if -6e52 < c < -2.89999999999999985e-137 or 5.99999999999999977e-161 < c < 3.6500000000000001e59Initial program 84.2%
if -2.89999999999999985e-137 < c < 5.99999999999999977e-161Initial program 69.4%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6496.0
Applied rewrites96.0%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6496.0
Applied rewrites96.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -2.45e+136)
(/ b c)
(if (<= c -2.2e-79)
(/ (- (* b c) (* a d)) (* c c))
(if (<= c 4e-13) (/ (- (/ (* c b) d) a) d) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.45e+136) {
tmp = b / c;
} else if (c <= -2.2e-79) {
tmp = ((b * c) - (a * d)) / (c * c);
} else if (c <= 4e-13) {
tmp = (((c * b) / d) - a) / d;
} else {
tmp = b / 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(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 (c <= (-2.45d+136)) then
tmp = b / c
else if (c <= (-2.2d-79)) then
tmp = ((b * c) - (a * d)) / (c * c)
else if (c <= 4d-13) then
tmp = (((c * b) / d) - a) / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.45e+136) {
tmp = b / c;
} else if (c <= -2.2e-79) {
tmp = ((b * c) - (a * d)) / (c * c);
} else if (c <= 4e-13) {
tmp = (((c * b) / d) - a) / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -2.45e+136: tmp = b / c elif c <= -2.2e-79: tmp = ((b * c) - (a * d)) / (c * c) elif c <= 4e-13: tmp = (((c * b) / d) - a) / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -2.45e+136) tmp = Float64(b / c); elseif (c <= -2.2e-79) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c)); elseif (c <= 4e-13) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -2.45e+136) tmp = b / c; elseif (c <= -2.2e-79) tmp = ((b * c) - (a * d)) / (c * c); elseif (c <= 4e-13) tmp = (((c * b) / d) - a) / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.45e+136], N[(b / c), $MachinePrecision], If[LessEqual[c, -2.2e-79], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e-13], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{+136}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -2.2 \cdot 10^{-79}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-13}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -2.45000000000000006e136 or 4.0000000000000001e-13 < c Initial program 43.3%
Taylor expanded in c around inf
lower-/.f6470.9
Applied rewrites70.9%
if -2.45000000000000006e136 < c < -2.1999999999999999e-79Initial program 75.8%
Taylor expanded in c around inf
pow2N/A
lift-*.f6466.7
Applied rewrites66.7%
if -2.1999999999999999e-79 < c < 4.0000000000000001e-13Initial program 74.1%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6485.3
Applied rewrites85.3%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6485.3
Applied rewrites85.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3.5e-76) (not (<= c 6.5e-20))) (/ (- b (* d (/ a c))) c) (/ (- (/ (* c b) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.5e-76) || !(c <= 6.5e-20)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((c * b) / d) - a) / 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 ((c <= (-3.5d-76)) .or. (.not. (c <= 6.5d-20))) then
tmp = (b - (d * (a / c))) / c
else
tmp = (((c * b) / d) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3.5e-76) || !(c <= 6.5e-20)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = (((c * b) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3.5e-76) or not (c <= 6.5e-20): tmp = (b - (d * (a / c))) / c else: tmp = (((c * b) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3.5e-76) || !(c <= 6.5e-20)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); else tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -3.5e-76) || ~((c <= 6.5e-20))) tmp = (b - (d * (a / c))) / c; else tmp = (((c * b) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.5e-76], N[Not[LessEqual[c, 6.5e-20]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.5 \cdot 10^{-76} \lor \neg \left(c \leq 6.5 \cdot 10^{-20}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -3.49999999999999997e-76 or 6.50000000000000032e-20 < c Initial program 50.4%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6478.2
Applied rewrites78.2%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6481.7
Applied rewrites81.7%
if -3.49999999999999997e-76 < c < 6.50000000000000032e-20Initial program 74.1%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6485.3
Applied rewrites85.3%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6485.3
Applied rewrites85.3%
Final simplification83.2%
(FPCore (a b c d) :precision binary64 (if (<= c -2.1e-79) (/ (fma a (/ d c) (- b)) (- c)) (if (<= c 6.5e-20) (/ (- (/ (* c b) d) a) d) (/ (- b (* d (/ a c))) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -2.1e-79) {
tmp = fma(a, (d / c), -b) / -c;
} else if (c <= 6.5e-20) {
tmp = (((c * b) / d) - a) / d;
} else {
tmp = (b - (d * (a / c))) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -2.1e-79) tmp = Float64(fma(a, Float64(d / c), Float64(-b)) / Float64(-c)); elseif (c <= 6.5e-20) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); else tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.1e-79], N[(N[(a * N[(d / c), $MachinePrecision] + (-b)), $MachinePrecision] / (-c)), $MachinePrecision], If[LessEqual[c, 6.5e-20], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.1 \cdot 10^{-79}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{d}{c}, -b\right)}{-c}\\
\mathbf{elif}\;c \leq 6.5 \cdot 10^{-20}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\end{array}
\end{array}
if c < -2.0999999999999999e-79Initial program 49.4%
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.8
Applied rewrites83.8%
if -2.0999999999999999e-79 < c < 6.50000000000000032e-20Initial program 73.9%
Taylor expanded in d around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6486.1
Applied rewrites86.1%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6486.1
Applied rewrites86.1%
if 6.50000000000000032e-20 < c Initial program 52.1%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6477.7
Applied rewrites77.7%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6480.5
Applied rewrites80.5%
Final simplification83.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2e+71) (not (<= d 3.15e+50))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2e+71) || !(d <= 3.15e+50)) {
tmp = -a / d;
} else {
tmp = b / 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(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 <= (-2d+71)) .or. (.not. (d <= 3.15d+50))) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2e+71) || !(d <= 3.15e+50)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2e+71) or not (d <= 3.15e+50): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2e+71) || !(d <= 3.15e+50)) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2e+71) || ~((d <= 3.15e+50))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2e+71], N[Not[LessEqual[d, 3.15e+50]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{+71} \lor \neg \left(d \leq 3.15 \cdot 10^{+50}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.0000000000000001e71 or 3.14999999999999993e50 < d Initial program 39.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6468.0
Applied rewrites68.0%
if -2.0000000000000001e71 < d < 3.14999999999999993e50Initial program 72.3%
Taylor expanded in c around inf
lower-/.f6465.9
Applied rewrites65.9%
Final simplification66.6%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / 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 = b / c
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 60.6%
Taylor expanded in c around inf
lower-/.f6448.6
Applied rewrites48.6%
herbie shell --seed 2025085
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (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))))