Complex division, real part

Percentage Accurate: 61.4% → 84.9%
Time: 11.4s
Alternatives: 11
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 11 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: 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 5 \cdot 10^{+299}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+299)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (+ (/ a c) (/ b (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+299) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (a / c) + (b / (c * (c / d)));
	}
	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))) <= 5e+299)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	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], 5e+299], 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], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+299}:\\
\;\;\;\;\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{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\


\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))) < 5.0000000000000003e299

    1. Initial program 78.2%

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d}} \]
      3. fma-def78.2%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt78.2%

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

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

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

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

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

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

        \[\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-rr93.4%

      \[\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 5.0000000000000003e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 13.8%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified49.2%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv49.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv44.6%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt23.1%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod44.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg44.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\sqrt{\color{blue}{d \cdot d}}}} \]
      13. sqrt-prod28.8%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt56.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+299}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 79.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot c + b \cdot d\\ t_1 := b + a \cdot \frac{c}{d}\\ \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{t\_1}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{-169}:\\ \;\;\;\;\frac{t\_0}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{+66}:\\ \;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))) (t_1 (+ b (* a (/ c d)))))
   (if (<= d -2.7e+36)
     (/ t_1 (- (hypot c d)))
     (if (<= d -1.8e-169)
       (/ t_0 (pow (hypot c d) 2.0))
       (if (<= d 1e-293)
         (+ (/ a c) (/ b (* c (/ c d))))
         (if (<= d 4.4e+66)
           (/ t_0 (+ (* c c) (* d d)))
           (/ t_1 (hypot c d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double t_1 = b + (a * (c / d));
	double tmp;
	if (d <= -2.7e+36) {
		tmp = t_1 / -hypot(c, d);
	} else if (d <= -1.8e-169) {
		tmp = t_0 / pow(hypot(c, d), 2.0);
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 4.4e+66) {
		tmp = t_0 / ((c * c) + (d * d));
	} else {
		tmp = t_1 / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double t_1 = b + (a * (c / d));
	double tmp;
	if (d <= -2.7e+36) {
		tmp = t_1 / -Math.hypot(c, d);
	} else if (d <= -1.8e-169) {
		tmp = t_0 / Math.pow(Math.hypot(c, d), 2.0);
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 4.4e+66) {
		tmp = t_0 / ((c * c) + (d * d));
	} else {
		tmp = t_1 / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a * c) + (b * d)
	t_1 = b + (a * (c / d))
	tmp = 0
	if d <= -2.7e+36:
		tmp = t_1 / -math.hypot(c, d)
	elif d <= -1.8e-169:
		tmp = t_0 / math.pow(math.hypot(c, d), 2.0)
	elif d <= 1e-293:
		tmp = (a / c) + (b / (c * (c / d)))
	elif d <= 4.4e+66:
		tmp = t_0 / ((c * c) + (d * d))
	else:
		tmp = t_1 / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) + Float64(b * d))
	t_1 = Float64(b + Float64(a * Float64(c / d)))
	tmp = 0.0
	if (d <= -2.7e+36)
		tmp = Float64(t_1 / Float64(-hypot(c, d)));
	elseif (d <= -1.8e-169)
		tmp = Float64(t_0 / (hypot(c, d) ^ 2.0));
	elseif (d <= 1e-293)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (d <= 4.4e+66)
		tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(t_1 / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a * c) + (b * d);
	t_1 = b + (a * (c / d));
	tmp = 0.0;
	if (d <= -2.7e+36)
		tmp = t_1 / -hypot(c, d);
	elseif (d <= -1.8e-169)
		tmp = t_0 / (hypot(c, d) ^ 2.0);
	elseif (d <= 1e-293)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (d <= 4.4e+66)
		tmp = t_0 / ((c * c) + (d * d));
	else
		tmp = t_1 / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.7e+36], N[(t$95$1 / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[d, -1.8e-169], N[(t$95$0 / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.4e+66], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1.8 \cdot 10^{-169}:\\
\;\;\;\;\frac{t\_0}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\

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

\mathbf{elif}\;d \leq 4.4 \cdot 10^{+66}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -2.7000000000000001e36

    1. Initial program 48.1%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt48.1%

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

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

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

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

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

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

        \[\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-rr69.1%

      \[\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.6%

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)}{\mathsf{hypot}\left(c, d\right)}} \]
      2. *-un-lft-identity81.8%

        \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
      3. frac-2neg81.8%

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

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

    if -2.7000000000000001e36 < d < -1.80000000000000001e-169

    1. Initial program 81.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u79.3%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(c \cdot c + d \cdot d\right)\right)}} \]
      2. expm1-udef45.7%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{e^{\mathsf{log1p}\left(c \cdot c + d \cdot d\right)} - 1}} \]
      3. fma-def45.7%

        \[\leadsto \frac{a \cdot c + b \cdot d}{e^{\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)} - 1} \]
      4. add-sqr-sqrt45.7%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{e^{\mathsf{log1p}\left({\left(\sqrt{\color{blue}{c \cdot c + d \cdot d}}\right)}^{2}\right)} - 1} \]
      7. hypot-def45.7%

        \[\leadsto \frac{a \cdot c + b \cdot d}{e^{\mathsf{log1p}\left({\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}\right)} - 1} \]
    4. Applied egg-rr45.7%

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{e^{\mathsf{log1p}\left({\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}\right)} - 1}} \]
    5. Step-by-step derivation
      1. expm1-def79.3%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}\right)\right)}} \]
      2. expm1-log1p81.5%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}} \]
    6. Simplified81.5%

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

    if -1.80000000000000001e-169 < d < 1.0000000000000001e-293

    1. Initial program 67.3%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv82.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv68.0%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt61.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod68.5%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg68.5%

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt85.5%

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

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

    if 1.0000000000000001e-293 < d < 4.3999999999999997e66

    1. Initial program 80.3%

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

    if 4.3999999999999997e66 < d

    1. Initial program 35.1%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt35.2%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-def63.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-rr63.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 15.1%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)} \]
    6. Step-by-step derivation
      1. expm1-log1p-u15.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)\right)\right)} \]
      2. expm1-udef15.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)\right)} - 1} \]
    7. Applied egg-rr23.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-def65.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\right)\right)} \]
      2. expm1-log1p81.2%

        \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}} \]
    9. Simplified81.2%

      \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification81.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{-169}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{+66}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 77.0% 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{b}{d} + c \cdot \frac{a}{{d}^{2}}\\ \mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -5.5 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{+62}:\\ \;\;\;\;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 (+ (/ b d) (* c (/ a (pow d 2.0))))))
   (if (<= d -3.6e+46)
     t_1
     (if (<= d -5.5e-170)
       t_0
       (if (<= d 1e-293)
         (+ (/ a c) (/ b (* c (/ c d))))
         (if (<= d 1.25e+62) 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 = (b / d) + (c * (a / pow(d, 2.0)));
	double tmp;
	if (d <= -3.6e+46) {
		tmp = t_1;
	} else if (d <= -5.5e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 1.25e+62) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (b / d) + (c * (a / (d ** 2.0d0)))
    if (d <= (-3.6d+46)) then
        tmp = t_1
    else if (d <= (-5.5d-170)) then
        tmp = t_0
    else if (d <= 1d-293) then
        tmp = (a / c) + (b / (c * (c / d)))
    else if (d <= 1.25d+62) then
        tmp = t_0
    else
        tmp = t_1
    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 t_1 = (b / d) + (c * (a / Math.pow(d, 2.0)));
	double tmp;
	if (d <= -3.6e+46) {
		tmp = t_1;
	} else if (d <= -5.5e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 1.25e+62) {
		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 = (b / d) + (c * (a / math.pow(d, 2.0)))
	tmp = 0
	if d <= -3.6e+46:
		tmp = t_1
	elif d <= -5.5e-170:
		tmp = t_0
	elif d <= 1e-293:
		tmp = (a / c) + (b / (c * (c / d)))
	elif d <= 1.25e+62:
		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(b / d) + Float64(c * Float64(a / (d ^ 2.0))))
	tmp = 0.0
	if (d <= -3.6e+46)
		tmp = t_1;
	elseif (d <= -5.5e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (d <= 1.25e+62)
		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 = (b / d) + (c * (a / (d ^ 2.0)));
	tmp = 0.0;
	if (d <= -3.6e+46)
		tmp = t_1;
	elseif (d <= -5.5e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (d <= 1.25e+62)
		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[(b / d), $MachinePrecision] + N[(c * N[(a / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.6e+46], t$95$1, If[LessEqual[d, -5.5e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.25e+62], 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{b}{d} + c \cdot \frac{a}{{d}^{2}}\\
\mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -5.5 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.25 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.5999999999999999e46 or 1.25000000000000007e62 < d

    1. Initial program 41.9%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.5%

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

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

    if -3.5999999999999999e46 < d < -5.50000000000000018e-170 or 1.0000000000000001e-293 < d < 1.25000000000000007e62

    1. Initial program 81.1%

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

    if -5.50000000000000018e-170 < d < 1.0000000000000001e-293

    1. Initial program 67.3%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv82.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv68.0%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt61.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod68.5%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg68.5%

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt85.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\ \mathbf{elif}\;d \leq -5.5 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{+62}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.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}\\ \mathbf{if}\;d \leq -4.3 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\ \mathbf{elif}\;d \leq -5.4 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{+66}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -4.3e+46)
     (+ (/ b d) (* c (/ a (pow d 2.0))))
     (if (<= d -5.4e-170)
       t_0
       (if (<= d 1e-293)
         (+ (/ a c) (/ b (* c (/ c d))))
         (if (<= d 1.25e+66) t_0 (/ (+ b (* a (/ c d))) (hypot c 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 (d <= -4.3e+46) {
		tmp = (b / d) + (c * (a / pow(d, 2.0)));
	} else if (d <= -5.4e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 1.25e+66) {
		tmp = t_0;
	} else {
		tmp = (b + (a * (c / d))) / hypot(c, d);
	}
	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 tmp;
	if (d <= -4.3e+46) {
		tmp = (b / d) + (c * (a / Math.pow(d, 2.0)));
	} else if (d <= -5.4e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 1.25e+66) {
		tmp = t_0;
	} else {
		tmp = (b + (a * (c / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -4.3e+46:
		tmp = (b / d) + (c * (a / math.pow(d, 2.0)))
	elif d <= -5.4e-170:
		tmp = t_0
	elif d <= 1e-293:
		tmp = (a / c) + (b / (c * (c / d)))
	elif d <= 1.25e+66:
		tmp = t_0
	else:
		tmp = (b + (a * (c / d))) / math.hypot(c, 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 (d <= -4.3e+46)
		tmp = Float64(Float64(b / d) + Float64(c * Float64(a / (d ^ 2.0))));
	elseif (d <= -5.4e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (d <= 1.25e+66)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d));
	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 <= -4.3e+46)
		tmp = (b / d) + (c * (a / (d ^ 2.0)));
	elseif (d <= -5.4e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (d <= 1.25e+66)
		tmp = t_0;
	else
		tmp = (b + (a * (c / d))) / hypot(c, d);
	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, -4.3e+46], N[(N[(b / d), $MachinePrecision] + N[(c * N[(a / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.4e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.25e+66], t$95$0, N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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 -4.3 \cdot 10^{+46}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\

\mathbf{elif}\;d \leq -5.4 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.25 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 46.4%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.8%

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{{d}^{2}} \cdot c} \]
    5. Simplified76.8%

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

    if -4.30000000000000005e46 < d < -5.3999999999999997e-170 or 1.0000000000000001e-293 < d < 1.24999999999999998e66

    1. Initial program 81.1%

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

    if -5.3999999999999997e-170 < d < 1.0000000000000001e-293

    1. Initial program 67.3%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv82.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv68.0%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt61.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod68.5%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg68.5%

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt85.5%

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

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

    if 1.24999999999999998e66 < d

    1. Initial program 35.1%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt35.2%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-def63.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-rr63.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 15.1%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)} \]
    6. Step-by-step derivation
      1. expm1-log1p-u15.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)\right)\right)} \]
      2. expm1-udef15.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)\right)} - 1} \]
    7. Applied egg-rr23.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-def65.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\right)\right)} \]
      2. expm1-log1p81.2%

        \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}} \]
    9. Simplified81.2%

      \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification80.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.3 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\ \mathbf{elif}\;d \leq -5.4 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{+66}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 79.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 := b + a \cdot \frac{c}{d}\\ \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{t\_1}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{+60}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (+ b (* a (/ c d)))))
   (if (<= d -2.7e+36)
     (/ t_1 (- (hypot c d)))
     (if (<= d -1.3e-170)
       t_0
       (if (<= d 1e-293)
         (+ (/ a c) (/ b (* c (/ c d))))
         (if (<= d 2.4e+60) t_0 (/ t_1 (hypot c d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = b + (a * (c / d));
	double tmp;
	if (d <= -2.7e+36) {
		tmp = t_1 / -hypot(c, d);
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 2.4e+60) {
		tmp = t_0;
	} else {
		tmp = t_1 / hypot(c, d);
	}
	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 = b + (a * (c / d));
	double tmp;
	if (d <= -2.7e+36) {
		tmp = t_1 / -Math.hypot(c, d);
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 2.4e+60) {
		tmp = t_0;
	} else {
		tmp = t_1 / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = b + (a * (c / d))
	tmp = 0
	if d <= -2.7e+36:
		tmp = t_1 / -math.hypot(c, d)
	elif d <= -1.3e-170:
		tmp = t_0
	elif d <= 1e-293:
		tmp = (a / c) + (b / (c * (c / d)))
	elif d <= 2.4e+60:
		tmp = t_0
	else:
		tmp = t_1 / math.hypot(c, 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)))
	t_1 = Float64(b + Float64(a * Float64(c / d)))
	tmp = 0.0
	if (d <= -2.7e+36)
		tmp = Float64(t_1 / Float64(-hypot(c, d)));
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (d <= 2.4e+60)
		tmp = t_0;
	else
		tmp = Float64(t_1 / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = b + (a * (c / d));
	tmp = 0.0;
	if (d <= -2.7e+36)
		tmp = t_1 / -hypot(c, d);
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (d <= 2.4e+60)
		tmp = t_0;
	else
		tmp = t_1 / hypot(c, d);
	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[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.7e+36], N[(t$95$1 / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[d, -1.3e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.4e+60], t$95$0, N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.4 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 48.1%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt48.1%

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

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

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

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

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

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

        \[\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-rr69.1%

      \[\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.6%

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)}{\mathsf{hypot}\left(c, d\right)}} \]
      2. *-un-lft-identity81.8%

        \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
      3. frac-2neg81.8%

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

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

    if -2.7000000000000001e36 < d < -1.3000000000000001e-170 or 1.0000000000000001e-293 < d < 2.4e60

    1. Initial program 80.8%

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

    if -1.3000000000000001e-170 < d < 1.0000000000000001e-293

    1. Initial program 67.3%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv82.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv68.0%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt61.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod68.5%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg68.5%

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt85.5%

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

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

    if 2.4e60 < d

    1. Initial program 35.1%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt35.2%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-def63.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-rr63.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 15.1%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)} \]
    6. Step-by-step derivation
      1. expm1-log1p-u15.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)\right)\right)} \]
      2. expm1-udef15.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}\right)\right)} - 1} \]
    7. Applied egg-rr23.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-def65.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\right)\right)} \]
      2. expm1-log1p81.2%

        \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}} \]
    9. Simplified81.2%

      \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification81.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{+60}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 76.5% 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}\\ \mathbf{if}\;d \leq -1 \cdot 10^{+129}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{+81}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -1e+129)
     (* b (/ -1.0 (hypot c d)))
     (if (<= d -1.3e-170)
       t_0
       (if (<= d 1e-293)
         (+ (/ a c) (/ b (* c (/ c d))))
         (if (<= d 2.2e+81) t_0 (* b (/ 1.0 (hypot c 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 (d <= -1e+129) {
		tmp = b * (-1.0 / hypot(c, d));
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 2.2e+81) {
		tmp = t_0;
	} else {
		tmp = b * (1.0 / hypot(c, d));
	}
	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 tmp;
	if (d <= -1e+129) {
		tmp = b * (-1.0 / Math.hypot(c, d));
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 2.2e+81) {
		tmp = t_0;
	} else {
		tmp = b * (1.0 / Math.hypot(c, d));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1e+129:
		tmp = b * (-1.0 / math.hypot(c, d))
	elif d <= -1.3e-170:
		tmp = t_0
	elif d <= 1e-293:
		tmp = (a / c) + (b / (c * (c / d)))
	elif d <= 2.2e+81:
		tmp = t_0
	else:
		tmp = b * (1.0 / math.hypot(c, 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 (d <= -1e+129)
		tmp = Float64(b * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (d <= 2.2e+81)
		tmp = t_0;
	else
		tmp = Float64(b * Float64(1.0 / hypot(c, d)));
	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 <= -1e+129)
		tmp = b * (-1.0 / hypot(c, d));
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (d <= 2.2e+81)
		tmp = t_0;
	else
		tmp = b * (1.0 / hypot(c, d));
	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, -1e+129], N[(b * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.3e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.2e+81], t$95$0, N[(b * N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $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 -1 \cdot 10^{+129}:\\
\;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.2 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 31.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-identity31.0%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt31.0%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-def62.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-rr62.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 75.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot b\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg75.7%

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

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

    if -1e129 < d < -1.3000000000000001e-170 or 1.0000000000000001e-293 < d < 2.19999999999999987e81

    1. Initial program 79.6%

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

    if -1.3000000000000001e-170 < d < 1.0000000000000001e-293

    1. Initial program 67.3%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv82.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv68.0%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt61.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod68.5%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg68.5%

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt85.5%

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

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

    if 2.19999999999999987e81 < d

    1. Initial program 34.2%

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d}} \]
      3. fma-def34.2%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt34.3%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-def64.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-rr64.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 c around 0 72.7%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{b} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification78.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{+129}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 75.3% 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}\\ t_1 := \frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{if}\;c \leq -2.7 \cdot 10^{+76}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{-107}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-146}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 9 \cdot 10^{+36}:\\ \;\;\;\;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 (+ (/ a c) (/ b (* c (/ c d))))))
   (if (<= c -2.7e+76)
     t_1
     (if (<= c -2.1e-107)
       t_0
       (if (<= c 1.2e-146) (/ b d) (if (<= c 9e+36) 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 = (a / c) + (b / (c * (c / d)));
	double tmp;
	if (c <= -2.7e+76) {
		tmp = t_1;
	} else if (c <= -2.1e-107) {
		tmp = t_0;
	} else if (c <= 1.2e-146) {
		tmp = b / d;
	} else if (c <= 9e+36) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (a / c) + (b / (c * (c / d)))
    if (c <= (-2.7d+76)) then
        tmp = t_1
    else if (c <= (-2.1d-107)) then
        tmp = t_0
    else if (c <= 1.2d-146) then
        tmp = b / d
    else if (c <= 9d+36) then
        tmp = t_0
    else
        tmp = t_1
    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 t_1 = (a / c) + (b / (c * (c / d)));
	double tmp;
	if (c <= -2.7e+76) {
		tmp = t_1;
	} else if (c <= -2.1e-107) {
		tmp = t_0;
	} else if (c <= 1.2e-146) {
		tmp = b / d;
	} else if (c <= 9e+36) {
		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 = (a / c) + (b / (c * (c / d)))
	tmp = 0
	if c <= -2.7e+76:
		tmp = t_1
	elif c <= -2.1e-107:
		tmp = t_0
	elif c <= 1.2e-146:
		tmp = b / d
	elif c <= 9e+36:
		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(a / c) + Float64(b / Float64(c * Float64(c / d))))
	tmp = 0.0
	if (c <= -2.7e+76)
		tmp = t_1;
	elseif (c <= -2.1e-107)
		tmp = t_0;
	elseif (c <= 1.2e-146)
		tmp = Float64(b / d);
	elseif (c <= 9e+36)
		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 = (a / c) + (b / (c * (c / d)));
	tmp = 0.0;
	if (c <= -2.7e+76)
		tmp = t_1;
	elseif (c <= -2.1e-107)
		tmp = t_0;
	elseif (c <= 1.2e-146)
		tmp = b / d;
	elseif (c <= 9e+36)
		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[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.7e+76], t$95$1, If[LessEqual[c, -2.1e-107], t$95$0, If[LessEqual[c, 1.2e-146], N[(b / d), $MachinePrecision], If[LessEqual[c, 9e+36], 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{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+76}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -2.1 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.2 \cdot 10^{-146}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq 9 \cdot 10^{+36}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.6999999999999999e76 or 8.99999999999999994e36 < c

    1. Initial program 48.3%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified79.4%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv79.4%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv69.3%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt41.6%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod67.6%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg67.6%

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt81.5%

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

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

    if -2.6999999999999999e76 < c < -2.0999999999999999e-107 or 1.2000000000000001e-146 < c < 8.99999999999999994e36

    1. Initial program 76.7%

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

    if -2.0999999999999999e-107 < c < 1.2000000000000001e-146

    1. Initial program 66.7%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.7 \cdot 10^{+76}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{-107}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-146}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 9 \cdot 10^{+36}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 67.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{if}\;c \leq -80000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq -1.86 \cdot 10^{-93}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{-73}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ a c) (/ b (* c (/ c d))))))
   (if (<= c -80000000.0)
     t_0
     (if (<= c -6e-33)
       (/ b d)
       (if (<= c -1.86e-93)
         (/ (* a c) (+ (* c c) (* d d)))
         (if (<= c 2.1e-73) (/ b d) t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + (b / (c * (c / d)));
	double tmp;
	if (c <= -80000000.0) {
		tmp = t_0;
	} else if (c <= -6e-33) {
		tmp = b / d;
	} else if (c <= -1.86e-93) {
		tmp = (a * c) / ((c * c) + (d * d));
	} else if (c <= 2.1e-73) {
		tmp = b / 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 / c) + (b / (c * (c / d)))
    if (c <= (-80000000.0d0)) then
        tmp = t_0
    else if (c <= (-6d-33)) then
        tmp = b / d
    else if (c <= (-1.86d-93)) then
        tmp = (a * c) / ((c * c) + (d * d))
    else if (c <= 2.1d-73) then
        tmp = b / 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 / c) + (b / (c * (c / d)));
	double tmp;
	if (c <= -80000000.0) {
		tmp = t_0;
	} else if (c <= -6e-33) {
		tmp = b / d;
	} else if (c <= -1.86e-93) {
		tmp = (a * c) / ((c * c) + (d * d));
	} else if (c <= 2.1e-73) {
		tmp = b / d;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a / c) + (b / (c * (c / d)))
	tmp = 0
	if c <= -80000000.0:
		tmp = t_0
	elif c <= -6e-33:
		tmp = b / d
	elif c <= -1.86e-93:
		tmp = (a * c) / ((c * c) + (d * d))
	elif c <= 2.1e-73:
		tmp = b / d
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))))
	tmp = 0.0
	if (c <= -80000000.0)
		tmp = t_0;
	elseif (c <= -6e-33)
		tmp = Float64(b / d);
	elseif (c <= -1.86e-93)
		tmp = Float64(Float64(a * c) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 2.1e-73)
		tmp = Float64(b / d);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a / c) + (b / (c * (c / d)));
	tmp = 0.0;
	if (c <= -80000000.0)
		tmp = t_0;
	elseif (c <= -6e-33)
		tmp = b / d;
	elseif (c <= -1.86e-93)
		tmp = (a * c) / ((c * c) + (d * d));
	elseif (c <= 2.1e-73)
		tmp = b / d;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -80000000.0], t$95$0, If[LessEqual[c, -6e-33], N[(b / d), $MachinePrecision], If[LessEqual[c, -1.86e-93], N[(N[(a * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.1e-73], N[(b / d), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\
\mathbf{if}\;c \leq -80000000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq -6 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq -1.86 \cdot 10^{-93}:\\
\;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;c \leq 2.1 \cdot 10^{-73}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -8e7 or 2.0999999999999999e-73 < c

    1. Initial program 57.6%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified70.6%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv70.6%

        \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{{c}^{2} \cdot \frac{1}{d}}} \]
      2. unpow270.6%

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv59.3%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt33.3%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod58.8%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg58.8%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\sqrt{\color{blue}{d \cdot d}}}} \]
      13. sqrt-prod31.2%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt72.1%

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

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

    if -8e7 < c < -6.0000000000000003e-33 or -1.8600000000000001e-93 < c < 2.0999999999999999e-73

    1. Initial program 67.8%

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

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

    if -6.0000000000000003e-33 < c < -1.8600000000000001e-93

    1. Initial program 87.6%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    5. Simplified67.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -80000000:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq -1.86 \cdot 10^{-93}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{-73}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 68.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -410000 \lor \neg \left(c \leq 7.2 \cdot 10^{-72}\right):\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.1e5 or 7.2e-72 < c

    1. Initial program 57.6%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    5. Simplified70.6%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}} \]
    6. Step-by-step derivation
      1. div-inv70.6%

        \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{{c}^{2} \cdot \frac{1}{d}}} \]
      2. unpow270.6%

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \left(c \cdot \frac{1}{\color{blue}{-d}}\right)} \]
      9. div-inv59.3%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \color{blue}{\frac{c}{-d}}} \]
      10. add-sqr-sqrt33.3%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{-d} \cdot \sqrt{-d}}}} \]
      11. sqrt-unprod58.8%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{\left(-d\right) \cdot \left(-d\right)}}}} \]
      12. sqr-neg58.8%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\sqrt{\color{blue}{d \cdot d}}}} \]
      13. sqrt-prod31.2%

        \[\leadsto \frac{a}{c} + \frac{b}{c \cdot \frac{c}{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}} \]
      14. add-sqr-sqrt72.1%

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

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

    if -4.1e5 < c < 7.2e-72

    1. Initial program 70.3%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.5%

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

Alternative 10: 63.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -8 \cdot 10^{+48} \lor \neg \left(c \leq 2.1 \cdot 10^{-66}\right):\\
\;\;\;\;\frac{a}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.00000000000000035e48 or 2.1e-66 < c

    1. Initial program 58.1%

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]

    if -8.00000000000000035e48 < c < 2.1e-66

    1. Initial program 68.9%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.7%

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

Alternative 11: 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 63.8%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification40.5%

    \[\leadsto \frac{a}{c} \]
  5. 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 2024040 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :herbie-target
  (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))))