Complex division, real part

Percentage Accurate: 61.2% → 85.5%
Time: 12.4s
Alternatives: 17
Speedup: 0.6×

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 17 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 85.5% 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{\frac{b}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\\ \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)))
   (/ (/ b (hypot c d)) (/ (hypot c d) 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 = (b / hypot(c, d)) / (hypot(c, d) / 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(b / hypot(c, d)) / Float64(hypot(c, d) / 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[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / d), $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{\frac{b}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\\


\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 80.8%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine80.8%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define94.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-rr94.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)}} \]

    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 0 1.3%

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt1.3%

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

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

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

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

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

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

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

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

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

    \[\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{\frac{b}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ \mathbf{if}\;d \leq -7.2 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.05 \cdot 10^{-144}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{t\_0}\\ \mathbf{elif}\;d \leq 3.8 \cdot 10^{-133}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+74}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{t\_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d))))
   (if (<= d -7.2e-21)
     (* (/ b (hypot c d)) (/ d (hypot c d)))
     (if (<= d -1.05e-144)
       (/ (fma c a (* b d)) t_0)
       (if (<= d 3.8e-133)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 1.9e+74)
           (/ (+ (* a c) (* b d)) t_0)
           (/ 1.0 (/ (hypot c d) (fma a (/ c d) b)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double tmp;
	if (d <= -7.2e-21) {
		tmp = (b / hypot(c, d)) * (d / hypot(c, d));
	} else if (d <= -1.05e-144) {
		tmp = fma(c, a, (b * d)) / t_0;
	} else if (d <= 3.8e-133) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 1.9e+74) {
		tmp = ((a * c) + (b * d)) / t_0;
	} else {
		tmp = 1.0 / (hypot(c, d) / fma(a, (c / d), b));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	tmp = 0.0
	if (d <= -7.2e-21)
		tmp = Float64(Float64(b / hypot(c, d)) * Float64(d / hypot(c, d)));
	elseif (d <= -1.05e-144)
		tmp = Float64(fma(c, a, Float64(b * d)) / t_0);
	elseif (d <= 3.8e-133)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 1.9e+74)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / t_0);
	else
		tmp = Float64(1.0 / Float64(hypot(c, d) / fma(a, Float64(c / d), b)));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.2e-21], N[(N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.05e-144], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[d, 3.8e-133], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.9e+74], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(1.0 / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;d \leq 1.9 \cdot 10^{+74}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -7.19999999999999979e-21

    1. Initial program 47.8%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt43.7%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. hypot-undefine43.7%

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

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

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

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

    if -7.19999999999999979e-21 < d < -1.0500000000000001e-144

    1. Initial program 99.7%

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

        \[\leadsto \frac{\color{blue}{c \cdot a} + b \cdot d}{c \cdot c + d \cdot d} \]
      2. fma-define99.7%

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

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

    if -1.0500000000000001e-144 < d < 3.8000000000000003e-133

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    if 3.8000000000000003e-133 < d < 1.8999999999999999e74

    1. Initial program 88.7%

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

    if 1.8999999999999999e74 < d

    1. Initial program 44.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine44.4%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define59.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-rr59.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 28.3%

      \[\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. distribute-lft-out28.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.05 \cdot 10^{-144}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.8 \cdot 10^{-133}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+74}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ \mathbf{if}\;d \leq -7.2 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -7.6 \cdot 10^{-147}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{t\_0}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{-131}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{+63}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{t\_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d))))
   (if (<= d -7.2e-21)
     (* (/ b (hypot c d)) (/ d (hypot c d)))
     (if (<= d -7.6e-147)
       (/ (fma c a (* b d)) t_0)
       (if (<= d 2.05e-131)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 4.1e+63)
           (/ (+ (* a c) (* b d)) t_0)
           (* (/ 1.0 (hypot c d)) (+ b (* c (/ a d))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double tmp;
	if (d <= -7.2e-21) {
		tmp = (b / hypot(c, d)) * (d / hypot(c, d));
	} else if (d <= -7.6e-147) {
		tmp = fma(c, a, (b * d)) / t_0;
	} else if (d <= 2.05e-131) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 4.1e+63) {
		tmp = ((a * c) + (b * d)) / t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * (b + (c * (a / d)));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	tmp = 0.0
	if (d <= -7.2e-21)
		tmp = Float64(Float64(b / hypot(c, d)) * Float64(d / hypot(c, d)));
	elseif (d <= -7.6e-147)
		tmp = Float64(fma(c, a, Float64(b * d)) / t_0);
	elseif (d <= 2.05e-131)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 4.1e+63)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / t_0);
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(c * Float64(a / d))));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.2e-21], N[(N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -7.6e-147], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[d, 2.05e-131], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.1e+63], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;d \leq 4.1 \cdot 10^{+63}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -7.19999999999999979e-21

    1. Initial program 47.8%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt43.7%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. hypot-undefine43.7%

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

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

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

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

    if -7.19999999999999979e-21 < d < -7.60000000000000055e-147

    1. Initial program 99.7%

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

        \[\leadsto \frac{\color{blue}{c \cdot a} + b \cdot d}{c \cdot c + d \cdot d} \]
      2. fma-define99.7%

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

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

    if -7.60000000000000055e-147 < d < 2.0500000000000001e-131

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    if 2.0500000000000001e-131 < d < 4.09999999999999993e63

    1. Initial program 88.2%

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

    if 4.09999999999999993e63 < d

    1. Initial program 46.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine46.5%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define60.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-rr60.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)}} \]
    5. Taylor expanded in c around 0 92.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -7.6 \cdot 10^{-147}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{-131}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{+63}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.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}\\ t_1 := b + c \cdot \frac{a}{d}\\ \mathbf{if}\;d \leq -3.7 \cdot 10^{+83}:\\ \;\;\;\;t\_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.3 \cdot 10^{-147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 8.2 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+63}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot 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 (* c (/ a d)))))
   (if (<= d -3.7e+83)
     (* t_1 (/ -1.0 (hypot c d)))
     (if (<= d -2.3e-147)
       t_0
       (if (<= d 8.2e-134)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 7.5e+63) t_0 (* (/ 1.0 (hypot c d)) 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 + (c * (a / d));
	double tmp;
	if (d <= -3.7e+83) {
		tmp = t_1 * (-1.0 / hypot(c, d));
	} else if (d <= -2.3e-147) {
		tmp = t_0;
	} else if (d <= 8.2e-134) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 7.5e+63) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * t_1;
	}
	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 t_1 = b + (c * (a / d));
	double tmp;
	if (d <= -3.7e+83) {
		tmp = t_1 * (-1.0 / Math.hypot(c, d));
	} else if (d <= -2.3e-147) {
		tmp = t_0;
	} else if (d <= 8.2e-134) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 7.5e+63) {
		tmp = t_0;
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = b + (c * (a / d))
	tmp = 0
	if d <= -3.7e+83:
		tmp = t_1 * (-1.0 / math.hypot(c, d))
	elif d <= -2.3e-147:
		tmp = t_0
	elif d <= 8.2e-134:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 7.5e+63:
		tmp = t_0
	else:
		tmp = (1.0 / math.hypot(c, d)) * 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(b + Float64(c * Float64(a / d)))
	tmp = 0.0
	if (d <= -3.7e+83)
		tmp = Float64(t_1 * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -2.3e-147)
		tmp = t_0;
	elseif (d <= 8.2e-134)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 7.5e+63)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * 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 + (c * (a / d));
	tmp = 0.0;
	if (d <= -3.7e+83)
		tmp = t_1 * (-1.0 / hypot(c, d));
	elseif (d <= -2.3e-147)
		tmp = t_0;
	elseif (d <= 8.2e-134)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 7.5e+63)
		tmp = t_0;
	else
		tmp = (1.0 / hypot(c, d)) * 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[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.7e+83], N[(t$95$1 * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.3e-147], t$95$0, If[LessEqual[d, 8.2e-134], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.5e+63], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := b + c \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -3.7 \cdot 10^{+83}:\\
\;\;\;\;t\_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -2.3 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 7.5 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 40.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine40.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.7000000000000002e83 < d < -2.2999999999999999e-147 or 8.2000000000000004e-134 < d < 7.5000000000000005e63

    1. Initial program 84.4%

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

    if -2.2999999999999999e-147 < d < 8.2000000000000004e-134

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    if 7.5000000000000005e63 < d

    1. Initial program 46.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine46.5%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define60.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-rr60.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)}} \]
    5. Taylor expanded in c around 0 92.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.7 \cdot 10^{+83}:\\ \;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.3 \cdot 10^{-147}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 8.2 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+63}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 82.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := b + c \cdot \frac{a}{d}\\ \mathbf{if}\;d \leq -8.4 \cdot 10^{+83}:\\ \;\;\;\;t\_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.06 \cdot 10^{-138}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{t\_0}\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{-132}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{+64}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{t\_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d))) (t_1 (+ b (* c (/ a d)))))
   (if (<= d -8.4e+83)
     (* t_1 (/ -1.0 (hypot c d)))
     (if (<= d -1.06e-138)
       (/ (fma c a (* b d)) t_0)
       (if (<= d 3.4e-132)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 1.35e+64)
           (/ (+ (* a c) (* b d)) t_0)
           (* (/ 1.0 (hypot c d)) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = b + (c * (a / d));
	double tmp;
	if (d <= -8.4e+83) {
		tmp = t_1 * (-1.0 / hypot(c, d));
	} else if (d <= -1.06e-138) {
		tmp = fma(c, a, (b * d)) / t_0;
	} else if (d <= 3.4e-132) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 1.35e+64) {
		tmp = ((a * c) + (b * d)) / t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	t_1 = Float64(b + Float64(c * Float64(a / d)))
	tmp = 0.0
	if (d <= -8.4e+83)
		tmp = Float64(t_1 * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -1.06e-138)
		tmp = Float64(fma(c, a, Float64(b * d)) / t_0);
	elseif (d <= 3.4e-132)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 1.35e+64)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / t_0);
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -8.4e+83], N[(t$95$1 * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.06e-138], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[d, 3.4e-132], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.35e+64], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := c \cdot c + d \cdot d\\
t_1 := b + c \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -8.4 \cdot 10^{+83}:\\
\;\;\;\;t\_1 \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

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

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

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

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


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

    1. Initial program 40.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine40.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.4000000000000001e83 < d < -1.0599999999999999e-138

    1. Initial program 80.3%

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

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

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

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

    if -1.0599999999999999e-138 < d < 3.39999999999999983e-132

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    if 3.39999999999999983e-132 < d < 1.35e64

    1. Initial program 88.2%

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

    if 1.35e64 < d

    1. Initial program 46.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine46.5%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define60.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-rr60.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)}} \]
    5. Taylor expanded in c around 0 92.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.4 \cdot 10^{+83}:\\ \;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.06 \cdot 10^{-138}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{-132}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{+64}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 79.7% 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.85 \cdot 10^{+84}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-138}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.72 \cdot 10^{-133}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{+63}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -1.85e+84)
     (* b (/ -1.0 (hypot c d)))
     (if (<= d -1.3e-138)
       t_0
       (if (<= d 1.72e-133)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 1.2e+63) t_0 (+ (/ b d) (* c (/ a (pow d 2.0))))))))))
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 <= -1.85e+84) {
		tmp = b * (-1.0 / hypot(c, d));
	} else if (d <= -1.3e-138) {
		tmp = t_0;
	} else if (d <= 1.72e-133) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 1.2e+63) {
		tmp = t_0;
	} else {
		tmp = (b / d) + (c * (a / pow(d, 2.0)));
	}
	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 <= -1.85e+84) {
		tmp = b * (-1.0 / Math.hypot(c, d));
	} else if (d <= -1.3e-138) {
		tmp = t_0;
	} else if (d <= 1.72e-133) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 1.2e+63) {
		tmp = t_0;
	} else {
		tmp = (b / d) + (c * (a / Math.pow(d, 2.0)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.85e+84:
		tmp = b * (-1.0 / math.hypot(c, d))
	elif d <= -1.3e-138:
		tmp = t_0
	elif d <= 1.72e-133:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 1.2e+63:
		tmp = t_0
	else:
		tmp = (b / d) + (c * (a / math.pow(d, 2.0)))
	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 <= -1.85e+84)
		tmp = Float64(b * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -1.3e-138)
		tmp = t_0;
	elseif (d <= 1.72e-133)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 1.2e+63)
		tmp = t_0;
	else
		tmp = Float64(Float64(b / d) + Float64(c * Float64(a / (d ^ 2.0))));
	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 <= -1.85e+84)
		tmp = b * (-1.0 / hypot(c, d));
	elseif (d <= -1.3e-138)
		tmp = t_0;
	elseif (d <= 1.72e-133)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 1.2e+63)
		tmp = t_0;
	else
		tmp = (b / d) + (c * (a / (d ^ 2.0)));
	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, -1.85e+84], N[(b * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.3e-138], t$95$0, If[LessEqual[d, 1.72e-133], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.2e+63], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(c * N[(a / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;d \leq 1.2 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 40.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine40.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.85e84 < d < -1.3e-138 or 1.71999999999999995e-133 < d < 1.2e63

    1. Initial program 84.4%

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

    if -1.3e-138 < d < 1.71999999999999995e-133

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    if 1.2e63 < d

    1. Initial program 46.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.85 \cdot 10^{+84}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.3 \cdot 10^{-138}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.72 \cdot 10^{-133}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{+63}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 80.1% 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 -3.9 \cdot 10^{+83}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-147}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 4.7 \cdot 10^{+72}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{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 -3.9e+83)
     (* b (/ -1.0 (hypot c d)))
     (if (<= d -5e-147)
       t_0
       (if (<= d 5.6e-134)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 4.7e+72) t_0 (/ (+ b (/ (* a c) 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 <= -3.9e+83) {
		tmp = b * (-1.0 / hypot(c, d));
	} else if (d <= -5e-147) {
		tmp = t_0;
	} else if (d <= 5.6e-134) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 4.7e+72) {
		tmp = t_0;
	} else {
		tmp = (b + ((a * c) / 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 <= -3.9e+83) {
		tmp = b * (-1.0 / Math.hypot(c, d));
	} else if (d <= -5e-147) {
		tmp = t_0;
	} else if (d <= 5.6e-134) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 4.7e+72) {
		tmp = t_0;
	} else {
		tmp = (b + ((a * c) / 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 <= -3.9e+83:
		tmp = b * (-1.0 / math.hypot(c, d))
	elif d <= -5e-147:
		tmp = t_0
	elif d <= 5.6e-134:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 4.7e+72:
		tmp = t_0
	else:
		tmp = (b + ((a * c) / 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 <= -3.9e+83)
		tmp = Float64(b * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -5e-147)
		tmp = t_0;
	elseif (d <= 5.6e-134)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 4.7e+72)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(Float64(a * c) / 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 <= -3.9e+83)
		tmp = b * (-1.0 / hypot(c, d));
	elseif (d <= -5e-147)
		tmp = t_0;
	elseif (d <= 5.6e-134)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 4.7e+72)
		tmp = t_0;
	else
		tmp = (b + ((a * c) / 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, -3.9e+83], N[(b * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5e-147], t$95$0, If[LessEqual[d, 5.6e-134], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.7e+72], t$95$0, N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $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 -3.9 \cdot 10^{+83}:\\
\;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -5 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.7 \cdot 10^{+72}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 40.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine40.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.9000000000000002e83 < d < -5.00000000000000013e-147 or 5.5999999999999997e-134 < d < 4.70000000000000034e72

    1. Initial program 84.8%

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

    if -5.00000000000000013e-147 < d < 5.5999999999999997e-134

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    if 4.70000000000000034e72 < d

    1. Initial program 44.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine44.4%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define59.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-rr59.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 28.3%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{a}{d} \cdot c}{\mathsf{hypot}\left(c, d\right)}} \]
      3. cancel-sign-sub-inv28.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + \color{blue}{\frac{a}{d}} \cdot c}{\mathsf{hypot}\left(c, d\right)} \]
      12. add-sqr-sqrt13.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.9 \cdot 10^{+83}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-147}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 4.7 \cdot 10^{+72}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 78.8% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 53.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.80000000000000035e-84 < d < 2.2000000000000001e-133

    1. Initial program 77.0%

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

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

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

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

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

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

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

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

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

    if 2.2000000000000001e-133 < d < 2.7e62

    1. Initial program 88.2%

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

    if 2.7e62 < d

    1. Initial program 46.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine46.5%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define60.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-rr60.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)}} \]
    5. Taylor expanded in c around 0 92.5%

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

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

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

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

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

Alternative 9: 79.5% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 53.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.89999999999999998e-86 < d < 5.9999999999999999e-132

    1. Initial program 77.0%

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

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

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

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

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

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

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

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

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

    if 5.9999999999999999e-132 < d < 9.5000000000000003e63

    1. Initial program 88.2%

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

    if 9.5000000000000003e63 < d

    1. Initial program 46.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine46.5%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define60.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-rr60.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)}} \]
    5. Taylor expanded in c around 0 92.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.9 \cdot 10^{-86}:\\ \;\;\;\;\left(b + \frac{a}{\frac{d}{c}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{-132}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{+63}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 77.9% accurate, 0.1× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 53.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.79999999999999986e-84 < d < 5.5999999999999997e-133

    1. Initial program 77.0%

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

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

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

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

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

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

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

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

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

    if 5.5999999999999997e-133 < d < 1.2000000000000001e69

    1. Initial program 88.7%

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

    if 1.2000000000000001e69 < d

    1. Initial program 44.4%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine44.4%

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

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

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

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

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

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

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

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

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

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

        \[\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}}} \]
      13. hypot-define59.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-rr59.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 28.3%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{a}{d} \cdot c}{\mathsf{hypot}\left(c, d\right)}} \]
      3. cancel-sign-sub-inv28.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-b\right) + \color{blue}{\frac{a}{d}} \cdot c}{\mathsf{hypot}\left(c, d\right)} \]
      12. add-sqr-sqrt13.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.8 \cdot 10^{-84}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{-133}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{+69}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 79.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -7.9 \cdot 10^{+83}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-139}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{-133}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9.8 \cdot 10^{+83}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -7.9e+83)
     (* b (/ -1.0 (hypot c d)))
     (if (<= d -1.7e-139)
       t_0
       (if (<= d 3.1e-133)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 9.8e+83) t_0 (/ b 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 <= -7.9e+83) {
		tmp = b * (-1.0 / hypot(c, d));
	} else if (d <= -1.7e-139) {
		tmp = t_0;
	} else if (d <= 3.1e-133) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 9.8e+83) {
		tmp = t_0;
	} else {
		tmp = b / 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 <= -7.9e+83) {
		tmp = b * (-1.0 / Math.hypot(c, d));
	} else if (d <= -1.7e-139) {
		tmp = t_0;
	} else if (d <= 3.1e-133) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 9.8e+83) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -7.9e+83:
		tmp = b * (-1.0 / math.hypot(c, d))
	elif d <= -1.7e-139:
		tmp = t_0
	elif d <= 3.1e-133:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 9.8e+83:
		tmp = t_0
	else:
		tmp = b / 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 <= -7.9e+83)
		tmp = Float64(b * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -1.7e-139)
		tmp = t_0;
	elseif (d <= 3.1e-133)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 9.8e+83)
		tmp = t_0;
	else
		tmp = Float64(b / 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 <= -7.9e+83)
		tmp = b * (-1.0 / hypot(c, d));
	elseif (d <= -1.7e-139)
		tmp = t_0;
	elseif (d <= 3.1e-133)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 9.8e+83)
		tmp = t_0;
	else
		tmp = b / 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, -7.9e+83], N[(b * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.7e-139], t$95$0, If[LessEqual[d, 3.1e-133], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9.8e+83], t$95$0, N[(b / d), $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 -7.9 \cdot 10^{+83}:\\
\;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -1.7 \cdot 10^{-139}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 9.8 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 40.5%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine40.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.89999999999999974e83 < d < -1.69999999999999999e-139 or 3.10000000000000016e-133 < d < 9.79999999999999957e83

    1. Initial program 85.1%

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

    if -1.69999999999999999e-139 < d < 3.10000000000000016e-133

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    if 9.79999999999999957e83 < d

    1. Initial program 42.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.9 \cdot 10^{+83}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-139}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{-133}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9.8 \cdot 10^{+83}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 79.0% accurate, 0.4× 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.18 \cdot 10^{+83}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.4 \cdot 10^{-146}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-131}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9.8 \cdot 10^{+83}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -1.18e+83)
     (/ b d)
     (if (<= d -1.4e-146)
       t_0
       (if (<= d 1.45e-131)
         (+ (/ a c) (/ (/ (* b d) c) c))
         (if (<= d 9.8e+83) t_0 (/ b 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 <= -1.18e+83) {
		tmp = b / d;
	} else if (d <= -1.4e-146) {
		tmp = t_0;
	} else if (d <= 1.45e-131) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 9.8e+83) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-1.18d+83)) then
        tmp = b / d
    else if (d <= (-1.4d-146)) then
        tmp = t_0
    else if (d <= 1.45d-131) then
        tmp = (a / c) + (((b * d) / c) / c)
    else if (d <= 9.8d+83) then
        tmp = t_0
    else
        tmp = b / d
    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 tmp;
	if (d <= -1.18e+83) {
		tmp = b / d;
	} else if (d <= -1.4e-146) {
		tmp = t_0;
	} else if (d <= 1.45e-131) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 9.8e+83) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.18e+83:
		tmp = b / d
	elif d <= -1.4e-146:
		tmp = t_0
	elif d <= 1.45e-131:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 9.8e+83:
		tmp = t_0
	else:
		tmp = b / 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 <= -1.18e+83)
		tmp = Float64(b / d);
	elseif (d <= -1.4e-146)
		tmp = t_0;
	elseif (d <= 1.45e-131)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 9.8e+83)
		tmp = t_0;
	else
		tmp = Float64(b / 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 <= -1.18e+83)
		tmp = b / d;
	elseif (d <= -1.4e-146)
		tmp = t_0;
	elseif (d <= 1.45e-131)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 9.8e+83)
		tmp = t_0;
	else
		tmp = b / 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, -1.18e+83], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.4e-146], t$95$0, If[LessEqual[d, 1.45e-131], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9.8e+83], t$95$0, N[(b / d), $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.18 \cdot 10^{+83}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq -1.4 \cdot 10^{-146}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 9.8 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.1799999999999999e83 or 9.79999999999999957e83 < d

    1. Initial program 42.1%

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

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

    if -1.1799999999999999e83 < d < -1.40000000000000001e-146 or 1.4500000000000001e-131 < d < 9.79999999999999957e83

    1. Initial program 85.0%

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

    if -1.40000000000000001e-146 < d < 1.4500000000000001e-131

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.18 \cdot 10^{+83}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.4 \cdot 10^{-146}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-131}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9.8 \cdot 10^{+83}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 72.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.8 \cdot 10^{+17} \lor \neg \left(d \leq 2.6 \cdot 10^{-66}\right) \land \left(d \leq 8.5 \cdot 10^{-33} \lor \neg \left(d \leq 1.8 \cdot 10^{+62}\right)\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.8e17 or 2.5999999999999999e-66 < d < 8.49999999999999945e-33 or 1.8e62 < d

    1. Initial program 51.8%

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

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

    if -3.8e17 < d < 2.5999999999999999e-66 or 8.49999999999999945e-33 < d < 1.8e62

    1. Initial program 78.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.8 \cdot 10^{+17} \lor \neg \left(d \leq 2.6 \cdot 10^{-66}\right) \land \left(d \leq 8.5 \cdot 10^{-33} \lor \neg \left(d \leq 1.8 \cdot 10^{+62}\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 72.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{if}\;d \leq -4.4 \cdot 10^{+14}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-97}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 330000000:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{+62}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ a c) (/ (/ (* b d) c) c))))
   (if (<= d -4.4e+14)
     (/ b d)
     (if (<= d 1.5e-97)
       t_0
       (if (<= d 330000000.0)
         (/ (* b d) (+ (* c c) (* d d)))
         (if (<= d 1.85e+62) t_0 (/ b d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + (((b * d) / c) / c);
	double tmp;
	if (d <= -4.4e+14) {
		tmp = b / d;
	} else if (d <= 1.5e-97) {
		tmp = t_0;
	} else if (d <= 330000000.0) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 1.85e+62) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = (a / c) + (((b * d) / c) / c)
    if (d <= (-4.4d+14)) then
        tmp = b / d
    else if (d <= 1.5d-97) then
        tmp = t_0
    else if (d <= 330000000.0d0) then
        tmp = (b * d) / ((c * c) + (d * d))
    else if (d <= 1.85d+62) then
        tmp = t_0
    else
        tmp = b / d
    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);
	double tmp;
	if (d <= -4.4e+14) {
		tmp = b / d;
	} else if (d <= 1.5e-97) {
		tmp = t_0;
	} else if (d <= 330000000.0) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 1.85e+62) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a / c) + (((b * d) / c) / c)
	tmp = 0
	if d <= -4.4e+14:
		tmp = b / d
	elif d <= 1.5e-97:
		tmp = t_0
	elif d <= 330000000.0:
		tmp = (b * d) / ((c * c) + (d * d))
	elif d <= 1.85e+62:
		tmp = t_0
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c))
	tmp = 0.0
	if (d <= -4.4e+14)
		tmp = Float64(b / d);
	elseif (d <= 1.5e-97)
		tmp = t_0;
	elseif (d <= 330000000.0)
		tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1.85e+62)
		tmp = t_0;
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a / c) + (((b * d) / c) / c);
	tmp = 0.0;
	if (d <= -4.4e+14)
		tmp = b / d;
	elseif (d <= 1.5e-97)
		tmp = t_0;
	elseif (d <= 330000000.0)
		tmp = (b * d) / ((c * c) + (d * d));
	elseif (d <= 1.85e+62)
		tmp = t_0;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.4e+14], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.5e-97], t$95$0, If[LessEqual[d, 330000000.0], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.85e+62], t$95$0, N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq 1.5 \cdot 10^{-97}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 330000000:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;d \leq 1.85 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.4e14 or 1.85000000000000007e62 < d

    1. Initial program 47.2%

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

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

    if -4.4e14 < d < 1.50000000000000012e-97 or 3.3e8 < d < 1.85000000000000007e62

    1. Initial program 75.6%

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

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

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

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

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

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

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

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

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

    if 1.50000000000000012e-97 < d < 3.3e8

    1. Initial program 96.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.4 \cdot 10^{+14}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-97}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 330000000:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{+62}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 62.2% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{-94} \lor \neg \left(d \leq 2.35 \cdot 10^{-66}\right) \land \left(d \leq 330000000 \lor \neg \left(d \leq 7.2 \cdot 10^{+62}\right)\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.2e-94 or 2.35e-66 < d < 3.3e8 or 7.2e62 < d

    1. Initial program 57.4%

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

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

    if -7.2e-94 < d < 2.35e-66 or 3.3e8 < d < 7.2e62

    1. Initial program 77.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{-94} \lor \neg \left(d \leq 2.35 \cdot 10^{-66}\right) \land \left(d \leq 330000000 \lor \neg \left(d \leq 7.2 \cdot 10^{+62}\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 42.5% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 70.8%

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

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

    if 4.00000000000000023e84 < d

    1. Initial program 43.2%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-undefine43.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      12. +-commutative43.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}}} \]
      13. hypot-define59.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-rr59.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 c around inf 20.2%

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

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

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

Alternative 17: 42.6% 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 65.4%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification39.9%

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