
(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 11 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 -8.8e-13)
t_0
(if (<= c 1.5e-110)
(/ (fma b (/ c d) (- a)) d)
(if (<= c 31000000000.0)
(/ (- (* b c) (* a d)) (fma 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 <= -8.8e-13) {
tmp = t_0;
} else if (c <= 1.5e-110) {
tmp = fma(b, (c / d), -a) / d;
} else if (c <= 31000000000.0) {
tmp = ((b * c) - (a * d)) / fma(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 <= -8.8e-13) tmp = t_0; elseif (c <= 1.5e-110) tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d); elseif (c <= 31000000000.0) tmp = Float64(Float64(Float64(b * c) - Float64(a * 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[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -8.8e-13], t$95$0, If[LessEqual[c, 1.5e-110], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 31000000000.0], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + 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 -8.8 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.5 \cdot 10^{-110}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{elif}\;c \leq 31000000000:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -8.79999999999999986e-13 or 3.1e10 < c Initial program 48.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-*.f6476.5
Applied rewrites76.5%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6483.2
Applied rewrites83.2%
if -8.79999999999999986e-13 < c < 1.49999999999999993e-110Initial program 77.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.f6487.8
Applied rewrites87.8%
if 1.49999999999999993e-110 < c < 3.1e10Initial program 81.6%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6481.6
Applied rewrites81.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (* b c) (* a d))))
(if (<= c -1.26e+107)
(/ b c)
(if (<= c -6e-134)
(/ (fma (- a) d (* c b)) (* c c))
(if (<= c 7.8e-177)
(/ t_0 (* d d))
(if (<= c 4e-86)
(/ (- a) d)
(if (<= c 1.25e+101) (/ t_0 (* c c)) (/ b c))))))))
double code(double a, double b, double c, double d) {
double t_0 = (b * c) - (a * d);
double tmp;
if (c <= -1.26e+107) {
tmp = b / c;
} else if (c <= -6e-134) {
tmp = fma(-a, d, (c * b)) / (c * c);
} else if (c <= 7.8e-177) {
tmp = t_0 / (d * d);
} else if (c <= 4e-86) {
tmp = -a / d;
} else if (c <= 1.25e+101) {
tmp = t_0 / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(b * c) - Float64(a * d)) tmp = 0.0 if (c <= -1.26e+107) tmp = Float64(b / c); elseif (c <= -6e-134) tmp = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c)); elseif (c <= 7.8e-177) tmp = Float64(t_0 / Float64(d * d)); elseif (c <= 4e-86) tmp = Float64(Float64(-a) / d); elseif (c <= 1.25e+101) tmp = Float64(t_0 / Float64(c * c)); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -6e-134], N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.8e-177], N[(t$95$0 / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.25e+101], N[(t$95$0 / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
\mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -6 \cdot 10^{-134}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\
\mathbf{elif}\;c \leq 7.8 \cdot 10^{-177}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{+101}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.25999999999999995e107 or 1.24999999999999997e101 < c Initial program 34.1%
Taylor expanded in c around inf
lower-/.f6476.0
Applied rewrites76.0%
if -1.25999999999999995e107 < c < -6e-134Initial program 76.9%
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-*.f6462.1
Applied rewrites62.1%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6460.0
Applied rewrites60.0%
if -6e-134 < c < 7.80000000000000028e-177Initial program 82.5%
Taylor expanded in c around 0
pow2N/A
lift-*.f6480.7
Applied rewrites80.7%
if 7.80000000000000028e-177 < c < 4.00000000000000034e-86Initial program 72.2%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6479.5
Applied rewrites79.5%
if 4.00000000000000034e-86 < c < 1.24999999999999997e101Initial program 76.1%
Taylor expanded in c around inf
pow2N/A
lift-*.f6464.9
Applied rewrites64.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) d (* c b)) (* c c))))
(if (<= c -1.26e+107)
(/ b c)
(if (<= c -8.8e-13)
t_0
(if (<= c 1.9e-78)
(/ (- (/ (* c b) d) a) d)
(if (<= c 1.02e+104) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, d, (c * b)) / (c * c);
double tmp;
if (c <= -1.26e+107) {
tmp = b / c;
} else if (c <= -8.8e-13) {
tmp = t_0;
} else if (c <= 1.9e-78) {
tmp = (((c * b) / d) - a) / d;
} else if (c <= 1.02e+104) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c)) tmp = 0.0 if (c <= -1.26e+107) tmp = Float64(b / c); elseif (c <= -8.8e-13) tmp = t_0; elseif (c <= 1.9e-78) tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d); elseif (c <= 1.02e+104) tmp = t_0; else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -8.8e-13], t$95$0, If[LessEqual[c, 1.9e-78], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.02e+104], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\
\mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -8.8 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{-78}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.02 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.25999999999999995e107 or 1.02e104 < c Initial program 34.4%
Taylor expanded in c around inf
lower-/.f6476.8
Applied rewrites76.8%
if -1.25999999999999995e107 < c < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c < 1.02e104Initial program 74.5%
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-*.f6471.7
Applied rewrites71.7%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6467.2
Applied rewrites67.2%
if -8.79999999999999986e-13 < c < 1.8999999999999999e-78Initial program 79.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.8
Applied rewrites85.8%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6485.8
Applied rewrites85.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.26e+107)
(/ b c)
(if (<= c -4.6e-134)
(/ (fma (- a) d (* c b)) (* c c))
(if (<= c 4e-86)
(/ (- a) d)
(if (<= c 1.25e+101) (/ (- (* b c) (* a d)) (* c c)) (/ b c))))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.26e+107) {
tmp = b / c;
} else if (c <= -4.6e-134) {
tmp = fma(-a, d, (c * b)) / (c * c);
} else if (c <= 4e-86) {
tmp = -a / d;
} else if (c <= 1.25e+101) {
tmp = ((b * c) - (a * d)) / (c * c);
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.26e+107) tmp = Float64(b / c); elseif (c <= -4.6e-134) tmp = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c)); elseif (c <= 4e-86) tmp = Float64(Float64(-a) / d); elseif (c <= 1.25e+101) tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(c * c)); else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.6e-134], N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.25e+101], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -4.6 \cdot 10^{-134}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 1.25 \cdot 10^{+101}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.25999999999999995e107 or 1.24999999999999997e101 < c Initial program 34.1%
Taylor expanded in c around inf
lower-/.f6476.0
Applied rewrites76.0%
if -1.25999999999999995e107 < c < -4.6000000000000001e-134Initial program 76.9%
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-*.f6462.1
Applied rewrites62.1%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6460.0
Applied rewrites60.0%
if -4.6000000000000001e-134 < c < 4.00000000000000034e-86Initial program 79.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6474.5
Applied rewrites74.5%
if 4.00000000000000034e-86 < c < 1.24999999999999997e101Initial program 76.1%
Taylor expanded in c around inf
pow2N/A
lift-*.f6464.9
Applied rewrites64.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (- a) d (* c b)) (* c c))))
(if (<= c -1.26e+107)
(/ b c)
(if (<= c -4.6e-134)
t_0
(if (<= c 4e-86) (/ (- a) d) (if (<= c 1.02e+104) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(-a, d, (c * b)) / (c * c);
double tmp;
if (c <= -1.26e+107) {
tmp = b / c;
} else if (c <= -4.6e-134) {
tmp = t_0;
} else if (c <= 4e-86) {
tmp = -a / d;
} else if (c <= 1.02e+104) {
tmp = t_0;
} else {
tmp = b / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(-a), d, Float64(c * b)) / Float64(c * c)) tmp = 0.0 if (c <= -1.26e+107) tmp = Float64(b / c); elseif (c <= -4.6e-134) tmp = t_0; elseif (c <= 4e-86) tmp = Float64(Float64(-a) / d); elseif (c <= 1.02e+104) tmp = t_0; else tmp = Float64(b / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[((-a) * d + N[(c * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.26e+107], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.6e-134], t$95$0, If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 1.02e+104], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-a, d, c \cdot b\right)}{c \cdot c}\\
\mathbf{if}\;c \leq -1.26 \cdot 10^{+107}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -4.6 \cdot 10^{-134}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{elif}\;c \leq 1.02 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -1.25999999999999995e107 or 1.02e104 < c Initial program 34.4%
Taylor expanded in c around inf
lower-/.f6476.8
Applied rewrites76.8%
if -1.25999999999999995e107 < c < -4.6000000000000001e-134 or 4.00000000000000034e-86 < c < 1.02e104Initial program 75.8%
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-*.f6464.8
Applied rewrites64.8%
Taylor expanded in c around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
cancel-sign-sub-invN/A
lower-/.f64N/A
cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
mul-1-negN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lift-*.f6461.5
Applied rewrites61.5%
if -4.6000000000000001e-134 < c < 4.00000000000000034e-86Initial program 79.1%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6474.5
Applied rewrites74.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8.8e-13) (not (<= c 1.9e-78))) (/ (- b (* d (/ a c))) c) (/ (fma b (/ c d) (- a)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.8e-13) || !(c <= 1.9e-78)) {
tmp = (b - (d * (a / c))) / c;
} else {
tmp = fma(b, (c / d), -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -8.8e-13) || !(c <= 1.9e-78)) tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / 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, -8.8e-13], N[Not[LessEqual[c, 1.9e-78]], $MachinePrecision]], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\end{array}
\end{array}
if c < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c Initial program 51.5%
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-*.f6474.7
Applied rewrites74.7%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6480.0
Applied rewrites80.0%
if -8.79999999999999986e-13 < c < 1.8999999999999999e-78Initial program 79.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.f6486.0
Applied rewrites86.0%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8.8e-13) (not (<= c 1.9e-78))) (/ (- b (* d (/ a c))) c) (/ (- (/ (* c b) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.8e-13) || !(c <= 1.9e-78)) {
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 <= (-8.8d-13)) .or. (.not. (c <= 1.9d-78))) 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 <= -8.8e-13) || !(c <= 1.9e-78)) {
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 <= -8.8e-13) or not (c <= 1.9e-78): 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 <= -8.8e-13) || !(c <= 1.9e-78)) 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 <= -8.8e-13) || ~((c <= 1.9e-78))) 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, -8.8e-13], N[Not[LessEqual[c, 1.9e-78]], $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 -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\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 < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c Initial program 51.5%
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-*.f6474.7
Applied rewrites74.7%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6480.0
Applied rewrites80.0%
if -8.79999999999999986e-13 < c < 1.8999999999999999e-78Initial program 79.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.8
Applied rewrites85.8%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6485.8
Applied rewrites85.8%
Final simplification82.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -8.8e-13) (not (<= c 1.9e-78))) (/ (- b (* a (/ d c))) c) (/ (- (/ (* c b) d) a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -8.8e-13) || !(c <= 1.9e-78)) {
tmp = (b - (a * (d / 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 <= (-8.8d-13)) .or. (.not. (c <= 1.9d-78))) then
tmp = (b - (a * (d / 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 <= -8.8e-13) || !(c <= 1.9e-78)) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = (((c * b) / d) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -8.8e-13) or not (c <= 1.9e-78): tmp = (b - (a * (d / c))) / c else: tmp = (((c * b) / d) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -8.8e-13) || !(c <= 1.9e-78)) tmp = Float64(Float64(b - Float64(a * Float64(d / 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 <= -8.8e-13) || ~((c <= 1.9e-78))) tmp = (b - (a * (d / c))) / c; else tmp = (((c * b) / d) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -8.8e-13], N[Not[LessEqual[c, 1.9e-78]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / 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 -8.8 \cdot 10^{-13} \lor \neg \left(c \leq 1.9 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\
\end{array}
\end{array}
if c < -8.79999999999999986e-13 or 1.8999999999999999e-78 < c Initial program 51.5%
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-*.f6474.7
Applied rewrites74.7%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6479.3
Applied rewrites79.3%
if -8.79999999999999986e-13 < c < 1.8999999999999999e-78Initial program 79.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.8
Applied rewrites85.8%
Taylor expanded in d around inf
lower-/.f64N/A
lower--.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6485.8
Applied rewrites85.8%
Final simplification82.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -4.7e+35)
(/ b c)
(if (<= c -4.1e-12)
(/ (* (- a) d) (* c c))
(if (<= c 4e-86) (/ (- a) d) (/ b c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.7e+35) {
tmp = b / c;
} else if (c <= -4.1e-12) {
tmp = (-a * d) / (c * c);
} else if (c <= 4e-86) {
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 (c <= (-4.7d+35)) then
tmp = b / c
else if (c <= (-4.1d-12)) then
tmp = (-a * d) / (c * c)
else if (c <= 4d-86) 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 (c <= -4.7e+35) {
tmp = b / c;
} else if (c <= -4.1e-12) {
tmp = (-a * d) / (c * c);
} else if (c <= 4e-86) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.7e+35: tmp = b / c elif c <= -4.1e-12: tmp = (-a * d) / (c * c) elif c <= 4e-86: tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.7e+35) tmp = Float64(b / c); elseif (c <= -4.1e-12) tmp = Float64(Float64(Float64(-a) * d) / Float64(c * c)); elseif (c <= 4e-86) 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 (c <= -4.7e+35) tmp = b / c; elseif (c <= -4.1e-12) tmp = (-a * d) / (c * c); elseif (c <= 4e-86) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.7e+35], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.1e-12], N[(N[((-a) * d), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e-86], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.7 \cdot 10^{+35}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -4.1 \cdot 10^{-12}:\\
\;\;\;\;\frac{\left(-a\right) \cdot d}{c \cdot c}\\
\mathbf{elif}\;c \leq 4 \cdot 10^{-86}:\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if c < -4.70000000000000033e35 or 4.00000000000000034e-86 < c Initial program 49.2%
Taylor expanded in c around inf
lower-/.f6468.0
Applied rewrites68.0%
if -4.70000000000000033e35 < c < -4.0999999999999999e-12Initial program 84.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-*.f6476.9
Applied rewrites76.9%
Taylor expanded in a around inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lift-neg.f64N/A
pow2N/A
lift-*.f6460.3
Applied rewrites60.3%
if -4.0999999999999999e-12 < c < 4.00000000000000034e-86Initial program 78.6%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6467.8
Applied rewrites67.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.45e+14) (not (<= c 4e-86))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.45e+14) || !(c <= 4e-86)) {
tmp = b / c;
} else {
tmp = -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 <= (-1.45d+14)) .or. (.not. (c <= 4d-86))) then
tmp = b / c
else
tmp = -a / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.45e+14) || !(c <= 4e-86)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -1.45e+14) or not (c <= 4e-86): tmp = b / c else: tmp = -a / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.45e+14) || !(c <= 4e-86)) tmp = Float64(b / c); else tmp = Float64(Float64(-a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -1.45e+14) || ~((c <= 4e-86))) tmp = b / c; else tmp = -a / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.45e+14], N[Not[LessEqual[c, 4e-86]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{+14} \lor \neg \left(c \leq 4 \cdot 10^{-86}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\
\end{array}
\end{array}
if c < -1.45e14 or 4.00000000000000034e-86 < c Initial program 51.2%
Taylor expanded in c around inf
lower-/.f6465.3
Applied rewrites65.3%
if -1.45e14 < c < 4.00000000000000034e-86Initial program 78.7%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6466.5
Applied rewrites66.5%
Final simplification65.8%
(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 62.7%
Taylor expanded in c around inf
lower-/.f6445.5
Applied rewrites45.5%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / 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 (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2025037
(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))))