
(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 7 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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
(if (<= c -2.8e+85)
(/ (fma (/ d c) b a) c)
(if (<= c -6e-24)
t_0
(if (<= c 3.6e-149)
(/ (fma (/ a d) c b) d)
(if (<= c 4.4e+35) t_0 (/ (fma (/ b c) d a) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
double tmp;
if (c <= -2.8e+85) {
tmp = fma((d / c), b, a) / c;
} else if (c <= -6e-24) {
tmp = t_0;
} else if (c <= 3.6e-149) {
tmp = fma((a / d), c, b) / d;
} else if (c <= 4.4e+35) {
tmp = t_0;
} else {
tmp = fma((b / c), d, a) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) tmp = 0.0 if (c <= -2.8e+85) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (c <= -6e-24) tmp = t_0; elseif (c <= 3.6e-149) tmp = Float64(fma(Float64(a / d), c, b) / d); elseif (c <= 4.4e+35) tmp = t_0; else tmp = Float64(fma(Float64(b / c), d, a) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.8e+85], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -6e-24], t$95$0, If[LessEqual[c, 3.6e-149], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.4e+35], t$95$0, N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -2.8 \cdot 10^{+85}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;c \leq -6 \cdot 10^{-24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 3.6 \cdot 10^{-149}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\end{array}
\end{array}
if c < -2.7999999999999999e85Initial program 40.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-/.f6494.8
Applied rewrites94.8%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6494.8
Applied rewrites94.8%
if -2.7999999999999999e85 < c < -5.99999999999999991e-24 or 3.6000000000000002e-149 < c < 4.3999999999999997e35Initial program 83.4%
if -5.99999999999999991e-24 < c < 3.6000000000000002e-149Initial program 70.0%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.7
Applied rewrites91.7%
if 4.3999999999999997e35 < c Initial program 49.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-/.f6477.0
Applied rewrites77.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -9e+152)
(/ a c)
(if (<= c -2.6e-22)
(/ (fma d b (* c a)) (* c c))
(if (<= c 1.1e+33) (/ (fma (/ a d) c b) d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+152) {
tmp = a / c;
} else if (c <= -2.6e-22) {
tmp = fma(d, b, (c * a)) / (c * c);
} else if (c <= 1.1e+33) {
tmp = fma((a / d), c, b) / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -9e+152) tmp = Float64(a / c); elseif (c <= -2.6e-22) tmp = Float64(fma(d, b, Float64(c * a)) / Float64(c * c)); elseif (c <= 1.1e+33) tmp = Float64(fma(Float64(a / d), c, b) / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+152], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.6e-22], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.1e+33], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+152}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -2.6 \cdot 10^{-22}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{c \cdot c}\\
\mathbf{elif}\;c \leq 1.1 \cdot 10^{+33}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -9.0000000000000002e152 or 1.09999999999999997e33 < c Initial program 40.2%
Taylor expanded in c around inf
lower-/.f6473.9
Applied rewrites73.9%
if -9.0000000000000002e152 < c < -2.6e-22Initial program 82.2%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6472.1
Applied rewrites72.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6472.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6472.1
Applied rewrites72.1%
if -2.6e-22 < c < 1.09999999999999997e33Initial program 71.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6484.7
Applied rewrites84.7%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.6e-22) (not (<= c 5.2e+31))) (/ (fma (/ b c) d a) c) (/ (fma (/ a d) c b) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.6e-22) || !(c <= 5.2e+31)) {
tmp = fma((b / c), d, a) / c;
} else {
tmp = fma((a / d), c, b) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.6e-22) || !(c <= 5.2e+31)) tmp = Float64(fma(Float64(b / c), d, a) / c); else tmp = Float64(fma(Float64(a / d), c, b) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e-22], N[Not[LessEqual[c, 5.2e+31]], $MachinePrecision]], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{-22} \lor \neg \left(c \leq 5.2 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
\end{array}
\end{array}
if c < -2.6e-22 or 5.2e31 < c Initial program 54.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-/.f6483.8
Applied rewrites83.8%
if -2.6e-22 < c < 5.2e31Initial program 71.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6484.7
Applied rewrites84.7%
Final simplification84.2%
(FPCore (a b c d) :precision binary64 (if (<= c -2.6e-22) (/ (fma (/ d c) b a) c) (if (<= c 5.2e+31) (/ (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 (c <= -2.6e-22) {
tmp = fma((d / c), b, a) / c;
} else if (c <= 5.2e+31) {
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 (c <= -2.6e-22) tmp = Float64(fma(Float64(d / c), b, a) / c); elseif (c <= 5.2e+31) 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[LessEqual[c, -2.6e-22], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 5.2e+31], 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}\;c \leq -2.6 \cdot 10^{-22}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\
\mathbf{elif}\;c \leq 5.2 \cdot 10^{+31}:\\
\;\;\;\;\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 c < -2.6e-22Initial program 56.3%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.4
Applied rewrites88.4%
Taylor expanded in c around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6488.4
Applied rewrites88.4%
if -2.6e-22 < c < 5.2e31Initial program 71.5%
Taylor expanded in d around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6484.7
Applied rewrites84.7%
if 5.2e31 < c Initial program 51.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-/.f6476.0
Applied rewrites76.0%
(FPCore (a b c d)
:precision binary64
(if (<= c -9e+152)
(/ a c)
(if (<= c -8.2e-27)
(/ (fma d b (* c a)) (* c c))
(if (<= c 8e+31) (/ b d) (/ a c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e+152) {
tmp = a / c;
} else if (c <= -8.2e-27) {
tmp = fma(d, b, (c * a)) / (c * c);
} else if (c <= 8e+31) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -9e+152) tmp = Float64(a / c); elseif (c <= -8.2e-27) tmp = Float64(fma(d, b, Float64(c * a)) / Float64(c * c)); elseif (c <= 8e+31) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e+152], N[(a / c), $MachinePrecision], If[LessEqual[c, -8.2e-27], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8e+31], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{+152}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -8.2 \cdot 10^{-27}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{c \cdot c}\\
\mathbf{elif}\;c \leq 8 \cdot 10^{+31}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -9.0000000000000002e152 or 7.9999999999999997e31 < c Initial program 40.2%
Taylor expanded in c around inf
lower-/.f6473.9
Applied rewrites73.9%
if -9.0000000000000002e152 < c < -8.1999999999999997e-27Initial program 82.6%
Taylor expanded in c around inf
unpow2N/A
lower-*.f6470.7
Applied rewrites70.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6470.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6470.7
Applied rewrites70.7%
if -8.1999999999999997e-27 < c < 7.9999999999999997e31Initial program 71.2%
Taylor expanded in c around 0
lower-/.f6474.4
Applied rewrites74.4%
(FPCore (a b c d) :precision binary64 (if (or (<= c -2.7e-24) (not (<= c 8e+31))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -2.7e-24) || !(c <= 8e+31)) {
tmp = a / c;
} else {
tmp = b / 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 ((c <= (-2.7d-24)) .or. (.not. (c <= 8d+31))) 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 <= -2.7e-24) || !(c <= 8e+31)) {
tmp = a / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (c <= -2.7e-24) or not (c <= 8e+31): tmp = a / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if ((c <= -2.7e-24) || !(c <= 8e+31)) 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 <= -2.7e-24) || ~((c <= 8e+31))) tmp = a / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.7e-24], N[Not[LessEqual[c, 8e+31]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.7 \cdot 10^{-24} \lor \neg \left(c \leq 8 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if c < -2.70000000000000007e-24 or 7.9999999999999997e31 < c Initial program 54.7%
Taylor expanded in c around inf
lower-/.f6469.0
Applied rewrites69.0%
if -2.70000000000000007e-24 < c < 7.9999999999999997e31Initial program 71.2%
Taylor expanded in c around 0
lower-/.f6474.4
Applied rewrites74.4%
Final simplification71.6%
(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 62.6%
Taylor expanded in c around inf
lower-/.f6443.6
Applied rewrites43.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 2024318
(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))))