Complex division, real part

Percentage Accurate: 62.2% → 86.4%
Time: 9.2s
Alternatives: 10
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 10 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 86.4% accurate, 0.0× speedup?

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

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

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;\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(\frac{-a}{\frac{d}{c}} - b\right)\\


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

    1. Initial program 47.7%

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

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

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

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

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

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

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

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

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

    1. Initial program 84.6%

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

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

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

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

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

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

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

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

    1. Initial program 7.6%

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

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

        \[\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-frac7.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-def7.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-def7.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-def12.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-rr12.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 22.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. neg-mul-122.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq -\infty:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+302}:\\ \;\;\;\;\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(\frac{-a}{\frac{d}{c}} - b\right)\\ \end{array} \]

Alternative 2: 79.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5.2 \cdot 10^{-158}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.4 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{\frac{d}{c}}{a}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.56e+121)
   (/ (- (/ (- a) (/ d c)) b) (hypot c d))
   (if (<= d -5.2e-158)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 5.4e-15)
       (+ (/ a c) (/ b (* c (/ c d))))
       (/ (+ b (/ 1.0 (/ (/ d c) a))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.56e+121) {
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	} else if (d <= -5.2e-158) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 5.4e-15) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else {
		tmp = (b + (1.0 / ((d / c) / a))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.56e+121) {
		tmp = ((-a / (d / c)) - b) / Math.hypot(c, d);
	} else if (d <= -5.2e-158) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 5.4e-15) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else {
		tmp = (b + (1.0 / ((d / c) / a))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -1.56e+121:
		tmp = ((-a / (d / c)) - b) / math.hypot(c, d)
	elif d <= -5.2e-158:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif d <= 5.4e-15:
		tmp = (a / c) + (b / (c * (c / d)))
	else:
		tmp = (b + (1.0 / ((d / c) / a))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.56e+121)
		tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d));
	elseif (d <= -5.2e-158)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 5.4e-15)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	else
		tmp = Float64(Float64(b + Float64(1.0 / Float64(Float64(d / c) / a))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -1.56e+121)
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	elseif (d <= -5.2e-158)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (d <= 5.4e-15)
		tmp = (a / c) + (b / (c * (c / d)));
	else
		tmp = (b + (1.0 / ((d / c) / a))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.56e+121], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.2e-158], 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.4e-15], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 39.4%

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

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

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

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

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

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

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

      \[\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. neg-mul-183.6%

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

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

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

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

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

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

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

    if -1.5599999999999999e121 < d < -5.2000000000000001e-158

    1. Initial program 83.0%

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

    if -5.2000000000000001e-158 < d < 5.40000000000000018e-15

    1. Initial program 70.4%

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

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

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

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

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

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

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

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

    if 5.40000000000000018e-15 < d

    1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5.2 \cdot 10^{-158}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.4 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{\frac{d}{c}}{a}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 79.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\ \mathbf{elif}\;d \leq -2.4 \cdot 10^{-162}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{-14}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.56e+121)
   (* (/ -1.0 d) (- (/ (- a) (/ d c)) b))
   (if (<= d -2.4e-162)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 2.3e-14)
       (+ (/ a c) (/ b (* c (/ c d))))
       (/ (+ b (* a (/ c d))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.56e+121) {
		tmp = (-1.0 / d) * ((-a / (d / c)) - b);
	} else if (d <= -2.4e-162) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 2.3e-14) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else {
		tmp = (b + (a * (c / d))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.56e+121) {
		tmp = (-1.0 / d) * ((-a / (d / c)) - b);
	} else if (d <= -2.4e-162) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 2.3e-14) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else {
		tmp = (b + (a * (c / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -1.56e+121:
		tmp = (-1.0 / d) * ((-a / (d / c)) - b)
	elif d <= -2.4e-162:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif d <= 2.3e-14:
		tmp = (a / c) + (b / (c * (c / d)))
	else:
		tmp = (b + (a * (c / d))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.56e+121)
		tmp = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-a) / Float64(d / c)) - b));
	elseif (d <= -2.4e-162)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 2.3e-14)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -1.56e+121)
		tmp = (-1.0 / d) * ((-a / (d / c)) - b);
	elseif (d <= -2.4e-162)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (d <= 2.3e-14)
		tmp = (a / c) + (b / (c * (c / d)));
	else
		tmp = (b + (a * (c / d))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.56e+121], N[(N[(-1.0 / d), $MachinePrecision] * N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.4e-162], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.3e-14], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 39.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.5599999999999999e121 < d < -2.4000000000000002e-162

    1. Initial program 83.0%

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

    if -2.4000000000000002e-162 < d < 2.29999999999999998e-14

    1. Initial program 70.4%

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

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

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

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

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

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

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

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

    if 2.29999999999999998e-14 < d

    1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\ \mathbf{elif}\;d \leq -2.4 \cdot 10^{-162}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{-14}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 4: 79.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{-161}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.56e+121)
   (/ (- (/ (- a) (/ d c)) b) (hypot c d))
   (if (<= d -7.5e-161)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 1.6e-15)
       (+ (/ a c) (/ b (* c (/ c d))))
       (/ (+ b (* a (/ c d))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.56e+121) {
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	} else if (d <= -7.5e-161) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 1.6e-15) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else {
		tmp = (b + (a * (c / d))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.56e+121) {
		tmp = ((-a / (d / c)) - b) / Math.hypot(c, d);
	} else if (d <= -7.5e-161) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 1.6e-15) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else {
		tmp = (b + (a * (c / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -1.56e+121:
		tmp = ((-a / (d / c)) - b) / math.hypot(c, d)
	elif d <= -7.5e-161:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif d <= 1.6e-15:
		tmp = (a / c) + (b / (c * (c / d)))
	else:
		tmp = (b + (a * (c / d))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.56e+121)
		tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d));
	elseif (d <= -7.5e-161)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1.6e-15)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -1.56e+121)
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	elseif (d <= -7.5e-161)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (d <= 1.6e-15)
		tmp = (a / c) + (b / (c * (c / d)));
	else
		tmp = (b + (a * (c / d))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.56e+121], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -7.5e-161], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.6e-15], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 39.4%

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

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

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

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

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

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

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

      \[\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. neg-mul-183.6%

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

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

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

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

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

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

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

    if -1.5599999999999999e121 < d < -7.49999999999999991e-161

    1. Initial program 83.0%

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

    if -7.49999999999999991e-161 < d < 1.6e-15

    1. Initial program 70.4%

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

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

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

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

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

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

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

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

    if 1.6e-15 < d

    1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{-161}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 5: 79.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\ \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -2.55 \cdot 10^{-159}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ -1.0 d) (- (/ (- a) (/ d c)) b))))
   (if (<= d -1.56e+121)
     t_0
     (if (<= d -2.55e-159)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (if (<= d 7.2e-15) (+ (/ a c) (/ b (* c (/ c d)))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (-1.0 / d) * ((-a / (d / c)) - b);
	double tmp;
	if (d <= -1.56e+121) {
		tmp = t_0;
	} else if (d <= -2.55e-159) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 7.2e-15) {
		tmp = (a / c) + (b / (c * (c / 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) / d) * ((-a / (d / c)) - b)
    if (d <= (-1.56d+121)) then
        tmp = t_0
    else if (d <= (-2.55d-159)) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
    else if (d <= 7.2d-15) then
        tmp = (a / c) + (b / (c * (c / 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 / d) * ((-a / (d / c)) - b);
	double tmp;
	if (d <= -1.56e+121) {
		tmp = t_0;
	} else if (d <= -2.55e-159) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 7.2e-15) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (-1.0 / d) * ((-a / (d / c)) - b)
	tmp = 0
	if d <= -1.56e+121:
		tmp = t_0
	elif d <= -2.55e-159:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif d <= 7.2e-15:
		tmp = (a / c) + (b / (c * (c / d)))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-a) / Float64(d / c)) - b))
	tmp = 0.0
	if (d <= -1.56e+121)
		tmp = t_0;
	elseif (d <= -2.55e-159)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 7.2e-15)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (-1.0 / d) * ((-a / (d / c)) - b);
	tmp = 0.0;
	if (d <= -1.56e+121)
		tmp = t_0;
	elseif (d <= -2.55e-159)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (d <= 7.2e-15)
		tmp = (a / c) + (b / (c * (c / d)));
	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[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.56e+121], t$95$0, If[LessEqual[d, -2.55e-159], 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, 7.2e-15], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.5599999999999999e121 or 7.2000000000000002e-15 < d

    1. Initial program 48.7%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Taylor expanded in d around -inf 50.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. neg-mul-150.1%

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

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

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

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

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

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

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

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

    if -1.5599999999999999e121 < d < -2.5499999999999997e-159

    1. Initial program 83.0%

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

    if -2.5499999999999997e-159 < d < 7.2000000000000002e-15

    1. Initial program 70.4%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.56 \cdot 10^{+121}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\ \mathbf{elif}\;d \leq -2.55 \cdot 10^{-159}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{-15}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\ \end{array} \]

Alternative 6: 73.3% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.4 \cdot 10^{+23} \lor \neg \left(c \leq 8.8 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.4e23 or 8.80000000000000007e24 < c

    1. Initial program 45.4%

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

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

    if -1.4e23 < c < 8.80000000000000007e24

    1. Initial program 77.2%

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

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

      \[\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. neg-mul-156.8%

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

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

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

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

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

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

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

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

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

Alternative 7: 75.5% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{-61} \lor \neg \left(d \leq 1.95 \cdot 10^{-13}\right):\\
\;\;\;\;\frac{-1}{d} \cdot \left(\frac{-a}{\frac{d}{c}} - b\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.95000000000000016e-61 or 1.95000000000000002e-13 < d

    1. Initial program 57.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.95000000000000016e-61 < d < 1.95000000000000002e-13

    1. Initial program 72.9%

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

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

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

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

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

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

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

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

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

Alternative 8: 63.9% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.8 \cdot 10^{+22} \lor \neg \left(c \leq 2.05 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -9.79999999999999958e22 or 2.05e24 < c

    1. Initial program 45.4%

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

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

    if -9.79999999999999958e22 < c < 2.05e24

    1. Initial program 77.2%

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

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

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

Alternative 9: 43.5% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 66.6%

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

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

    if 5.00000000000000034e173 < d

    1. Initial program 48.6%

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

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

        \[\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.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-def48.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-def48.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-def62.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-rr62.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 49.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. neg-mul-149.2%

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

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

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

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

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

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

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

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

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

Alternative 10: 42.8% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification37.5%

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

Developer target: 99.4% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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