Complex division, real part

Percentage Accurate: 61.0% → 84.9%
Time: 9.7s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 61.0% accurate, 1.0× speedup?

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

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

Alternative 1: 84.9% accurate, 0.0× speedup?

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

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

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


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

    1. Initial program 79.7%

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

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

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

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

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

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

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

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

    if 1.0000000000000001e287 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 15.2%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac15.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-def15.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-def15.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-def22.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 10^{+287}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]

Alternative 2: 82.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -1.25 \cdot 10^{+66}:\\ \;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-86}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)} + \frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -1.25e+66)
     (* (+ a (/ b (/ c d))) (/ -1.0 (hypot c d)))
     (if (<= c -1.5e-105)
       t_0
       (if (<= c 1.15e-86)
         (* (/ -1.0 d) (- (- b) (/ (* a c) d)))
         (if (<= c 7.2e+47)
           t_0
           (+ (/ a (hypot c d)) (* (/ b (hypot c d)) (/ d c)))))))))
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 <= -1.25e+66) {
		tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d));
	} else if (c <= -1.5e-105) {
		tmp = t_0;
	} else if (c <= 1.15e-86) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		tmp = t_0;
	} else {
		tmp = (a / hypot(c, d)) + ((b / hypot(c, d)) * (d / c));
	}
	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 <= -1.25e+66) {
		tmp = (a + (b / (c / d))) * (-1.0 / Math.hypot(c, d));
	} else if (c <= -1.5e-105) {
		tmp = t_0;
	} else if (c <= 1.15e-86) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		tmp = t_0;
	} else {
		tmp = (a / Math.hypot(c, d)) + ((b / Math.hypot(c, d)) * (d / c));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.25e+66:
		tmp = (a + (b / (c / d))) * (-1.0 / math.hypot(c, d))
	elif c <= -1.5e-105:
		tmp = t_0
	elif c <= 1.15e-86:
		tmp = (-1.0 / d) * (-b - ((a * c) / d))
	elif c <= 7.2e+47:
		tmp = t_0
	else:
		tmp = (a / math.hypot(c, d)) + ((b / math.hypot(c, d)) * (d / c))
	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 <= -1.25e+66)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) * Float64(-1.0 / hypot(c, d)));
	elseif (c <= -1.5e-105)
		tmp = t_0;
	elseif (c <= 1.15e-86)
		tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d)));
	elseif (c <= 7.2e+47)
		tmp = t_0;
	else
		tmp = Float64(Float64(a / hypot(c, d)) + Float64(Float64(b / hypot(c, d)) * Float64(d / c)));
	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 <= -1.25e+66)
		tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d));
	elseif (c <= -1.5e-105)
		tmp = t_0;
	elseif (c <= 1.15e-86)
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	elseif (c <= 7.2e+47)
		tmp = t_0;
	else
		tmp = (a / hypot(c, d)) + ((b / hypot(c, d)) * (d / c));
	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, -1.25e+66], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.5e-105], t$95$0, If[LessEqual[c, 1.15e-86], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], t$95$0, N[(N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / c), $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 -1.25 \cdot 10^{+66}:\\
\;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -1.5 \cdot 10^{-105}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 1.15 \cdot 10^{-86}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\

\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 43.4%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac43.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-def43.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-def43.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-def65.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)}} \]
    3. Applied egg-rr65.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)}} \]
    4. Taylor expanded in c around -inf 86.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)} \]
    5. Step-by-step derivation
      1. mul-1-neg86.3%

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

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

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

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

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

    if -1.24999999999999998e66 < c < -1.5e-105 or 1.14999999999999998e-86 < c < 7.20000000000000015e47

    1. Initial program 87.9%

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

    if -1.5e-105 < c < 1.14999999999999998e-86

    1. Initial program 74.4%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def88.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)}} \]
    3. Applied egg-rr88.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)}} \]
    4. Taylor expanded in d around -inf 60.4%

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

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

    if 7.20000000000000015e47 < c

    1. Initial program 48.3%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac48.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-def48.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-def48.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-def72.7%

        \[\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)}} \]
    3. Applied egg-rr72.7%

      \[\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)}} \]
    4. Taylor expanded in c around inf 90.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.25 \cdot 10^{+66}:\\ \;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-86}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)} + \frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{c}\\ \end{array} \]

Alternative 3: 82.1% accurate, 0.1× speedup?

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

\mathbf{elif}\;c \leq -1.22 \cdot 10^{-105}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 3.6 \cdot 10^{-80}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\

\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 43.4%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac43.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-def43.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-def43.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-def65.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)}} \]
    3. Applied egg-rr65.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)}} \]
    4. Taylor expanded in c around -inf 86.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)} \]
    5. Step-by-step derivation
      1. mul-1-neg86.3%

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

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

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

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

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

    if -1.24999999999999998e66 < c < -1.22000000000000001e-105 or 3.6e-80 < c < 7.20000000000000015e47

    1. Initial program 87.9%

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

    if -1.22000000000000001e-105 < c < 3.6e-80

    1. Initial program 74.4%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def88.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)}} \]
    3. Applied egg-rr88.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)}} \]
    4. Taylor expanded in d around -inf 60.4%

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

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

    if 7.20000000000000015e47 < c

    1. Initial program 48.3%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac48.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-def48.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-def48.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-def72.7%

        \[\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)}} \]
    3. Applied egg-rr72.7%

      \[\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)}} \]
    4. Taylor expanded in c around inf 90.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.25 \cdot 10^{+66}:\\ \;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.22 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-80}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;\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{1}{\frac{\frac{c}{d}}{b}}\right)\\ \end{array} \]

Alternative 4: 82.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := a + \frac{b}{\frac{c}{d}}\\ \mathbf{if}\;c \leq -1.45 \cdot 10^{+80}:\\ \;\;\;\;\frac{1}{c} \cdot t_1\\ \mathbf{elif}\;c \leq -1.4 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{-81}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \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 (+ a (/ b (/ c d)))))
   (if (<= c -1.45e+80)
     (* (/ 1.0 c) t_1)
     (if (<= c -1.4e-105)
       t_0
       (if (<= c 1.45e-81)
         (* (/ -1.0 d) (- (- b) (/ (* a c) d)))
         (if (<= c 7.2e+47) t_0 (* (/ 1.0 (hypot c d)) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = a + (b / (c / d));
	double tmp;
	if (c <= -1.45e+80) {
		tmp = (1.0 / c) * t_1;
	} else if (c <= -1.4e-105) {
		tmp = t_0;
	} else if (c <= 1.45e-81) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * 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 = a + (b / (c / d));
	double tmp;
	if (c <= -1.45e+80) {
		tmp = (1.0 / c) * t_1;
	} else if (c <= -1.4e-105) {
		tmp = t_0;
	} else if (c <= 1.45e-81) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		tmp = t_0;
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = a + (b / (c / d))
	tmp = 0
	if c <= -1.45e+80:
		tmp = (1.0 / c) * t_1
	elif c <= -1.4e-105:
		tmp = t_0
	elif c <= 1.45e-81:
		tmp = (-1.0 / d) * (-b - ((a * c) / d))
	elif c <= 7.2e+47:
		tmp = t_0
	else:
		tmp = (1.0 / math.hypot(c, d)) * 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(a + Float64(b / Float64(c / d)))
	tmp = 0.0
	if (c <= -1.45e+80)
		tmp = Float64(Float64(1.0 / c) * t_1);
	elseif (c <= -1.4e-105)
		tmp = t_0;
	elseif (c <= 1.45e-81)
		tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d)));
	elseif (c <= 7.2e+47)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = a + (b / (c / d));
	tmp = 0.0;
	if (c <= -1.45e+80)
		tmp = (1.0 / c) * t_1;
	elseif (c <= -1.4e-105)
		tmp = t_0;
	elseif (c <= 1.45e-81)
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	elseif (c <= 7.2e+47)
		tmp = t_0;
	else
		tmp = (1.0 / hypot(c, d)) * 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[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.45e+80], N[(N[(1.0 / c), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[c, -1.4e-105], t$95$0, If[LessEqual[c, 1.45e-81], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $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 := a + \frac{b}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -1.45 \cdot 10^{+80}:\\
\;\;\;\;\frac{1}{c} \cdot t_1\\

\mathbf{elif}\;c \leq -1.4 \cdot 10^{-105}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 1.45 \cdot 10^{-81}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\

\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 40.4%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac40.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-def40.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-def40.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-def64.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)}} \]
    3. Applied egg-rr64.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)}} \]
    4. Taylor expanded in c around inf 27.3%

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

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

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

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

    if -1.44999999999999993e80 < c < -1.4e-105 or 1.44999999999999994e-81 < c < 7.20000000000000015e47

    1. Initial program 87.2%

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

    if -1.4e-105 < c < 1.44999999999999994e-81

    1. Initial program 74.4%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def88.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)}} \]
    3. Applied egg-rr88.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)}} \]
    4. Taylor expanded in d around -inf 60.4%

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

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

    if 7.20000000000000015e47 < c

    1. Initial program 48.3%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac48.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-def48.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-def48.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-def72.7%

        \[\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)}} \]
    3. Applied egg-rr72.7%

      \[\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)}} \]
    4. Taylor expanded in c around inf 90.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{+80}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;c \leq -1.4 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{-81}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;\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} \]

Alternative 5: 82.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := a + \frac{b}{\frac{c}{d}}\\ \mathbf{if}\;c \leq -3.1 \cdot 10^{+65}:\\ \;\;\;\;t_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{-83}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \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 (+ a (/ b (/ c d)))))
   (if (<= c -3.1e+65)
     (* t_1 (/ -1.0 (hypot c d)))
     (if (<= c -1.2e-105)
       t_0
       (if (<= c 3.9e-83)
         (* (/ -1.0 d) (- (- b) (/ (* a c) d)))
         (if (<= c 7.2e+47) t_0 (* (/ 1.0 (hypot c d)) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = a + (b / (c / d));
	double tmp;
	if (c <= -3.1e+65) {
		tmp = t_1 * (-1.0 / hypot(c, d));
	} else if (c <= -1.2e-105) {
		tmp = t_0;
	} else if (c <= 3.9e-83) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * 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 = a + (b / (c / d));
	double tmp;
	if (c <= -3.1e+65) {
		tmp = t_1 * (-1.0 / Math.hypot(c, d));
	} else if (c <= -1.2e-105) {
		tmp = t_0;
	} else if (c <= 3.9e-83) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		tmp = t_0;
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = a + (b / (c / d))
	tmp = 0
	if c <= -3.1e+65:
		tmp = t_1 * (-1.0 / math.hypot(c, d))
	elif c <= -1.2e-105:
		tmp = t_0
	elif c <= 3.9e-83:
		tmp = (-1.0 / d) * (-b - ((a * c) / d))
	elif c <= 7.2e+47:
		tmp = t_0
	else:
		tmp = (1.0 / math.hypot(c, d)) * 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(a + Float64(b / Float64(c / d)))
	tmp = 0.0
	if (c <= -3.1e+65)
		tmp = Float64(t_1 * Float64(-1.0 / hypot(c, d)));
	elseif (c <= -1.2e-105)
		tmp = t_0;
	elseif (c <= 3.9e-83)
		tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d)));
	elseif (c <= 7.2e+47)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = a + (b / (c / d));
	tmp = 0.0;
	if (c <= -3.1e+65)
		tmp = t_1 * (-1.0 / hypot(c, d));
	elseif (c <= -1.2e-105)
		tmp = t_0;
	elseif (c <= 3.9e-83)
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	elseif (c <= 7.2e+47)
		tmp = t_0;
	else
		tmp = (1.0 / hypot(c, d)) * 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[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.1e+65], N[(t$95$1 * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.2e-105], t$95$0, If[LessEqual[c, 3.9e-83], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $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 := a + \frac{b}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -3.1 \cdot 10^{+65}:\\
\;\;\;\;t_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 3.9 \cdot 10^{-83}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\

\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 43.4%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac43.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-def43.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-def43.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-def65.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)}} \]
    3. Applied egg-rr65.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)}} \]
    4. Taylor expanded in c around -inf 86.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)} \]
    5. Step-by-step derivation
      1. mul-1-neg86.3%

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

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

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

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

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

    if -3.09999999999999991e65 < c < -1.20000000000000007e-105 or 3.9e-83 < c < 7.20000000000000015e47

    1. Initial program 87.9%

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

    if -1.20000000000000007e-105 < c < 3.9e-83

    1. Initial program 74.4%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def88.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)}} \]
    3. Applied egg-rr88.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)}} \]
    4. Taylor expanded in d around -inf 60.4%

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

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

    if 7.20000000000000015e47 < c

    1. Initial program 48.3%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac48.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-def48.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-def48.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-def72.7%

        \[\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)}} \]
    3. Applied egg-rr72.7%

      \[\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)}} \]
    4. Taylor expanded in c around inf 90.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.1 \cdot 10^{+65}:\\ \;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{-83}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;\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} \]

Alternative 6: 81.9% 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(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{if}\;c \leq -3.4 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.35 \cdot 10^{-87}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;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) (+ a (/ b (/ c d))))))
   (if (<= c -3.4e+79)
     t_1
     (if (<= c -1.2e-105)
       t_0
       (if (<= c 3.35e-87)
         (* (/ -1.0 d) (- (- b) (/ (* a c) d)))
         (if (<= c 7.2e+47) 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) * (a + (b / (c / d)));
	double tmp;
	if (c <= -3.4e+79) {
		tmp = t_1;
	} else if (c <= -1.2e-105) {
		tmp = t_0;
	} else if (c <= 3.35e-87) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		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) * (a + (b / (c / d)))
    if (c <= (-3.4d+79)) then
        tmp = t_1
    else if (c <= (-1.2d-105)) then
        tmp = t_0
    else if (c <= 3.35d-87) then
        tmp = ((-1.0d0) / d) * (-b - ((a * c) / d))
    else if (c <= 7.2d+47) 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) * (a + (b / (c / d)));
	double tmp;
	if (c <= -3.4e+79) {
		tmp = t_1;
	} else if (c <= -1.2e-105) {
		tmp = t_0;
	} else if (c <= 3.35e-87) {
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	} else if (c <= 7.2e+47) {
		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) * (a + (b / (c / d)))
	tmp = 0
	if c <= -3.4e+79:
		tmp = t_1
	elif c <= -1.2e-105:
		tmp = t_0
	elif c <= 3.35e-87:
		tmp = (-1.0 / d) * (-b - ((a * c) / d))
	elif c <= 7.2e+47:
		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(a + Float64(b / Float64(c / d))))
	tmp = 0.0
	if (c <= -3.4e+79)
		tmp = t_1;
	elseif (c <= -1.2e-105)
		tmp = t_0;
	elseif (c <= 3.35e-87)
		tmp = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(Float64(a * c) / d)));
	elseif (c <= 7.2e+47)
		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) * (a + (b / (c / d)));
	tmp = 0.0;
	if (c <= -3.4e+79)
		tmp = t_1;
	elseif (c <= -1.2e-105)
		tmp = t_0;
	elseif (c <= 3.35e-87)
		tmp = (-1.0 / d) * (-b - ((a * c) / d));
	elseif (c <= 7.2e+47)
		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[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.4e+79], t$95$1, If[LessEqual[c, -1.2e-105], t$95$0, If[LessEqual[c, 3.35e-87], N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e+47], 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(a + \frac{b}{\frac{c}{d}}\right)\\
\mathbf{if}\;c \leq -3.4 \cdot 10^{+79}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 3.35 \cdot 10^{-87}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\

\mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.40000000000000032e79 or 7.20000000000000015e47 < c

    1. Initial program 45.0%

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

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

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

        \[\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-def44.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-def44.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-def69.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)}} \]
    3. Applied egg-rr69.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)}} \]
    4. Taylor expanded in c around inf 63.9%

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

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

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

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

    if -3.40000000000000032e79 < c < -1.20000000000000007e-105 or 3.35e-87 < c < 7.20000000000000015e47

    1. Initial program 87.2%

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

    if -1.20000000000000007e-105 < c < 3.35e-87

    1. Initial program 74.4%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def88.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)}} \]
    3. Applied egg-rr88.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)}} \]
    4. Taylor expanded in d around -inf 60.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.4 \cdot 10^{+79}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;c \leq -1.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.35 \cdot 10^{-87}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{+47}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]

Alternative 7: 76.5% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.8 \cdot 10^{-10} \lor \neg \left(c \leq 3.8 \cdot 10^{-63} \lor \neg \left(c \leq 240000000000\right) \land c \leq 7.2 \cdot 10^{+47}\right):\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -6.8000000000000003e-10 or 3.80000000000000017e-63 < c < 2.4e11 or 7.20000000000000015e47 < c

    1. Initial program 56.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.8000000000000003e-10 < c < 3.80000000000000017e-63 or 2.4e11 < c < 7.20000000000000015e47

    1. Initial program 76.0%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac76.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-def76.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-def76.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-def88.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.8 \cdot 10^{-10} \lor \neg \left(c \leq 3.8 \cdot 10^{-63} \lor \neg \left(c \leq 240000000000\right) \land c \leq 7.2 \cdot 10^{+47}\right):\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a \cdot c}{d}\right)\\ \end{array} \]

Alternative 8: 77.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{if}\;d \leq -8.4 \cdot 10^{+89}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -7.2 \cdot 10^{+64}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq -85000000000000 \lor \neg \left(d \leq 5.9 \cdot 10^{+26}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ b d) (* c (/ (/ a d) d)))))
   (if (<= d -8.4e+89)
     t_0
     (if (<= d -7.2e+64)
       (/ a c)
       (if (or (<= d -85000000000000.0) (not (<= d 5.9e+26)))
         t_0
         (* (/ 1.0 c) (+ a (/ b (/ c d)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + (c * ((a / d) / d));
	double tmp;
	if (d <= -8.4e+89) {
		tmp = t_0;
	} else if (d <= -7.2e+64) {
		tmp = a / c;
	} else if ((d <= -85000000000000.0) || !(d <= 5.9e+26)) {
		tmp = t_0;
	} else {
		tmp = (1.0 / c) * (a + (b / (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) :: t_0
    real(8) :: tmp
    t_0 = (b / d) + (c * ((a / d) / d))
    if (d <= (-8.4d+89)) then
        tmp = t_0
    else if (d <= (-7.2d+64)) then
        tmp = a / c
    else if ((d <= (-85000000000000.0d0)) .or. (.not. (d <= 5.9d+26))) then
        tmp = t_0
    else
        tmp = (1.0d0 / c) * (a + (b / (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + (c * ((a / d) / d));
	double tmp;
	if (d <= -8.4e+89) {
		tmp = t_0;
	} else if (d <= -7.2e+64) {
		tmp = a / c;
	} else if ((d <= -85000000000000.0) || !(d <= 5.9e+26)) {
		tmp = t_0;
	} else {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / d) + (c * ((a / d) / d))
	tmp = 0
	if d <= -8.4e+89:
		tmp = t_0
	elif d <= -7.2e+64:
		tmp = a / c
	elif (d <= -85000000000000.0) or not (d <= 5.9e+26):
		tmp = t_0
	else:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d)))
	tmp = 0.0
	if (d <= -8.4e+89)
		tmp = t_0;
	elseif (d <= -7.2e+64)
		tmp = Float64(a / c);
	elseif ((d <= -85000000000000.0) || !(d <= 5.9e+26))
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b / d) + (c * ((a / d) / d));
	tmp = 0.0;
	if (d <= -8.4e+89)
		tmp = t_0;
	elseif (d <= -7.2e+64)
		tmp = a / c;
	elseif ((d <= -85000000000000.0) || ~((d <= 5.9e+26)))
		tmp = t_0;
	else
		tmp = (1.0 / c) * (a + (b / (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -8.4e+89], t$95$0, If[LessEqual[d, -7.2e+64], N[(a / c), $MachinePrecision], If[Or[LessEqual[d, -85000000000000.0], N[Not[LessEqual[d, 5.9e+26]], $MachinePrecision]], t$95$0, N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -85000000000000 \lor \neg \left(d \leq 5.9 \cdot 10^{+26}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -8.39999999999999945e89 or -7.20000000000000027e64 < d < -8.5e13 or 5.9000000000000003e26 < d

    1. Initial program 58.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.39999999999999945e89 < d < -7.20000000000000027e64

    1. Initial program 61.5%

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

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

    if -8.5e13 < d < 5.9000000000000003e26

    1. Initial program 71.1%

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

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

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

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

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

        \[\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-def84.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)}} \]
    3. Applied egg-rr84.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)}} \]
    4. Taylor expanded in c around inf 53.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.4 \cdot 10^{+89}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq -7.2 \cdot 10^{+64}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq -85000000000000 \lor \neg \left(d \leq 5.9 \cdot 10^{+26}\right):\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]

Alternative 9: 76.1% accurate, 0.8× speedup?

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

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

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

\mathbf{elif}\;c \leq 2.6 \cdot 10^{+22} \lor \neg \left(c \leq 7.2 \cdot 10^{+47}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.00000000000000006e-9 or 3.39999999999999998e-63 < c < 2.6e22 or 7.20000000000000015e47 < c

    1. Initial program 57.9%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac57.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-def57.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-def57.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-def75.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)}} \]
    3. Applied egg-rr75.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)}} \]
    4. Taylor expanded in c around inf 57.9%

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

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

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

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

    if -1.00000000000000006e-9 < c < 3.39999999999999998e-63

    1. Initial program 77.2%

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

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

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

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

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

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

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

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

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

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

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

    if 2.6e22 < c < 7.20000000000000015e47

    1. Initial program 43.8%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1 \cdot 10^{-9}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;c \leq 3.4 \cdot 10^{-63}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{+22} \lor \neg \left(c \leq 7.2 \cdot 10^{+47}\right):\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \end{array} \]

Alternative 10: 72.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.8 \cdot 10^{+88} \lor \neg \left(d \leq 4.2 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -9.8000000000000005e88 or 4.19999999999999958e31 < d

    1. Initial program 56.3%

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

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

    if -9.8000000000000005e88 < d < 4.19999999999999958e31

    1. Initial program 71.1%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac71.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-def71.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-def71.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-def84.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)}} \]
    3. Applied egg-rr84.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)}} \]
    4. Taylor expanded in c around inf 51.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.8 \cdot 10^{+88} \lor \neg \left(d \leq 4.2 \cdot 10^{+31}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]

Alternative 11: 63.4% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{+88} \lor \neg \left(d \leq 1.8 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -9e88 or 1.79999999999999998e31 < d

    1. Initial program 56.3%

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

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

    if -9e88 < d < 1.79999999999999998e31

    1. Initial program 71.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9 \cdot 10^{+88} \lor \neg \left(d \leq 1.8 \cdot 10^{+31}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 12: 42.6% 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 65.6%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification48.2%

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

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 2023334 
(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))))