
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= d -7.2e+114)
(+ (* (/ a d) (/ c d)) (/ b d))
(if (<= d -4.2e-74)
t_0
(if (<= d 7.5e-145)
(/ (+ (/ (* d b) c) a) c)
(if (<= d 3.7e+102) t_0 (/ (+ (* c (/ a d)) b) d)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -7.2e+114) {
tmp = ((a / d) * (c / d)) + (b / d);
} else if (d <= -4.2e-74) {
tmp = t_0;
} else if (d <= 7.5e-145) {
tmp = (((d * b) / c) + a) / c;
} else if (d <= 3.7e+102) {
tmp = t_0;
} else {
tmp = ((c * (a / d)) + b) / d;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
if (d <= (-7.2d+114)) then
tmp = ((a / d) * (c / d)) + (b / d)
else if (d <= (-4.2d-74)) then
tmp = t_0
else if (d <= 7.5d-145) then
tmp = (((d * b) / c) + a) / c
else if (d <= 3.7d+102) then
tmp = t_0
else
tmp = ((c * (a / d)) + b) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (d <= -7.2e+114) {
tmp = ((a / d) * (c / d)) + (b / d);
} else if (d <= -4.2e-74) {
tmp = t_0;
} else if (d <= 7.5e-145) {
tmp = (((d * b) / c) + a) / c;
} else if (d <= 3.7e+102) {
tmp = t_0;
} else {
tmp = ((c * (a / d)) + b) / d;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) tmp = 0 if d <= -7.2e+114: tmp = ((a / d) * (c / d)) + (b / d) elif d <= -4.2e-74: tmp = t_0 elif d <= 7.5e-145: tmp = (((d * b) / c) + a) / c elif d <= 3.7e+102: tmp = t_0 else: tmp = ((c * (a / d)) + b) / d return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (d <= -7.2e+114) tmp = Float64(Float64(Float64(a / d) * Float64(c / d)) + Float64(b / d)); elseif (d <= -4.2e-74) tmp = t_0; elseif (d <= 7.5e-145) tmp = Float64(Float64(Float64(Float64(d * b) / c) + a) / c); elseif (d <= 3.7e+102) tmp = t_0; else tmp = Float64(Float64(Float64(c * Float64(a / d)) + b) / d); end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); tmp = 0.0; if (d <= -7.2e+114) tmp = ((a / d) * (c / d)) + (b / d); elseif (d <= -4.2e-74) tmp = t_0; elseif (d <= 7.5e-145) tmp = (((d * b) / c) + a) / c; elseif (d <= 3.7e+102) tmp = t_0; else tmp = ((c * (a / d)) + b) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.2e+114], N[(N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -4.2e-74], t$95$0, If[LessEqual[d, 7.5e-145], N[(N[(N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.7e+102], t$95$0, N[(N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{+114}:\\
\;\;\;\;\frac{a}{d} \cdot \frac{c}{d} + \frac{b}{d}\\
\mathbf{elif}\;d \leq -4.2 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{-145}:\\
\;\;\;\;\frac{\frac{d \cdot b}{c} + a}{c}\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{a}{d} + b}{d}\\
\end{array}
\end{array}
if d < -7.2000000000000001e114Initial program 44.2%
Taylor expanded in c around 0
+-commutativeN/A
lower-+.f64N/A
pow2N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6486.6
Applied rewrites86.6%
if -7.2000000000000001e114 < d < -4.2e-74 or 7.4999999999999996e-145 < d < 3.70000000000000023e102Initial program 81.7%
if -4.2e-74 < d < 7.4999999999999996e-145Initial program 68.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6489.0
Applied rewrites89.0%
if 3.70000000000000023e102 < d Initial program 44.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.5
Applied rewrites91.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6491.5
Applied rewrites91.5%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(t_1 (/ (+ (* c (/ a d)) b) d)))
(if (<= d -7.2e+114)
t_1
(if (<= d -4.2e-74)
t_0
(if (<= d 7.5e-145)
(/ (+ (/ (* d b) c) a) c)
(if (<= d 3.7e+102) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = ((c * (a / d)) + b) / d;
double tmp;
if (d <= -7.2e+114) {
tmp = t_1;
} else if (d <= -4.2e-74) {
tmp = t_0;
} else if (d <= 7.5e-145) {
tmp = (((d * b) / c) + a) / c;
} else if (d <= 3.7e+102) {
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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
t_1 = ((c * (a / d)) + b) / d
if (d <= (-7.2d+114)) then
tmp = t_1
else if (d <= (-4.2d-74)) then
tmp = t_0
else if (d <= 7.5d-145) then
tmp = (((d * b) / c) + a) / c
else if (d <= 3.7d+102) 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 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double t_1 = ((c * (a / d)) + b) / d;
double tmp;
if (d <= -7.2e+114) {
tmp = t_1;
} else if (d <= -4.2e-74) {
tmp = t_0;
} else if (d <= 7.5e-145) {
tmp = (((d * b) / c) + a) / c;
} else if (d <= 3.7e+102) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)) t_1 = ((c * (a / d)) + b) / d tmp = 0 if d <= -7.2e+114: tmp = t_1 elif d <= -4.2e-74: tmp = t_0 elif d <= 7.5e-145: tmp = (((d * b) / c) + a) / c elif d <= 3.7e+102: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(Float64(c * Float64(a / d)) + b) / d) tmp = 0.0 if (d <= -7.2e+114) tmp = t_1; elseif (d <= -4.2e-74) tmp = t_0; elseif (d <= 7.5e-145) tmp = Float64(Float64(Float64(Float64(d * b) / c) + a) / c); elseif (d <= 3.7e+102) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d)); t_1 = ((c * (a / d)) + b) / d; tmp = 0.0; if (d <= -7.2e+114) tmp = t_1; elseif (d <= -4.2e-74) tmp = t_0; elseif (d <= 7.5e-145) tmp = (((d * b) / c) + a) / c; elseif (d <= 3.7e+102) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7.2e+114], t$95$1, If[LessEqual[d, -4.2e-74], t$95$0, If[LessEqual[d, 7.5e-145], N[(N[(N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.7e+102], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{c \cdot \frac{a}{d} + b}{d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{+114}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -4.2 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{-145}:\\
\;\;\;\;\frac{\frac{d \cdot b}{c} + a}{c}\\
\mathbf{elif}\;d \leq 3.7 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -7.2000000000000001e114 or 3.70000000000000023e102 < d Initial program 44.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6485.5
Applied rewrites85.5%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6489.3
Applied rewrites89.3%
if -7.2000000000000001e114 < d < -4.2e-74 or 7.4999999999999996e-145 < d < 3.70000000000000023e102Initial program 81.7%
if -4.2e-74 < d < 7.4999999999999996e-145Initial program 68.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6489.0
Applied rewrites89.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* (/ b c) (/ d c)) (/ a c))))
(if (<= c -9.2e+82)
t_0
(if (<= c -1.95e-135)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= c 2.05e+22) (/ (+ (/ (* c a) d) b) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = ((b / c) * (d / c)) + (a / c);
double tmp;
if (c <= -9.2e+82) {
tmp = t_0;
} else if (c <= -1.95e-135) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.05e+22) {
tmp = (((c * a) / d) + b) / d;
} else {
tmp = t_0;
}
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) :: tmp
t_0 = ((b / c) * (d / c)) + (a / c)
if (c <= (-9.2d+82)) then
tmp = t_0
else if (c <= (-1.95d-135)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (c <= 2.05d+22) then
tmp = (((c * a) / d) + b) / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((b / c) * (d / c)) + (a / c);
double tmp;
if (c <= -9.2e+82) {
tmp = t_0;
} else if (c <= -1.95e-135) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else if (c <= 2.05e+22) {
tmp = (((c * a) / d) + b) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((b / c) * (d / c)) + (a / c) tmp = 0 if c <= -9.2e+82: tmp = t_0 elif c <= -1.95e-135: tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)) elif c <= 2.05e+22: tmp = (((c * a) / d) + b) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(b / c) * Float64(d / c)) + Float64(a / c)) tmp = 0.0 if (c <= -9.2e+82) tmp = t_0; elseif (c <= -1.95e-135) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.05e+22) tmp = Float64(Float64(Float64(Float64(c * a) / d) + b) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((b / c) * (d / c)) + (a / c); tmp = 0.0; if (c <= -9.2e+82) tmp = t_0; elseif (c <= -1.95e-135) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); elseif (c <= 2.05e+22) tmp = (((c * a) / d) + b) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -9.2e+82], t$95$0, If[LessEqual[c, -1.95e-135], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.05e+22], N[(N[(N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{c} \cdot \frac{d}{c} + \frac{a}{c}\\
\mathbf{if}\;c \leq -9.2 \cdot 10^{+82}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1.95 \cdot 10^{-135}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.05 \cdot 10^{+22}:\\
\;\;\;\;\frac{\frac{c \cdot a}{d} + b}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -9.19999999999999953e82 or 2.0499999999999999e22 < c Initial program 49.7%
Taylor expanded in d around 0
+-commutativeN/A
lower-+.f64N/A
pow2N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
if -9.19999999999999953e82 < c < -1.95000000000000011e-135Initial program 83.1%
if -1.95000000000000011e-135 < c < 2.0499999999999999e22Initial program 72.1%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6486.2
Applied rewrites86.2%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.5e-61) (not (<= d 5.4e+18))) (/ (+ (* c (/ a d)) b) d) (/ (+ (/ (* d b) c) a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.5e-61) || !(d <= 5.4e+18)) {
tmp = ((c * (a / d)) + b) / d;
} else {
tmp = (((d * b) / c) + a) / 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 <= (-2.5d-61)) .or. (.not. (d <= 5.4d+18))) then
tmp = ((c * (a / d)) + b) / d
else
tmp = (((d * b) / c) + a) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.5e-61) || !(d <= 5.4e+18)) {
tmp = ((c * (a / d)) + b) / d;
} else {
tmp = (((d * b) / c) + a) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.5e-61) or not (d <= 5.4e+18): tmp = ((c * (a / d)) + b) / d else: tmp = (((d * b) / c) + a) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.5e-61) || !(d <= 5.4e+18)) tmp = Float64(Float64(Float64(c * Float64(a / d)) + b) / d); else tmp = Float64(Float64(Float64(Float64(d * b) / c) + a) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.5e-61) || ~((d <= 5.4e+18))) tmp = ((c * (a / d)) + b) / d; else tmp = (((d * b) / c) + a) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.5e-61], N[Not[LessEqual[d, 5.4e+18]], $MachinePrecision]], N[(N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.5 \cdot 10^{-61} \lor \neg \left(d \leq 5.4 \cdot 10^{+18}\right):\\
\;\;\;\;\frac{c \cdot \frac{a}{d} + b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{d \cdot b}{c} + a}{c}\\
\end{array}
\end{array}
if d < -2.4999999999999999e-61 or 5.4e18 < d Initial program 59.3%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6476.8
Applied rewrites76.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
if -2.4999999999999999e-61 < d < 5.4e18Initial program 73.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6482.1
Applied rewrites82.1%
Final simplification80.5%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.2e+82) (not (<= c 2.1e+71))) (/ a c) (/ (+ (/ (* c a) d) b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e+82) || !(c <= 2.1e+71)) {
tmp = a / c;
} else {
tmp = (((c * a) / d) + b) / d;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.2d+82)) .or. (.not. (c <= 2.1d+71))) then
tmp = a / c
else
tmp = (((c * a) / d) + b) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e+82) || !(c <= 2.1e+71)) {
tmp = a / c;
} else {
tmp = (((c * a) / d) + b) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.2e+82) or not (c <= 2.1e+71): tmp = a / c else: tmp = (((c * a) / d) + b) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.2e+82) || !(c <= 2.1e+71)) tmp = Float64(a / c); else tmp = Float64(Float64(Float64(Float64(c * a) / d) + b) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.2e+82) || ~((c <= 2.1e+71))) tmp = a / c; else tmp = (((c * a) / d) + b) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.2e+82], N[Not[LessEqual[c, 2.1e+71]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{+82} \lor \neg \left(c \leq 2.1 \cdot 10^{+71}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{c \cdot a}{d} + b}{d}\\
\end{array}
\end{array}
if c < -5.1999999999999997e82 or 2.09999999999999989e71 < c Initial program 46.3%
Taylor expanded in c around inf
lower-/.f6478.0
Applied rewrites78.0%
if -5.1999999999999997e82 < c < 2.09999999999999989e71Initial program 76.3%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.2
Applied rewrites75.2%
Final simplification76.2%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.4e+82) (not (<= c 3.1e+71))) (/ a c) (/ (+ (* c (/ a d)) b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.4e+82) || !(c <= 3.1e+71)) {
tmp = a / c;
} else {
tmp = ((c * (a / d)) + b) / d;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.4d+82)) .or. (.not. (c <= 3.1d+71))) then
tmp = a / c
else
tmp = ((c * (a / d)) + b) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.4e+82) || !(c <= 3.1e+71)) {
tmp = a / c;
} else {
tmp = ((c * (a / d)) + b) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.4e+82) or not (c <= 3.1e+71): tmp = a / c else: tmp = ((c * (a / d)) + b) / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.4e+82) || !(c <= 3.1e+71)) tmp = Float64(a / c); else tmp = Float64(Float64(Float64(c * Float64(a / d)) + b) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.4e+82) || ~((c <= 3.1e+71))) tmp = a / c; else tmp = ((c * (a / d)) + b) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.4e+82], N[Not[LessEqual[c, 3.1e+71]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.4 \cdot 10^{+82} \lor \neg \left(c \leq 3.1 \cdot 10^{+71}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{a}{d} + b}{d}\\
\end{array}
\end{array}
if c < -5.3999999999999999e82 or 3.10000000000000018e71 < c Initial program 46.3%
Taylor expanded in c around inf
lower-/.f6478.0
Applied rewrites78.0%
if -5.3999999999999999e82 < c < 3.10000000000000018e71Initial program 76.3%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.2
Applied rewrites75.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6472.7
Applied rewrites72.7%
Final simplification74.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -9.2e+82)
(/ a c)
(if (<= c -1.55e-117)
(/ (* c a) (+ (* c c) (* d d)))
(if (<= c 2.05e+22) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9.2e+82) {
tmp = a / c;
} else if (c <= -1.55e-117) {
tmp = (c * a) / ((c * c) + (d * d));
} else if (c <= 2.05e+22) {
tmp = b / d;
} else {
tmp = a / 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 <= (-9.2d+82)) then
tmp = a / c
else if (c <= (-1.55d-117)) then
tmp = (c * a) / ((c * c) + (d * d))
else if (c <= 2.05d+22) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9.2e+82) {
tmp = a / c;
} else if (c <= -1.55e-117) {
tmp = (c * a) / ((c * c) + (d * d));
} else if (c <= 2.05e+22) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -9.2e+82: tmp = a / c elif c <= -1.55e-117: tmp = (c * a) / ((c * c) + (d * d)) elif c <= 2.05e+22: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -9.2e+82) tmp = Float64(a / c); elseif (c <= -1.55e-117) tmp = Float64(Float64(c * a) / Float64(Float64(c * c) + Float64(d * d))); elseif (c <= 2.05e+22) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -9.2e+82) tmp = a / c; elseif (c <= -1.55e-117) tmp = (c * a) / ((c * c) + (d * d)); elseif (c <= 2.05e+22) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -9.2e+82], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.55e-117], N[(N[(c * a), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.05e+22], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.2 \cdot 10^{+82}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.55 \cdot 10^{-117}:\\
\;\;\;\;\frac{c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;c \leq 2.05 \cdot 10^{+22}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -9.19999999999999953e82 or 2.0499999999999999e22 < c Initial program 49.7%
Taylor expanded in c around inf
lower-/.f6474.8
Applied rewrites74.8%
if -9.19999999999999953e82 < c < -1.55000000000000005e-117Initial program 81.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f6455.5
Applied rewrites55.5%
if -1.55000000000000005e-117 < c < 2.0499999999999999e22Initial program 73.3%
Taylor expanded in c around 0
lower-/.f6467.8
Applied rewrites67.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -5.2e+82) (not (<= c 2.05e+22))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e+82) || !(c <= 2.05e+22)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if ((c <= (-5.2d+82)) .or. (.not. (c <= 2.05d+22))) then
tmp = a / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -5.2e+82) || !(c <= 2.05e+22)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -5.2e+82) or not (c <= 2.05e+22): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -5.2e+82) || !(c <= 2.05e+22)) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((c <= -5.2e+82) || ~((c <= 2.05e+22))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -5.2e+82], N[Not[LessEqual[c, 2.05e+22]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{+82} \lor \neg \left(c \leq 2.05 \cdot 10^{+22}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -5.1999999999999997e82 or 2.0499999999999999e22 < c Initial program 49.7%
Taylor expanded in c around inf
lower-/.f6474.8
Applied rewrites74.8%
if -5.1999999999999997e82 < c < 2.0499999999999999e22Initial program 75.7%
Taylor expanded in c around 0
lower-/.f6458.5
Applied rewrites58.5%
Final simplification64.6%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 66.0%
Taylor expanded in c around inf
lower-/.f6442.4
Applied rewrites42.4%
herbie shell --seed 2025058
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))