
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))) (t_1 (/ a t_0)))
(if (<= c -7.2e+109)
(/ (- b (* (/ a c) d)) c)
(if (<= c -2.5e-103)
(fma (/ c t_0) b (* t_1 (- d)))
(if (<= c 7.2e-42)
(/ (- (* (/ c d) b) a) d)
(if (<= c 9.2e+73)
(- (* (/ b t_0) c) (* t_1 d))
(/ (- b (* (/ d c) a)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = a / t_0;
double tmp;
if (c <= -7.2e+109) {
tmp = (b - ((a / c) * d)) / c;
} else if (c <= -2.5e-103) {
tmp = fma((c / t_0), b, (t_1 * -d));
} else if (c <= 7.2e-42) {
tmp = (((c / d) * b) - a) / d;
} else if (c <= 9.2e+73) {
tmp = ((b / t_0) * c) - (t_1 * d);
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(a / t_0) tmp = 0.0 if (c <= -7.2e+109) tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c); elseif (c <= -2.5e-103) tmp = fma(Float64(c / t_0), b, Float64(t_1 * Float64(-d))); elseif (c <= 7.2e-42) tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); elseif (c <= 9.2e+73) tmp = Float64(Float64(Float64(b / t_0) * c) - Float64(t_1 * d)); else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a / t$95$0), $MachinePrecision]}, If[LessEqual[c, -7.2e+109], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.5e-103], N[(N[(c / t$95$0), $MachinePrecision] * b + N[(t$95$1 * (-d)), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e-42], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9.2e+73], N[(N[(N[(b / t$95$0), $MachinePrecision] * c), $MachinePrecision] - N[(t$95$1 * d), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{a}{t\_0}\\
\mathbf{if}\;c \leq -7.2 \cdot 10^{+109}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{elif}\;c \leq -2.5 \cdot 10^{-103}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{t\_0}, b, t\_1 \cdot \left(-d\right)\right)\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\mathbf{elif}\;c \leq 9.2 \cdot 10^{+73}:\\
\;\;\;\;\frac{b}{t\_0} \cdot c - t\_1 \cdot d\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if c < -7.2e109Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6452.7
Applied rewrites52.7%
if -7.2e109 < c < -2.49999999999999983e-103Initial program 61.4%
lift-/.f64N/A
lift--.f64N/A
sub-flipN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites61.2%
if -2.49999999999999983e-103 < c < 7.2000000000000004e-42Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.9
Applied rewrites52.9%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.9
Applied rewrites54.9%
if 7.2000000000000004e-42 < c < 9.199999999999999e73Initial program 61.4%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
Applied rewrites58.7%
if 9.199999999999999e73 < c Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))) (t_1 (- (* (/ b t_0) c) (* (/ a t_0) d))))
(if (<= c -4.2e+110)
(/ (- b (* (/ a c) d)) c)
(if (<= c -2.5e-103)
t_1
(if (<= c 7.2e-42)
(/ (- (* (/ c d) b) a) d)
(if (<= c 9.2e+73) t_1 (/ (- b (* (/ d c) a)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double t_1 = ((b / t_0) * c) - ((a / t_0) * d);
double tmp;
if (c <= -4.2e+110) {
tmp = (b - ((a / c) * d)) / c;
} else if (c <= -2.5e-103) {
tmp = t_1;
} else if (c <= 7.2e-42) {
tmp = (((c / d) * b) - a) / d;
} else if (c <= 9.2e+73) {
tmp = t_1;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) t_1 = Float64(Float64(Float64(b / t_0) * c) - Float64(Float64(a / t_0) * d)) tmp = 0.0 if (c <= -4.2e+110) tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c); elseif (c <= -2.5e-103) tmp = t_1; elseif (c <= 7.2e-42) tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); elseif (c <= 9.2e+73) tmp = t_1; else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(b / t$95$0), $MachinePrecision] * c), $MachinePrecision] - N[(N[(a / t$95$0), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.2e+110], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.5e-103], t$95$1, If[LessEqual[c, 7.2e-42], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9.2e+73], t$95$1, N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
t_1 := \frac{b}{t\_0} \cdot c - \frac{a}{t\_0} \cdot d\\
\mathbf{if}\;c \leq -4.2 \cdot 10^{+110}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{elif}\;c \leq -2.5 \cdot 10^{-103}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq 7.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\mathbf{elif}\;c \leq 9.2 \cdot 10^{+73}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if c < -4.2000000000000003e110Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6452.7
Applied rewrites52.7%
if -4.2000000000000003e110 < c < -2.49999999999999983e-103 or 7.2000000000000004e-42 < c < 9.199999999999999e73Initial program 61.4%
lift-/.f64N/A
lift--.f64N/A
div-subN/A
lower--.f64N/A
Applied rewrites58.7%
if -2.49999999999999983e-103 < c < 7.2000000000000004e-42Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.9
Applied rewrites52.9%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.9
Applied rewrites54.9%
if 9.199999999999999e73 < c Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ 1.0 (/ (fma d d (* c c)) (- (* c b) (* d a))))))
(if (<= c -1.65e+105)
(/ (- b (* (/ a c) d)) c)
(if (<= c -4.6e-140)
t_0
(if (<= c 7.5e-42)
(/ (- (* (/ c d) b) a) d)
(if (<= c 8e+73) t_0 (/ (- b (* (/ d c) a)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = 1.0 / (fma(d, d, (c * c)) / ((c * b) - (d * a)));
double tmp;
if (c <= -1.65e+105) {
tmp = (b - ((a / c) * d)) / c;
} else if (c <= -4.6e-140) {
tmp = t_0;
} else if (c <= 7.5e-42) {
tmp = (((c / d) * b) - a) / d;
} else if (c <= 8e+73) {
tmp = t_0;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(1.0 / Float64(fma(d, d, Float64(c * c)) / Float64(Float64(c * b) - Float64(d * a)))) tmp = 0.0 if (c <= -1.65e+105) tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c); elseif (c <= -4.6e-140) tmp = t_0; elseif (c <= 7.5e-42) tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); elseif (c <= 8e+73) tmp = t_0; else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(1.0 / N[(N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.65e+105], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.6e-140], t$95$0, If[LessEqual[c, 7.5e-42], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+73], t$95$0, N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{c \cdot b - d \cdot a}}\\
\mathbf{if}\;c \leq -1.65 \cdot 10^{+105}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{elif}\;c \leq -4.6 \cdot 10^{-140}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{-42}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if c < -1.64999999999999999e105Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6452.7
Applied rewrites52.7%
if -1.64999999999999999e105 < c < -4.6000000000000002e-140 or 7.49999999999999972e-42 < c < 7.99999999999999986e73Initial program 61.4%
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6461.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
sqr-abs-revN/A
sqr-neg-revN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
distribute-lft-neg-inN/A
sqr-neg-revN/A
sqr-abs-revN/A
lift-*.f64N/A
remove-double-negN/A
lower-fma.f6461.2
Applied rewrites61.2%
if -4.6000000000000002e-140 < c < 7.49999999999999972e-42Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.9
Applied rewrites52.9%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.9
Applied rewrites54.9%
if 7.99999999999999986e73 < c Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- (* c b) (* d a)) (fma d d (* c c)))))
(if (<= c -1.65e+105)
(/ (- b (* (/ a c) d)) c)
(if (<= c -4.6e-140)
t_0
(if (<= c 7.5e-42)
(/ (- (* (/ c d) b) a) d)
(if (<= c 8e+73) t_0 (/ (- b (* (/ d c) a)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((c * b) - (d * a)) / fma(d, d, (c * c));
double tmp;
if (c <= -1.65e+105) {
tmp = (b - ((a / c) * d)) / c;
} else if (c <= -4.6e-140) {
tmp = t_0;
} else if (c <= 7.5e-42) {
tmp = (((c / d) * b) - a) / d;
} else if (c <= 8e+73) {
tmp = t_0;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / fma(d, d, Float64(c * c))) tmp = 0.0 if (c <= -1.65e+105) tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c); elseif (c <= -4.6e-140) tmp = t_0; elseif (c <= 7.5e-42) tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); elseif (c <= 8e+73) tmp = t_0; else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.65e+105], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.6e-140], t$95$0, If[LessEqual[c, 7.5e-42], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+73], t$95$0, N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;c \leq -1.65 \cdot 10^{+105}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{elif}\;c \leq -4.6 \cdot 10^{-140}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{-42}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if c < -1.64999999999999999e105Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6452.7
Applied rewrites52.7%
if -1.64999999999999999e105 < c < -4.6000000000000002e-140 or 7.49999999999999972e-42 < c < 7.99999999999999986e73Initial program 61.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6461.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6461.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
sqr-abs-revN/A
sqr-neg-revN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
distribute-lft-neg-inN/A
sqr-neg-revN/A
sqr-abs-revN/A
lift-*.f64N/A
remove-double-negN/A
lower-fma.f6461.4
Applied rewrites61.4%
if -4.6000000000000002e-140 < c < 7.49999999999999972e-42Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.9
Applied rewrites52.9%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.9
Applied rewrites54.9%
if 7.99999999999999986e73 < c Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- b (* (/ a c) d)) c)))
(if (<= c -3.2e-64)
t_0
(if (<= c 1.85e-41) (/ (- (* (/ c d) b) a) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b - ((a / c) * d)) / c;
double tmp;
if (c <= -3.2e-64) {
tmp = t_0;
} else if (c <= 1.85e-41) {
tmp = (((c / d) * b) - a) / 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 - ((a / c) * d)) / c
if (c <= (-3.2d-64)) then
tmp = t_0
else if (c <= 1.85d-41) then
tmp = (((c / d) * b) - a) / 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 - ((a / c) * d)) / c;
double tmp;
if (c <= -3.2e-64) {
tmp = t_0;
} else if (c <= 1.85e-41) {
tmp = (((c / d) * b) - a) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b - ((a / c) * d)) / c tmp = 0 if c <= -3.2e-64: tmp = t_0 elif c <= 1.85e-41: tmp = (((c / d) * b) - a) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b - Float64(Float64(a / c) * d)) / c) tmp = 0.0 if (c <= -3.2e-64) tmp = t_0; elseif (c <= 1.85e-41) tmp = Float64(Float64(Float64(Float64(c / d) * b) - a) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b - ((a / c) * d)) / c; tmp = 0.0; if (c <= -3.2e-64) tmp = t_0; elseif (c <= 1.85e-41) tmp = (((c / d) * b) - a) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.2e-64], t$95$0, If[LessEqual[c, 1.85e-41], N[(N[(N[(N[(c / d), $MachinePrecision] * b), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -3.2 \cdot 10^{-64}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.85 \cdot 10^{-41}:\\
\;\;\;\;\frac{\frac{c}{d} \cdot b - a}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.19999999999999975e-64 or 1.8500000000000001e-41 < c Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6452.7
Applied rewrites52.7%
if -3.19999999999999975e-64 < c < 1.8500000000000001e-41Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
lower--.f6452.9
Applied rewrites52.9%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6454.9
Applied rewrites54.9%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.7e+63)
t_0
(if (<= d 1.8e+134) (/ (- b (* (/ d c) a)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.7e+63) {
tmp = t_0;
} else if (d <= 1.8e+134) {
tmp = (b - ((d / c) * a)) / c;
} 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 = -a / d
if (d <= (-2.7d+63)) then
tmp = t_0
else if (d <= 1.8d+134) then
tmp = (b - ((d / c) * a)) / c
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 = -a / d;
double tmp;
if (d <= -2.7e+63) {
tmp = t_0;
} else if (d <= 1.8e+134) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -2.7e+63: tmp = t_0 elif d <= 1.8e+134: tmp = (b - ((d / c) * a)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.7e+63) tmp = t_0; elseif (d <= 1.8e+134) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (d <= -2.7e+63) tmp = t_0; elseif (d <= 1.8e+134) tmp = (b - ((d / c) * a)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.7e+63], t$95$0, If[LessEqual[d, 1.8e+134], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+134}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.70000000000000017e63 or 1.79999999999999994e134 < d Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
Taylor expanded in a around inf
lower-*.f6443.1
Applied rewrites43.1%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6443.1
Applied rewrites43.1%
if -2.70000000000000017e63 < d < 1.79999999999999994e134Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (- a) d)))
(if (<= d -2.7e+63)
t_0
(if (<= d 1.8e+134) (/ (- b (* (/ a c) d)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -2.7e+63) {
tmp = t_0;
} else if (d <= 1.8e+134) {
tmp = (b - ((a / c) * d)) / c;
} 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 = -a / d
if (d <= (-2.7d+63)) then
tmp = t_0
else if (d <= 1.8d+134) then
tmp = (b - ((a / c) * d)) / c
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 = -a / d;
double tmp;
if (d <= -2.7e+63) {
tmp = t_0;
} else if (d <= 1.8e+134) {
tmp = (b - ((a / c) * d)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -2.7e+63: tmp = t_0 elif d <= 1.8e+134: tmp = (b - ((a / c) * d)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -2.7e+63) tmp = t_0; elseif (d <= 1.8e+134) tmp = Float64(Float64(b - Float64(Float64(a / c) * d)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (d <= -2.7e+63) tmp = t_0; elseif (d <= 1.8e+134) tmp = (b - ((a / c) * d)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -2.7e+63], t$95$0, If[LessEqual[d, 1.8e+134], N[(N[(b - N[(N[(a / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -2.7 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+134}:\\
\;\;\;\;\frac{b - \frac{a}{c} \cdot d}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.70000000000000017e63 or 1.79999999999999994e134 < d Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
Taylor expanded in a around inf
lower-*.f6443.1
Applied rewrites43.1%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6443.1
Applied rewrites43.1%
if -2.70000000000000017e63 < d < 1.79999999999999994e134Initial program 61.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.5
Applied rewrites51.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-neg2N/A
distribute-neg-fracN/A
lift-/.f64N/A
mul-1-negN/A
lift-*.f64N/A
lower-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
distribute-frac-neg2N/A
frac-2negN/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites53.6%
lift-fma.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
distribute-frac-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
lower-*.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6452.7
Applied rewrites52.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (- a) d))) (if (<= d -1.52e+63) t_0 (if (<= d 4.3e+116) (/ b c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = -a / d;
double tmp;
if (d <= -1.52e+63) {
tmp = t_0;
} else if (d <= 4.3e+116) {
tmp = b / c;
} 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 = -a / d
if (d <= (-1.52d+63)) then
tmp = t_0
else if (d <= 4.3d+116) then
tmp = b / c
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 = -a / d;
double tmp;
if (d <= -1.52e+63) {
tmp = t_0;
} else if (d <= 4.3e+116) {
tmp = b / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = -a / d tmp = 0 if d <= -1.52e+63: tmp = t_0 elif d <= 4.3e+116: tmp = b / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(-a) / d) tmp = 0.0 if (d <= -1.52e+63) tmp = t_0; elseif (d <= 4.3e+116) tmp = Float64(b / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = -a / d; tmp = 0.0; if (d <= -1.52e+63) tmp = t_0; elseif (d <= 4.3e+116) tmp = b / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -1.52e+63], t$95$0, If[LessEqual[d, 4.3e+116], N[(b / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -1.52 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 4.3 \cdot 10^{+116}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -1.51999999999999993e63 or 4.3e116 < d Initial program 61.4%
Taylor expanded in d around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6452.9
Applied rewrites52.9%
Taylor expanded in a around inf
lower-*.f6443.1
Applied rewrites43.1%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6443.1
Applied rewrites43.1%
if -1.51999999999999993e63 < d < 4.3e116Initial program 61.4%
Taylor expanded in c around inf
lower-/.f6442.1
Applied rewrites42.1%
(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 61.4%
Taylor expanded in c around inf
lower-/.f6442.1
Applied rewrites42.1%
(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 2025162
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform c (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))))