Complex division, real part

Percentage Accurate: 61.4% → 81.4%
Time: 7.5s
Alternatives: 8
Speedup: 1.1×

Specification

?
\[\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
 (/ (+ (* 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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 61.4% accurate, 1.0× speedup?

\[\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
 (/ (+ (* 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}

Alternative 1: 81.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;d \leq -1.2 \cdot 10^{+84}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -2.1 \cdot 10^{-35}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 4.8 \cdot 10^{-86}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.8 \cdot 10^{+75}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{+136}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (* (/ d (hypot c d)) (/ b (hypot c d)))))
   (if (<= d -1.2e+84)
     t_1
     (if (<= d -2.1e-35)
       t_0
       (if (<= d 4.8e-86)
         (/ (+ a (/ (* b d) c)) c)
         (if (<= d 1.8e+75)
           t_0
           (if (<= d 5.8e+136) (/ (fma a (/ c d) b) d) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (d / hypot(c, d)) * (b / hypot(c, d));
	double tmp;
	if (d <= -1.2e+84) {
		tmp = t_1;
	} else if (d <= -2.1e-35) {
		tmp = t_0;
	} else if (d <= 4.8e-86) {
		tmp = (a + ((b * d) / c)) / c;
	} else if (d <= 1.8e+75) {
		tmp = t_0;
	} else if (d <= 5.8e+136) {
		tmp = fma(a, (c / d), b) / d;
	} else {
		tmp = t_1;
	}
	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)))
	t_1 = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, d)))
	tmp = 0.0
	if (d <= -1.2e+84)
		tmp = t_1;
	elseif (d <= -2.1e-35)
		tmp = t_0;
	elseif (d <= 4.8e-86)
		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
	elseif (d <= 1.8e+75)
		tmp = t_0;
	elseif (d <= 5.8e+136)
		tmp = Float64(fma(a, Float64(c / d), b) / d);
	else
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+84], t$95$1, If[LessEqual[d, -2.1e-35], t$95$0, If[LessEqual[d, 4.8e-86], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.8e+75], t$95$0, If[LessEqual[d, 5.8e+136], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -1.2 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -2.1 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 4.8 \cdot 10^{-86}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\

\mathbf{elif}\;d \leq 1.8 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 5.8 \cdot 10^{+136}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.2e84 or 5.79999999999999949e136 < d

    1. Initial program 36.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 34.2%

      \[\leadsto \frac{\color{blue}{b \cdot d}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. *-commutative34.2%

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt34.2%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. hypot-undefine34.2%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{c \cdot c + d \cdot d}} \]
      4. hypot-undefine34.2%

        \[\leadsto \frac{d \cdot b}{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
      5. times-frac84.9%

        \[\leadsto \color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Applied egg-rr84.9%

      \[\leadsto \color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} \]

    if -1.2e84 < d < -2.1e-35 or 4.80000000000000026e-86 < d < 1.8e75

    1. Initial program 87.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -2.1e-35 < d < 4.80000000000000026e-86

    1. Initial program 68.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 93.3%

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]

    if 1.8e75 < d < 5.79999999999999949e136

    1. Initial program 51.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf 79.3%

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. +-commutative79.3%

        \[\leadsto \frac{\color{blue}{\frac{a \cdot c}{d} + b}}{d} \]
      2. associate-/l*86.1%

        \[\leadsto \frac{\color{blue}{a \cdot \frac{c}{d}} + b}{d} \]
      3. fma-define86.1%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}}{d} \]
    5. Simplified86.1%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 2: 84.9% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
   (/ (+ a (* d (/ b c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (a + (d * (b / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0

    1. Initial program 74.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-sqr-sqrt74.9%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. associate-/r*75.0%

        \[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}} \]
      3. fma-define75.0%

        \[\leadsto \frac{\frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}} \]
      4. hypot-define75.0%

        \[\leadsto \frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-define94.2%

        \[\leadsto \frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Applied egg-rr94.2%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} \]

    if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 0.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 44.4%

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative44.4%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*56.4%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
    5. Applied egg-rr56.4%

      \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 82.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -3.1 \cdot 10^{+108}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -1.5 \cdot 10^{+84}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-36}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq 1.56 \cdot 10^{-86}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+79}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma a (/ c d) b) d))
        (t_1 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -3.1e+108)
     t_0
     (if (<= d -1.5e+84)
       (/ (+ a (* d (/ b c))) c)
       (if (<= d -9.5e-36)
         t_1
         (if (<= d 1.56e-86)
           (/ (+ a (/ (* b d) c)) c)
           (if (<= d 3.6e+79) t_1 t_0)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(a, (c / d), b) / d;
	double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -3.1e+108) {
		tmp = t_0;
	} else if (d <= -1.5e+84) {
		tmp = (a + (d * (b / c))) / c;
	} else if (d <= -9.5e-36) {
		tmp = t_1;
	} else if (d <= 1.56e-86) {
		tmp = (a + ((b * d) / c)) / c;
	} else if (d <= 3.6e+79) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(a, Float64(c / d), b) / d)
	t_1 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -3.1e+108)
		tmp = t_0;
	elseif (d <= -1.5e+84)
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	elseif (d <= -9.5e-36)
		tmp = t_1;
	elseif (d <= 1.56e-86)
		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
	elseif (d <= 3.6e+79)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.1e+108], t$95$0, If[LessEqual[d, -1.5e+84], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, -9.5e-36], t$95$1, If[LessEqual[d, 1.56e-86], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.6e+79], t$95$1, t$95$0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -3.1 \cdot 10^{+108}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq -1.5 \cdot 10^{+84}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\

\mathbf{elif}\;d \leq -9.5 \cdot 10^{-36}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq 1.56 \cdot 10^{-86}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\

\mathbf{elif}\;d \leq 3.6 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -3.1000000000000001e108 or 3.5999999999999999e79 < d

    1. Initial program 40.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf 77.9%

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. +-commutative77.9%

        \[\leadsto \frac{\color{blue}{\frac{a \cdot c}{d} + b}}{d} \]
      2. associate-/l*82.8%

        \[\leadsto \frac{\color{blue}{a \cdot \frac{c}{d}} + b}{d} \]
      3. fma-define82.8%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}}{d} \]
    5. Simplified82.8%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}} \]

    if -3.1000000000000001e108 < d < -1.49999999999999998e84

    1. Initial program 23.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 67.6%

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative67.6%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*100.0%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
    5. Applied egg-rr100.0%

      \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]

    if -1.49999999999999998e84 < d < -9.5000000000000003e-36 or 1.5599999999999999e-86 < d < 3.5999999999999999e79

    1. Initial program 87.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -9.5000000000000003e-36 < d < 1.5599999999999999e-86

    1. Initial program 68.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 93.3%

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 4: 79.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a + d \cdot \frac{b}{c}}{c}\\ \mathbf{if}\;c \leq -6.2 \cdot 10^{-51}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.16 \cdot 10^{-110}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 6.4 \cdot 10^{+42}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ a (* d (/ b c))) c)))
   (if (<= c -6.2e-51)
     t_0
     (if (<= c 1.16e-110)
       (/ (+ b (/ (* a c) d)) d)
       (if (<= c 6.4e+42) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (a + (d * (b / c))) / c;
	double tmp;
	if (c <= -6.2e-51) {
		tmp = t_0;
	} else if (c <= 1.16e-110) {
		tmp = (b + ((a * c) / d)) / d;
	} else if (c <= 6.4e+42) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (a + (d * (b / c))) / c
    if (c <= (-6.2d-51)) then
        tmp = t_0
    else if (c <= 1.16d-110) then
        tmp = (b + ((a * c) / d)) / d
    else if (c <= 6.4d+42) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (a + (d * (b / c))) / c;
	double tmp;
	if (c <= -6.2e-51) {
		tmp = t_0;
	} else if (c <= 1.16e-110) {
		tmp = (b + ((a * c) / d)) / d;
	} else if (c <= 6.4e+42) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a + (d * (b / c))) / c
	tmp = 0
	if c <= -6.2e-51:
		tmp = t_0
	elif c <= 1.16e-110:
		tmp = (b + ((a * c) / d)) / d
	elif c <= 6.4e+42:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a + Float64(d * Float64(b / c))) / c)
	tmp = 0.0
	if (c <= -6.2e-51)
		tmp = t_0;
	elseif (c <= 1.16e-110)
		tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d);
	elseif (c <= 6.4e+42)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a + (d * (b / c))) / c;
	tmp = 0.0;
	if (c <= -6.2e-51)
		tmp = t_0;
	elseif (c <= 1.16e-110)
		tmp = (b + ((a * c) / d)) / d;
	elseif (c <= 6.4e+42)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -6.2e-51], t$95$0, If[LessEqual[c, 1.16e-110], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.4e+42], 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{a + d \cdot \frac{b}{c}}{c}\\
\mathbf{if}\;c \leq -6.2 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.16 \cdot 10^{-110}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\

\mathbf{elif}\;c \leq 6.4 \cdot 10^{+42}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -6.1999999999999995e-51 or 6.40000000000000004e42 < c

    1. Initial program 51.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 79.9%

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative79.9%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*84.2%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
    5. Applied egg-rr84.2%

      \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]

    if -6.1999999999999995e-51 < c < 1.16000000000000001e-110

    1. Initial program 71.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf 86.2%

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]

    if 1.16000000000000001e-110 < c < 6.40000000000000004e42

    1. Initial program 90.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 76.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{-51} \lor \neg \left(c \leq 2.9 \cdot 10^{-50}\right):\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -6.2e-51) (not (<= c 2.9e-50)))
   (/ (+ a (* d (/ b c))) c)
   (/ (+ b (/ (* a c) d)) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -6.2e-51) || !(c <= 2.9e-50)) {
		tmp = (a + (d * (b / c))) / c;
	} else {
		tmp = (b + ((a * c) / d)) / 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 <= (-6.2d-51)) .or. (.not. (c <= 2.9d-50))) then
        tmp = (a + (d * (b / c))) / c
    else
        tmp = (b + ((a * c) / d)) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -6.2e-51) || !(c <= 2.9e-50)) {
		tmp = (a + (d * (b / c))) / c;
	} else {
		tmp = (b + ((a * c) / d)) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -6.2e-51) or not (c <= 2.9e-50):
		tmp = (a + (d * (b / c))) / c
	else:
		tmp = (b + ((a * c) / d)) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -6.2e-51) || !(c <= 2.9e-50))
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	else
		tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -6.2e-51) || ~((c <= 2.9e-50)))
		tmp = (a + (d * (b / c))) / c;
	else
		tmp = (b + ((a * c) / d)) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6.2e-51], N[Not[LessEqual[c, 2.9e-50]], $MachinePrecision]], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-51} \lor \neg \left(c \leq 2.9 \cdot 10^{-50}\right):\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -6.1999999999999995e-51 or 2.90000000000000008e-50 < c

    1. Initial program 54.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 79.2%

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative79.2%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*83.2%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
    5. Applied egg-rr83.2%

      \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]

    if -6.1999999999999995e-51 < c < 2.90000000000000008e-50

    1. Initial program 74.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf 84.6%

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{-51} \lor \neg \left(c \leq 2.9 \cdot 10^{-50}\right):\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 72.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4 \cdot 10^{+109} \lor \neg \left(d \leq 1850000000000\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -4e+109) (not (<= d 1850000000000.0)))
   (/ b d)
   (/ (+ a (* d (/ b c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -4e+109) || !(d <= 1850000000000.0)) {
		tmp = b / d;
	} else {
		tmp = (a + (d * (b / c))) / 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 ((d <= (-4d+109)) .or. (.not. (d <= 1850000000000.0d0))) then
        tmp = b / d
    else
        tmp = (a + (d * (b / c))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -4e+109) || !(d <= 1850000000000.0)) {
		tmp = b / d;
	} else {
		tmp = (a + (d * (b / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -4e+109) or not (d <= 1850000000000.0):
		tmp = b / d
	else:
		tmp = (a + (d * (b / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -4e+109) || !(d <= 1850000000000.0))
		tmp = Float64(b / d);
	else
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -4e+109) || ~((d <= 1850000000000.0)))
		tmp = b / d;
	else
		tmp = (a + (d * (b / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4e+109], N[Not[LessEqual[d, 1850000000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4 \cdot 10^{+109} \lor \neg \left(d \leq 1850000000000\right):\\
\;\;\;\;\frac{b}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.99999999999999993e109 or 1.85e12 < d

    1. Initial program 48.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 73.5%

      \[\leadsto \color{blue}{\frac{b}{d}} \]

    if -3.99999999999999993e109 < d < 1.85e12

    1. Initial program 71.1%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 81.9%

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative81.9%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*82.6%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
    5. Applied egg-rr82.6%

      \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4 \cdot 10^{+109} \lor \neg \left(d \leq 1850000000000\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 64.7% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -8.5 \cdot 10^{-34} \lor \neg \left(d \leq 11000000\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -8.5e-34) (not (<= d 11000000.0))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -8.5e-34) || !(d <= 11000000.0)) {
		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 ((d <= (-8.5d-34)) .or. (.not. (d <= 11000000.0d0))) 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 <= -8.5e-34) || !(d <= 11000000.0)) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -8.5e-34) or not (d <= 11000000.0):
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -8.5e-34) || !(d <= 11000000.0))
		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 <= -8.5e-34) || ~((d <= 11000000.0)))
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8.5e-34], N[Not[LessEqual[d, 11000000.0]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.5 \cdot 10^{-34} \lor \neg \left(d \leq 11000000\right):\\
\;\;\;\;\frac{b}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.5000000000000001e-34 or 1.1e7 < d

    1. Initial program 55.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 64.0%

      \[\leadsto \color{blue}{\frac{b}{d}} \]

    if -8.5000000000000001e-34 < d < 1.1e7

    1. Initial program 69.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 79.1%

      \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.5 \cdot 10^{-34} \lor \neg \left(d \leq 11000000\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 42.1% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{a}{c} \end{array} \]
(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}
Derivation
  1. Initial program 62.6%

    \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Taylor expanded in c around inf 49.7%

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Add Preprocessing

Developer target: 99.3% accurate, 0.1× speedup?

\[\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} \]
(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}

Reproduce

?
herbie shell --seed 2024096 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (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))))