Complex division, real part

Percentage Accurate: 61.4% → 85.1%
Time: 11.4s
Alternatives: 12
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 61.4% 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: 85.1% 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{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{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)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b 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 = (1.0 / hypot(c, d)) * (fma(a, c, (b * 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(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * 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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(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{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{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 73.6%

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

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

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

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

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

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

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

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

        \[\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(c, c, d \cdot d\right)}} \]
      9. fma-define73.6%

        \[\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}}} \]
      10. hypot-define88.9%

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

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

    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. Add Preprocessing
    3. Taylor expanded in a around inf 1.5%

      \[\leadsto \frac{\color{blue}{a \cdot c}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. *-commutative1.5%

        \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    5. Simplified1.5%

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

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

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

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

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

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

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

Alternative 2: 78.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot c + b \cdot d\\ \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{c \cdot \frac{a}{-d} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-171}:\\ \;\;\;\;\frac{t\_0}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{+64}:\\ \;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))))
   (if (<= d -2.7e+36)
     (/ (- (* c (/ a (- d))) b) (hypot c d))
     (if (<= d -1e-171)
       (/ t_0 (pow (hypot d c) 2.0))
       (if (<= d 8e-294)
         (+ (/ a c) (* b (/ d (pow c 2.0))))
         (if (<= d 2.15e+64)
           (/ t_0 (+ (* c c) (* d d)))
           (/ (+ b (* c (/ a d))) (hypot c d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if (d <= -2.7e+36) {
		tmp = ((c * (a / -d)) - b) / hypot(c, d);
	} else if (d <= -1e-171) {
		tmp = t_0 / pow(hypot(d, c), 2.0);
	} else if (d <= 8e-294) {
		tmp = (a / c) + (b * (d / pow(c, 2.0)));
	} else if (d <= 2.15e+64) {
		tmp = t_0 / ((c * c) + (d * d));
	} else {
		tmp = (b + (c * (a / d))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if (d <= -2.7e+36) {
		tmp = ((c * (a / -d)) - b) / Math.hypot(c, d);
	} else if (d <= -1e-171) {
		tmp = t_0 / Math.pow(Math.hypot(d, c), 2.0);
	} else if (d <= 8e-294) {
		tmp = (a / c) + (b * (d / Math.pow(c, 2.0)));
	} else if (d <= 2.15e+64) {
		tmp = t_0 / ((c * c) + (d * d));
	} else {
		tmp = (b + (c * (a / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a * c) + (b * d)
	tmp = 0
	if d <= -2.7e+36:
		tmp = ((c * (a / -d)) - b) / math.hypot(c, d)
	elif d <= -1e-171:
		tmp = t_0 / math.pow(math.hypot(d, c), 2.0)
	elif d <= 8e-294:
		tmp = (a / c) + (b * (d / math.pow(c, 2.0)))
	elif d <= 2.15e+64:
		tmp = t_0 / ((c * c) + (d * d))
	else:
		tmp = (b + (c * (a / d))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) + Float64(b * d))
	tmp = 0.0
	if (d <= -2.7e+36)
		tmp = Float64(Float64(Float64(c * Float64(a / Float64(-d))) - b) / hypot(c, d));
	elseif (d <= -1e-171)
		tmp = Float64(t_0 / (hypot(d, c) ^ 2.0));
	elseif (d <= 8e-294)
		tmp = Float64(Float64(a / c) + Float64(b * Float64(d / (c ^ 2.0))));
	elseif (d <= 2.15e+64)
		tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a * c) + (b * d);
	tmp = 0.0;
	if (d <= -2.7e+36)
		tmp = ((c * (a / -d)) - b) / hypot(c, d);
	elseif (d <= -1e-171)
		tmp = t_0 / (hypot(d, c) ^ 2.0);
	elseif (d <= 8e-294)
		tmp = (a / c) + (b * (d / (c ^ 2.0)));
	elseif (d <= 2.15e+64)
		tmp = t_0 / ((c * c) + (d * d));
	else
		tmp = (b + (c * (a / d))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.7e+36], N[(N[(N[(c * N[(a / (-d)), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e-171], N[(t$95$0 / N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8e-294], N[(N[(a / c), $MachinePrecision] + N[(b * N[(d / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.15e+64], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1 \cdot 10^{-171}:\\
\;\;\;\;\frac{t\_0}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}\\

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

\mathbf{elif}\;d \leq 2.15 \cdot 10^{+64}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -2.7000000000000001e36

    1. Initial program 48.1%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define48.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(c, c, d \cdot d\right)}} \]
      9. fma-define48.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}}} \]
      10. hypot-define69.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)}} \]
    4. Applied egg-rr69.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)}} \]
    5. Taylor expanded in d around -inf 81.6%

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

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

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

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

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

    if -2.7000000000000001e36 < d < -9.9999999999999998e-172

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{{\color{blue}{\left(\sqrt{c \cdot c + d \cdot d}\right)}}^{2}} \]
      10. unpow281.4%

        \[\leadsto \frac{a \cdot c + b \cdot d}{{\left(\sqrt{\color{blue}{{c}^{2}} + d \cdot d}\right)}^{2}} \]
      11. unpow281.4%

        \[\leadsto \frac{a \cdot c + b \cdot d}{{\left(\sqrt{{c}^{2} + \color{blue}{{d}^{2}}}\right)}^{2}} \]
      12. +-commutative81.4%

        \[\leadsto \frac{a \cdot c + b \cdot d}{{\left(\sqrt{\color{blue}{{d}^{2} + {c}^{2}}}\right)}^{2}} \]
      13. unpow281.4%

        \[\leadsto \frac{a \cdot c + b \cdot d}{{\left(\sqrt{\color{blue}{d \cdot d} + {c}^{2}}\right)}^{2}} \]
      14. unpow281.4%

        \[\leadsto \frac{a \cdot c + b \cdot d}{{\left(\sqrt{d \cdot d + \color{blue}{c \cdot c}}\right)}^{2}} \]
      15. hypot-define81.5%

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

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

    if -9.9999999999999998e-172 < d < 8.00000000000000013e-294

    1. Initial program 67.3%

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

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

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

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

    if 8.00000000000000013e-294 < d < 2.1499999999999999e64

    1. Initial program 80.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if 2.1499999999999999e64 < d

    1. Initial program 35.1%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define35.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(c, c, d \cdot d\right)}} \]
      9. fma-define35.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}}} \]
      10. hypot-define63.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)}} \]
    4. Applied egg-rr63.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)}} \]
    5. Taylor expanded in d around -inf 15.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{c \cdot \frac{a}{-d} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-171}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{+64}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.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}\\ t_1 := \frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{+66}:\\ \;\;\;\;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) (* a (/ c (pow d 2.0))))))
   (if (<= d -3.6e+46)
     t_1
     (if (<= d -3.6e-170)
       t_0
       (if (<= d 1e-293)
         (+ (/ a c) (* b (/ d (pow c 2.0))))
         (if (<= d 6e+66) 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) + (a * (c / pow(d, 2.0)));
	double tmp;
	if (d <= -3.6e+46) {
		tmp = t_1;
	} else if (d <= -3.6e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b * (d / pow(c, 2.0)));
	} else if (d <= 6e+66) {
		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) + (a * (c / (d ** 2.0d0)))
    if (d <= (-3.6d+46)) then
        tmp = t_1
    else if (d <= (-3.6d-170)) then
        tmp = t_0
    else if (d <= 1d-293) then
        tmp = (a / c) + (b * (d / (c ** 2.0d0)))
    else if (d <= 6d+66) 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) + (a * (c / Math.pow(d, 2.0)));
	double tmp;
	if (d <= -3.6e+46) {
		tmp = t_1;
	} else if (d <= -3.6e-170) {
		tmp = t_0;
	} else if (d <= 1e-293) {
		tmp = (a / c) + (b * (d / Math.pow(c, 2.0)));
	} else if (d <= 6e+66) {
		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) + (a * (c / math.pow(d, 2.0)))
	tmp = 0
	if d <= -3.6e+46:
		tmp = t_1
	elif d <= -3.6e-170:
		tmp = t_0
	elif d <= 1e-293:
		tmp = (a / c) + (b * (d / math.pow(c, 2.0)))
	elif d <= 6e+66:
		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(a * Float64(c / (d ^ 2.0))))
	tmp = 0.0
	if (d <= -3.6e+46)
		tmp = t_1;
	elseif (d <= -3.6e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = Float64(Float64(a / c) + Float64(b * Float64(d / (c ^ 2.0))));
	elseif (d <= 6e+66)
		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) + (a * (c / (d ^ 2.0)));
	tmp = 0.0;
	if (d <= -3.6e+46)
		tmp = t_1;
	elseif (d <= -3.6e-170)
		tmp = t_0;
	elseif (d <= 1e-293)
		tmp = (a / c) + (b * (d / (c ^ 2.0)));
	elseif (d <= 6e+66)
		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[(a * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.6e+46], t$95$1, If[LessEqual[d, -3.6e-170], t$95$0, If[LessEqual[d, 1e-293], N[(N[(a / c), $MachinePrecision] + N[(b * N[(d / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6e+66], 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} + a \cdot \frac{c}{{d}^{2}}\\
\mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -3.6 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 6 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.5999999999999999e46 or 6.00000000000000005e66 < d

    1. Initial program 41.9%

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

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

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

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

    if -3.5999999999999999e46 < d < -3.6000000000000003e-170 or 1.0000000000000001e-293 < d < 6.00000000000000005e66

    1. Initial program 81.1%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -3.6000000000000003e-170 < d < 1.0000000000000001e-293

    1. Initial program 67.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 10^{-293}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{+66}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.9% 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 -4.3 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{elif}\;d \leq -5.4 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 9 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{+66}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\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 -4.3e+46)
     (+ (/ b d) (* a (/ c (pow d 2.0))))
     (if (<= d -5.4e-170)
       t_0
       (if (<= d 9e-294)
         (+ (/ a c) (* b (/ d (pow c 2.0))))
         (if (<= d 1.25e+66) t_0 (/ (+ b (* c (/ a d))) (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 <= -4.3e+46) {
		tmp = (b / d) + (a * (c / pow(d, 2.0)));
	} else if (d <= -5.4e-170) {
		tmp = t_0;
	} else if (d <= 9e-294) {
		tmp = (a / c) + (b * (d / pow(c, 2.0)));
	} else if (d <= 1.25e+66) {
		tmp = t_0;
	} else {
		tmp = (b + (c * (a / d))) / 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 <= -4.3e+46) {
		tmp = (b / d) + (a * (c / Math.pow(d, 2.0)));
	} else if (d <= -5.4e-170) {
		tmp = t_0;
	} else if (d <= 9e-294) {
		tmp = (a / c) + (b * (d / Math.pow(c, 2.0)));
	} else if (d <= 1.25e+66) {
		tmp = t_0;
	} else {
		tmp = (b + (c * (a / d))) / 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 <= -4.3e+46:
		tmp = (b / d) + (a * (c / math.pow(d, 2.0)))
	elif d <= -5.4e-170:
		tmp = t_0
	elif d <= 9e-294:
		tmp = (a / c) + (b * (d / math.pow(c, 2.0)))
	elif d <= 1.25e+66:
		tmp = t_0
	else:
		tmp = (b + (c * (a / d))) / 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 <= -4.3e+46)
		tmp = Float64(Float64(b / d) + Float64(a * Float64(c / (d ^ 2.0))));
	elseif (d <= -5.4e-170)
		tmp = t_0;
	elseif (d <= 9e-294)
		tmp = Float64(Float64(a / c) + Float64(b * Float64(d / (c ^ 2.0))));
	elseif (d <= 1.25e+66)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / 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 <= -4.3e+46)
		tmp = (b / d) + (a * (c / (d ^ 2.0)));
	elseif (d <= -5.4e-170)
		tmp = t_0;
	elseif (d <= 9e-294)
		tmp = (a / c) + (b * (d / (c ^ 2.0)));
	elseif (d <= 1.25e+66)
		tmp = t_0;
	else
		tmp = (b + (c * (a / d))) / 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, -4.3e+46], N[(N[(b / d), $MachinePrecision] + N[(a * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.4e-170], t$95$0, If[LessEqual[d, 9e-294], N[(N[(a / c), $MachinePrecision] + N[(b * N[(d / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.25e+66], t$95$0, N[(N[(b + N[(c * N[(a / d), $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 -4.3 \cdot 10^{+46}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\

\mathbf{elif}\;d \leq -5.4 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.25 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 46.4%

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

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

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

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

    if -4.30000000000000005e46 < d < -5.3999999999999997e-170 or 8.99999999999999963e-294 < d < 1.24999999999999998e66

    1. Initial program 81.1%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -5.3999999999999997e-170 < d < 8.99999999999999963e-294

    1. Initial program 67.3%

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

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

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

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

    if 1.24999999999999998e66 < d

    1. Initial program 35.1%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define35.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(c, c, d \cdot d\right)}} \]
      9. fma-define35.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}}} \]
      10. hypot-define63.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)}} \]
    4. Applied egg-rr63.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)}} \]
    5. Taylor expanded in d around -inf 15.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.3 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{elif}\;d \leq -5.4 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{+66}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{c \cdot \frac{a}{-d} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 8.2 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{+60}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\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.7e+36)
     (/ (- (* c (/ a (- d))) b) (hypot c d))
     (if (<= d -1.3e-170)
       t_0
       (if (<= d 8.2e-294)
         (+ (/ a c) (* b (/ d (pow c 2.0))))
         (if (<= d 2.4e+60) t_0 (/ (+ b (* c (/ a d))) (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.7e+36) {
		tmp = ((c * (a / -d)) - b) / hypot(c, d);
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 8.2e-294) {
		tmp = (a / c) + (b * (d / pow(c, 2.0)));
	} else if (d <= 2.4e+60) {
		tmp = t_0;
	} else {
		tmp = (b + (c * (a / d))) / 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.7e+36) {
		tmp = ((c * (a / -d)) - b) / Math.hypot(c, d);
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 8.2e-294) {
		tmp = (a / c) + (b * (d / Math.pow(c, 2.0)));
	} else if (d <= 2.4e+60) {
		tmp = t_0;
	} else {
		tmp = (b + (c * (a / d))) / 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.7e+36:
		tmp = ((c * (a / -d)) - b) / math.hypot(c, d)
	elif d <= -1.3e-170:
		tmp = t_0
	elif d <= 8.2e-294:
		tmp = (a / c) + (b * (d / math.pow(c, 2.0)))
	elif d <= 2.4e+60:
		tmp = t_0
	else:
		tmp = (b + (c * (a / d))) / 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.7e+36)
		tmp = Float64(Float64(Float64(c * Float64(a / Float64(-d))) - b) / hypot(c, d));
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 8.2e-294)
		tmp = Float64(Float64(a / c) + Float64(b * Float64(d / (c ^ 2.0))));
	elseif (d <= 2.4e+60)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / 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.7e+36)
		tmp = ((c * (a / -d)) - b) / hypot(c, d);
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 8.2e-294)
		tmp = (a / c) + (b * (d / (c ^ 2.0)));
	elseif (d <= 2.4e+60)
		tmp = t_0;
	else
		tmp = (b + (c * (a / d))) / 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.7e+36], N[(N[(N[(c * N[(a / (-d)), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.3e-170], t$95$0, If[LessEqual[d, 8.2e-294], N[(N[(a / c), $MachinePrecision] + N[(b * N[(d / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.4e+60], t$95$0, N[(N[(b + N[(c * N[(a / d), $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.7 \cdot 10^{+36}:\\
\;\;\;\;\frac{c \cdot \frac{a}{-d} - b}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.4 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 48.1%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define48.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(c, c, d \cdot d\right)}} \]
      9. fma-define48.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}}} \]
      10. hypot-define69.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)}} \]
    4. Applied egg-rr69.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)}} \]
    5. Taylor expanded in d around -inf 81.6%

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

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

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

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

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

    if -2.7000000000000001e36 < d < -1.3000000000000001e-170 or 8.1999999999999998e-294 < d < 2.4e60

    1. Initial program 80.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -1.3000000000000001e-170 < d < 8.1999999999999998e-294

    1. Initial program 67.3%

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

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

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

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

    if 2.4e60 < d

    1. Initial program 35.1%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define35.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(c, c, d \cdot d\right)}} \]
      9. fma-define35.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}}} \]
      10. hypot-define63.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)}} \]
    4. Applied egg-rr63.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)}} \]
    5. Taylor expanded in d around -inf 15.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{+36}:\\ \;\;\;\;\frac{c \cdot \frac{a}{-d} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 8.2 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{+60}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 75.5% 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 -1 \cdot 10^{+129}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{+81}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -1e+129)
     (* b (/ -1.0 (hypot c d)))
     (if (<= d -1.3e-170)
       t_0
       (if (<= d 9.5e-294)
         (+ (/ a c) (* b (/ d (pow c 2.0))))
         (if (<= d 2.2e+81) t_0 (* b (/ 1.0 (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 <= -1e+129) {
		tmp = b * (-1.0 / hypot(c, d));
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 9.5e-294) {
		tmp = (a / c) + (b * (d / pow(c, 2.0)));
	} else if (d <= 2.2e+81) {
		tmp = t_0;
	} else {
		tmp = b * (1.0 / 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 <= -1e+129) {
		tmp = b * (-1.0 / Math.hypot(c, d));
	} else if (d <= -1.3e-170) {
		tmp = t_0;
	} else if (d <= 9.5e-294) {
		tmp = (a / c) + (b * (d / Math.pow(c, 2.0)));
	} else if (d <= 2.2e+81) {
		tmp = t_0;
	} else {
		tmp = b * (1.0 / 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 <= -1e+129:
		tmp = b * (-1.0 / math.hypot(c, d))
	elif d <= -1.3e-170:
		tmp = t_0
	elif d <= 9.5e-294:
		tmp = (a / c) + (b * (d / math.pow(c, 2.0)))
	elif d <= 2.2e+81:
		tmp = t_0
	else:
		tmp = b * (1.0 / 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 <= -1e+129)
		tmp = Float64(b * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 9.5e-294)
		tmp = Float64(Float64(a / c) + Float64(b * Float64(d / (c ^ 2.0))));
	elseif (d <= 2.2e+81)
		tmp = t_0;
	else
		tmp = Float64(b * Float64(1.0 / 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 <= -1e+129)
		tmp = b * (-1.0 / hypot(c, d));
	elseif (d <= -1.3e-170)
		tmp = t_0;
	elseif (d <= 9.5e-294)
		tmp = (a / c) + (b * (d / (c ^ 2.0)));
	elseif (d <= 2.2e+81)
		tmp = t_0;
	else
		tmp = b * (1.0 / 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, -1e+129], N[(b * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.3e-170], t$95$0, If[LessEqual[d, 9.5e-294], N[(N[(a / c), $MachinePrecision] + N[(b * N[(d / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.2e+81], t$95$0, N[(b * N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $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}\;d \leq -1 \cdot 10^{+129}:\\
\;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.2 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 31.0%

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

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

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

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

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

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

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

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

        \[\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(c, c, d \cdot d\right)}} \]
      9. fma-define31.0%

        \[\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}}} \]
      10. hypot-define62.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)}} \]
    4. Applied egg-rr62.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)}} \]
    5. Taylor expanded in d around -inf 75.7%

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

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

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

    if -1e129 < d < -1.3000000000000001e-170 or 9.499999999999999e-294 < d < 2.19999999999999987e81

    1. Initial program 79.6%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -1.3000000000000001e-170 < d < 9.499999999999999e-294

    1. Initial program 67.3%

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

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

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

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

    if 2.19999999999999987e81 < d

    1. Initial program 34.2%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define34.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(c, c, d \cdot d\right)}} \]
      9. fma-define34.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}}} \]
      10. hypot-define64.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)}} \]
    4. Applied egg-rr64.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)}} \]
    5. Taylor expanded in c around 0 72.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{+129}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-170}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-294}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{+81}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 73.5% accurate, 0.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.5999999999999999e113

    1. Initial program 37.4%

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

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

    if -2.5999999999999999e113 < d < 2.6999999999999999e81

    1. Initial program 76.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if 2.6999999999999999e81 < d

    1. Initial program 34.2%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define34.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(c, c, d \cdot d\right)}} \]
      9. fma-define34.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}}} \]
      10. hypot-define64.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)}} \]
    4. Applied egg-rr64.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)}} \]
    5. Taylor expanded in c around 0 72.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.6 \cdot 10^{+113}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{+81}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 73.6% accurate, 0.1× speedup?

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

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

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

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


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

    1. Initial program 31.0%

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

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

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

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

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

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

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

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

        \[\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(c, c, d \cdot d\right)}} \]
      9. fma-define31.0%

        \[\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}}} \]
      10. hypot-define62.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)}} \]
    4. Applied egg-rr62.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)}} \]
    5. Taylor expanded in d around -inf 75.7%

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

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

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

    if -4.0000000000000003e128 < d < 2.6999999999999999e81

    1. Initial program 77.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if 2.6999999999999999e81 < d

    1. Initial program 34.2%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      8. fma-define34.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(c, c, d \cdot d\right)}} \]
      9. fma-define34.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}}} \]
      10. hypot-define64.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)}} \]
    4. Applied egg-rr64.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)}} \]
    5. Taylor expanded in c around 0 72.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4 \cdot 10^{+128}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{+81}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 64.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -1.6 \cdot 10^{+49}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -4.6 \cdot 10^{-30}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq -2.9 \cdot 10^{-93}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-70}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 1.55 \cdot 10^{+39}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (* a c) (+ (* c c) (* d d)))))
   (if (<= c -1.6e+49)
     (/ a c)
     (if (<= c -4.6e-30)
       (/ b d)
       (if (<= c -2.9e-93)
         t_0
         (if (<= c 1.25e-70) (/ b d) (if (<= c 1.55e+39) t_0 (/ a c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.6e+49) {
		tmp = a / c;
	} else if (c <= -4.6e-30) {
		tmp = b / d;
	} else if (c <= -2.9e-93) {
		tmp = t_0;
	} else if (c <= 1.25e-70) {
		tmp = b / d;
	} else if (c <= 1.55e+39) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = (a * c) / ((c * c) + (d * d))
    if (c <= (-1.6d+49)) then
        tmp = a / c
    else if (c <= (-4.6d-30)) then
        tmp = b / d
    else if (c <= (-2.9d-93)) then
        tmp = t_0
    else if (c <= 1.25d-70) then
        tmp = b / d
    else if (c <= 1.55d+39) then
        tmp = t_0
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (a * c) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.6e+49) {
		tmp = a / c;
	} else if (c <= -4.6e-30) {
		tmp = b / d;
	} else if (c <= -2.9e-93) {
		tmp = t_0;
	} else if (c <= 1.25e-70) {
		tmp = b / d;
	} else if (c <= 1.55e+39) {
		tmp = t_0;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a * c) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.6e+49:
		tmp = a / c
	elif c <= -4.6e-30:
		tmp = b / d
	elif c <= -2.9e-93:
		tmp = t_0
	elif c <= 1.25e-70:
		tmp = b / d
	elif c <= 1.55e+39:
		tmp = t_0
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -1.6e+49)
		tmp = Float64(a / c);
	elseif (c <= -4.6e-30)
		tmp = Float64(b / d);
	elseif (c <= -2.9e-93)
		tmp = t_0;
	elseif (c <= 1.25e-70)
		tmp = Float64(b / d);
	elseif (c <= 1.55e+39)
		tmp = t_0;
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a * c) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -1.6e+49)
		tmp = a / c;
	elseif (c <= -4.6e-30)
		tmp = b / d;
	elseif (c <= -2.9e-93)
		tmp = t_0;
	elseif (c <= 1.25e-70)
		tmp = b / d;
	elseif (c <= 1.55e+39)
		tmp = t_0;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.6e+49], N[(a / c), $MachinePrecision], If[LessEqual[c, -4.6e-30], N[(b / d), $MachinePrecision], If[LessEqual[c, -2.9e-93], t$95$0, If[LessEqual[c, 1.25e-70], N[(b / d), $MachinePrecision], If[LessEqual[c, 1.55e+39], t$95$0, N[(a / c), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.6 \cdot 10^{-30}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq -2.9 \cdot 10^{-93}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.25 \cdot 10^{-70}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq 1.55 \cdot 10^{+39}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.60000000000000007e49 or 1.5500000000000001e39 < c

    1. Initial program 52.6%

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

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

    if -1.60000000000000007e49 < c < -4.59999999999999968e-30 or -2.8999999999999998e-93 < c < 1.25e-70

    1. Initial program 66.4%

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

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

    if -4.59999999999999968e-30 < c < -2.8999999999999998e-93 or 1.25e-70 < c < 1.5500000000000001e39

    1. Initial program 84.6%

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

      \[\leadsto \frac{\color{blue}{a \cdot c}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. *-commutative65.9%

        \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    5. Simplified65.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.6 \cdot 10^{+49}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -4.6 \cdot 10^{-30}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq -2.9 \cdot 10^{-93}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-70}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 1.55 \cdot 10^{+39}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 73.7% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.2 \cdot 10^{+115} \lor \neg \left(d \leq 3.1 \cdot 10^{+112}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.19999999999999925e115 or 3.09999999999999983e112 < d

    1. Initial program 34.0%

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

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

    if -8.19999999999999925e115 < d < 3.09999999999999983e112

    1. Initial program 75.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification76.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.2 \cdot 10^{+115} \lor \neg \left(d \leq 3.1 \cdot 10^{+112}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 63.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.02 \cdot 10^{+49} \lor \neg \left(c \leq 9 \cdot 10^{-67}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.02e49 or 9.00000000000000031e-67 < c

    1. Initial program 58.1%

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

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

    if -1.02e49 < c < 9.00000000000000031e-67

    1. Initial program 68.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.02 \cdot 10^{+49} \lor \neg \left(c \leq 9 \cdot 10^{-67}\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 42.3% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification40.5%

    \[\leadsto \frac{a}{c} \]
  5. Add Preprocessing

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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