Complex division, real part

Percentage Accurate: 61.3% → 82.0%
Time: 7.8s
Alternatives: 9
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 9 alternatives:

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

Initial Program: 61.3% 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: 82.0% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{+59}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{-105}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{+27}:\\ \;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{{\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} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -7e+59)
   (+ (/ b d) (* c (/ (/ a d) d)))
   (if (<= d -1.15e-167)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 8.4e-105)
       (* (/ -1.0 c) (- (- a) (/ (* b d) c)))
       (if (<= d 4.2e+27)
         (* (fma a c (* b d)) (/ 1.0 (pow (hypot c d) 2.0)))
         (/ (+ b (/ a (/ d c))) (hypot c d)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -7e+59) {
		tmp = (b / d) + (c * ((a / d) / d));
	} else if (d <= -1.15e-167) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 8.4e-105) {
		tmp = (-1.0 / c) * (-a - ((b * d) / c));
	} else if (d <= 4.2e+27) {
		tmp = fma(a, c, (b * d)) * (1.0 / pow(hypot(c, d), 2.0));
	} else {
		tmp = (b + (a / (d / c))) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -7e+59)
		tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d)));
	elseif (d <= -1.15e-167)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 8.4e-105)
		tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(Float64(b * d) / c)));
	elseif (d <= 4.2e+27)
		tmp = Float64(fma(a, c, Float64(b * d)) * Float64(1.0 / (hypot(c, d) ^ 2.0)));
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -7e+59], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.15e-167], 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, 8.4e-105], N[(N[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+27], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{+59}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\

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

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

\mathbf{elif}\;d \leq 4.2 \cdot 10^{+27}:\\
\;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{{\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}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -7e59

    1. Initial program 51.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -7e59 < d < -1.1500000000000001e-167

    1. Initial program 84.3%

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

    if -1.1500000000000001e-167 < d < 8.3999999999999999e-105

    1. Initial program 66.6%

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

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

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

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

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

    if 8.3999999999999999e-105 < d < 4.19999999999999989e27

    1. Initial program 87.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. div-inv88.0%

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

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

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

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

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

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

    if 4.19999999999999989e27 < d

    1. Initial program 53.0%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac53.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-def53.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-def53.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-def73.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-rr73.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. Step-by-step derivation
      1. associate-*l/73.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-identity73.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-rr73.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 c around 0 90.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{+59}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{-105}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{+27}:\\ \;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{{\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.6% 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 \infty:\\ \;\;\;\;\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{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
   (* (/ c (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (c / hypot(c, d)) * (a / hypot(c, d));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], 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[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $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 \infty:\\
\;\;\;\;\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{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 77.7%

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

        \[\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.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-def77.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-def77.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-def96.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-rr96.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/96.4%

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

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

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

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

    1. Initial program 0.0%

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

      \[\leadsto \frac{\color{blue}{a \cdot c}}{c \cdot c + d \cdot d} \]
    3. Step-by-step derivation
      1. *-commutative2.0%

        \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    4. Simplified2.0%

      \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt2.0%

        \[\leadsto \frac{c \cdot a}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. hypot-udef2.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 82.2% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 5.7 \cdot 10^{+35}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 51.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.3499999999999999e60 < d < -1.1500000000000001e-167 or 1.59999999999999991e-105 < d < 5.69999999999999993e35

    1. Initial program 85.7%

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

    if -1.1500000000000001e-167 < d < 1.59999999999999991e-105

    1. Initial program 66.6%

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

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

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

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

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

    if 5.69999999999999993e35 < d

    1. Initial program 52.2%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.35 \cdot 10^{+60}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-105}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 5.7 \cdot 10^{+35}:\\ \;\;\;\;\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: 81.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{if}\;d \leq -1.65 \cdot 10^{+52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{-105}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+28}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (+ (/ b d) (* c (/ (/ a d) d)))))
   (if (<= d -1.65e+52)
     t_1
     (if (<= d -1.15e-167)
       t_0
       (if (<= d 1.18e-105)
         (* (/ -1.0 c) (- (- a) (/ (* b d) c)))
         (if (<= d 7.5e+28) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (b / d) + (c * ((a / d) / d));
	double tmp;
	if (d <= -1.65e+52) {
		tmp = t_1;
	} else if (d <= -1.15e-167) {
		tmp = t_0;
	} else if (d <= 1.18e-105) {
		tmp = (-1.0 / c) * (-a - ((b * d) / c));
	} else if (d <= 7.5e+28) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (b / d) + (c * ((a / d) / d))
    if (d <= (-1.65d+52)) then
        tmp = t_1
    else if (d <= (-1.15d-167)) then
        tmp = t_0
    else if (d <= 1.18d-105) then
        tmp = ((-1.0d0) / c) * (-a - ((b * d) / c))
    else if (d <= 7.5d+28) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (b / d) + (c * ((a / d) / d));
	double tmp;
	if (d <= -1.65e+52) {
		tmp = t_1;
	} else if (d <= -1.15e-167) {
		tmp = t_0;
	} else if (d <= 1.18e-105) {
		tmp = (-1.0 / c) * (-a - ((b * d) / c));
	} else if (d <= 7.5e+28) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (b / d) + (c * ((a / d) / d))
	tmp = 0
	if d <= -1.65e+52:
		tmp = t_1
	elif d <= -1.15e-167:
		tmp = t_0
	elif d <= 1.18e-105:
		tmp = (-1.0 / c) * (-a - ((b * d) / c))
	elif d <= 7.5e+28:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(b / d) + Float64(c * Float64(Float64(a / d) / d)))
	tmp = 0.0
	if (d <= -1.65e+52)
		tmp = t_1;
	elseif (d <= -1.15e-167)
		tmp = t_0;
	elseif (d <= 1.18e-105)
		tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(Float64(b * d) / c)));
	elseif (d <= 7.5e+28)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (b / d) + (c * ((a / d) / d));
	tmp = 0.0;
	if (d <= -1.65e+52)
		tmp = t_1;
	elseif (d <= -1.15e-167)
		tmp = t_0;
	elseif (d <= 1.18e-105)
		tmp = (-1.0 / c) * (-a - ((b * d) / c));
	elseif (d <= 7.5e+28)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.65e+52], t$95$1, If[LessEqual[d, -1.15e-167], t$95$0, If[LessEqual[d, 1.18e-105], N[(N[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.5e+28], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 7.5 \cdot 10^{+28}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.65e52 or 7.4999999999999998e28 < d

    1. Initial program 52.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.65e52 < d < -1.1500000000000001e-167 or 1.1799999999999999e-105 < d < 7.4999999999999998e28

    1. Initial program 85.5%

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

    if -1.1500000000000001e-167 < d < 1.1799999999999999e-105

    1. Initial program 66.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.65 \cdot 10^{+52}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-167}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{-105}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+28}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\ \end{array} \]

Alternative 5: 75.9% accurate, 0.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.80000000000000009e-69 or 3.2499999999999999e-68 < d

    1. Initial program 61.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.80000000000000009e-69 < d < 3.2499999999999999e-68

    1. Initial program 73.1%

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

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

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

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

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

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

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

Alternative 6: 69.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{-69} \lor \neg \left(d \leq 1.28 \cdot 10^{-70}\right):\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{\frac{a}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.70000000000000004e-69 or 1.28e-70 < d

    1. Initial program 61.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.70000000000000004e-69 < d < 1.28e-70

    1. Initial program 73.1%

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

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

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

Alternative 7: 63.9% accurate, 2.1× speedup?

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

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

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


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

    1. Initial program 58.8%

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

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

    if -0.00949999999999999976 < d < 1.35e-19

    1. Initial program 73.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -0.0095 \lor \neg \left(d \leq 1.35 \cdot 10^{-19}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 8: 43.3% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 70.7%

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

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

    if 4.39999999999999997e126 < d

    1. Initial program 41.7%

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

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

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

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

        \[\leadsto \color{blue}{\frac{b}{c} + \frac{a}{d}} \]
    7. Simplified3.8%

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

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

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

Alternative 9: 43.0% 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 66.1%

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

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

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