Complex division, real part

Percentage Accurate: 62.2% → 84.6%
Time: 8.9s
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: 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: 84.6% 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{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;t_0 \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{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\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 d) c) c))
     (if (<= t_0 INFINITY)
       (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
       (+ (/ a c) (* d (* (/ 1.0 c) (/ b c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (a / c) + (d * ((1.0 / c) * (b / c)));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (t_0 <= Inf)
		tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(a / c) + Float64(d * Float64(Float64(1.0 / c) * Float64(b / c))));
	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[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 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[(a / c), $MachinePrecision] + N[(d * N[(N[(1.0 / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t_0 \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{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\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 67.0%

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

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

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

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

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

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

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

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

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

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

    1. Initial program 78.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Step-by-step derivation
      1. associate-*l/94.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-identity94.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-rr94.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)}} \]

    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 c around inf 43.5%

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

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

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

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

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

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

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

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

    \[\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{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;\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{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \end{array} \]

Alternative 2: 80.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.65 \cdot 10^{+31}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{-121}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \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 -1.65e+31)
   (/ (- (/ (- a) (/ d c)) b) (hypot c d))
   (if (<= d 3e-121)
     (+ (/ a c) (/ (/ (* b d) c) c))
     (if (<= d 3.3e+28)
       (/ (fma a c (* b d)) (fma d d (* c c)))
       (/ (+ b (/ a (/ d c))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.65e+31) {
		tmp = ((-a / (d / c)) - b) / hypot(c, d);
	} else if (d <= 3e-121) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 3.3e+28) {
		tmp = fma(a, c, (b * d)) / fma(d, d, (c * c));
	} else {
		tmp = (b + (a / (d / c))) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.65e+31)
		tmp = Float64(Float64(Float64(Float64(-a) / Float64(d / c)) - b) / hypot(c, d));
	elseif (d <= 3e-121)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 3.3e+28)
		tmp = Float64(fma(a, c, Float64(b * d)) / fma(d, d, Float64(c * c)));
	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, -1.65e+31], N[(N[(N[((-a) / N[(d / c), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3e-121], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.3e+28], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $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 -1.65 \cdot 10^{+31}:\\
\;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\

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

\mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\

\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 < -1.64999999999999996e31

    1. Initial program 44.9%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      12. hypot-def56.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-rr56.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/56.7%

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

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

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

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

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

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

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

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

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

    if -1.64999999999999996e31 < d < 2.9999999999999999e-121

    1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

    if 2.9999999999999999e-121 < d < 3.3e28

    1. Initial program 84.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-def84.9%

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

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

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

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

    if 3.3e28 < d

    1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      12. hypot-def61.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-rr61.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/61.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.65 \cdot 10^{+31}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{-121}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 80.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.5 \cdot 10^{+29}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{-121}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.75 \cdot 10^{+28}:\\ \;\;\;\;\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} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -5.5e+29)
   (+ (/ b d) (* (/ c d) (/ a d)))
   (if (<= d 3.6e-121)
     (+ (/ a c) (/ (/ (* b d) c) c))
     (if (<= d 2.75e+28)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (/ (+ b (/ a (/ d c))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.5e+29) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (d <= 3.6e-121) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 2.75e+28) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a / (d / c))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.5e+29) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (d <= 3.6e-121) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 2.75e+28) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a / (d / c))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -5.5e+29:
		tmp = (b / d) + ((c / d) * (a / d))
	elif d <= 3.6e-121:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 2.75e+28:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = (b + (a / (d / c))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -5.5e+29)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	elseif (d <= 3.6e-121)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 2.75e+28)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	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)
	tmp = 0.0;
	if (d <= -5.5e+29)
		tmp = (b / d) + ((c / d) * (a / d));
	elseif (d <= 3.6e-121)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 2.75e+28)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = (b + (a / (d / c))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.5e+29], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.6e-121], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.75e+28], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $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 -5.5 \cdot 10^{+29}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\

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

\mathbf{elif}\;d \leq 2.75 \cdot 10^{+28}:\\
\;\;\;\;\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}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -5.5e29

    1. Initial program 44.9%

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

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

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

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

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

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

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

      \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
    7. Step-by-step derivation
      1. /-rgt-identity73.2%

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

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

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

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

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

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

    if -5.5e29 < d < 3.59999999999999984e-121

    1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

    if 3.59999999999999984e-121 < d < 2.7500000000000002e28

    1. Initial program 84.8%

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

    if 2.7500000000000002e28 < d

    1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      12. hypot-def61.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-rr61.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/61.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.5 \cdot 10^{+29}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{-121}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.75 \cdot 10^{+28}:\\ \;\;\;\;\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: 80.5% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;\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}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.99999999999999978e30

    1. Initial program 44.9%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      12. hypot-def56.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-rr56.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/56.7%

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

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

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

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

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

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

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

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

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

    if -2.99999999999999978e30 < d < 2.0999999999999999e-121

    1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

    if 2.0999999999999999e-121 < d < 3.3e28

    1. Initial program 84.8%

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

    if 3.3e28 < d

    1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      12. hypot-def61.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-rr61.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/61.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3 \cdot 10^{+30}:\\ \;\;\;\;\frac{\frac{-a}{\frac{d}{c}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-121}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 5: 80.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{if}\;d \leq -5.6 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.45 \cdot 10^{-121}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ b d) (* (/ c d) (/ a d)))))
   (if (<= d -5.6e+29)
     t_0
     (if (<= d 2.45e-121)
       (+ (/ a c) (/ (/ (* b d) c) c))
       (if (<= d 3.3e+28) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -5.6e+29) {
		tmp = t_0;
	} else if (d <= 2.45e-121) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 3.3e+28) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * 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 = (b / d) + ((c / d) * (a / d))
    if (d <= (-5.6d+29)) then
        tmp = t_0
    else if (d <= 2.45d-121) then
        tmp = (a / c) + (((b * d) / c) / c)
    else if (d <= 3.3d+28) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * 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 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -5.6e+29) {
		tmp = t_0;
	} else if (d <= 2.45e-121) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 3.3e+28) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / d) + ((c / d) * (a / d))
	tmp = 0
	if d <= -5.6e+29:
		tmp = t_0
	elif d <= 2.45e-121:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 3.3e+28:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)))
	tmp = 0.0
	if (d <= -5.6e+29)
		tmp = t_0;
	elseif (d <= 2.45e-121)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 3.3e+28)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b / d) + ((c / d) * (a / d));
	tmp = 0.0;
	if (d <= -5.6e+29)
		tmp = t_0;
	elseif (d <= 2.45e-121)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 3.3e+28)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.6e+29], t$95$0, If[LessEqual[d, 2.45e-121], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.3e+28], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.5999999999999999e29 or 3.3e28 < d

    1. Initial program 42.8%

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

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

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

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

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

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

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

      \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
    7. Step-by-step derivation
      1. /-rgt-identity72.4%

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

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

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

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

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

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

    if -5.5999999999999999e29 < d < 2.45e-121

    1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

    if 2.45e-121 < d < 3.3e28

    1. Initial program 84.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.6 \cdot 10^{+29}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.45 \cdot 10^{-121}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+28}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 6: 71.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.6 \cdot 10^{+111} \lor \neg \left(d \leq 9.5 \cdot 10^{-30}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.6000000000000002e111 or 9.49999999999999939e-30 < d

    1. Initial program 44.1%

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

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

    if -3.6000000000000002e111 < d < 9.49999999999999939e-30

    1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.4 \cdot 10^{+30} \lor \neg \left(d \leq 5.4 \cdot 10^{-32}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.40000000000000032e30 or 5.39999999999999962e-32 < d

    1. Initial program 46.4%

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

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

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

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

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

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

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

      \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
    7. Step-by-step derivation
      1. /-rgt-identity72.9%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{1}{\frac{d}{c}} \cdot \frac{a}{d}} \]
      5. clear-num77.8%

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

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

    if -7.40000000000000032e30 < d < 5.39999999999999962e-32

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

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

Alternative 8: 62.5% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.05 \cdot 10^{-85} \lor \neg \left(c \leq 3.5 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.04999999999999997e-85 or 3.5000000000000002e-25 < c

    1. Initial program 50.3%

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

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

    if -2.04999999999999997e-85 < c < 3.5000000000000002e-25

    1. Initial program 76.7%

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

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

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

Alternative 9: 41.9% 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 61.8%

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

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

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

Developer target: 99.2% 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 2023322 
(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))))