
(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 11 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 (fma d d (* c c))))
(if (<= c -3.6e+151)
(/ (fma (/ (fma (/ d c) (- a) b) c) d a) c)
(if (<= c -1.35e-125)
(fma b (/ d t_0) (* c (/ a t_0)))
(if (<= c 1.65e-52)
(/ (fma (/ c d) a b) d)
(if (<= c 1e+142)
(fma a (/ c t_0) (* d (/ b t_0)))
(/ (fma (/ d c) b a) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double tmp;
if (c <= -3.6e+151) {
tmp = fma((fma((d / c), -a, b) / c), d, a) / c;
} else if (c <= -1.35e-125) {
tmp = fma(b, (d / t_0), (c * (a / t_0)));
} else if (c <= 1.65e-52) {
tmp = fma((c / d), a, b) / d;
} else if (c <= 1e+142) {
tmp = fma(a, (c / t_0), (d * (b / t_0)));
} else {
tmp = fma((d / c), b, a) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) tmp = 0.0 if (c <= -3.6e+151) tmp = Float64(fma(Float64(fma(Float64(d / c), Float64(-a), b) / c), d, a) / c); elseif (c <= -1.35e-125) tmp = fma(b, Float64(d / t_0), Float64(c * Float64(a / t_0))); elseif (c <= 1.65e-52) tmp = Float64(fma(Float64(c / d), a, b) / d); elseif (c <= 1e+142) tmp = fma(a, Float64(c / t_0), Float64(d * Float64(b / t_0))); else tmp = Float64(fma(Float64(d / c), b, a) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.6e+151], N[(N[(N[(N[(N[(d / c), $MachinePrecision] * (-a) + b), $MachinePrecision] / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.35e-125], N[(b * N[(d / t$95$0), $MachinePrecision] + N[(c * N[(a / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.65e-52], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1e+142], N[(a * N[(c / t$95$0), $MachinePrecision] + N[(d * N[(b / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;c \leq -3.6 \cdot 10^{+151}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(\frac{d}{c}, -a, b\right)}{c}, d, a\right)}{c}\\
\mathbf{elif}\;c \leq -1.35 \cdot 10^{-125}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{d}{t\_0}, c \cdot \frac{a}{t\_0}\right)\\
\mathbf{elif}\;c \leq 1.65 \cdot 10^{-52}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{elif}\;c \leq 10^{+142}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{c}{t\_0}, d \cdot \frac{b}{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\end{array}
\end{array}
if c < -3.6e151Initial program 28.8%
Taylor expanded in c around inf
Applied rewrites80.0%
Applied rewrites91.7%
if -3.6e151 < c < -1.3499999999999999e-125Initial program 72.4%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6478.3
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.3
Applied rewrites78.3%
if -1.3499999999999999e-125 < c < 1.64999999999999998e-52Initial program 68.4%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6466.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6466.8
Applied rewrites66.8%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.9
Applied rewrites88.9%
if 1.64999999999999998e-52 < c < 1.00000000000000005e142Initial program 77.2%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6484.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6484.8
Applied rewrites84.8%
if 1.00000000000000005e142 < c Initial program 45.3%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6446.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6446.5
Applied rewrites46.5%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6487.8
Applied rewrites87.8%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d b (* c a)) (fma d d (* c c))))
(t_1 (/ (fma (/ b c) d a) c)))
(if (<= c -6.6e+88)
t_1
(if (<= c -1.35e-125)
t_0
(if (<= c 6.3e-105)
(/ (fma (/ c d) a b) d)
(if (<= c 9.5e+122) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (c * a)) / fma(d, d, (c * c));
double t_1 = fma((b / c), d, a) / c;
double tmp;
if (c <= -6.6e+88) {
tmp = t_1;
} else if (c <= -1.35e-125) {
tmp = t_0;
} else if (c <= 6.3e-105) {
tmp = fma((c / d), a, b) / d;
} else if (c <= 9.5e+122) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))) t_1 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -6.6e+88) tmp = t_1; elseif (c <= -1.35e-125) tmp = t_0; elseif (c <= 6.3e-105) tmp = Float64(fma(Float64(c / d), a, b) / d); elseif (c <= 9.5e+122) tmp = t_0; else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.6e+88], t$95$1, If[LessEqual[c, -1.35e-125], t$95$0, If[LessEqual[c, 6.3e-105], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9.5e+122], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
t_1 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -6.6 \cdot 10^{+88}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;c \leq -1.35 \cdot 10^{-125}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 6.3 \cdot 10^{-105}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{elif}\;c \leq 9.5 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if c < -6.6000000000000006e88 or 9.49999999999999986e122 < c Initial program 40.8%
Taylor expanded in c around inf
lower-/.f64N/A
*-lft-identityN/A
metadata-evalN/A
associate-*r*N/A
distribute-lft-outN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
*-commutativeN/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
lower-/.f6486.7
Applied rewrites86.7%
if -6.6000000000000006e88 < c < -1.3499999999999999e-125 or 6.3e-105 < c < 9.49999999999999986e122Initial program 77.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6477.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6477.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6477.7
Applied rewrites77.7%
if -1.3499999999999999e-125 < c < 6.3e-105Initial program 66.9%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6468.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6468.7
Applied rewrites68.7%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.3
Applied rewrites93.3%
Final simplification85.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma (/ a d) (/ c d) (/ b d))))
(if (<= d -6.8e+76)
t_0
(if (<= d -2.2e-161)
(* (/ (fma (/ b a) d c) (fma c c (* d d))) a)
(if (<= d 7e+31) (/ (fma (/ d c) b a) c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), (c / d), (b / d));
double tmp;
if (d <= -6.8e+76) {
tmp = t_0;
} else if (d <= -2.2e-161) {
tmp = (fma((b / a), d, c) / fma(c, c, (d * d))) * a;
} else if (d <= 7e+31) {
tmp = fma((d / c), b, a) / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(Float64(a / d), Float64(c / d), Float64(b / d)) tmp = 0.0 if (d <= -6.8e+76) tmp = t_0; elseif (d <= -2.2e-161) tmp = Float64(Float64(fma(Float64(b / a), d, c) / fma(c, c, Float64(d * d))) * a); elseif (d <= 7e+31) tmp = Float64(fma(Float64(d / c), b, a) / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.8e+76], t$95$0, If[LessEqual[d, -2.2e-161], N[(N[(N[(N[(b / a), $MachinePrecision] * d + c), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], If[LessEqual[d, 7e+31], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -6.8 \cdot 10^{+76}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.2 \cdot 10^{-161}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{a}, d, c\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot a\\
\mathbf{elif}\;d \leq 7 \cdot 10^{+31}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -6.7999999999999994e76 or 7e31 < d Initial program 38.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6438.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6438.2
Applied rewrites38.2%
Taylor expanded in c around 0
+-commutativeN/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
if -6.7999999999999994e76 < d < -2.20000000000000002e-161Initial program 80.9%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6478.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.5
Applied rewrites78.5%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
times-fracN/A
associate-*r/N/A
div-add-revN/A
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6481.8
Applied rewrites81.8%
if -2.20000000000000002e-161 < d < 7e31Initial program 70.7%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6465.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6465.4
Applied rewrites65.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.7
Applied rewrites88.7%
Final simplification84.1%
(FPCore (a b c d)
:precision binary64
(if (<= c -3e-15)
(/ a c)
(if (<= c 1.65e-52)
(/ b d)
(if (<= c 1.4e+125) (* a (/ c (fma c c (* d d)))) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-15) {
tmp = a / c;
} else if (c <= 1.65e-52) {
tmp = b / d;
} else if (c <= 1.4e+125) {
tmp = a * (c / fma(c, c, (d * d)));
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-15) tmp = Float64(a / c); elseif (c <= 1.65e-52) tmp = Float64(b / d); elseif (c <= 1.4e+125) tmp = Float64(a * Float64(c / fma(c, c, Float64(d * d)))); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-15], N[(a / c), $MachinePrecision], If[LessEqual[c, 1.65e-52], N[(b / d), $MachinePrecision], If[LessEqual[c, 1.4e+125], N[(a * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-15}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 1.65 \cdot 10^{-52}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{+125}:\\
\;\;\;\;a \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3e-15 or 1.4e125 < c Initial program 47.5%
Taylor expanded in c around inf
lower-/.f6472.0
Applied rewrites72.0%
if -3e-15 < c < 1.64999999999999998e-52Initial program 69.7%
Taylor expanded in c around 0
lower-/.f6469.2
Applied rewrites69.2%
if 1.64999999999999998e-52 < c < 1.4e125Initial program 78.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6478.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.0
Applied rewrites78.0%
Taylor expanded in a around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6462.2
Applied rewrites62.2%
Final simplification69.5%
(FPCore (a b c d)
:precision binary64
(if (<= c -3e-15)
(/ a c)
(if (<= c 2.8e-51)
(/ b d)
(if (<= c 7.4e+122) (* (/ a (fma d d (* c c))) c) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -3e-15) {
tmp = a / c;
} else if (c <= 2.8e-51) {
tmp = b / d;
} else if (c <= 7.4e+122) {
tmp = (a / fma(d, d, (c * c))) * c;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -3e-15) tmp = Float64(a / c); elseif (c <= 2.8e-51) tmp = Float64(b / d); elseif (c <= 7.4e+122) tmp = Float64(Float64(a / fma(d, d, Float64(c * c))) * c); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -3e-15], N[(a / c), $MachinePrecision], If[LessEqual[c, 2.8e-51], N[(b / d), $MachinePrecision], If[LessEqual[c, 7.4e+122], N[(N[(a / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-15}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 2.8 \cdot 10^{-51}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 7.4 \cdot 10^{+122}:\\
\;\;\;\;\frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -3e-15 or 7.3999999999999993e122 < c Initial program 47.5%
Taylor expanded in c around inf
lower-/.f6472.0
Applied rewrites72.0%
if -3e-15 < c < 2.8e-51Initial program 69.7%
Taylor expanded in c around 0
lower-/.f6469.2
Applied rewrites69.2%
if 2.8e-51 < c < 7.3999999999999993e122Initial program 78.0%
Taylor expanded in a around inf
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.1
Applied rewrites59.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.42e+24) (not (<= c 4.5e-13))) (/ (fma (/ b c) d a) c) (/ (fma (/ c d) a b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.42e+24) || !(c <= 4.5e-13)) {
tmp = fma((b / c), d, a) / c;
} else {
tmp = fma((c / d), a, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.42e+24) || !(c <= 4.5e-13)) tmp = Float64(fma(Float64(b / c), d, a) / c); else tmp = Float64(fma(Float64(c / d), a, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.42e+24], N[Not[LessEqual[c, 4.5e-13]], $MachinePrecision]], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.42 \cdot 10^{+24} \lor \neg \left(c \leq 4.5 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\end{array}
\end{array}
if c < -1.42e24 or 4.5e-13 < c Initial program 51.0%
Taylor expanded in c around inf
lower-/.f64N/A
*-lft-identityN/A
metadata-evalN/A
associate-*r*N/A
distribute-lft-outN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
*-commutativeN/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
lower-/.f6480.1
Applied rewrites80.1%
if -1.42e24 < c < 4.5e-13Initial program 71.9%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6470.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6470.1
Applied rewrites70.1%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.2
Applied rewrites80.2%
Final simplification80.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -1.5e+24) (not (<= c 2.6e+45))) (/ (fma (/ d c) b a) c) (/ (fma (/ c d) a b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -1.5e+24) || !(c <= 2.6e+45)) {
tmp = fma((d / c), b, a) / c;
} else {
tmp = fma((c / d), a, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -1.5e+24) || !(c <= 2.6e+45)) tmp = Float64(fma(Float64(d / c), b, a) / c); else tmp = Float64(fma(Float64(c / d), a, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.5e+24], N[Not[LessEqual[c, 2.6e+45]], $MachinePrecision]], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.5 \cdot 10^{+24} \lor \neg \left(c \leq 2.6 \cdot 10^{+45}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\end{array}
\end{array}
if c < -1.49999999999999997e24 or 2.60000000000000007e45 < c Initial program 48.7%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6452.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6452.9
Applied rewrites52.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.7
Applied rewrites81.7%
if -1.49999999999999997e24 < c < 2.60000000000000007e45Initial program 72.5%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6471.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6471.0
Applied rewrites71.0%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.0
Applied rewrites78.0%
Final simplification79.9%
(FPCore (a b c d) :precision binary64 (if (or (<= c -7.8e-14) (not (<= c 1.24e+82))) (/ a c) (/ (fma (/ c d) a b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -7.8e-14) || !(c <= 1.24e+82)) {
tmp = a / c;
} else {
tmp = fma((c / d), a, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -7.8e-14) || !(c <= 1.24e+82)) tmp = Float64(a / c); else tmp = Float64(fma(Float64(c / d), a, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.8e-14], N[Not[LessEqual[c, 1.24e+82]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.8 \cdot 10^{-14} \lor \neg \left(c \leq 1.24 \cdot 10^{+82}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\end{array}
\end{array}
if c < -7.7999999999999996e-14 or 1.24e82 < c Initial program 50.6%
Taylor expanded in c around inf
lower-/.f6469.6
Applied rewrites69.6%
if -7.7999999999999996e-14 < c < 1.24e82Initial program 71.1%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6470.3
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6470.3
Applied rewrites70.3%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.3
Applied rewrites78.3%
Final simplification73.9%
(FPCore (a b c d)
:precision binary64
(if (<= d -1.25e+154)
(/ b d)
(if (<= d -2.4e-129)
(* (/ d (fma d d (* c c))) b)
(if (<= d 7.5e+54) (/ a c) (/ b d)))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.25e+154) {
tmp = b / d;
} else if (d <= -2.4e-129) {
tmp = (d / fma(d, d, (c * c))) * b;
} else if (d <= 7.5e+54) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (d <= -1.25e+154) tmp = Float64(b / d); elseif (d <= -2.4e-129) tmp = Float64(Float64(d / fma(d, d, Float64(c * c))) * b); elseif (d <= 7.5e+54) tmp = Float64(a / c); else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.25e+154], N[(b / d), $MachinePrecision], If[LessEqual[d, -2.4e-129], N[(N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[d, 7.5e+54], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{+154}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -2.4 \cdot 10^{-129}:\\
\;\;\;\;\frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{elif}\;d \leq 7.5 \cdot 10^{+54}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -1.25000000000000001e154 or 7.50000000000000042e54 < d Initial program 31.2%
Taylor expanded in c around 0
lower-/.f6471.4
Applied rewrites71.4%
if -1.25000000000000001e154 < d < -2.39999999999999989e-129Initial program 74.9%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
unpow2N/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6456.1
Applied rewrites56.1%
Applied rewrites67.4%
if -2.39999999999999989e-129 < d < 7.50000000000000042e54Initial program 72.5%
Taylor expanded in c around inf
lower-/.f6469.3
Applied rewrites69.3%
(FPCore (a b c d) :precision binary64 (if (or (<= c -3e-15) (not (<= c 2.8e-51))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -3e-15) || !(c <= 2.8e-51)) {
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 <= (-3d-15)) .or. (.not. (c <= 2.8d-51))) 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 <= -3e-15) || !(c <= 2.8e-51)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -3e-15) or not (c <= 2.8e-51): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -3e-15) || !(c <= 2.8e-51)) 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 <= -3e-15) || ~((c <= 2.8e-51))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3e-15], N[Not[LessEqual[c, 2.8e-51]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-15} \lor \neg \left(c \leq 2.8 \cdot 10^{-51}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -3e-15 or 2.8e-51 < c Initial program 54.6%
Taylor expanded in c around inf
lower-/.f6465.3
Applied rewrites65.3%
if -3e-15 < c < 2.8e-51Initial program 69.7%
Taylor expanded in c around 0
lower-/.f6469.2
Applied rewrites69.2%
Final simplification66.9%
(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 60.7%
Taylor expanded in c around inf
lower-/.f6444.9
Applied rewrites44.9%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2025007
(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))))