
(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));
}
real(8) function code(a, b, c, d)
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 8 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));
}
real(8) function code(a, b, c, d)
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 (/ b c) d a) c)))
(if (<= c -3e+131)
t_0
(if (<= c -1e-90)
(/ (+ (* d b) (* a c)) (+ (* d d) (* c c)))
(if (<= c 1.8e+73) (/ (fma (/ c d) a b) d) t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / c), d, a) / c;
double tmp;
if (c <= -3e+131) {
tmp = t_0;
} else if (c <= -1e-90) {
tmp = ((d * b) + (a * c)) / ((d * d) + (c * c));
} else if (c <= 1.8e+73) {
tmp = fma((c / d), a, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -3e+131) tmp = t_0; elseif (c <= -1e-90) tmp = Float64(Float64(Float64(d * b) + Float64(a * c)) / Float64(Float64(d * d) + Float64(c * c))); elseif (c <= 1.8e+73) tmp = Float64(fma(Float64(c / d), a, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3e+131], t$95$0, If[LessEqual[c, -1e-90], N[(N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.8e+73], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -3 \cdot 10^{+131}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq -1 \cdot 10^{-90}:\\
\;\;\;\;\frac{d \cdot b + a \cdot c}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{+73}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.0000000000000001e131 or 1.7999999999999999e73 < c Initial program 37.7%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.9
Applied rewrites92.9%
if -3.0000000000000001e131 < c < -9.99999999999999995e-91Initial program 84.5%
if -9.99999999999999995e-91 < c < 1.7999999999999999e73Initial program 63.1%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6425.7
Applied rewrites25.7%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.0
Applied rewrites88.0%
Final simplification89.2%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma (/ b c) d a) c))) (if (<= c -3.8e-5) t_0 (if (<= c 1.8e+73) (/ (fma (/ c d) a b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / c), d, a) / c;
double tmp;
if (c <= -3.8e-5) {
tmp = t_0;
} else if (c <= 1.8e+73) {
tmp = fma((c / d), a, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -3.8e-5) tmp = t_0; elseif (c <= 1.8e+73) tmp = Float64(fma(Float64(c / d), a, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.8e-5], t$95$0, If[LessEqual[c, 1.8e+73], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -3.8 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{+73}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.8000000000000002e-5 or 1.7999999999999999e73 < c Initial program 47.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6489.4
Applied rewrites89.4%
if -3.8000000000000002e-5 < c < 1.7999999999999999e73Initial program 65.2%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6425.4
Applied rewrites25.4%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6485.4
Applied rewrites85.4%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma (/ b c) d a) c))) (if (<= c -3.8e-5) t_0 (if (<= c 1.8e+73) (/ (fma (/ a d) c b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma((b / c), d, a) / c;
double tmp;
if (c <= -3.8e-5) {
tmp = t_0;
} else if (c <= 1.8e+73) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(Float64(b / c), d, a) / c) tmp = 0.0 if (c <= -3.8e-5) tmp = t_0; elseif (c <= 1.8e+73) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.8e-5], t$95$0, If[LessEqual[c, 1.8e+73], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{if}\;c \leq -3.8 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{+73}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.8000000000000002e-5 or 1.7999999999999999e73 < c Initial program 47.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6489.4
Applied rewrites89.4%
if -3.8000000000000002e-5 < c < 1.7999999999999999e73Initial program 65.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.7
Applied rewrites82.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma b (/ d c) a) c))) (if (<= c -3.8e-5) t_0 (if (<= c 1.8e+73) (/ (fma (/ a d) c b) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -3.8e-5) {
tmp = t_0;
} else if (c <= 1.8e+73) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -3.8e-5) tmp = t_0; elseif (c <= 1.8e+73) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.8e-5], t$95$0, If[LessEqual[c, 1.8e+73], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -3.8 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.8 \cdot 10^{+73}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -3.8000000000000002e-5 or 1.7999999999999999e73 < c Initial program 47.9%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6489.4
Applied rewrites89.4%
Applied rewrites88.7%
if -3.8000000000000002e-5 < c < 1.7999999999999999e73Initial program 65.2%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6482.7
Applied rewrites82.7%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (fma b (/ d c) a) c))) (if (<= c -6e-11) t_0 (if (<= c 1.4e-28) (/ b d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = fma(b, (d / c), a) / c;
double tmp;
if (c <= -6e-11) {
tmp = t_0;
} else if (c <= 1.4e-28) {
tmp = b / d;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(b, Float64(d / c), a) / c) tmp = 0.0 if (c <= -6e-11) tmp = t_0; elseif (c <= 1.4e-28) tmp = Float64(b / d); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6e-11], t$95$0, If[LessEqual[c, 1.4e-28], N[(b / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -6 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.4 \cdot 10^{-28}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -6e-11 or 1.3999999999999999e-28 < c Initial program 49.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6484.2
Applied rewrites84.2%
Applied rewrites83.6%
if -6e-11 < c < 1.3999999999999999e-28Initial program 65.7%
Taylor expanded in c around 0
lower-/.f6473.2
Applied rewrites73.2%
(FPCore (a b c d)
:precision binary64
(if (<= c -1.5e+132)
(/ a c)
(if (<= c -6e-11)
(/ (fma c a (* d b)) (* c c))
(if (<= c 5.7e+23) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.5e+132) {
tmp = a / c;
} else if (c <= -6e-11) {
tmp = fma(c, a, (d * b)) / (c * c);
} else if (c <= 5.7e+23) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -1.5e+132) tmp = Float64(a / c); elseif (c <= -6e-11) tmp = Float64(fma(c, a, Float64(d * b)) / Float64(c * c)); elseif (c <= 5.7e+23) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.5e+132], N[(a / c), $MachinePrecision], If[LessEqual[c, -6e-11], N[(N[(c * a + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.7e+23], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.5 \cdot 10^{+132}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -6 \cdot 10^{-11}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{c \cdot c}\\
\mathbf{elif}\;c \leq 5.7 \cdot 10^{+23}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.4999999999999999e132 or 5.7e23 < c Initial program 39.8%
Taylor expanded in c around inf
lower-/.f6469.6
Applied rewrites69.6%
if -1.4999999999999999e132 < c < -6e-11Initial program 87.3%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6475.7
Applied rewrites75.7%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6475.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6475.7
Applied rewrites75.7%
if -6e-11 < c < 5.7e23Initial program 65.3%
Taylor expanded in c around 0
lower-/.f6471.7
Applied rewrites71.7%
(FPCore (a b c d) :precision binary64 (if (<= c -1.9e-10) (/ a c) (if (<= c 5.7e+23) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.9e-10) {
tmp = a / c;
} else if (c <= 5.7e+23) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-1.9d-10)) then
tmp = a / c
else if (c <= 5.7d+23) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -1.9e-10) {
tmp = a / c;
} else if (c <= 5.7e+23) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -1.9e-10: tmp = a / c elif c <= 5.7e+23: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -1.9e-10) tmp = Float64(a / c); elseif (c <= 5.7e+23) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -1.9e-10) tmp = a / c; elseif (c <= 5.7e+23) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.9e-10], N[(a / c), $MachinePrecision], If[LessEqual[c, 5.7e+23], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{-10}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 5.7 \cdot 10^{+23}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -1.8999999999999999e-10 or 5.7e23 < c Initial program 48.9%
Taylor expanded in c around inf
lower-/.f6467.1
Applied rewrites67.1%
if -1.8999999999999999e-10 < c < 5.7e23Initial program 65.3%
Taylor expanded in c around 0
lower-/.f6471.7
Applied rewrites71.7%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
real(8) function code(a, b, c, d)
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 57.3%
Taylor expanded in c around inf
lower-/.f6440.6
Applied rewrites40.6%
(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;
}
real(8) function code(a, b, c, d)
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 2024248
(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))))