Complex division, real part

Percentage Accurate: 62.0% → 81.8%
Time: 11.6s
Alternatives: 13
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 13 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: 62.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: 81.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{\frac{d}{c}}\\ t_1 := \mathsf{fma}\left(c, a, b \cdot d\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{if}\;d \leq -7.6 \cdot 10^{+128}:\\ \;\;\;\;\frac{\left(-b\right) - t_0}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+75}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -2.05 \cdot 10^{+51}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-88}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b + t_0}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ a (/ d c))) (t_1 (* (fma c a (* b d)) (pow (hypot c d) -2.0))))
   (if (<= d -7.6e+128)
     (/ (- (- b) t_0) (hypot c d))
     (if (<= d -5e+75)
       (+ (/ a c) (* (/ d c) (/ b c)))
       (if (<= d -2.05e+51)
         (/ b d)
         (if (<= d -1.9e-97)
           t_1
           (if (<= d 8e-88)
             (/ (fma b (/ d c) a) c)
             (if (<= d 2.1e+100) t_1 (/ (+ b t_0) (hypot c d))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = a / (d / c);
	double t_1 = fma(c, a, (b * d)) * pow(hypot(c, d), -2.0);
	double tmp;
	if (d <= -7.6e+128) {
		tmp = (-b - t_0) / hypot(c, d);
	} else if (d <= -5e+75) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -2.05e+51) {
		tmp = b / d;
	} else if (d <= -1.9e-97) {
		tmp = t_1;
	} else if (d <= 8e-88) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 2.1e+100) {
		tmp = t_1;
	} else {
		tmp = (b + t_0) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(a / Float64(d / c))
	t_1 = Float64(fma(c, a, Float64(b * d)) * (hypot(c, d) ^ -2.0))
	tmp = 0.0
	if (d <= -7.6e+128)
		tmp = Float64(Float64(Float64(-b) - t_0) / hypot(c, d));
	elseif (d <= -5e+75)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -2.05e+51)
		tmp = Float64(b / d);
	elseif (d <= -1.9e-97)
		tmp = t_1;
	elseif (d <= 8e-88)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 2.1e+100)
		tmp = t_1;
	else
		tmp = Float64(Float64(b + t_0) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] * N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.6e+128], N[(N[((-b) - t$95$0), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5e+75], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.05e+51], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.9e-97], t$95$1, If[LessEqual[d, 8e-88], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.1e+100], t$95$1, N[(N[(b + t$95$0), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -2.05 \cdot 10^{+51}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq -1.9 \cdot 10^{-97}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d \leq 2.1 \cdot 10^{+100}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if d < -7.5999999999999998e128

    1. Initial program 25.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt25.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-frac25.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-def25.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-def25.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-def55.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-rr55.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. Step-by-step derivation
      1. associate-*l/55.3%

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

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

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

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

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

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

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

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

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

    if -7.5999999999999998e128 < d < -5.0000000000000002e75

    1. Initial program 16.3%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt16.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-frac16.3%

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

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

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

      \[\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*44.4%

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

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

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

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

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

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

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

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

    if -5.0000000000000002e75 < d < -2.05000000000000005e51

    1. Initial program 67.0%

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

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

    if -2.05000000000000005e51 < d < -1.9e-97 or 7.99999999999999947e-88 < d < 2.0999999999999999e100

    1. Initial program 77.8%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt77.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-frac77.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-def77.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-def77.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-def84.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-rr84.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. Step-by-step derivation
      1. expm1-log1p-u58.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\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)}\right)\right)} \]
      2. expm1-udef29.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\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)}\right)} - 1} \]
      3. frac-times29.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(c, a, b \cdot d\right) \cdot \left({\left(\mathsf{hypot}\left(c, d\right)\right)}^{-1} \cdot \color{blue}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{-1}}\right) \]
      16. pow-sqr79.0%

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

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

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

    if -1.9e-97 < d < 7.99999999999999947e-88

    1. Initial program 73.5%

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

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

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

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

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

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

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

      \[\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 95.1%

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\frac{b}{\frac{c}{d}} + a}}{c}\right)} - 1 \]
      6. div-inv37.3%

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)} - 1} \]
    10. Step-by-step derivation
      1. expm1-def64.4%

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

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

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

    if 2.0999999999999999e100 < d

    1. Initial program 35.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt35.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-frac35.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.6 \cdot 10^{+128}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+75}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -2.05 \cdot 10^{+51}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{-97}:\\ \;\;\;\;\mathsf{fma}\left(c, a, b \cdot d\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-88}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+100}:\\ \;\;\;\;\mathsf{fma}\left(c, a, b \cdot d\right) \cdot {\left(\mathsf{hypot}\left(c, d\right)\right)}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 2: 85.9% accurate, 0.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\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))) < 5.00000000000000033e293

    1. Initial program 78.3%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt78.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-frac78.3%

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

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

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

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

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

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

    if 5.00000000000000033e293 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 9.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt9.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-frac9.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-def9.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-def9.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-def13.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-rr13.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 d around -inf 25.1%

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

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

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

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

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

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

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

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

Alternative 3: 81.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{\frac{d}{c}}\\ t_1 := \frac{-1}{d} \cdot \left(\left(-b\right) - t_0\right)\\ t_2 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -6.2 \cdot 10^{+143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.55 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.72 \cdot 10^{-97}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{-82}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{+100}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{b + t_0}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ a (/ d c)))
        (t_1 (* (/ -1.0 d) (- (- b) t_0)))
        (t_2 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -6.2e+143)
     t_1
     (if (<= d -1.55e+81)
       (+ (/ a c) (* (/ d c) (/ b c)))
       (if (<= d -3.8e+29)
         t_1
         (if (<= d -1.72e-97)
           t_2
           (if (<= d 3.9e-82)
             (/ (fma b (/ d c) a) c)
             (if (<= d 4.1e+100) t_2 (/ (+ b t_0) (hypot c d))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = a / (d / c);
	double t_1 = (-1.0 / d) * (-b - t_0);
	double t_2 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -6.2e+143) {
		tmp = t_1;
	} else if (d <= -1.55e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -3.8e+29) {
		tmp = t_1;
	} else if (d <= -1.72e-97) {
		tmp = t_2;
	} else if (d <= 3.9e-82) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 4.1e+100) {
		tmp = t_2;
	} else {
		tmp = (b + t_0) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(a / Float64(d / c))
	t_1 = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - t_0))
	t_2 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -6.2e+143)
		tmp = t_1;
	elseif (d <= -1.55e+81)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -3.8e+29)
		tmp = t_1;
	elseif (d <= -1.72e-97)
		tmp = t_2;
	elseif (d <= 3.9e-82)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 4.1e+100)
		tmp = t_2;
	else
		tmp = Float64(Float64(b + t_0) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.2e+143], t$95$1, If[LessEqual[d, -1.55e+81], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.8e+29], t$95$1, If[LessEqual[d, -1.72e-97], t$95$2, If[LessEqual[d, 3.9e-82], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.1e+100], t$95$2, N[(N[(b + t$95$0), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -3.8 \cdot 10^{+29}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq -1.72 \cdot 10^{-97}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;d \leq 4.1 \cdot 10^{+100}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -6.1999999999999998e143 or -1.55e81 < d < -3.79999999999999971e29

    1. Initial program 31.9%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt31.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-frac32.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-def32.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-def32.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-def55.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-rr55.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 78.2%

      \[\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. Step-by-step derivation
      1. mul-1-neg78.2%

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

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

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

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

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

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

    if -6.1999999999999998e143 < d < -1.55e81

    1. Initial program 22.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt22.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-frac22.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-def22.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-def22.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def46.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-rr46.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 c around inf 39.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*39.3%

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

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(a + \frac{b}{\frac{c}{d}}\right) \]
    8. Step-by-step derivation
      1. distribute-rgt-in73.5%

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

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

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

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

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

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

    if -3.79999999999999971e29 < d < -1.71999999999999995e-97 or 3.89999999999999973e-82 < d < 4.1000000000000003e100

    1. Initial program 77.7%

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

    if -1.71999999999999995e-97 < d < 3.89999999999999973e-82

    1. Initial program 74.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt74.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-frac74.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-def74.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-def74.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-def87.2%

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

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

      \[\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*53.9%

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

      \[\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 95.2%

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{1 \cdot \left(a + \frac{b}{\frac{c}{d}}\right)}{c}}\right)} - 1 \]
      4. *-un-lft-identity36.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{a + \frac{b}{\frac{c}{d}}}}{c}\right)} - 1 \]
      5. +-commutative36.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\frac{b}{\frac{c}{d}} + a}}{c}\right)} - 1 \]
      6. div-inv36.5%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    9. Applied egg-rr36.5%

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p95.5%

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

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

    if 4.1000000000000003e100 < d

    1. Initial program 35.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt35.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-frac35.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.2 \cdot 10^{+143}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.55 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{+29}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.72 \cdot 10^{-97}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{-82}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{+100}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 4: 82.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{a}{\frac{d}{c}}\\ t_2 := \left(-b\right) - t_1\\ \mathbf{if}\;d \leq -7.6 \cdot 10^{+128}:\\ \;\;\;\;\frac{t_2}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{+29}:\\ \;\;\;\;\frac{-1}{d} \cdot t_2\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-80}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{+100}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (/ a (/ d c)))
        (t_2 (- (- b) t_1)))
   (if (<= d -7.6e+128)
     (/ t_2 (hypot c d))
     (if (<= d -1.95e+81)
       (+ (/ a c) (* (/ d c) (/ b c)))
       (if (<= d -3.8e+29)
         (* (/ -1.0 d) t_2)
         (if (<= d -1.7e-97)
           t_0
           (if (<= d 1.4e-80)
             (/ (fma b (/ d c) a) c)
             (if (<= d 2.7e+100) t_0 (/ (+ b t_1) (hypot c d))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = a / (d / c);
	double t_2 = -b - t_1;
	double tmp;
	if (d <= -7.6e+128) {
		tmp = t_2 / hypot(c, d);
	} else if (d <= -1.95e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -3.8e+29) {
		tmp = (-1.0 / d) * t_2;
	} else if (d <= -1.7e-97) {
		tmp = t_0;
	} else if (d <= 1.4e-80) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 2.7e+100) {
		tmp = t_0;
	} else {
		tmp = (b + t_1) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(a / Float64(d / c))
	t_2 = Float64(Float64(-b) - t_1)
	tmp = 0.0
	if (d <= -7.6e+128)
		tmp = Float64(t_2 / hypot(c, d));
	elseif (d <= -1.95e+81)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -3.8e+29)
		tmp = Float64(Float64(-1.0 / d) * t_2);
	elseif (d <= -1.7e-97)
		tmp = t_0;
	elseif (d <= 1.4e-80)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 2.7e+100)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + t_1) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[((-b) - t$95$1), $MachinePrecision]}, If[LessEqual[d, -7.6e+128], N[(t$95$2 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.95e+81], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.8e+29], N[(N[(-1.0 / d), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[d, -1.7e-97], t$95$0, If[LessEqual[d, 1.4e-80], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.7e+100], t$95$0, N[(N[(b + t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -3.8 \cdot 10^{+29}:\\
\;\;\;\;\frac{-1}{d} \cdot t_2\\

\mathbf{elif}\;d \leq -1.7 \cdot 10^{-97}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 2.7 \cdot 10^{+100}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if d < -7.5999999999999998e128

    1. Initial program 25.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt25.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-frac25.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-def25.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-def25.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-def55.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-rr55.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. Step-by-step derivation
      1. associate-*l/55.3%

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

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

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

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

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

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

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

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

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

    if -7.5999999999999998e128 < d < -1.95e81

    1. Initial program 16.3%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt16.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-frac16.3%

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

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

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

      \[\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*44.4%

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

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

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

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

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

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

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

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

    if -1.95e81 < d < -3.79999999999999971e29

    1. Initial program 66.7%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt66.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-frac67.3%

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

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

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

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

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

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

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

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

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

    if -3.79999999999999971e29 < d < -1.6999999999999999e-97 or 1.39999999999999995e-80 < d < 2.69999999999999998e100

    1. Initial program 77.7%

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

    if -1.6999999999999999e-97 < d < 1.39999999999999995e-80

    1. Initial program 74.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt74.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-frac74.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-def74.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-def74.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-def87.2%

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

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

      \[\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*53.9%

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

      \[\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 95.2%

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{1 \cdot \left(a + \frac{b}{\frac{c}{d}}\right)}{c}}\right)} - 1 \]
      4. *-un-lft-identity36.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{a + \frac{b}{\frac{c}{d}}}}{c}\right)} - 1 \]
      5. +-commutative36.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\frac{b}{\frac{c}{d}} + a}}{c}\right)} - 1 \]
      6. div-inv36.5%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    9. Applied egg-rr36.5%

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p95.5%

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

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

    if 2.69999999999999998e100 < d

    1. Initial program 35.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt35.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-frac35.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.6 \cdot 10^{+128}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{+29}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-97}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-80}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{+100}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 5: 81.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -5.2 \cdot 10^{+143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -2.95 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.72 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-81}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+101}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ -1.0 d) (- (- b) (/ a (/ d c)))))
        (t_1 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -5.2e+143)
     t_0
     (if (<= d -1.2e+81)
       (+ (/ a c) (* (/ d c) (/ b c)))
       (if (<= d -2.95e+29)
         t_0
         (if (<= d -1.72e-97)
           t_1
           (if (<= d 1.4e-81)
             (/ (fma b (/ d c) a) c)
             (if (<= d 2.8e+101) t_1 t_0))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (-1.0 / d) * (-b - (a / (d / c)));
	double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -5.2e+143) {
		tmp = t_0;
	} else if (d <= -1.2e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -2.95e+29) {
		tmp = t_0;
	} else if (d <= -1.72e-97) {
		tmp = t_1;
	} else if (d <= 1.4e-81) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 2.8e+101) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(a / Float64(d / c))))
	t_1 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -5.2e+143)
		tmp = t_0;
	elseif (d <= -1.2e+81)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -2.95e+29)
		tmp = t_0;
	elseif (d <= -1.72e-97)
		tmp = t_1;
	elseif (d <= 1.4e-81)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 2.8e+101)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.2e+143], t$95$0, If[LessEqual[d, -1.2e+81], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.95e+29], t$95$0, If[LessEqual[d, -1.72e-97], t$95$1, If[LessEqual[d, 1.4e-81], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.8e+101], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -2.95 \cdot 10^{+29}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -1.72 \cdot 10^{-97}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d \leq 2.8 \cdot 10^{+101}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -5.1999999999999998e143 or -1.19999999999999995e81 < d < -2.9499999999999999e29 or 2.79999999999999981e101 < d

    1. Initial program 33.3%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt33.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-frac33.3%

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def51.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-rr51.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 d around -inf 52.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. Step-by-step derivation
      1. mul-1-neg52.7%

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

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

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

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

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

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

    if -5.1999999999999998e143 < d < -1.19999999999999995e81

    1. Initial program 22.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt22.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-frac22.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-def22.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-def22.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def46.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-rr46.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 c around inf 39.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*39.3%

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

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(a + \frac{b}{\frac{c}{d}}\right) \]
    8. Step-by-step derivation
      1. distribute-rgt-in73.5%

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

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

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

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

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

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

    if -2.9499999999999999e29 < d < -1.71999999999999995e-97 or 1.3999999999999999e-81 < d < 2.79999999999999981e101

    1. Initial program 77.7%

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

    if -1.71999999999999995e-97 < d < 1.3999999999999999e-81

    1. Initial program 74.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt74.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-frac74.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-def74.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-def74.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-def87.2%

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

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

      \[\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*53.9%

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

      \[\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 95.2%

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{1 \cdot \left(a + \frac{b}{\frac{c}{d}}\right)}{c}}\right)} - 1 \]
      4. *-un-lft-identity36.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{a + \frac{b}{\frac{c}{d}}}}{c}\right)} - 1 \]
      5. +-commutative36.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\frac{b}{\frac{c}{d}} + a}}{c}\right)} - 1 \]
      6. div-inv36.5%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    9. Applied egg-rr36.5%

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p95.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+143}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -2.95 \cdot 10^{+29}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.72 \cdot 10^{-97}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-81}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+101}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \end{array} \]

Alternative 6: 80.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ t_1 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -5.2 \cdot 10^{+143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 9.6 \cdot 10^{-88}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ -1.0 d) (- (- b) (/ a (/ d c)))))
        (t_1 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -5.2e+143)
     t_0
     (if (<= d -1.95e+81)
       (+ (/ a c) (* (/ d c) (/ b c)))
       (if (<= d -1e+29)
         t_0
         (if (<= d -1.9e-97)
           t_1
           (if (<= d 9.6e-88)
             (* (/ 1.0 c) (+ a (/ b (/ c d))))
             (if (<= d 3.9e+100) t_1 t_0))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (-1.0 / d) * (-b - (a / (d / c)));
	double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -5.2e+143) {
		tmp = t_0;
	} else if (d <= -1.95e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -1e+29) {
		tmp = t_0;
	} else if (d <= -1.9e-97) {
		tmp = t_1;
	} else if (d <= 9.6e-88) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 3.9e+100) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((-1.0d0) / d) * (-b - (a / (d / c)))
    t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-5.2d+143)) then
        tmp = t_0
    else if (d <= (-1.95d+81)) then
        tmp = (a / c) + ((d / c) * (b / c))
    else if (d <= (-1d+29)) then
        tmp = t_0
    else if (d <= (-1.9d-97)) then
        tmp = t_1
    else if (d <= 9.6d-88) then
        tmp = (1.0d0 / c) * (a + (b / (c / d)))
    else if (d <= 3.9d+100) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (-1.0 / d) * (-b - (a / (d / c)));
	double t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -5.2e+143) {
		tmp = t_0;
	} else if (d <= -1.95e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -1e+29) {
		tmp = t_0;
	} else if (d <= -1.9e-97) {
		tmp = t_1;
	} else if (d <= 9.6e-88) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 3.9e+100) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (-1.0 / d) * (-b - (a / (d / c)))
	t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -5.2e+143:
		tmp = t_0
	elif d <= -1.95e+81:
		tmp = (a / c) + ((d / c) * (b / c))
	elif d <= -1e+29:
		tmp = t_0
	elif d <= -1.9e-97:
		tmp = t_1
	elif d <= 9.6e-88:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	elif d <= 3.9e+100:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(a / Float64(d / c))))
	t_1 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -5.2e+143)
		tmp = t_0;
	elseif (d <= -1.95e+81)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -1e+29)
		tmp = t_0;
	elseif (d <= -1.9e-97)
		tmp = t_1;
	elseif (d <= 9.6e-88)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif (d <= 3.9e+100)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (-1.0 / d) * (-b - (a / (d / c)));
	t_1 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -5.2e+143)
		tmp = t_0;
	elseif (d <= -1.95e+81)
		tmp = (a / c) + ((d / c) * (b / c));
	elseif (d <= -1e+29)
		tmp = t_0;
	elseif (d <= -1.9e-97)
		tmp = t_1;
	elseif (d <= 9.6e-88)
		tmp = (1.0 / c) * (a + (b / (c / d)));
	elseif (d <= 3.9e+100)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.2e+143], t$95$0, If[LessEqual[d, -1.95e+81], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e+29], t$95$0, If[LessEqual[d, -1.9e-97], t$95$1, If[LessEqual[d, 9.6e-88], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.9e+100], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -1 \cdot 10^{+29}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -1.9 \cdot 10^{-97}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d \leq 3.9 \cdot 10^{+100}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -5.1999999999999998e143 or -1.95e81 < d < -9.99999999999999914e28 or 3.9e100 < d

    1. Initial program 33.3%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt33.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-frac33.3%

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def51.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-rr51.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 d around -inf 52.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. Step-by-step derivation
      1. mul-1-neg52.7%

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

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

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

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

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

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

    if -5.1999999999999998e143 < d < -1.95e81

    1. Initial program 22.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt22.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-frac22.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-def22.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-def22.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def46.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-rr46.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 c around inf 39.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*39.3%

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

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(a + \frac{b}{\frac{c}{d}}\right) \]
    8. Step-by-step derivation
      1. distribute-rgt-in73.5%

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

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

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

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

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

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

    if -9.99999999999999914e28 < d < -1.9e-97 or 9.5999999999999998e-88 < d < 3.9e100

    1. Initial program 78.3%

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

    if -1.9e-97 < d < 9.5999999999999998e-88

    1. Initial program 73.5%

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

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

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

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

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

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

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

      \[\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 95.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+143}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{+29}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{-97}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 9.6 \cdot 10^{-88}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{+100}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \end{array} \]

Alternative 7: 76.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{if}\;d \leq -6.2 \cdot 10^{+143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -9 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 9 \cdot 10^{-71}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{-13}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+14}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ -1.0 d) (- (- b) (/ a (/ d c))))))
   (if (<= d -6.2e+143)
     t_0
     (if (<= d -1.95e+81)
       (+ (/ a c) (* (/ d c) (/ b c)))
       (if (<= d -9e+29)
         t_0
         (if (<= d 9e-71)
           (* (/ 1.0 c) (+ a (/ b (/ c d))))
           (if (<= d 2.8e-13)
             (/ (* b d) (+ (* c c) (* d d)))
             (if (<= d 1.7e+14) (* (/ 1.0 c) (+ a (* d (/ b c)))) t_0))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (-1.0 / d) * (-b - (a / (d / c)));
	double tmp;
	if (d <= -6.2e+143) {
		tmp = t_0;
	} else if (d <= -1.95e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -9e+29) {
		tmp = t_0;
	} else if (d <= 9e-71) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 2.8e-13) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 1.7e+14) {
		tmp = (1.0 / c) * (a + (d * (b / c)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((-1.0d0) / d) * (-b - (a / (d / c)))
    if (d <= (-6.2d+143)) then
        tmp = t_0
    else if (d <= (-1.95d+81)) then
        tmp = (a / c) + ((d / c) * (b / c))
    else if (d <= (-9d+29)) then
        tmp = t_0
    else if (d <= 9d-71) then
        tmp = (1.0d0 / c) * (a + (b / (c / d)))
    else if (d <= 2.8d-13) then
        tmp = (b * d) / ((c * c) + (d * d))
    else if (d <= 1.7d+14) then
        tmp = (1.0d0 / c) * (a + (d * (b / c)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (-1.0 / d) * (-b - (a / (d / c)));
	double tmp;
	if (d <= -6.2e+143) {
		tmp = t_0;
	} else if (d <= -1.95e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -9e+29) {
		tmp = t_0;
	} else if (d <= 9e-71) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 2.8e-13) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 1.7e+14) {
		tmp = (1.0 / c) * (a + (d * (b / c)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (-1.0 / d) * (-b - (a / (d / c)))
	tmp = 0
	if d <= -6.2e+143:
		tmp = t_0
	elif d <= -1.95e+81:
		tmp = (a / c) + ((d / c) * (b / c))
	elif d <= -9e+29:
		tmp = t_0
	elif d <= 9e-71:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	elif d <= 2.8e-13:
		tmp = (b * d) / ((c * c) + (d * d))
	elif d <= 1.7e+14:
		tmp = (1.0 / c) * (a + (d * (b / c)))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(-1.0 / d) * Float64(Float64(-b) - Float64(a / Float64(d / c))))
	tmp = 0.0
	if (d <= -6.2e+143)
		tmp = t_0;
	elseif (d <= -1.95e+81)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -9e+29)
		tmp = t_0;
	elseif (d <= 9e-71)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif (d <= 2.8e-13)
		tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1.7e+14)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(d * Float64(b / c))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (-1.0 / d) * (-b - (a / (d / c)));
	tmp = 0.0;
	if (d <= -6.2e+143)
		tmp = t_0;
	elseif (d <= -1.95e+81)
		tmp = (a / c) + ((d / c) * (b / c));
	elseif (d <= -9e+29)
		tmp = t_0;
	elseif (d <= 9e-71)
		tmp = (1.0 / c) * (a + (b / (c / d)));
	elseif (d <= 2.8e-13)
		tmp = (b * d) / ((c * c) + (d * d));
	elseif (d <= 1.7e+14)
		tmp = (1.0 / c) * (a + (d * (b / c)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(-1.0 / d), $MachinePrecision] * N[((-b) - N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.2e+143], t$95$0, If[LessEqual[d, -1.95e+81], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -9e+29], t$95$0, If[LessEqual[d, 9e-71], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.8e-13], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.7e+14], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -9 \cdot 10^{+29}:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;d \leq 1.7 \cdot 10^{+14}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -6.1999999999999998e143 or -1.95e81 < d < -9.0000000000000005e29 or 1.7e14 < d

    1. Initial program 39.8%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac39.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-def39.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-def39.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-def55.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-rr55.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 d around -inf 43.0%

      \[\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. Step-by-step derivation
      1. mul-1-neg43.0%

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

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

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

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

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

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

    if -6.1999999999999998e143 < d < -1.95e81

    1. Initial program 22.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt22.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-frac22.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-def22.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-def22.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def46.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-rr46.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 c around inf 39.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*39.3%

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

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(a + \frac{b}{\frac{c}{d}}\right) \]
    8. Step-by-step derivation
      1. distribute-rgt-in73.5%

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

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

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

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

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

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

    if -9.0000000000000005e29 < d < 9.0000000000000004e-71

    1. Initial program 75.9%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt75.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-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 c around inf 49.2%

      \[\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*49.1%

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

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

    if 9.0000000000000004e-71 < d < 2.8000000000000002e-13

    1. Initial program 84.0%

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

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

    if 2.8000000000000002e-13 < d < 1.7e14

    1. Initial program 76.7%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt76.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-frac76.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-def76.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-def76.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-def87.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-rr87.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 c around inf 52.6%

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

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

      \[\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 76.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.2 \cdot 10^{+143}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -9 \cdot 10^{+29}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;d \leq 9 \cdot 10^{-71}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{-13}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+14}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\left(-b\right) - \frac{a}{\frac{d}{c}}\right)\\ \end{array} \]

Alternative 8: 71.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+144} \lor \neg \left(d \leq -1.55 \cdot 10^{+77}\right) \land \left(d \leq -1.16 \cdot 10^{+38} \lor \neg \left(d \leq 7.9 \cdot 10^{-35}\right) \land \left(d \leq 1.1 \cdot 10^{-13} \lor \neg \left(d \leq 3.4 \cdot 10^{+34}\right)\right)\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.09999999999999996e144 or -1.54999999999999999e77 < d < -1.15999999999999991e38 or 7.89999999999999983e-35 < d < 1.09999999999999998e-13 or 3.3999999999999999e34 < d

    1. Initial program 42.2%

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

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

    if -2.09999999999999996e144 < d < -1.54999999999999999e77 or -1.15999999999999991e38 < d < 7.89999999999999983e-35 or 1.09999999999999998e-13 < d < 3.3999999999999999e34

    1. Initial program 71.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt71.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-frac71.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-def71.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-def71.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-def83.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-rr83.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 46.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*46.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{+144} \lor \neg \left(d \leq -1.55 \cdot 10^{+77}\right) \land \left(d \leq -1.16 \cdot 10^{+38} \lor \neg \left(d \leq 7.9 \cdot 10^{-35}\right) \land \left(d \leq 1.1 \cdot 10^{-13} \lor \neg \left(d \leq 3.4 \cdot 10^{+34}\right)\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \]

Alternative 9: 71.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -4.8 \cdot 10^{+69}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -7.4 \cdot 10^{+38}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 2.4 \cdot 10^{-13} \lor \neg \left(d \leq 7.5 \cdot 10^{+34}\right):\\
\;\;\;\;\frac{b}{d}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.1999999999999998e143 or -4.8000000000000003e69 < d < -7.4000000000000002e38 or 1.60000000000000001e-34 < d < 2.3999999999999999e-13 or 7.49999999999999976e34 < d

    1. Initial program 42.2%

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

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

    if -5.1999999999999998e143 < d < -4.8000000000000003e69 or 2.3999999999999999e-13 < d < 7.49999999999999976e34

    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.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-def48.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-def48.1%

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

      \[\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*35.9%

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

      \[\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 67.9%

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

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

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

    if -7.4000000000000002e38 < d < 1.60000000000000001e-34

    1. Initial program 75.9%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt75.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-frac75.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-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-def87.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-rr87.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 48.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*48.0%

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

      \[\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 84.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+143}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{+69}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq -7.4 \cdot 10^{+38}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-34}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{-13} \lor \neg \left(d \leq 7.5 \cdot 10^{+34}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \]

Alternative 10: 71.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+143}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -2 \cdot 10^{+79}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -7.8 \cdot 10^{+38}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.62 \cdot 10^{-34}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-13} \lor \neg \left(d \leq 1.35 \cdot 10^{+35}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -5.2e+143)
   (/ b d)
   (if (<= d -2e+79)
     (+ (/ a c) (* (/ d c) (/ b c)))
     (if (<= d -7.8e+38)
       (/ b d)
       (if (<= d 1.62e-34)
         (* (/ 1.0 c) (+ a (/ b (/ c d))))
         (if (or (<= d 1.2e-13) (not (<= d 1.35e+35)))
           (/ b d)
           (* (/ 1.0 c) (+ a (* d (/ b c))))))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.2e+143) {
		tmp = b / d;
	} else if (d <= -2e+79) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -7.8e+38) {
		tmp = b / d;
	} else if (d <= 1.62e-34) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if ((d <= 1.2e-13) || !(d <= 1.35e+35)) {
		tmp = b / d;
	} else {
		tmp = (1.0 / c) * (a + (d * (b / 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 <= (-5.2d+143)) then
        tmp = b / d
    else if (d <= (-2d+79)) then
        tmp = (a / c) + ((d / c) * (b / c))
    else if (d <= (-7.8d+38)) then
        tmp = b / d
    else if (d <= 1.62d-34) then
        tmp = (1.0d0 / c) * (a + (b / (c / d)))
    else if ((d <= 1.2d-13) .or. (.not. (d <= 1.35d+35))) then
        tmp = b / d
    else
        tmp = (1.0d0 / c) * (a + (d * (b / c)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.2e+143) {
		tmp = b / d;
	} else if (d <= -2e+79) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -7.8e+38) {
		tmp = b / d;
	} else if (d <= 1.62e-34) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if ((d <= 1.2e-13) || !(d <= 1.35e+35)) {
		tmp = b / d;
	} else {
		tmp = (1.0 / c) * (a + (d * (b / c)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -5.2e+143:
		tmp = b / d
	elif d <= -2e+79:
		tmp = (a / c) + ((d / c) * (b / c))
	elif d <= -7.8e+38:
		tmp = b / d
	elif d <= 1.62e-34:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	elif (d <= 1.2e-13) or not (d <= 1.35e+35):
		tmp = b / d
	else:
		tmp = (1.0 / c) * (a + (d * (b / c)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -5.2e+143)
		tmp = Float64(b / d);
	elseif (d <= -2e+79)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -7.8e+38)
		tmp = Float64(b / d);
	elseif (d <= 1.62e-34)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif ((d <= 1.2e-13) || !(d <= 1.35e+35))
		tmp = Float64(b / d);
	else
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(d * Float64(b / c))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -5.2e+143)
		tmp = b / d;
	elseif (d <= -2e+79)
		tmp = (a / c) + ((d / c) * (b / c));
	elseif (d <= -7.8e+38)
		tmp = b / d;
	elseif (d <= 1.62e-34)
		tmp = (1.0 / c) * (a + (b / (c / d)));
	elseif ((d <= 1.2e-13) || ~((d <= 1.35e+35)))
		tmp = b / d;
	else
		tmp = (1.0 / c) * (a + (d * (b / c)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.2e+143], N[(b / d), $MachinePrecision], If[LessEqual[d, -2e+79], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -7.8e+38], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.62e-34], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[d, 1.2e-13], N[Not[LessEqual[d, 1.35e+35]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -7.8 \cdot 10^{+38}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 1.2 \cdot 10^{-13} \lor \neg \left(d \leq 1.35 \cdot 10^{+35}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -5.1999999999999998e143 or -1.99999999999999993e79 < d < -7.80000000000000047e38 or 1.62000000000000006e-34 < d < 1.1999999999999999e-13 or 1.35000000000000001e35 < d

    1. Initial program 42.2%

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

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

    if -5.1999999999999998e143 < d < -1.99999999999999993e79

    1. Initial program 22.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt22.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-frac22.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-def22.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-def22.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def46.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-rr46.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 c around inf 39.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*39.3%

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

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(a + \frac{b}{\frac{c}{d}}\right) \]
    8. Step-by-step derivation
      1. distribute-rgt-in73.5%

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

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

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

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

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

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

    if -7.80000000000000047e38 < d < 1.62000000000000006e-34

    1. Initial program 75.9%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt75.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-frac75.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-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-def87.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-rr87.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 48.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*48.0%

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

      \[\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 84.9%

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

    if 1.1999999999999999e-13 < d < 1.35000000000000001e35

    1. Initial program 70.2%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt70.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-frac69.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-def69.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-def69.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-def77.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-rr77.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 33.0%

      \[\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*33.0%

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

      \[\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 63.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+143}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -2 \cdot 10^{+79}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -7.8 \cdot 10^{+38}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.62 \cdot 10^{-34}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-13} \lor \neg \left(d \leq 1.35 \cdot 10^{+35}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \]

Alternative 11: 72.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+143}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{+42}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-72}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -5.8e+143)
   (/ b d)
   (if (<= d -1.9e+81)
     (+ (/ a c) (* (/ d c) (/ b c)))
     (if (<= d -1.8e+42)
       (/ b d)
       (if (<= d 1.5e-72)
         (* (/ 1.0 c) (+ a (/ b (/ c d))))
         (if (<= d 3.6e+78) (/ (* b d) (+ (* c c) (* d d))) (/ b d)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.8e+143) {
		tmp = b / d;
	} else if (d <= -1.9e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -1.8e+42) {
		tmp = b / d;
	} else if (d <= 1.5e-72) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 3.6e+78) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= (-5.8d+143)) then
        tmp = b / d
    else if (d <= (-1.9d+81)) then
        tmp = (a / c) + ((d / c) * (b / c))
    else if (d <= (-1.8d+42)) then
        tmp = b / d
    else if (d <= 1.5d-72) then
        tmp = (1.0d0 / c) * (a + (b / (c / d)))
    else if (d <= 3.6d+78) then
        tmp = (b * d) / ((c * c) + (d * d))
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.8e+143) {
		tmp = b / d;
	} else if (d <= -1.9e+81) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else if (d <= -1.8e+42) {
		tmp = b / d;
	} else if (d <= 1.5e-72) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 3.6e+78) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -5.8e+143:
		tmp = b / d
	elif d <= -1.9e+81:
		tmp = (a / c) + ((d / c) * (b / c))
	elif d <= -1.8e+42:
		tmp = b / d
	elif d <= 1.5e-72:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	elif d <= 3.6e+78:
		tmp = (b * d) / ((c * c) + (d * d))
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -5.8e+143)
		tmp = Float64(b / d);
	elseif (d <= -1.9e+81)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	elseif (d <= -1.8e+42)
		tmp = Float64(b / d);
	elseif (d <= 1.5e-72)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif (d <= 3.6e+78)
		tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -5.8e+143)
		tmp = b / d;
	elseif (d <= -1.9e+81)
		tmp = (a / c) + ((d / c) * (b / c));
	elseif (d <= -1.8e+42)
		tmp = b / d;
	elseif (d <= 1.5e-72)
		tmp = (1.0 / c) * (a + (b / (c / d)));
	elseif (d <= 3.6e+78)
		tmp = (b * d) / ((c * c) + (d * d));
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.8e+143], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.9e+81], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.8e+42], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.5e-72], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.6e+78], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -1.8 \cdot 10^{+42}:\\
\;\;\;\;\frac{b}{d}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -5.7999999999999996e143 or -1.9e81 < d < -1.8e42 or 3.6000000000000002e78 < d

    1. Initial program 35.2%

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

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

    if -5.7999999999999996e143 < d < -1.9e81

    1. Initial program 22.4%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt22.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-frac22.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-def22.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-def22.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def46.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-rr46.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 c around inf 39.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*39.3%

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

      \[\leadsto \color{blue}{\frac{1}{c}} \cdot \left(a + \frac{b}{\frac{c}{d}}\right) \]
    8. Step-by-step derivation
      1. distribute-rgt-in73.5%

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

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

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

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

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

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

    if -1.8e42 < d < 1.5e-72

    1. Initial program 76.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt76.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-frac76.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-def76.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-def76.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-def89.0%

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

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

      \[\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*48.7%

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

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

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

    if 1.5e-72 < d < 3.6000000000000002e78

    1. Initial program 77.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+143}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{+81}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{+42}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-72}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 12: 64.6% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{+35} \lor \neg \left(d \leq 1.05 \cdot 10^{-72}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.95e35 or 1.05e-72 < d

    1. Initial program 45.3%

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

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

    if -1.95e35 < d < 1.05e-72

    1. Initial program 76.1%

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

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

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

Alternative 13: 43.1% accurate, 5.0× speedup?

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

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

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

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

    \[\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 2023333 
(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))))