
(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 10 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 (/ a d) c b) d)))
(if (<= d -2.95e+103)
t_0
(if (<= d -1.75e-141)
(/ (fma d b (* c a)) (fma d d (* c c)))
(if (<= d 2.1e-72)
(/
(-
a
(/ (fma (- b) d (/ (fma (* d d) a (/ (* (pow d 3.0) b) c)) c)) c))
c)
(if (<= d 1.8e+69)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -2.95e+103) {
tmp = t_0;
} else if (d <= -1.75e-141) {
tmp = fma(d, b, (c * a)) / fma(d, d, (c * c));
} else if (d <= 2.1e-72) {
tmp = (a - (fma(-b, d, (fma((d * d), a, ((pow(d, 3.0) * b) / c)) / c)) / c)) / c;
} else if (d <= 1.8e+69) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -2.95e+103) tmp = t_0; elseif (d <= -1.75e-141) tmp = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))); elseif (d <= 2.1e-72) tmp = Float64(Float64(a - Float64(fma(Float64(-b), d, Float64(fma(Float64(d * d), a, Float64(Float64((d ^ 3.0) * b) / c)) / c)) / c)) / c); elseif (d <= 1.8e+69) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.95e+103], t$95$0, If[LessEqual[d, -1.75e-141], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.1e-72], N[(N[(a - N[(N[((-b) * d + N[(N[(N[(d * d), $MachinePrecision] * a + N[(N[(N[Power[d, 3.0], $MachinePrecision] * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+69], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -2.95 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -1.75 \cdot 10^{-141}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-72}:\\
\;\;\;\;\frac{a - \frac{\mathsf{fma}\left(-b, d, \frac{\mathsf{fma}\left(d \cdot d, a, \frac{{d}^{3} \cdot b}{c}\right)}{c}\right)}{c}}{c}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+69}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.9499999999999999e103 or 1.8000000000000001e69 < d Initial program 42.0%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.8
Applied rewrites83.8%
if -2.9499999999999999e103 < d < -1.7500000000000001e-141Initial program 88.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6488.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6488.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6488.8
Applied rewrites88.8%
if -1.7500000000000001e-141 < d < 2.1e-72Initial program 63.7%
Taylor expanded in c around inf
Applied rewrites91.4%
if 2.1e-72 < d < 1.8000000000000001e69Initial program 91.4%
Final simplification88.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* a c) (* b d))) (t_1 (/ (fma (/ a d) c b) d)))
(if (<= d -2.95e+103)
t_1
(if (<= d -8.2e-98)
(/ t_0 (* (fma c (/ c (* d d)) 1.0) (* d d)))
(if (<= d 2.1e-72)
(/ (fma (/ d c) b a) c)
(if (<= d 1.8e+69) (/ t_0 (+ (* c c) (* d d))) t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = (a * c) + (b * d);
double t_1 = fma((a / d), c, b) / d;
double tmp;
if (d <= -2.95e+103) {
tmp = t_1;
} else if (d <= -8.2e-98) {
tmp = t_0 / (fma(c, (c / (d * d)), 1.0) * (d * d));
} else if (d <= 2.1e-72) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 1.8e+69) {
tmp = t_0 / ((c * c) + (d * d));
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(a * c) + Float64(b * d)) t_1 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -2.95e+103) tmp = t_1; elseif (d <= -8.2e-98) tmp = Float64(t_0 / Float64(fma(c, Float64(c / Float64(d * d)), 1.0) * Float64(d * d))); elseif (d <= 2.1e-72) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 1.8e+69) tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_1; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.95e+103], t$95$1, If[LessEqual[d, -8.2e-98], N[(t$95$0 / N[(N[(c * N[(c / N[(d * d), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.1e-72], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+69], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
t_1 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -2.95 \cdot 10^{+103}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -8.2 \cdot 10^{-98}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, \frac{c}{d \cdot d}, 1\right) \cdot \left(d \cdot d\right)}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-72}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+69}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -2.9499999999999999e103 or 1.8000000000000001e69 < d Initial program 42.0%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.8
Applied rewrites83.8%
if -2.9499999999999999e103 < d < -8.1999999999999996e-98Initial program 86.8%
Taylor expanded in d around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6486.7
Applied rewrites86.7%
Applied rewrites86.8%
if -8.1999999999999996e-98 < d < 2.1e-72Initial program 68.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6468.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6468.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6468.1
Applied rewrites68.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.0
Applied rewrites91.0%
if 2.1e-72 < d < 1.8000000000000001e69Initial program 91.4%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ a d) c b) d)))
(if (<= d -2.95e+103)
t_0
(if (<= d -8e-98)
(/ (fma d b (* c a)) (fma d d (* c c)))
(if (<= d 2.1e-72)
(/ (fma (/ d c) b a) c)
(if (<= d 1.8e+69)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
t_0))))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -2.95e+103) {
tmp = t_0;
} else if (d <= -8e-98) {
tmp = fma(d, b, (c * a)) / fma(d, d, (c * c));
} else if (d <= 2.1e-72) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 1.8e+69) {
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -2.95e+103) tmp = t_0; elseif (d <= -8e-98) tmp = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))); elseif (d <= 2.1e-72) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 1.8e+69) tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.95e+103], t$95$0, If[LessEqual[d, -8e-98], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.1e-72], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+69], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -2.95 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -8 \cdot 10^{-98}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-72}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+69}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.9499999999999999e103 or 1.8000000000000001e69 < d Initial program 42.0%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.8
Applied rewrites83.8%
if -2.9499999999999999e103 < d < -7.99999999999999951e-98Initial program 86.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6486.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6486.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6486.8
Applied rewrites86.8%
if -7.99999999999999951e-98 < d < 2.1e-72Initial program 68.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6468.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6468.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6468.1
Applied rewrites68.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.0
Applied rewrites91.0%
if 2.1e-72 < d < 1.8000000000000001e69Initial program 91.4%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d b (* c a)) (fma d d (* c c))))
(t_1 (/ (fma (/ a d) c b) d)))
(if (<= d -2.95e+103)
t_1
(if (<= d -8e-98)
t_0
(if (<= d 2.1e-72)
(/ (fma (/ d c) b a) c)
(if (<= d 1.8e+69) 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((a / d), c, b) / d;
double tmp;
if (d <= -2.95e+103) {
tmp = t_1;
} else if (d <= -8e-98) {
tmp = t_0;
} else if (d <= 2.1e-72) {
tmp = fma((d / c), b, a) / c;
} else if (d <= 1.8e+69) {
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(a / d), c, b) / d) tmp = 0.0 if (d <= -2.95e+103) tmp = t_1; elseif (d <= -8e-98) tmp = t_0; elseif (d <= 2.1e-72) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (d <= 1.8e+69) 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[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.95e+103], t$95$1, If[LessEqual[d, -8e-98], t$95$0, If[LessEqual[d, 2.1e-72], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+69], 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{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -2.95 \cdot 10^{+103}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -8 \cdot 10^{-98}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 2.1 \cdot 10^{-72}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;d \leq 1.8 \cdot 10^{+69}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -2.9499999999999999e103 or 1.8000000000000001e69 < d Initial program 42.0%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.8
Applied rewrites83.8%
if -2.9499999999999999e103 < d < -7.99999999999999951e-98 or 2.1e-72 < d < 1.8000000000000001e69Initial program 88.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6488.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6488.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6488.7
Applied rewrites88.7%
if -7.99999999999999951e-98 < d < 2.1e-72Initial program 68.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6468.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6468.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6468.1
Applied rewrites68.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.0
Applied rewrites91.0%
Final simplification87.7%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (* b (/ d (fma d d (* c c))))))
(if (<= d -3.5e+100)
(/ b d)
(if (<= d -2.3e-96)
t_0
(if (<= d 3.2e-73) (/ a c) (if (<= d 2.5e+115) t_0 (/ b d)))))))
double code(double a, double b, double c, double d) {
double t_0 = b * (d / fma(d, d, (c * c)));
double tmp;
if (d <= -3.5e+100) {
tmp = b / d;
} else if (d <= -2.3e-96) {
tmp = t_0;
} else if (d <= 3.2e-73) {
tmp = a / c;
} else if (d <= 2.5e+115) {
tmp = t_0;
} else {
tmp = b / d;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(b * Float64(d / fma(d, d, Float64(c * c)))) tmp = 0.0 if (d <= -3.5e+100) tmp = Float64(b / d); elseif (d <= -2.3e-96) tmp = t_0; elseif (d <= 3.2e-73) tmp = Float64(a / c); elseif (d <= 2.5e+115) tmp = t_0; else tmp = Float64(b / d); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.5e+100], N[(b / d), $MachinePrecision], If[LessEqual[d, -2.3e-96], t$95$0, If[LessEqual[d, 3.2e-73], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.5e+115], t$95$0, N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;d \leq -3.5 \cdot 10^{+100}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq -2.3 \cdot 10^{-96}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{-73}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;d \leq 2.5 \cdot 10^{+115}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -3.49999999999999976e100 or 2.50000000000000004e115 < d Initial program 39.9%
Taylor expanded in c around 0
lower-/.f6474.6
Applied rewrites74.6%
if -3.49999999999999976e100 < d < -2.3e-96 or 3.19999999999999986e-73 < d < 2.50000000000000004e115Initial program 82.7%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6466.6
Applied rewrites66.6%
Applied rewrites69.2%
if -2.3e-96 < d < 3.19999999999999986e-73Initial program 67.8%
Taylor expanded in c around inf
lower-/.f6476.9
Applied rewrites76.9%
Final simplification74.0%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma (/ a d) c b) d)))
(if (<= d -3.5e+100)
t_0
(if (<= d -2.3e-96)
(* b (/ d (fma d d (* c c))))
(if (<= d 3.2e-73) (/ a c) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((a / d), c, b) / d;
double tmp;
if (d <= -3.5e+100) {
tmp = t_0;
} else if (d <= -2.3e-96) {
tmp = b * (d / fma(d, d, (c * c)));
} else if (d <= 3.2e-73) {
tmp = a / c;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(a / d), c, b) / d) tmp = 0.0 if (d <= -3.5e+100) tmp = t_0; elseif (d <= -2.3e-96) tmp = Float64(b * Float64(d / fma(d, d, Float64(c * c)))); elseif (d <= 3.2e-73) tmp = Float64(a / c); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3.5e+100], t$95$0, If[LessEqual[d, -2.3e-96], N[(b * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.2e-73], N[(a / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{if}\;d \leq -3.5 \cdot 10^{+100}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq -2.3 \cdot 10^{-96}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{elif}\;d \leq 3.2 \cdot 10^{-73}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -3.49999999999999976e100 or 3.19999999999999986e-73 < d Initial program 52.7%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.0
Applied rewrites78.0%
if -3.49999999999999976e100 < d < -2.3e-96Initial program 85.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
lower-fma.f64N/A
unpow2N/A
lower-*.f6467.7
Applied rewrites67.7%
Applied rewrites70.7%
if -2.3e-96 < d < 3.19999999999999986e-73Initial program 67.8%
Taylor expanded in c around inf
lower-/.f6476.9
Applied rewrites76.9%
Final simplification76.7%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6600.0) (not (<= d 3.4e-5))) (/ (fma (/ a d) c b) d) (/ (fma (/ d c) b a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6600.0) || !(d <= 3.4e-5)) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = fma((d / c), b, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -6600.0) || !(d <= 3.4e-5)) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(fma(Float64(d / c), b, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6600.0], N[Not[LessEqual[d, 3.4e-5]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6600 \lor \neg \left(d \leq 3.4 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\end{array}
\end{array}
if d < -6600 or 3.4e-5 < d Initial program 54.6%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.3
Applied rewrites79.3%
if -6600 < d < 3.4e-5Initial program 71.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6471.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6471.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6471.0
Applied rewrites71.0%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.6
Applied rewrites86.6%
Final simplification82.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6600.0) (not (<= d 3.4e-5))) (/ (fma (/ a d) c b) d) (/ (fma (/ b c) d a) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6600.0) || !(d <= 3.4e-5)) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((d <= -6600.0) || !(d <= 3.4e-5)) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6600.0], N[Not[LessEqual[d, 3.4e-5]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6600 \lor \neg \left(d \leq 3.4 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if d < -6600 or 3.4e-5 < d Initial program 54.6%
Taylor expanded in c around 0
unpow2N/A
associate-/r*N/A
div-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6479.3
Applied rewrites79.3%
if -6600 < d < 3.4e-5Initial program 71.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-/.f6485.0
Applied rewrites85.0%
Final simplification82.0%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6200.0) (not (<= d 0.00065))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6200.0) || !(d <= 0.00065)) {
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 ((d <= (-6200.0d0)) .or. (.not. (d <= 0.00065d0))) 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 ((d <= -6200.0) || !(d <= 0.00065)) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6200.0) or not (d <= 0.00065): tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6200.0) || !(d <= 0.00065)) 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 ((d <= -6200.0) || ~((d <= 0.00065))) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6200.0], N[Not[LessEqual[d, 0.00065]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6200 \lor \neg \left(d \leq 0.00065\right):\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if d < -6200 or 6.4999999999999997e-4 < d Initial program 54.6%
Taylor expanded in c around 0
lower-/.f6468.3
Applied rewrites68.3%
if -6200 < d < 6.4999999999999997e-4Initial program 71.0%
Taylor expanded in c around inf
lower-/.f6469.1
Applied rewrites69.1%
Final simplification68.7%
(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 62.6%
Taylor expanded in c around inf
lower-/.f6443.8
Applied rewrites43.8%
Final simplification43.8%
(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 2025017
(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))))