Complex division, real part

Percentage Accurate: 61.3% → 85.0%
Time: 23.4s
Alternatives: 12
Speedup: 0.8×

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 12 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.3% 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: 85.0% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t\_0 \leq 2 \cdot 10^{+265}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= t_0 2e+265)
     (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
     (if (<= t_0 INFINITY)
       (/ (+ a (* b (/ d c))) c)
       (/ (+ b (* a (/ c d))) d)))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (t_0 <= 2e+265) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = (a + (b * (d / c))) / c;
	} else {
		tmp = (b + (a * (c / d))) / d;
	}
	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 (t_0 <= 2e+265)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	elseif (t_0 <= Inf)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	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[t$95$0, 2e+265], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+265}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\

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


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

    1. Initial program 80.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity80.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt80.5%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac80.4%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define80.4%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-define96.8%

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

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

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

    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 inf 94.5%

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

        \[\leadsto \frac{a + \color{blue}{b \cdot \frac{d}{c}}}{c} \]
    5. Simplified94.6%

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

    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. Step-by-step derivation
      1. *-un-lft-identity0.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt0.0%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac0.0%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define0.0%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-define2.8%

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Taylor expanded in d around inf 55.8%

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

        \[\leadsto \frac{b + \color{blue}{a \cdot \frac{c}{d}}}{d} \]
    7. Simplified66.5%

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

Alternative 2: 80.7% 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 -9.5 \cdot 10^{+143}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -1.6 \cdot 10^{-52}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-146}:\\ \;\;\;\;\frac{a + \frac{1}{\frac{c}{b \cdot d}}}{c}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+144}:\\ \;\;\;\;t\_0\\ \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 -9.5e+143)
     t_1
     (if (<= d -1.6e-52)
       t_0
       (if (<= d 5.8e-146)
         (/ (+ a (/ 1.0 (/ c (* b d)))) c)
         (if (<= d 6.5e+144) t_0 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 <= -9.5e+143) {
		tmp = t_1;
	} else if (d <= -1.6e-52) {
		tmp = t_0;
	} else if (d <= 5.8e-146) {
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	} else if (d <= 6.5e+144) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static 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 / Math.hypot(c, d)) * (b / Math.hypot(c, d));
	double tmp;
	if (d <= -9.5e+143) {
		tmp = t_1;
	} else if (d <= -1.6e-52) {
		tmp = t_0;
	} else if (d <= 5.8e-146) {
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	} else if (d <= 6.5e+144) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (d / math.hypot(c, d)) * (b / math.hypot(c, d))
	tmp = 0
	if d <= -9.5e+143:
		tmp = t_1
	elif d <= -1.6e-52:
		tmp = t_0
	elif d <= 5.8e-146:
		tmp = (a + (1.0 / (c / (b * d)))) / c
	elif d <= 6.5e+144:
		tmp = t_0
	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 <= -9.5e+143)
		tmp = t_1;
	elseif (d <= -1.6e-52)
		tmp = t_0;
	elseif (d <= 5.8e-146)
		tmp = Float64(Float64(a + Float64(1.0 / Float64(c / Float64(b * d)))) / c);
	elseif (d <= 6.5e+144)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (d / hypot(c, d)) * (b / hypot(c, d));
	tmp = 0.0;
	if (d <= -9.5e+143)
		tmp = t_1;
	elseif (d <= -1.6e-52)
		tmp = t_0;
	elseif (d <= 5.8e-146)
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	elseif (d <= 6.5e+144)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = 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, -9.5e+143], t$95$1, If[LessEqual[d, -1.6e-52], t$95$0, If[LessEqual[d, 5.8e-146], N[(N[(a + N[(1.0 / N[(c / N[(b * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6.5e+144], t$95$0, 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 -9.5 \cdot 10^{+143}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -1.6 \cdot 10^{-52}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 5.8 \cdot 10^{-146}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{c}{b \cdot d}}}{c}\\

\mathbf{elif}\;d \leq 6.5 \cdot 10^{+144}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -9.50000000000000066e143 or 6.50000000000000007e144 < d

    1. Initial program 40.5%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    5. Simplified40.5%

      \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt40.5%

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

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

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

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

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

    if -9.50000000000000066e143 < d < -1.60000000000000005e-52 or 5.80000000000000022e-146 < d < 6.50000000000000007e144

    1. Initial program 88.7%

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

    if -1.60000000000000005e-52 < d < 5.80000000000000022e-146

    1. Initial program 63.7%

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{1}{\frac{c}{b \cdot d}}}}{c} \]
      2. inv-pow88.4%

        \[\leadsto \frac{a + \color{blue}{{\left(\frac{c}{b \cdot d}\right)}^{-1}}}{c} \]
      3. *-commutative88.4%

        \[\leadsto \frac{a + {\left(\frac{c}{\color{blue}{d \cdot b}}\right)}^{-1}}{c} \]
    5. Applied egg-rr88.4%

      \[\leadsto \frac{a + \color{blue}{{\left(\frac{c}{d \cdot b}\right)}^{-1}}}{c} \]
    6. Step-by-step derivation
      1. unpow-188.4%

        \[\leadsto \frac{a + \color{blue}{\frac{1}{\frac{c}{d \cdot b}}}}{c} \]
      2. *-commutative88.4%

        \[\leadsto \frac{a + \frac{1}{\frac{c}{\color{blue}{b \cdot d}}}}{c} \]
    7. Simplified88.4%

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

Alternative 3: 82.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -6.5 \cdot 10^{+90}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-52}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{-143}:\\ \;\;\;\;\frac{a + \frac{1}{\frac{c}{b \cdot d}}}{c}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{+124}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d \cdot \frac{d}{a}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -6.5e+90)
     (+ (/ b d) (/ (/ a d) (/ d c)))
     (if (<= d -1.45e-52)
       t_0
       (if (<= d 6.6e-143)
         (/ (+ a (/ 1.0 (/ c (* b d)))) c)
         (if (<= d 6.8e+124) t_0 (+ (/ b d) (/ c (* d (/ d a))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -6.5e+90) {
		tmp = (b / d) + ((a / d) / (d / c));
	} else if (d <= -1.45e-52) {
		tmp = t_0;
	} else if (d <= 6.6e-143) {
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	} else if (d <= 6.8e+124) {
		tmp = t_0;
	} else {
		tmp = (b / d) + (c / (d * (d / a)));
	}
	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 * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-6.5d+90)) then
        tmp = (b / d) + ((a / d) / (d / c))
    else if (d <= (-1.45d-52)) then
        tmp = t_0
    else if (d <= 6.6d-143) then
        tmp = (a + (1.0d0 / (c / (b * d)))) / c
    else if (d <= 6.8d+124) then
        tmp = t_0
    else
        tmp = (b / d) + (c / (d * (d / a)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -6.5e+90) {
		tmp = (b / d) + ((a / d) / (d / c));
	} else if (d <= -1.45e-52) {
		tmp = t_0;
	} else if (d <= 6.6e-143) {
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	} else if (d <= 6.8e+124) {
		tmp = t_0;
	} else {
		tmp = (b / d) + (c / (d * (d / a)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -6.5e+90:
		tmp = (b / d) + ((a / d) / (d / c))
	elif d <= -1.45e-52:
		tmp = t_0
	elif d <= 6.6e-143:
		tmp = (a + (1.0 / (c / (b * d)))) / c
	elif d <= 6.8e+124:
		tmp = t_0
	else:
		tmp = (b / d) + (c / (d * (d / a)))
	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 (d <= -6.5e+90)
		tmp = Float64(Float64(b / d) + Float64(Float64(a / d) / Float64(d / c)));
	elseif (d <= -1.45e-52)
		tmp = t_0;
	elseif (d <= 6.6e-143)
		tmp = Float64(Float64(a + Float64(1.0 / Float64(c / Float64(b * d)))) / c);
	elseif (d <= 6.8e+124)
		tmp = t_0;
	else
		tmp = Float64(Float64(b / d) + Float64(c / Float64(d * Float64(d / a))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -6.5e+90)
		tmp = (b / d) + ((a / d) / (d / c));
	elseif (d <= -1.45e-52)
		tmp = t_0;
	elseif (d <= 6.6e-143)
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	elseif (d <= 6.8e+124)
		tmp = t_0;
	else
		tmp = (b / d) + (c / (d * (d / a)));
	end
	tmp_2 = 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[d, -6.5e+90], N[(N[(b / d), $MachinePrecision] + N[(N[(a / d), $MachinePrecision] / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.45e-52], t$95$0, If[LessEqual[d, 6.6e-143], N[(N[(a + N[(1.0 / N[(c / N[(b * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6.8e+124], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(c / N[(d * N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -6.5 \cdot 10^{+90}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\

\mathbf{elif}\;d \leq -1.45 \cdot 10^{-52}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 6.6 \cdot 10^{-143}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{c}{b \cdot d}}}{c}\\

\mathbf{elif}\;d \leq 6.8 \cdot 10^{+124}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -6.5000000000000001e90

    1. Initial program 53.0%

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{{d}^{2}} \]
      2. pow285.7%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      3. times-frac87.6%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{d} \cdot \frac{c}{d}} \]
      2. clear-num87.7%

        \[\leadsto \frac{b}{d} + \frac{a}{d} \cdot \color{blue}{\frac{1}{\frac{d}{c}}} \]
      3. un-div-inv87.7%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{\frac{a}{d}}{\frac{d}{c}}} \]
    7. Applied egg-rr87.7%

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

    if -6.5000000000000001e90 < d < -1.4500000000000001e-52 or 6.6000000000000001e-143 < d < 6.8e124

    1. Initial program 89.9%

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

    if -1.4500000000000001e-52 < d < 6.6000000000000001e-143

    1. Initial program 63.7%

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{1}{\frac{c}{b \cdot d}}}}{c} \]
      2. inv-pow88.4%

        \[\leadsto \frac{a + \color{blue}{{\left(\frac{c}{b \cdot d}\right)}^{-1}}}{c} \]
      3. *-commutative88.4%

        \[\leadsto \frac{a + {\left(\frac{c}{\color{blue}{d \cdot b}}\right)}^{-1}}{c} \]
    5. Applied egg-rr88.4%

      \[\leadsto \frac{a + \color{blue}{{\left(\frac{c}{d \cdot b}\right)}^{-1}}}{c} \]
    6. Step-by-step derivation
      1. unpow-188.4%

        \[\leadsto \frac{a + \color{blue}{\frac{1}{\frac{c}{d \cdot b}}}}{c} \]
      2. *-commutative88.4%

        \[\leadsto \frac{a + \frac{1}{\frac{c}{\color{blue}{b \cdot d}}}}{c} \]
    7. Simplified88.4%

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

    if 6.8e124 < d

    1. Initial program 34.2%

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{{d}^{2}} \]
      2. pow288.9%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      3. times-frac94.6%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{d} \cdot \frac{c}{d}} \]
      2. clear-num94.6%

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{1 \cdot c}{\frac{d}{a} \cdot d}} \]
      4. *-un-lft-identity94.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.5 \cdot 10^{+90}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-52}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{-143}:\\ \;\;\;\;\frac{a + \frac{1}{\frac{c}{b \cdot d}}}{c}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{+124}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d \cdot \frac{d}{a}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 75.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3.5 \cdot 10^{-39}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{-125}:\\ \;\;\;\;\frac{a + \frac{1}{\frac{c}{b \cdot d}}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -3.5e-39)
   (+ (/ b d) (/ (/ a d) (/ d c)))
   (if (<= d 2.8e-125)
     (/ (+ a (/ 1.0 (/ c (* b d)))) c)
     (/ (+ b (/ a (/ d c))) d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -3.5e-39) {
		tmp = (b / d) + ((a / d) / (d / c));
	} else if (d <= 2.8e-125) {
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	} else {
		tmp = (b + (a / (d / 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 (d <= (-3.5d-39)) then
        tmp = (b / d) + ((a / d) / (d / c))
    else if (d <= 2.8d-125) then
        tmp = (a + (1.0d0 / (c / (b * d)))) / c
    else
        tmp = (b + (a / (d / c))) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -3.5e-39) {
		tmp = (b / d) + ((a / d) / (d / c));
	} else if (d <= 2.8e-125) {
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	} else {
		tmp = (b + (a / (d / c))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -3.5e-39:
		tmp = (b / d) + ((a / d) / (d / c))
	elif d <= 2.8e-125:
		tmp = (a + (1.0 / (c / (b * d)))) / c
	else:
		tmp = (b + (a / (d / c))) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -3.5e-39)
		tmp = Float64(Float64(b / d) + Float64(Float64(a / d) / Float64(d / c)));
	elseif (d <= 2.8e-125)
		tmp = Float64(Float64(a + Float64(1.0 / Float64(c / Float64(b * d)))) / c);
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -3.5e-39)
		tmp = (b / d) + ((a / d) / (d / c));
	elseif (d <= 2.8e-125)
		tmp = (a + (1.0 / (c / (b * d)))) / c;
	else
		tmp = (b + (a / (d / c))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.5e-39], N[(N[(b / d), $MachinePrecision] + N[(N[(a / d), $MachinePrecision] / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.8e-125], N[(N[(a + N[(1.0 / N[(c / N[(b * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.5 \cdot 10^{-39}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\

\mathbf{elif}\;d \leq 2.8 \cdot 10^{-125}:\\
\;\;\;\;\frac{a + \frac{1}{\frac{c}{b \cdot d}}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.5e-39

    1. Initial program 63.7%

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{{d}^{2}} \]
      2. pow282.0%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      3. times-frac83.4%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{d} \cdot \frac{c}{d}} \]
      2. clear-num83.4%

        \[\leadsto \frac{b}{d} + \frac{a}{d} \cdot \color{blue}{\frac{1}{\frac{d}{c}}} \]
      3. un-div-inv83.4%

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

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

    if -3.5e-39 < d < 2.8e-125

    1. Initial program 65.5%

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{1}{\frac{c}{b \cdot d}}}}{c} \]
      2. inv-pow85.8%

        \[\leadsto \frac{a + \color{blue}{{\left(\frac{c}{b \cdot d}\right)}^{-1}}}{c} \]
      3. *-commutative85.8%

        \[\leadsto \frac{a + {\left(\frac{c}{\color{blue}{d \cdot b}}\right)}^{-1}}{c} \]
    5. Applied egg-rr85.8%

      \[\leadsto \frac{a + \color{blue}{{\left(\frac{c}{d \cdot b}\right)}^{-1}}}{c} \]
    6. Step-by-step derivation
      1. unpow-185.8%

        \[\leadsto \frac{a + \color{blue}{\frac{1}{\frac{c}{d \cdot b}}}}{c} \]
      2. *-commutative85.8%

        \[\leadsto \frac{a + \frac{1}{\frac{c}{\color{blue}{b \cdot d}}}}{c} \]
    7. Simplified85.8%

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

    if 2.8e-125 < d

    1. Initial program 63.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity63.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt63.5%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac63.5%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define63.5%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Taylor expanded in d around inf 82.1%

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

        \[\leadsto \frac{b + \color{blue}{a \cdot \frac{c}{d}}}{d} \]
    7. Simplified83.3%

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
      2. un-div-inv83.4%

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

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

Alternative 5: 75.5% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.70000000000000001e-51 or 1.5000000000000001e-126 < d

    1. Initial program 63.6%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity63.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt63.6%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac63.6%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define63.6%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Taylor expanded in d around inf 81.2%

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

        \[\leadsto \frac{b + \color{blue}{a \cdot \frac{c}{d}}}{d} \]
    7. Simplified81.8%

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

    if -1.70000000000000001e-51 < d < 1.5000000000000001e-126

    1. Initial program 65.4%

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

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

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

Alternative 6: 69.9% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.3 \cdot 10^{-24} \lor \neg \left(d \leq 1.8 \cdot 10^{-103}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.3000000000000001e-24 or 1.7999999999999999e-103 < d

    1. Initial program 62.3%

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

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

    if -2.3000000000000001e-24 < d < 1.7999999999999999e-103

    1. Initial program 67.0%

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

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

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

Alternative 7: 69.7% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{-27} \lor \neg \left(d \leq 1.8 \cdot 10^{-103}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.05000000000000008e-27 or 1.7999999999999999e-103 < d

    1. Initial program 62.3%

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

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

    if -1.05000000000000008e-27 < d < 1.7999999999999999e-103

    1. Initial program 67.0%

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

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

        \[\leadsto \frac{a + \color{blue}{b \cdot \frac{d}{c}}}{c} \]
    5. Simplified83.7%

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

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

Alternative 8: 75.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.5 \cdot 10^{-38}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{-125}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -5.5e-38)
   (+ (/ b d) (/ (/ a d) (/ d c)))
   (if (<= d 2.8e-125) (/ (+ a (/ (* b d) c)) c) (/ (+ b (/ a (/ d c))) d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.5e-38) {
		tmp = (b / d) + ((a / d) / (d / c));
	} else if (d <= 2.8e-125) {
		tmp = (a + ((b * d) / c)) / c;
	} else {
		tmp = (b + (a / (d / 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 (d <= (-5.5d-38)) then
        tmp = (b / d) + ((a / d) / (d / c))
    else if (d <= 2.8d-125) then
        tmp = (a + ((b * d) / c)) / c
    else
        tmp = (b + (a / (d / c))) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.5e-38) {
		tmp = (b / d) + ((a / d) / (d / c));
	} else if (d <= 2.8e-125) {
		tmp = (a + ((b * d) / c)) / c;
	} else {
		tmp = (b + (a / (d / c))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -5.5e-38:
		tmp = (b / d) + ((a / d) / (d / c))
	elif d <= 2.8e-125:
		tmp = (a + ((b * d) / c)) / c
	else:
		tmp = (b + (a / (d / c))) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -5.5e-38)
		tmp = Float64(Float64(b / d) + Float64(Float64(a / d) / Float64(d / c)));
	elseif (d <= 2.8e-125)
		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -5.5e-38)
		tmp = (b / d) + ((a / d) / (d / c));
	elseif (d <= 2.8e-125)
		tmp = (a + ((b * d) / c)) / c;
	else
		tmp = (b + (a / (d / c))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.5e-38], N[(N[(b / d), $MachinePrecision] + N[(N[(a / d), $MachinePrecision] / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.8e-125], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.5 \cdot 10^{-38}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.50000000000000005e-38

    1. Initial program 63.7%

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{{d}^{2}} \]
      2. pow282.0%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      3. times-frac83.4%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{d} \cdot \frac{c}{d}} \]
      2. clear-num83.4%

        \[\leadsto \frac{b}{d} + \frac{a}{d} \cdot \color{blue}{\frac{1}{\frac{d}{c}}} \]
      3. un-div-inv83.4%

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

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

    if -5.50000000000000005e-38 < d < 2.8e-125

    1. Initial program 65.5%

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

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

    if 2.8e-125 < d

    1. Initial program 63.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity63.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt63.5%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac63.5%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define63.5%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Taylor expanded in d around inf 82.1%

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

        \[\leadsto \frac{b + \color{blue}{a \cdot \frac{c}{d}}}{d} \]
    7. Simplified83.3%

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
      2. un-div-inv83.4%

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

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

Alternative 9: 75.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{-35}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{-125}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -2.1e-35)
   (+ (/ b d) (* (/ c d) (/ a d)))
   (if (<= d 2.7e-125) (/ (+ a (/ (* b d) c)) c) (/ (+ b (/ a (/ d c))) d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -2.1e-35) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (d <= 2.7e-125) {
		tmp = (a + ((b * d) / c)) / c;
	} else {
		tmp = (b + (a / (d / 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 (d <= (-2.1d-35)) then
        tmp = (b / d) + ((c / d) * (a / d))
    else if (d <= 2.7d-125) then
        tmp = (a + ((b * d) / c)) / c
    else
        tmp = (b + (a / (d / c))) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -2.1e-35) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (d <= 2.7e-125) {
		tmp = (a + ((b * d) / c)) / c;
	} else {
		tmp = (b + (a / (d / c))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -2.1e-35:
		tmp = (b / d) + ((c / d) * (a / d))
	elif d <= 2.7e-125:
		tmp = (a + ((b * d) / c)) / c
	else:
		tmp = (b + (a / (d / c))) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -2.1e-35)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	elseif (d <= 2.7e-125)
		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -2.1e-35)
		tmp = (b / d) + ((c / d) * (a / d));
	elseif (d <= 2.7e-125)
		tmp = (a + ((b * d) / c)) / c;
	else
		tmp = (b + (a / (d / c))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.1e-35], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.7e-125], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{-35}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.1e-35

    1. Initial program 63.7%

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{{d}^{2}} \]
      2. pow282.0%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      3. times-frac83.4%

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

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

    if -2.1e-35 < d < 2.6999999999999998e-125

    1. Initial program 65.5%

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

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

    if 2.6999999999999998e-125 < d

    1. Initial program 63.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity63.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt63.5%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac63.5%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define63.5%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Taylor expanded in d around inf 82.1%

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

        \[\leadsto \frac{b + \color{blue}{a \cdot \frac{c}{d}}}{d} \]
    7. Simplified83.3%

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
      2. un-div-inv83.4%

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

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

Alternative 10: 75.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{-51}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.8e-51

    1. Initial program 63.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity63.8%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt63.8%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac63.7%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define63.7%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Taylor expanded in d around inf 80.3%

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

        \[\leadsto \frac{b + \color{blue}{a \cdot \frac{c}{d}}}{d} \]
    7. Simplified80.4%

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

    if -4.8e-51 < d < 2.8e-125

    1. Initial program 65.4%

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

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

    if 2.8e-125 < d

    1. Initial program 63.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity63.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt63.5%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac63.5%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define63.5%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Taylor expanded in d around inf 82.1%

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

        \[\leadsto \frac{b + \color{blue}{a \cdot \frac{c}{d}}}{d} \]
    7. Simplified83.3%

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
      2. un-div-inv83.4%

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

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

Alternative 11: 61.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.3 \cdot 10^{-73} \lor \neg \left(d \leq 1.15 \cdot 10^{-141}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.30000000000000004e-73 or 1.14999999999999997e-141 < d

    1. Initial program 64.8%

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

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

    if -3.30000000000000004e-73 < d < 1.14999999999999997e-141

    1. Initial program 63.5%

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

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

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

Alternative 12: 42.3% 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 64.4%

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

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

Developer Target 1: 99.2% 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 2024143 
(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))))