Complex division, real part

Percentage Accurate: 61.2% → 85.0%
Time: 12.3s
Alternatives: 14
Speedup: 2.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 14 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 85.0% accurate, 0.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\


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

    1. Initial program 84.3%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity84.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 32.5%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity63.6%

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

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

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

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

    1. Initial program 0.0%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification91.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+300}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.4% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(b, d, a \cdot c\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{if}\;c \leq -2.35 \cdot 10^{+80}:\\ \;\;\;\;\frac{-\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.6 \cdot 10^{-138}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{-153}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 1.76 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (fma b d (* a c)) (pow (hypot c d) -2.0))))
   (if (<= c -2.35e+80)
     (/ (- (fma d (/ b c) a)) (hypot c d))
     (if (<= c -8.6e-138)
       t_0
       (if (<= c 5.5e-153)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 1.76e+81)
           t_0
           (* (/ 1.0 (hypot c d)) (+ a (/ b (/ c d))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(b, d, (a * c)) * pow(hypot(c, d), -2.0);
	double tmp;
	if (c <= -2.35e+80) {
		tmp = -fma(d, (b / c), a) / hypot(c, d);
	} else if (c <= -8.6e-138) {
		tmp = t_0;
	} else if (c <= 5.5e-153) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 1.76e+81) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * (a + (b / (c / d)));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(b, d, Float64(a * c)) * (hypot(c, d) ^ -2.0))
	tmp = 0.0
	if (c <= -2.35e+80)
		tmp = Float64(Float64(-fma(d, Float64(b / c), a)) / hypot(c, d));
	elseif (c <= -8.6e-138)
		tmp = t_0;
	elseif (c <= 5.5e-153)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 1.76e+81)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(b / Float64(c / d))));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b * d + N[(a * c), $MachinePrecision]), $MachinePrecision] * N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.35e+80], N[((-N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision]) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8.6e-138], t$95$0, If[LessEqual[c, 5.5e-153], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.76e+81], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -8.6 \cdot 10^{-138}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.76 \cdot 10^{+81}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.35000000000000005e80

    1. Initial program 34.8%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity34.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{\mathsf{hypot}\left(c, d\right)} \]
      6. fma-udef90.3%

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

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

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

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

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

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

    if -2.35000000000000005e80 < c < -8.6000000000000001e-138 or 5.49999999999999962e-153 < c < 1.76000000000000002e81

    1. Initial program 86.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{-1}} \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\right) \cdot \frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{1} \]
      12. unpow-187.0%

        \[\leadsto \left({\left(\mathsf{hypot}\left(c, d\right)\right)}^{-1} \cdot \color{blue}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{-1}}\right) \cdot \frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{1} \]
      13. pow-sqr87.4%

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

        \[\leadsto {\left(\mathsf{hypot}\left(c, d\right)\right)}^{\color{blue}{-2}} \cdot \frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{1} \]
      15. /-rgt-identity87.4%

        \[\leadsto {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2} \cdot \color{blue}{\mathsf{fma}\left(b, d, a \cdot c\right)} \]
      16. *-commutative87.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, d, a \cdot c\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}} \]
      17. *-commutative87.4%

        \[\leadsto \mathsf{fma}\left(b, d, \color{blue}{c \cdot a}\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2} \]
    8. Simplified87.4%

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

    if -8.6000000000000001e-138 < c < 5.49999999999999962e-153

    1. Initial program 65.3%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity80.6%

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

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

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

    if 1.76000000000000002e81 < c

    1. Initial program 40.1%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity40.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.35 \cdot 10^{+80}:\\ \;\;\;\;\frac{-\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.6 \cdot 10^{-138}:\\ \;\;\;\;\mathsf{fma}\left(b, d, a \cdot c\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{-153}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 1.76 \cdot 10^{+81}:\\ \;\;\;\;\mathsf{fma}\left(b, d, a \cdot c\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot c + b \cdot d\\ \mathbf{if}\;c \leq -1.72 \cdot 10^{+78}:\\ \;\;\;\;\frac{-\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{-150}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{+80}:\\ \;\;\;\;\frac{t_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))))
   (if (<= c -1.72e+78)
     (/ (- (fma d (/ b c) a)) (hypot c d))
     (if (<= c -8.2e-138)
       (/ t_0 (+ (* c c) (* d d)))
       (if (<= c 8.5e-150)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 1.6e+80)
           (/ t_0 (fma c c (* d d)))
           (* (/ 1.0 (hypot c d)) (+ a (/ b (/ c d))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if (c <= -1.72e+78) {
		tmp = -fma(d, (b / c), a) / hypot(c, d);
	} else if (c <= -8.2e-138) {
		tmp = t_0 / ((c * c) + (d * d));
	} else if (c <= 8.5e-150) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 1.6e+80) {
		tmp = t_0 / fma(c, c, (d * d));
	} else {
		tmp = (1.0 / hypot(c, d)) * (a + (b / (c / d)));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) + Float64(b * d))
	tmp = 0.0
	if (c <= -1.72e+78)
		tmp = Float64(Float64(-fma(d, Float64(b / c), a)) / hypot(c, d));
	elseif (c <= -8.2e-138)
		tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 8.5e-150)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 1.6e+80)
		tmp = Float64(t_0 / fma(c, c, Float64(d * d)));
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(b / Float64(c / d))));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.72e+78], N[((-N[(d * N[(b / c), $MachinePrecision] + a), $MachinePrecision]) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8.2e-138], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.5e-150], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.6e+80], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\
\;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\

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

\mathbf{elif}\;c \leq 1.6 \cdot 10^{+80}:\\
\;\;\;\;\frac{t_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -1.71999999999999997e78

    1. Initial program 36.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity36.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Step-by-step derivation
      1. fma-def46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.71999999999999997e78 < c < -8.19999999999999998e-138

    1. Initial program 90.0%

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

    if -8.19999999999999998e-138 < c < 8.4999999999999997e-150

    1. Initial program 65.7%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity80.9%

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

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

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

    if 8.4999999999999997e-150 < c < 1.59999999999999995e80

    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. fma-def82.4%

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-def82.4%

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

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

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

    if 1.59999999999999995e80 < c

    1. Initial program 40.1%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity40.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.72 \cdot 10^{+78}:\\ \;\;\;\;\frac{-\mathsf{fma}\left(d, \frac{b}{c}, a\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{-150}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{+80}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot c + b \cdot d\\ \mathbf{if}\;c \leq -6.4 \cdot 10^{+78}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{-151}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{+80}:\\ \;\;\;\;\frac{t_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))))
   (if (<= c -6.4e+78)
     (/ (- (/ (- b) (/ c d)) a) (hypot c d))
     (if (<= c -8.2e-138)
       (/ t_0 (+ (* c c) (* d d)))
       (if (<= c 5.2e-151)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 2.7e+80)
           (/ t_0 (fma c c (* d d)))
           (* (/ 1.0 (hypot c d)) (+ a (/ b (/ c d))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if (c <= -6.4e+78) {
		tmp = ((-b / (c / d)) - a) / hypot(c, d);
	} else if (c <= -8.2e-138) {
		tmp = t_0 / ((c * c) + (d * d));
	} else if (c <= 5.2e-151) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 2.7e+80) {
		tmp = t_0 / fma(c, c, (d * d));
	} else {
		tmp = (1.0 / hypot(c, d)) * (a + (b / (c / d)));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) + Float64(b * d))
	tmp = 0.0
	if (c <= -6.4e+78)
		tmp = Float64(Float64(Float64(Float64(-b) / Float64(c / d)) - a) / hypot(c, d));
	elseif (c <= -8.2e-138)
		tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 5.2e-151)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 2.7e+80)
		tmp = Float64(t_0 / fma(c, c, Float64(d * d)));
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(b / Float64(c / d))));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -6.4e+78], N[(N[(N[((-b) / N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8.2e-138], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.2e-151], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.7e+80], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\
\;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\

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

\mathbf{elif}\;c \leq 2.7 \cdot 10^{+80}:\\
\;\;\;\;\frac{t_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -6.39999999999999989e78

    1. Initial program 36.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity36.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Step-by-step derivation
      1. fma-def46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{a} \cdot \sqrt{a} + \color{blue}{\sqrt{\frac{b \cdot d}{c}} \cdot \sqrt{\frac{b \cdot d}{c}}}}{\mathsf{hypot}\left(c, d\right)} \]
      13. add-sqr-sqrt16.1%

        \[\leadsto \frac{\sqrt{a} \cdot \sqrt{a} + \color{blue}{\frac{b \cdot d}{c}}}{\mathsf{hypot}\left(c, d\right)} \]
      14. add-sqr-sqrt22.5%

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

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

        \[\leadsto \frac{\color{blue}{\left(--1\right)} \cdot \left(a + \frac{b \cdot d}{c}\right)}{\mathsf{hypot}\left(c, d\right)} \]
      17. distribute-lft-neg-in22.5%

        \[\leadsto \frac{\color{blue}{--1 \cdot \left(a + \frac{b \cdot d}{c}\right)}}{\mathsf{hypot}\left(c, d\right)} \]
      18. distribute-lft-out22.5%

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

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

    if -6.39999999999999989e78 < c < -8.19999999999999998e-138

    1. Initial program 90.0%

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

    if -8.19999999999999998e-138 < c < 5.2000000000000001e-151

    1. Initial program 65.7%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity80.9%

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

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

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

    if 5.2000000000000001e-151 < c < 2.69999999999999983e80

    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. fma-def82.4%

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-def82.4%

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

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

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

    if 2.69999999999999983e80 < c

    1. Initial program 40.1%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity40.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.4 \cdot 10^{+78}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{-151}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{+80}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 82.2% 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}\;c \leq -2.2 \cdot 10^{+79}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -9.5 \cdot 10^{-138}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-148}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{+80}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{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 (<= c -2.2e+79)
     (/ (- (/ (- b) (/ c d)) a) (hypot c d))
     (if (<= c -9.5e-138)
       t_0
       (if (<= c 1.25e-148)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 4e+80) t_0 (* (/ 1.0 (hypot c d)) (+ a (/ b (/ 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 (c <= -2.2e+79) {
		tmp = ((-b / (c / d)) - a) / hypot(c, d);
	} else if (c <= -9.5e-138) {
		tmp = t_0;
	} else if (c <= 1.25e-148) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 4e+80) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * (a + (b / (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 (c <= -2.2e+79) {
		tmp = ((-b / (c / d)) - a) / Math.hypot(c, d);
	} else if (c <= -9.5e-138) {
		tmp = t_0;
	} else if (c <= 1.25e-148) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 4e+80) {
		tmp = t_0;
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * (a + (b / (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -2.2e+79:
		tmp = ((-b / (c / d)) - a) / math.hypot(c, d)
	elif c <= -9.5e-138:
		tmp = t_0
	elif c <= 1.25e-148:
		tmp = (b / d) + (a / (d * (d / c)))
	elif c <= 4e+80:
		tmp = t_0
	else:
		tmp = (1.0 / math.hypot(c, d)) * (a + (b / (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 (c <= -2.2e+79)
		tmp = Float64(Float64(Float64(Float64(-b) / Float64(c / d)) - a) / hypot(c, d));
	elseif (c <= -9.5e-138)
		tmp = t_0;
	elseif (c <= 1.25e-148)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 4e+80)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(b / Float64(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 (c <= -2.2e+79)
		tmp = ((-b / (c / d)) - a) / hypot(c, d);
	elseif (c <= -9.5e-138)
		tmp = t_0;
	elseif (c <= 1.25e-148)
		tmp = (b / d) + (a / (d * (d / c)));
	elseif (c <= 4e+80)
		tmp = t_0;
	else
		tmp = (1.0 / hypot(c, d)) * (a + (b / (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[c, -2.2e+79], N[(N[(N[((-b) / N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -9.5e-138], t$95$0, If[LessEqual[c, 1.25e-148], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4e+80], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -9.5 \cdot 10^{-138}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 4 \cdot 10^{+80}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.1999999999999999e79

    1. Initial program 36.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity36.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Step-by-step derivation
      1. fma-def46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{a} \cdot \sqrt{a} + \color{blue}{\sqrt{\frac{b \cdot d}{c}} \cdot \sqrt{\frac{b \cdot d}{c}}}}{\mathsf{hypot}\left(c, d\right)} \]
      13. add-sqr-sqrt16.1%

        \[\leadsto \frac{\sqrt{a} \cdot \sqrt{a} + \color{blue}{\frac{b \cdot d}{c}}}{\mathsf{hypot}\left(c, d\right)} \]
      14. add-sqr-sqrt22.5%

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

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

        \[\leadsto \frac{\color{blue}{\left(--1\right)} \cdot \left(a + \frac{b \cdot d}{c}\right)}{\mathsf{hypot}\left(c, d\right)} \]
      17. distribute-lft-neg-in22.5%

        \[\leadsto \frac{\color{blue}{--1 \cdot \left(a + \frac{b \cdot d}{c}\right)}}{\mathsf{hypot}\left(c, d\right)} \]
      18. distribute-lft-out22.5%

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

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

    if -2.1999999999999999e79 < c < -9.49999999999999997e-138 or 1.25e-148 < c < 4e80

    1. Initial program 86.1%

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

    if -9.49999999999999997e-138 < c < 1.25e-148

    1. Initial program 65.7%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity80.9%

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

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

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

    if 4e80 < c

    1. Initial program 40.1%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity40.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.2 \cdot 10^{+79}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -9.5 \cdot 10^{-138}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-148}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{+80}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 81.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{-b}{\frac{c}{d}} - a\\ \mathbf{if}\;c \leq -1.95 \cdot 10^{+78}:\\ \;\;\;\;\frac{t_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{-149}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 3.1 \cdot 10^{+80}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{c} \cdot t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (- (/ (- b) (/ c d)) a)))
   (if (<= c -1.95e+78)
     (/ t_1 (hypot c d))
     (if (<= c -8.2e-138)
       t_0
       (if (<= c 1.7e-149)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 3.1e+80) t_0 (* (/ -1.0 c) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (-b / (c / d)) - a;
	double tmp;
	if (c <= -1.95e+78) {
		tmp = t_1 / hypot(c, d);
	} else if (c <= -8.2e-138) {
		tmp = t_0;
	} else if (c <= 1.7e-149) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 3.1e+80) {
		tmp = t_0;
	} else {
		tmp = (-1.0 / c) * t_1;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (-b / (c / d)) - a;
	double tmp;
	if (c <= -1.95e+78) {
		tmp = t_1 / Math.hypot(c, d);
	} else if (c <= -8.2e-138) {
		tmp = t_0;
	} else if (c <= 1.7e-149) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 3.1e+80) {
		tmp = t_0;
	} else {
		tmp = (-1.0 / c) * t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (-b / (c / d)) - a
	tmp = 0
	if c <= -1.95e+78:
		tmp = t_1 / math.hypot(c, d)
	elif c <= -8.2e-138:
		tmp = t_0
	elif c <= 1.7e-149:
		tmp = (b / d) + (a / (d * (d / c)))
	elif c <= 3.1e+80:
		tmp = t_0
	else:
		tmp = (-1.0 / c) * t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(Float64(-b) / Float64(c / d)) - a)
	tmp = 0.0
	if (c <= -1.95e+78)
		tmp = Float64(t_1 / hypot(c, d));
	elseif (c <= -8.2e-138)
		tmp = t_0;
	elseif (c <= 1.7e-149)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 3.1e+80)
		tmp = t_0;
	else
		tmp = Float64(Float64(-1.0 / c) * t_1);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (-b / (c / d)) - a;
	tmp = 0.0;
	if (c <= -1.95e+78)
		tmp = t_1 / hypot(c, d);
	elseif (c <= -8.2e-138)
		tmp = t_0;
	elseif (c <= 1.7e-149)
		tmp = (b / d) + (a / (d * (d / c)));
	elseif (c <= 3.1e+80)
		tmp = t_0;
	else
		tmp = (-1.0 / c) * t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b) / N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]}, If[LessEqual[c, -1.95e+78], N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8.2e-138], t$95$0, If[LessEqual[c, 1.7e-149], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.1e+80], t$95$0, N[(N[(-1.0 / c), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 3.1 \cdot 10^{+80}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{c} \cdot t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.9500000000000002e78

    1. Initial program 36.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity36.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Step-by-step derivation
      1. fma-def46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sqrt{a} \cdot \sqrt{a} + \color{blue}{\sqrt{\frac{b \cdot d}{c}} \cdot \sqrt{\frac{b \cdot d}{c}}}}{\mathsf{hypot}\left(c, d\right)} \]
      13. add-sqr-sqrt16.1%

        \[\leadsto \frac{\sqrt{a} \cdot \sqrt{a} + \color{blue}{\frac{b \cdot d}{c}}}{\mathsf{hypot}\left(c, d\right)} \]
      14. add-sqr-sqrt22.5%

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

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

        \[\leadsto \frac{\color{blue}{\left(--1\right)} \cdot \left(a + \frac{b \cdot d}{c}\right)}{\mathsf{hypot}\left(c, d\right)} \]
      17. distribute-lft-neg-in22.5%

        \[\leadsto \frac{\color{blue}{--1 \cdot \left(a + \frac{b \cdot d}{c}\right)}}{\mathsf{hypot}\left(c, d\right)} \]
      18. distribute-lft-out22.5%

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

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

    if -1.9500000000000002e78 < c < -8.19999999999999998e-138 or 1.6999999999999999e-149 < c < 3.09999999999999988e80

    1. Initial program 86.1%

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

    if -8.19999999999999998e-138 < c < 1.6999999999999999e-149

    1. Initial program 65.7%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity80.9%

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

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

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

    if 3.09999999999999988e80 < c

    1. Initial program 40.1%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity40.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right) \]
  3. Recombined 4 regimes into one program.
  4. Final simplification87.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.95 \cdot 10^{+78}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{-149}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 3.1 \cdot 10^{+80}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 81.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\ \mathbf{if}\;c \leq -1.8 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 9.6 \cdot 10^{-151}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{+80}:\\ \;\;\;\;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 (* (/ -1.0 c) (- (/ (- b) (/ c d)) a))))
   (if (<= c -1.8e+79)
     t_1
     (if (<= c -8.2e-138)
       t_0
       (if (<= c 9.6e-151)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 4.3e+80) 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 = (-1.0 / c) * ((-b / (c / d)) - a);
	double tmp;
	if (c <= -1.8e+79) {
		tmp = t_1;
	} else if (c <= -8.2e-138) {
		tmp = t_0;
	} else if (c <= 9.6e-151) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 4.3e+80) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = ((-1.0d0) / c) * ((-b / (c / d)) - a)
    if (c <= (-1.8d+79)) then
        tmp = t_1
    else if (c <= (-8.2d-138)) then
        tmp = t_0
    else if (c <= 9.6d-151) then
        tmp = (b / d) + (a / (d * (d / c)))
    else if (c <= 4.3d+80) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (-1.0 / c) * ((-b / (c / d)) - a);
	double tmp;
	if (c <= -1.8e+79) {
		tmp = t_1;
	} else if (c <= -8.2e-138) {
		tmp = t_0;
	} else if (c <= 9.6e-151) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 4.3e+80) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (-1.0 / c) * ((-b / (c / d)) - a)
	tmp = 0
	if c <= -1.8e+79:
		tmp = t_1
	elif c <= -8.2e-138:
		tmp = t_0
	elif c <= 9.6e-151:
		tmp = (b / d) + (a / (d * (d / c)))
	elif c <= 4.3e+80:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(-1.0 / c) * Float64(Float64(Float64(-b) / Float64(c / d)) - a))
	tmp = 0.0
	if (c <= -1.8e+79)
		tmp = t_1;
	elseif (c <= -8.2e-138)
		tmp = t_0;
	elseif (c <= 9.6e-151)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 4.3e+80)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (-1.0 / c) * ((-b / (c / d)) - a);
	tmp = 0.0;
	if (c <= -1.8e+79)
		tmp = t_1;
	elseif (c <= -8.2e-138)
		tmp = t_0;
	elseif (c <= 9.6e-151)
		tmp = (b / d) + (a / (d * (d / c)));
	elseif (c <= 4.3e+80)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-1.0 / c), $MachinePrecision] * N[(N[((-b) / N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.8e+79], t$95$1, If[LessEqual[c, -8.2e-138], t$95$0, If[LessEqual[c, 9.6e-151], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.3e+80], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\
\mathbf{if}\;c \leq -1.8 \cdot 10^{+79}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 4.3 \cdot 10^{+80}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.8e79 or 4.30000000000000004e80 < c

    1. Initial program 38.3%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity38.3%

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

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

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

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

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

      \[\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 -inf 53.6%

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

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

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

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

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

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

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

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

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

    if -1.8e79 < c < -8.19999999999999998e-138 or 9.6e-151 < c < 4.30000000000000004e80

    1. Initial program 86.1%

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

    if -8.19999999999999998e-138 < c < 9.6e-151

    1. Initial program 65.7%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity80.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.8 \cdot 10^{+79}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\ \mathbf{elif}\;c \leq -8.2 \cdot 10^{-138}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 9.6 \cdot 10^{-151}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{+80}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 65.6% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{+50}:\\
\;\;\;\;\frac{a}{c}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.89999999999999994e50 or 2.59999999999999982e80 < c

    1. Initial program 43.8%

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

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

    if -1.89999999999999994e50 < c < 7.2000000000000005e-79

    1. Initial program 75.2%

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

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

    if 7.2000000000000005e-79 < c < 2.59999999999999982e80

    1. Initial program 80.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.9 \cdot 10^{+50}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{-79}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{+80}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 72.9% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.5 \cdot 10^{-15} \lor \neg \left(d \leq 1.1 \cdot 10^{+66}\right):\\
\;\;\;\;\frac{b}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.4999999999999996e-15 or 1.0999999999999999e66 < d

    1. Initial program 55.9%

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

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

    if -7.4999999999999996e-15 < d < 1.0999999999999999e66

    1. Initial program 72.3%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.9%

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

Alternative 10: 76.3% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{-15} \lor \neg \left(d \leq 2.7 \cdot 10^{-40}\right):\\
\;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{-1}{c} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.8000000000000001e-15 or 2.7e-40 < d

    1. Initial program 59.8%

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-un-lft-identity73.2%

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

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

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

    if -1.8000000000000001e-15 < d < 2.7e-40

    1. Initial program 71.0%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity70.9%

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

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

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

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

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

      \[\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 -inf 50.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(\frac{-b}{\frac{c}{d}} - a\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.3%

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

Alternative 11: 65.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-153}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{-34}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -4.6e+78)
   (/ b d)
   (if (<= d -3.6e-153)
     (/ (* b d) (+ (* c c) (* d d)))
     (if (<= d 6.5e-34) (/ a c) (/ b d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.6e+78) {
		tmp = b / d;
	} else if (d <= -3.6e-153) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 6.5e-34) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= (-4.6d+78)) then
        tmp = b / d
    else if (d <= (-3.6d-153)) then
        tmp = (b * d) / ((c * c) + (d * d))
    else if (d <= 6.5d-34) then
        tmp = a / c
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.6e+78) {
		tmp = b / d;
	} else if (d <= -3.6e-153) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 6.5e-34) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -4.6e+78:
		tmp = b / d
	elif d <= -3.6e-153:
		tmp = (b * d) / ((c * c) + (d * d))
	elif d <= 6.5e-34:
		tmp = a / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -4.6e+78)
		tmp = Float64(b / d);
	elseif (d <= -3.6e-153)
		tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 6.5e-34)
		tmp = Float64(a / c);
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -4.6e+78)
		tmp = b / d;
	elseif (d <= -3.6e-153)
		tmp = (b * d) / ((c * c) + (d * d));
	elseif (d <= 6.5e-34)
		tmp = a / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.6e+78], N[(b / d), $MachinePrecision], If[LessEqual[d, -3.6e-153], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.5e-34], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.6 \cdot 10^{+78}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 6.5 \cdot 10^{-34}:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.6000000000000004e78 or 6.49999999999999985e-34 < d

    1. Initial program 55.4%

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

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

    if -4.6000000000000004e78 < d < -3.5999999999999998e-153

    1. Initial program 89.2%

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

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

    if -3.5999999999999998e-153 < d < 6.49999999999999985e-34

    1. Initial program 65.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-153}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{-34}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 64.4% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.7 \cdot 10^{+49} \lor \neg \left(c \leq 6.4 \cdot 10^{+79}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.70000000000000018e49 or 6.40000000000000005e79 < c

    1. Initial program 43.8%

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

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

    if -3.70000000000000018e49 < c < 6.40000000000000005e79

    1. Initial program 76.2%

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

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

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

Alternative 13: 43.9% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq 4.5 \cdot 10^{+178}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d) :precision binary64 (if (<= d 4.5e+178) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= 4.5e+178) {
		tmp = a / c;
	} else {
		tmp = a / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= 4.5d+178) then
        tmp = a / c
    else
        tmp = a / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= 4.5e+178) {
		tmp = a / c;
	} else {
		tmp = a / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= 4.5e+178:
		tmp = a / c
	else:
		tmp = a / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= 4.5e+178)
		tmp = Float64(a / c);
	else
		tmp = Float64(a / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= 4.5e+178)
		tmp = a / c;
	else
		tmp = a / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, 4.5e+178], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq 4.5 \cdot 10^{+178}:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 4.4999999999999997e178

    1. Initial program 66.3%

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

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

    if 4.4999999999999997e178 < d

    1. Initial program 51.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity51.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{b}{c} + \frac{a}{d}} \]
    10. Simplified7.9%

      \[\leadsto \color{blue}{\frac{b}{c} + \frac{a}{d}} \]
    11. Taylor expanded in b around 0 44.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 4.5 \cdot 10^{+178}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 43.1% accurate, 5.0× speedup?

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

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 64.9%

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

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

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

Developer target: 99.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (< (fabs d) (fabs c))
   (/ (+ a (* b (/ d c))) (+ c (* d (/ d c))))
   (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (abs(d) < abs(c)) then
        tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (Math.abs(d) < Math.abs(c)) {
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (abs(d) < abs(c))
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (abs(d) < abs(c))
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024019 
(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))))