Complex division, real part

Percentage Accurate: 61.9% → 85.4%
Time: 13.1s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 61.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}

Alternative 1: 85.4% 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{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+299)
   (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
   (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+299) {
		tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (a / c) + ((d / c) * (b / c));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 5e+299)
		tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+299], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $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{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 79.3%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity79.3%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/79.3%

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

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

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

        \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      8. +-commutative79.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(d, d, c \cdot c\right)}} \]
      9. hypot-def79.3%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      12. +-commutative79.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}}} \]
      13. hypot-def95.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-rr95.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. Step-by-step derivation
      1. associate-*l/95.4%

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

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

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

    if 5.0000000000000003e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 3.8%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity55.0%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c}{d}}} \cdot \frac{b}{c} \]
      5. clear-num55.0%

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

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

    \[\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{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -8.8 \cdot 10^{-86}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 1.38 \cdot 10^{+79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.2e+44)
   (/ (- (/ (- a) (/ d c)) b) (hypot c d))
   (if (<= d -8.8e-86)
     (/ (fma a c (* b d)) (fma d d (* c c)))
     (if (<= d 6.8e-25)
       (+ (/ a c) (* (/ d c) (/ b c)))
       (if (<= d 1.38e+79)
         (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
         (/ (+ b (/ a (/ d c))) (hypot c d)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.2e+44) {
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	} else if (d <= -8.8e-86) {
		tmp = fma(a, c, (b * d)) / fma(d, d, (c * c));
	} else if (d <= 6.8e-25) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 1.38e+79) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a / (d / c))) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.2e+44)
		tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d));
	elseif (d <= -8.8e-86)
		tmp = Float64(fma(a, c, Float64(b * d)) / fma(d, d, Float64(c * c)));
	elseif (d <= 6.8e-25)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= 1.38e+79)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.2e+44], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8.8e-86], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.8e-25], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.38e+79], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -8.8 \cdot 10^{-86}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\

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

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

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


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

    1. Initial program 47.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity47.6%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/47.6%

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      11. fma-udef47.6%

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

        \[\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}}} \]
      13. hypot-def63.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-rr63.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. Step-by-step derivation
      1. associate-*l/63.7%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. neg-mul-179.8%

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

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

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

        \[\leadsto \frac{\color{blue}{\left(-\frac{a \cdot c}{d}\right)} - b}{\mathsf{hypot}\left(c, d\right)} \]
      5. associate-/l*86.7%

        \[\leadsto \frac{\left(-\color{blue}{\frac{a}{\frac{d}{c}}}\right) - b}{\mathsf{hypot}\left(c, d\right)} \]
      6. distribute-neg-frac86.7%

        \[\leadsto \frac{\color{blue}{\frac{-a}{\frac{d}{c}}} - b}{\mathsf{hypot}\left(c, d\right)} \]
    9. Simplified86.7%

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

    if -1.20000000000000007e44 < d < -8.8000000000000006e-86

    1. Initial program 82.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-def82.4%

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

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

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

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

    if -8.8000000000000006e-86 < d < 6.80000000000000003e-25

    1. Initial program 66.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity84.3%

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

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

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

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

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

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

    if 6.80000000000000003e-25 < d < 1.38e79

    1. Initial program 85.0%

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

    if 1.38e79 < d

    1. Initial program 42.2%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-udef42.2%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/42.2%

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

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

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

        \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      8. +-commutative42.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(d, d, c \cdot c\right)}} \]
      9. hypot-def42.2%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      12. +-commutative42.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}}} \]
      13. hypot-def59.9%

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

      \[\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. Step-by-step derivation
      1. associate-*l/60.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -8.8 \cdot 10^{-86}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 1.38 \cdot 10^{+79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.1% 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.2 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-88}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{+78}:\\ \;\;\;\;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 -1.2e+43)
     (fma (/ (/ a d) d) c (/ b d))
     (if (<= d -1.7e-88)
       t_0
       (if (<= d 2.9e-24)
         (+ (/ a c) (* (/ d c) (/ b c)))
         (if (<= d 1.6e+78) 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 <= -1.2e+43) {
		tmp = fma(((a / d) / d), c, (b / d));
	} else if (d <= -1.7e-88) {
		tmp = t_0;
	} else if (d <= 2.9e-24) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 1.6e+78) {
		tmp = t_0;
	} else {
		tmp = (b + (a * (c / d))) / 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 <= -1.2e+43)
		tmp = fma(Float64(Float64(a / d) / d), c, Float64(b / d));
	elseif (d <= -1.7e-88)
		tmp = t_0;
	elseif (d <= 2.9e-24)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= 1.6e+78)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.2e+43], N[(N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision] * c + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.7e-88], t$95$0, If[LessEqual[d, 2.9e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.6e+78], 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 -1.2 \cdot 10^{+43}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\

\mathbf{elif}\;d \leq -1.7 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.6 \cdot 10^{+78}:\\
\;\;\;\;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 < -1.20000000000000012e43

    1. Initial program 47.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{a}{{d}^{2}}, c, \frac{b}{d}\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity81.4%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{1 \cdot a}}{{d}^{2}}, c, \frac{b}{d}\right) \]
      2. pow281.4%

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

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

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

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

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

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

    if -1.20000000000000012e43 < d < -1.69999999999999987e-88 or 2.8999999999999999e-24 < d < 1.59999999999999997e78

    1. Initial program 83.4%

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

    if -1.69999999999999987e-88 < d < 2.8999999999999999e-24

    1. Initial program 66.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity84.3%

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

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

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

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

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

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

    if 1.59999999999999997e78 < d

    1. Initial program 42.2%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-udef42.2%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/42.2%

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

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

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

        \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      8. +-commutative42.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(d, d, c \cdot c\right)}} \]
      9. hypot-def42.2%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      12. +-commutative42.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}}} \]
      13. hypot-def59.9%

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

      \[\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. Step-by-step derivation
      1. associate-*l/60.0%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{b + \frac{a}{\frac{d}{c}}}}{\mathsf{hypot}\left(c, d\right)} \]
    10. Step-by-step derivation
      1. clear-num80.7%

        \[\leadsto \frac{b + \color{blue}{\frac{1}{\frac{\frac{d}{c}}{a}}}}{\mathsf{hypot}\left(c, d\right)} \]
      2. associate-/r/80.7%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-88}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{+78}:\\ \;\;\;\;\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 4: 81.1% 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 -2.4 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -1.04 \cdot 10^{-81}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{+79}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\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 -2.4e+44)
     (fma (/ (/ a d) d) c (/ b d))
     (if (<= d -1.04e-81)
       t_0
       (if (<= d 6.8e-25)
         (+ (/ a c) (* (/ d c) (/ b c)))
         (if (<= d 3.1e+79) t_0 (/ (+ b (/ a (/ d c))) (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 <= -2.4e+44) {
		tmp = fma(((a / d) / d), c, (b / d));
	} else if (d <= -1.04e-81) {
		tmp = t_0;
	} else if (d <= 6.8e-25) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 3.1e+79) {
		tmp = t_0;
	} else {
		tmp = (b + (a / (d / c))) / 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 <= -2.4e+44)
		tmp = fma(Float64(Float64(a / d) / d), c, Float64(b / d));
	elseif (d <= -1.04e-81)
		tmp = t_0;
	elseif (d <= 6.8e-25)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= 3.1e+79)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.4e+44], N[(N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision] * c + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.04e-81], t$95$0, If[LessEqual[d, 6.8e-25], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.1e+79], t$95$0, N[(N[(b + N[(a / N[(d / c), $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 -2.4 \cdot 10^{+44}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\

\mathbf{elif}\;d \leq -1.04 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 3.1 \cdot 10^{+79}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 47.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{a}{{d}^{2}}, c, \frac{b}{d}\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity81.4%

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{1 \cdot a}}{{d}^{2}}, c, \frac{b}{d}\right) \]
      2. pow281.4%

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

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

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

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

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

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

    if -2.40000000000000013e44 < d < -1.04e-81 or 6.80000000000000003e-25 < d < 3.0999999999999999e79

    1. Initial program 83.4%

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

    if -1.04e-81 < d < 6.80000000000000003e-25

    1. Initial program 66.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity84.3%

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

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

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

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

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

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

    if 3.0999999999999999e79 < d

    1. Initial program 42.2%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-udef42.2%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/42.2%

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

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

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

        \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      8. +-commutative42.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(d, d, c \cdot c\right)}} \]
      9. hypot-def42.2%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      12. +-commutative42.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}}} \]
      13. hypot-def59.9%

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

      \[\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. Step-by-step derivation
      1. associate-*l/60.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.4 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -1.04 \cdot 10^{-81}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{+79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 81.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -2.4 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.15 \cdot 10^{-81}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+79}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\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 -2.4e+44)
     (/ (- (/ (- a) (/ d c)) b) (hypot c d))
     (if (<= d -3.15e-81)
       t_0
       (if (<= d 5e-24)
         (+ (/ a c) (* (/ d c) (/ b c)))
         (if (<= d 9e+79) t_0 (/ (+ b (/ a (/ d c))) (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 <= -2.4e+44) {
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	} else if (d <= -3.15e-81) {
		tmp = t_0;
	} else if (d <= 5e-24) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 9e+79) {
		tmp = t_0;
	} else {
		tmp = (b + (a / (d / c))) / 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 <= -2.4e+44) {
		tmp = ((-a / (d / c)) - b) / Math.hypot(c, d);
	} else if (d <= -3.15e-81) {
		tmp = t_0;
	} else if (d <= 5e-24) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 9e+79) {
		tmp = t_0;
	} else {
		tmp = (b + (a / (d / c))) / 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 <= -2.4e+44:
		tmp = ((-a / (d / c)) - b) / math.hypot(c, d)
	elif d <= -3.15e-81:
		tmp = t_0
	elif d <= 5e-24:
		tmp = (a / c) + ((d / c) * (b / c))
	elif d <= 9e+79:
		tmp = t_0
	else:
		tmp = (b + (a / (d / c))) / 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 <= -2.4e+44)
		tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d));
	elseif (d <= -3.15e-81)
		tmp = t_0;
	elseif (d <= 5e-24)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= 9e+79)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / 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 <= -2.4e+44)
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	elseif (d <= -3.15e-81)
		tmp = t_0;
	elseif (d <= 5e-24)
		tmp = (a / c) + ((d / c) * (b / c));
	elseif (d <= 9e+79)
		tmp = t_0;
	else
		tmp = (b + (a / (d / c))) / 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, -2.4e+44], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.15e-81], t$95$0, If[LessEqual[d, 5e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9e+79], t$95$0, N[(N[(b + N[(a / N[(d / c), $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 -2.4 \cdot 10^{+44}:\\
\;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -3.15 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 9 \cdot 10^{+79}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 47.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity47.6%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/47.6%

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      11. fma-udef47.6%

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

        \[\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}}} \]
      13. hypot-def63.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-rr63.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. Step-by-step derivation
      1. associate-*l/63.7%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. neg-mul-179.8%

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

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

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

        \[\leadsto \frac{\color{blue}{\left(-\frac{a \cdot c}{d}\right)} - b}{\mathsf{hypot}\left(c, d\right)} \]
      5. associate-/l*86.7%

        \[\leadsto \frac{\left(-\color{blue}{\frac{a}{\frac{d}{c}}}\right) - b}{\mathsf{hypot}\left(c, d\right)} \]
      6. distribute-neg-frac86.7%

        \[\leadsto \frac{\color{blue}{\frac{-a}{\frac{d}{c}}} - b}{\mathsf{hypot}\left(c, d\right)} \]
    9. Simplified86.7%

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

    if -2.40000000000000013e44 < d < -3.15000000000000011e-81 or 4.9999999999999998e-24 < d < 8.99999999999999987e79

    1. Initial program 83.4%

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

    if -3.15000000000000011e-81 < d < 4.9999999999999998e-24

    1. Initial program 66.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity84.3%

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

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

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

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

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

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

    if 8.99999999999999987e79 < d

    1. Initial program 42.2%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-udef42.2%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/42.2%

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

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

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

        \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      8. +-commutative42.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(d, d, c \cdot c\right)}} \]
      9. hypot-def42.2%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      12. +-commutative42.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}}} \]
      13. hypot-def59.9%

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

      \[\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. Step-by-step derivation
      1. associate-*l/60.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.4 \cdot 10^{+44}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.15 \cdot 10^{-81}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 80.6% 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 := \mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\ \mathbf{if}\;d \leq -2.4 \cdot 10^{+44}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-83}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\ \;\;\;\;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 (fma (/ (/ a d) d) c (/ b d))))
   (if (<= d -2.4e+44)
     t_1
     (if (<= d -9.5e-83)
       t_0
       (if (<= d 6.8e-25)
         (+ (/ a c) (* (/ d c) (/ b c)))
         (if (<= d 4.5e+139) 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 = fma(((a / d) / d), c, (b / d));
	double tmp;
	if (d <= -2.4e+44) {
		tmp = t_1;
	} else if (d <= -9.5e-83) {
		tmp = t_0;
	} else if (d <= 6.8e-25) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 4.5e+139) {
		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 = fma(Float64(Float64(a / d) / d), c, Float64(b / d))
	tmp = 0.0
	if (d <= -2.4e+44)
		tmp = t_1;
	elseif (d <= -9.5e-83)
		tmp = t_0;
	elseif (d <= 6.8e-25)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= 4.5e+139)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision] * c + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.4e+44], t$95$1, If[LessEqual[d, -9.5e-83], t$95$0, If[LessEqual[d, 6.8e-25], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.5e+139], 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 := \mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -2.4 \cdot 10^{+44}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -9.5 \cdot 10^{-83}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.40000000000000013e44 or 4.4999999999999999e139 < d

    1. Initial program 41.6%

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

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

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

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

        \[\leadsto \color{blue}{\frac{a}{{d}^{2}} \cdot c} + \frac{b}{d} \]
      4. fma-def79.6%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{a}{{d}^{2}}, c, \frac{b}{d}\right)} \]
    6. Step-by-step derivation
      1. *-un-lft-identity79.6%

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

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

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

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

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

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

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

    if -2.40000000000000013e44 < d < -9.50000000000000051e-83 or 6.80000000000000003e-25 < d < 4.4999999999999999e139

    1. Initial program 79.1%

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

    if -9.50000000000000051e-83 < d < 6.80000000000000003e-25

    1. Initial program 66.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity84.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.4 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-83}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-25}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{a}{d}}{d}, c, \frac{b}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.3% 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 -5.2 \cdot 10^{+141}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -5.9 \cdot 10^{-83}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+153}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\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 -5.2e+141)
     (/ b d)
     (if (<= d -5.9e-83)
       t_0
       (if (<= d 1.35e-24)
         (+ (/ a c) (* (/ d c) (/ b c)))
         (if (<= d 2.9e+153) t_0 (/ b (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 <= -5.2e+141) {
		tmp = b / d;
	} else if (d <= -5.9e-83) {
		tmp = t_0;
	} else if (d <= 1.35e-24) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 2.9e+153) {
		tmp = t_0;
	} else {
		tmp = b / 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 <= -5.2e+141) {
		tmp = b / d;
	} else if (d <= -5.9e-83) {
		tmp = t_0;
	} else if (d <= 1.35e-24) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 2.9e+153) {
		tmp = t_0;
	} else {
		tmp = b / 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 <= -5.2e+141:
		tmp = b / d
	elif d <= -5.9e-83:
		tmp = t_0
	elif d <= 1.35e-24:
		tmp = (a / c) + ((d / c) * (b / c))
	elif d <= 2.9e+153:
		tmp = t_0
	else:
		tmp = b / 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 <= -5.2e+141)
		tmp = Float64(b / d);
	elseif (d <= -5.9e-83)
		tmp = t_0;
	elseif (d <= 1.35e-24)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= 2.9e+153)
		tmp = t_0;
	else
		tmp = Float64(b / 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 <= -5.2e+141)
		tmp = b / d;
	elseif (d <= -5.9e-83)
		tmp = t_0;
	elseif (d <= 1.35e-24)
		tmp = (a / c) + ((d / c) * (b / c));
	elseif (d <= 2.9e+153)
		tmp = t_0;
	else
		tmp = b / 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, -5.2e+141], N[(b / d), $MachinePrecision], If[LessEqual[d, -5.9e-83], t$95$0, If[LessEqual[d, 1.35e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.9e+153], t$95$0, N[(b / 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 -5.2 \cdot 10^{+141}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq -5.9 \cdot 10^{-83}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.9 \cdot 10^{+153}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 32.9%

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

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

    if -5.1999999999999999e141 < d < -5.8999999999999997e-83 or 1.35000000000000003e-24 < d < 2.90000000000000002e153

    1. Initial program 77.9%

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

    if -5.8999999999999997e-83 < d < 1.35000000000000003e-24

    1. Initial program 66.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity84.3%

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

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

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

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

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

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

    if 2.90000000000000002e153 < d

    1. Initial program 29.8%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/29.8%

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      11. fma-udef29.8%

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

        \[\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}}} \]
      13. hypot-def46.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-rr46.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 c around 0 75.8%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot b\right)} - 1} \]
      3. associate-*l/41.3%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{1 \cdot b}{\mathsf{hypot}\left(c, d\right)}}\right)} - 1 \]
      4. *-un-lft-identity41.3%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{\mathsf{hypot}\left(c, d\right)}} \]
    9. Simplified76.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+141}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -5.9 \cdot 10^{-83}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+153}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 69.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{if}\;c \leq -3.6 \cdot 10^{-36}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -7.2 \cdot 10^{-128}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-35} \lor \neg \left(c \leq 1.8 \cdot 10^{+46}\right) \land c \leq 2.8 \cdot 10^{+63}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ a c) (* (/ d c) (/ b c)))))
   (if (<= c -3.6e-36)
     t_0
     (if (<= c -7.2e-128)
       (/ (* a c) (+ (* c c) (* d d)))
       (if (or (<= c 2.15e-35) (and (not (<= c 1.8e+46)) (<= c 2.8e+63)))
         (/ b d)
         t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + ((d / c) * (b / c));
	double tmp;
	if (c <= -3.6e-36) {
		tmp = t_0;
	} else if (c <= -7.2e-128) {
		tmp = (a * c) / ((c * c) + (d * d));
	} else if ((c <= 2.15e-35) || (!(c <= 1.8e+46) && (c <= 2.8e+63))) {
		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) + ((d / c) * (b / c))
    if (c <= (-3.6d-36)) then
        tmp = t_0
    else if (c <= (-7.2d-128)) then
        tmp = (a * c) / ((c * c) + (d * d))
    else if ((c <= 2.15d-35) .or. (.not. (c <= 1.8d+46)) .and. (c <= 2.8d+63)) 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) + ((d / c) * (b / c));
	double tmp;
	if (c <= -3.6e-36) {
		tmp = t_0;
	} else if (c <= -7.2e-128) {
		tmp = (a * c) / ((c * c) + (d * d));
	} else if ((c <= 2.15e-35) || (!(c <= 1.8e+46) && (c <= 2.8e+63))) {
		tmp = b / d;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a / c) + ((d / c) * (b / c))
	tmp = 0
	if c <= -3.6e-36:
		tmp = t_0
	elif c <= -7.2e-128:
		tmp = (a * c) / ((c * c) + (d * d))
	elif (c <= 2.15e-35) or (not (c <= 1.8e+46) and (c <= 2.8e+63)):
		tmp = b / d
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)))
	tmp = 0.0
	if (c <= -3.6e-36)
		tmp = t_0;
	elseif (c <= -7.2e-128)
		tmp = Float64(Float64(a * c) / Float64(Float64(c * c) + Float64(d * d)));
	elseif ((c <= 2.15e-35) || (!(c <= 1.8e+46) && (c <= 2.8e+63)))
		tmp = Float64(b / d);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a / c) + ((d / c) * (b / c));
	tmp = 0.0;
	if (c <= -3.6e-36)
		tmp = t_0;
	elseif (c <= -7.2e-128)
		tmp = (a * c) / ((c * c) + (d * d));
	elseif ((c <= 2.15e-35) || (~((c <= 1.8e+46)) && (c <= 2.8e+63)))
		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[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.6e-36], t$95$0, If[LessEqual[c, -7.2e-128], N[(N[(a * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[c, 2.15e-35], And[N[Not[LessEqual[c, 1.8e+46]], $MachinePrecision], LessEqual[c, 2.8e+63]]], N[(b / d), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;c \leq 2.15 \cdot 10^{-35} \lor \neg \left(c \leq 1.8 \cdot 10^{+46}\right) \land c \leq 2.8 \cdot 10^{+63}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.60000000000000032e-36 or 2.1500000000000001e-35 < c < 1.7999999999999999e46 or 2.79999999999999987e63 < c

    1. Initial program 53.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity73.0%

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

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

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

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

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

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

    if -3.60000000000000032e-36 < c < -7.20000000000000049e-128

    1. Initial program 83.7%

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

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

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

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

    if -7.20000000000000049e-128 < c < 2.1500000000000001e-35 or 1.7999999999999999e46 < c < 2.79999999999999987e63

    1. Initial program 67.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 simplification77.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.6 \cdot 10^{-36}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -7.2 \cdot 10^{-128}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-35} \lor \neg \left(c \leq 1.8 \cdot 10^{+46}\right) \land c \leq 2.8 \cdot 10^{+63}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 78.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -2.3 \cdot 10^{+140}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-88}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{+153}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -2.3e+140)
     (/ b d)
     (if (<= d -3.6e-88)
       t_0
       (if (<= d 2.6e-24)
         (+ (/ a c) (* (/ d c) (/ b c)))
         (if (<= d 3.2e+153) t_0 (/ b 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 <= -2.3e+140) {
		tmp = b / d;
	} else if (d <= -3.6e-88) {
		tmp = t_0;
	} else if (d <= 2.6e-24) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 3.2e+153) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-2.3d+140)) then
        tmp = b / d
    else if (d <= (-3.6d-88)) then
        tmp = t_0
    else if (d <= 2.6d-24) then
        tmp = (a / c) + ((d / c) * (b / c))
    else if (d <= 3.2d+153) then
        tmp = t_0
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -2.3e+140) {
		tmp = b / d;
	} else if (d <= -3.6e-88) {
		tmp = t_0;
	} else if (d <= 2.6e-24) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= 3.2e+153) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -2.3e+140:
		tmp = b / d
	elif d <= -3.6e-88:
		tmp = t_0
	elif d <= 2.6e-24:
		tmp = (a / c) + ((d / c) * (b / c))
	elif d <= 3.2e+153:
		tmp = t_0
	else:
		tmp = b / 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 <= -2.3e+140)
		tmp = Float64(b / d);
	elseif (d <= -3.6e-88)
		tmp = t_0;
	elseif (d <= 2.6e-24)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= 3.2e+153)
		tmp = t_0;
	else
		tmp = Float64(b / 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 <= -2.3e+140)
		tmp = b / d;
	elseif (d <= -3.6e-88)
		tmp = t_0;
	elseif (d <= 2.6e-24)
		tmp = (a / c) + ((d / c) * (b / c));
	elseif (d <= 3.2e+153)
		tmp = t_0;
	else
		tmp = b / 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, -2.3e+140], N[(b / d), $MachinePrecision], If[LessEqual[d, -3.6e-88], t$95$0, If[LessEqual[d, 2.6e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.2e+153], t$95$0, N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -3.6 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 3.2 \cdot 10^{+153}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.2999999999999999e140 or 3.2000000000000001e153 < d

    1. Initial program 31.3%

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

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

    if -2.2999999999999999e140 < d < -3.5999999999999999e-88 or 2.6e-24 < d < 3.2000000000000001e153

    1. Initial program 77.9%

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

    if -3.5999999999999999e-88 < d < 2.6e-24

    1. Initial program 66.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity84.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{+140}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-88}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{+153}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 69.9% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.4 \cdot 10^{-25} \lor \neg \left(c \leq 3.9 \cdot 10^{-35} \lor \neg \left(c \leq 1.4 \cdot 10^{+46}\right) \land c \leq 3.2 \cdot 10^{+64}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.40000000000000032e-25 or 3.8999999999999998e-35 < c < 1.40000000000000009e46 or 3.20000000000000019e64 < c

    1. Initial program 52.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \frac{b}{\color{blue}{c \cdot \left(c \cdot \frac{1}{d}\right)}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity72.8%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c}{d}}} \cdot \frac{b}{c} \]
      5. clear-num77.9%

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

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

    if -5.40000000000000032e-25 < c < 3.8999999999999998e-35 or 1.40000000000000009e46 < c < 3.20000000000000019e64

    1. Initial program 70.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.4 \cdot 10^{-25} \lor \neg \left(c \leq 3.9 \cdot 10^{-35} \lor \neg \left(c \leq 1.4 \cdot 10^{+46}\right) \land c \leq 3.2 \cdot 10^{+64}\right):\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 64.7% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5.9999999999999998e29 or 3.9999999999999999e-19 < d

    1. Initial program 52.1%

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

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

    if -5.9999999999999998e29 < d < 3.9999999999999999e-19

    1. Initial program 69.7%

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

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

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

Alternative 12: 42.9% 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 60.4%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification41.3%

    \[\leadsto \frac{a}{c} \]
  5. Add Preprocessing

Developer target: 99.4% 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 2024026 
(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))))