Complex division, real part

Percentage Accurate: 61.9% → 84.4%
Time: 13.1s
Alternatives: 17
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 84.4% accurate, 0.0× speedup?

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

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

\mathbf{elif}\;d \leq -2.5 \cdot 10^{-199}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

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

\mathbf{elif}\;d \leq 8.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{\frac{d \cdot b + a \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 23.9%

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}} \]
      6. times-frac23.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-udef23.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. +-commutative23.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-def23.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-def23.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-udef23.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. +-commutative23.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-def43.0%

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

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

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

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

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

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

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

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

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

    if -7.20000000000000011e86 < d < -2.4999999999999998e-199

    1. Initial program 81.9%

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

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

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

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

        \[\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-sqrt81.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-frac82.0%

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

        \[\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. +-commutative82.0%

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

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

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

        \[\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. +-commutative82.0%

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

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

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

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

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

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

    if -2.4999999999999998e-199 < d < 1.79999999999999997e-178

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.79999999999999997e-178 < d < 8.4e15

    1. Initial program 76.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. associate-*l/88.6%

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

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

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

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

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

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

    if 8.4e15 < d

    1. Initial program 39.8%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/39.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-sqrt39.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-frac39.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-199}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 1.8 \cdot 10^{-178}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{+15}:\\ \;\;\;\;\frac{\frac{d \cdot b + a \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.3% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -1.85 \cdot 10^{-134}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 9.6 \cdot 10^{+14}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.32 \cdot 10^{+138}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 28.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity28.6%

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

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

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

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

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

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

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

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

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

        \[\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-def46.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-rr46.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. Step-by-step derivation
      1. associate-*l/46.6%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-out86.0%

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

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

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

    if -5.8000000000000003e77 < d < -1.85e-134 or 2.09999999999999986e-138 < d < 9.6e14

    1. Initial program 80.1%

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

    if -1.85e-134 < d < 2.09999999999999986e-138

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.6e14 < d < 1.32000000000000001e138

    1. Initial program 53.9%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt54.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-udef54.3%

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

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

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

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

    if 1.32000000000000001e138 < d

    1. Initial program 34.1%

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

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

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

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

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

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

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

        \[\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. +-commutative34.0%

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

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

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

        \[\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. +-commutative34.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+77}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.85 \cdot 10^{-134}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 9.6 \cdot 10^{+14}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.32 \cdot 10^{+138}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.3% accurate, 0.1× speedup?

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

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

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

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

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

\mathbf{elif}\;d \leq 1.9 \cdot 10^{+136}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if d < -1.05e78

    1. Initial program 28.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity28.6%

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

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

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

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

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

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

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

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

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

        \[\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-def46.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-rr46.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. Step-by-step derivation
      1. associate-*l/46.6%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-out86.0%

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

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

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

    if -1.05e78 < d < -2.1e-135

    1. Initial program 77.7%

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

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

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

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

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

    if -2.1e-135 < d < 5.60000000000000002e-138

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.60000000000000002e-138 < d < 1.02e15

    1. Initial program 83.8%

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

    if 1.02e15 < d < 1.90000000000000007e136

    1. Initial program 53.9%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt54.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-udef54.3%

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

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

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

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

    if 1.90000000000000007e136 < d

    1. Initial program 34.1%

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

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

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

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

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

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

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

        \[\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. +-commutative34.0%

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

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

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

        \[\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. +-commutative34.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+78}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.1 \cdot 10^{-135}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+136}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 81.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ t_1 := \frac{a}{\frac{d}{c}}\\ \mathbf{if}\;d \leq -2.2 \cdot 10^{+77}:\\ \;\;\;\;\frac{\left(-b\right) - t_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.4 \cdot 10^{-140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.78 \cdot 10^{-137}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+136}:\\ \;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(d, d, {c}^{2}\right)}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* d b) (* a c)) (+ (* c c) (* d d)))) (t_1 (/ a (/ d c))))
   (if (<= d -2.2e+77)
     (/ (- (- b) t_1) (hypot c d))
     (if (<= d -3.4e-140)
       t_0
       (if (<= d 1.78e-137)
         (+ (/ a c) (/ b (/ c (/ d c))))
         (if (<= d 1.02e+15)
           t_0
           (if (<= d 1.02e+136)
             (/ b (/ (fma d d (pow c 2.0)) d))
             (/ (+ b t_1) (hypot c d)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d));
	double t_1 = a / (d / c);
	double tmp;
	if (d <= -2.2e+77) {
		tmp = (-b - t_1) / hypot(c, d);
	} else if (d <= -3.4e-140) {
		tmp = t_0;
	} else if (d <= 1.78e-137) {
		tmp = (a / c) + (b / (c / (d / c)));
	} else if (d <= 1.02e+15) {
		tmp = t_0;
	} else if (d <= 1.02e+136) {
		tmp = b / (fma(d, d, pow(c, 2.0)) / d);
	} else {
		tmp = (b + t_1) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(d * b) + Float64(a * c)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(a / Float64(d / c))
	tmp = 0.0
	if (d <= -2.2e+77)
		tmp = Float64(Float64(Float64(-b) - t_1) / hypot(c, d));
	elseif (d <= -3.4e-140)
		tmp = t_0;
	elseif (d <= 1.78e-137)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c / Float64(d / c))));
	elseif (d <= 1.02e+15)
		tmp = t_0;
	elseif (d <= 1.02e+136)
		tmp = Float64(b / Float64(fma(d, d, (c ^ 2.0)) / d));
	else
		tmp = Float64(Float64(b + t_1) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.2e+77], N[(N[((-b) - t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.4e-140], t$95$0, If[LessEqual[d, 1.78e-137], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.02e+15], t$95$0, If[LessEqual[d, 1.02e+136], N[(b / N[(N[(d * d + N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(N[(b + t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -3.4 \cdot 10^{-140}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.02 \cdot 10^{+136}:\\
\;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(d, d, {c}^{2}\right)}{d}}\\

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


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

    1. Initial program 28.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity28.6%

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

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

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

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

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

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

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

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

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

        \[\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-def46.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-rr46.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. Step-by-step derivation
      1. associate-*l/46.6%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-out86.0%

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

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

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

    if -2.2e77 < d < -3.40000000000000008e-140 or 1.7800000000000001e-137 < d < 1.02e15

    1. Initial program 80.1%

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

    if -3.40000000000000008e-140 < d < 1.7800000000000001e-137

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.02e15 < d < 1.01999999999999996e136

    1. Initial program 53.9%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. +-commutative79.3%

        \[\leadsto \frac{b}{\frac{\color{blue}{{d}^{2} + {c}^{2}}}{d}} \]
      3. unpow279.3%

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

        \[\leadsto \frac{b}{\frac{\color{blue}{\mathsf{fma}\left(d, d, {c}^{2}\right)}}{d}} \]
    5. Simplified79.3%

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

    if 1.01999999999999996e136 < d

    1. Initial program 34.1%

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

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

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

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

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

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

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

        \[\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. +-commutative34.0%

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

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

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

        \[\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. +-commutative34.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.2 \cdot 10^{+77}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.4 \cdot 10^{-140}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.78 \cdot 10^{-137}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+136}:\\ \;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(d, d, {c}^{2}\right)}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 84.4% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -6.5 \cdot 10^{-198}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 8.4 \cdot 10^{+15}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 23.9%

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}} \]
      6. times-frac23.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-udef23.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. +-commutative23.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-def23.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-def23.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-udef23.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. +-commutative23.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-def43.0%

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

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

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

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

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

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

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

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

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

    if -6.2000000000000004e86 < d < -6.5000000000000004e-198 or 1.12e-178 < d < 8.4e15

    1. Initial program 79.8%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/79.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-sqrt79.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-frac79.8%

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

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

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

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

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

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

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

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

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

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

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

    if -6.5000000000000004e-198 < d < 1.12e-178

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.4e15 < d

    1. Initial program 39.8%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/39.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-sqrt39.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-frac39.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -6.5 \cdot 10^{-198}:\\ \;\;\;\;\frac{\frac{d \cdot b + a \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 1.12 \cdot 10^{-178}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{+15}:\\ \;\;\;\;\frac{\frac{d \cdot b + a \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 81.7% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -2.46 \cdot 10^{-135}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 4.3 \cdot 10^{+139}:\\
\;\;\;\;b \cdot \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\

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


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

    1. Initial program 28.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity28.6%

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

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

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

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

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

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

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

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

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

        \[\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-def46.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-rr46.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. Step-by-step derivation
      1. associate-*l/46.6%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-out86.0%

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

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

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

    if -4.69999999999999984e75 < d < -2.46e-135 or 1.1199999999999999e-138 < d < 1.02e15

    1. Initial program 80.1%

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

    if -2.46e-135 < d < 1.1199999999999999e-138

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.02e15 < d < 4.2999999999999998e139

    1. Initial program 53.9%

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

      \[\leadsto \frac{\color{blue}{b \cdot d}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. expm1-log1p-u44.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot d}{c \cdot c + d \cdot d}\right)\right)} \]
      2. expm1-udef15.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b \cdot d}{c \cdot c + d \cdot d}\right)} - 1} \]
      3. add-sqr-sqrt15.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\right)} - 1 \]
      4. hypot-udef15.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{c \cdot c + d \cdot d}}\right)} - 1 \]
      5. hypot-udef15.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}}\right)} - 1 \]
      6. pow215.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\color{blue}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right)} - 1 \]
    5. Applied egg-rr15.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} - 1} \]
    6. Step-by-step derivation
      1. expm1-def44.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\right)} \]
      2. expm1-log1p54.3%

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

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

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

    if 4.2999999999999998e139 < d

    1. Initial program 34.1%

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

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

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

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

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

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

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

        \[\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. +-commutative34.0%

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

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

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

        \[\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. +-commutative34.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.7 \cdot 10^{+75}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.46 \cdot 10^{-135}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.12 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.3 \cdot 10^{+139}:\\ \;\;\;\;b \cdot \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 81.4% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -2.35 \cdot 10^{-135}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.02 \cdot 10^{+136}:\\
\;\;\;\;\frac{d}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{b}}\\

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


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

    1. Initial program 28.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity28.6%

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

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

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

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

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

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

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

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

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

        \[\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-def46.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-rr46.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. Step-by-step derivation
      1. associate-*l/46.6%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-out86.0%

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

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

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

    if -4.6e73 < d < -2.34999999999999988e-135 or 1.0799999999999999e-138 < d < 1.02e15

    1. Initial program 80.1%

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

    if -2.34999999999999988e-135 < d < 1.0799999999999999e-138

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.02e15 < d < 1.01999999999999996e136

    1. Initial program 53.9%

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

      \[\leadsto \frac{\color{blue}{b \cdot d}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. expm1-log1p-u44.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot d}{c \cdot c + d \cdot d}\right)\right)} \]
      2. expm1-udef15.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b \cdot d}{c \cdot c + d \cdot d}\right)} - 1} \]
      3. add-sqr-sqrt15.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\right)} - 1 \]
      4. hypot-udef15.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{c \cdot c + d \cdot d}}\right)} - 1 \]
      5. hypot-udef15.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}}\right)} - 1 \]
      6. pow215.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b \cdot d}{\color{blue}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right)} - 1 \]
    5. Applied egg-rr15.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{b \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} - 1} \]
    6. Step-by-step derivation
      1. expm1-def44.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\right)} \]
      2. expm1-log1p54.3%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{d}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{b}}} \]
    9. Applied egg-rr79.1%

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

    if 1.01999999999999996e136 < d

    1. Initial program 34.1%

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

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

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

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

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

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

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

        \[\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. +-commutative34.0%

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

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

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

        \[\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. +-commutative34.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.6 \cdot 10^{+73}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-135}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.08 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+15}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+136}:\\ \;\;\;\;\frac{d}{\frac{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 81.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ t_1 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{if}\;d \leq -1.35 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.04 \cdot 10^{-134}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.06 \cdot 10^{-137}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{+15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.08 \cdot 10^{+136}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* d b) (* a c)) (+ (* c c) (* d d))))
        (t_1 (+ (/ b d) (* (/ c d) (/ a d)))))
   (if (<= d -1.35e+79)
     t_1
     (if (<= d -1.04e-134)
       t_0
       (if (<= d 1.06e-137)
         (+ (/ a c) (/ b (/ c (/ d c))))
         (if (<= d 8.4e+15)
           t_0
           (if (<= d 1.08e+136) (* b (/ 1.0 (hypot c d))) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d));
	double t_1 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -1.35e+79) {
		tmp = t_1;
	} else if (d <= -1.04e-134) {
		tmp = t_0;
	} else if (d <= 1.06e-137) {
		tmp = (a / c) + (b / (c / (d / c)));
	} else if (d <= 8.4e+15) {
		tmp = t_0;
	} else if (d <= 1.08e+136) {
		tmp = b * (1.0 / hypot(c, d));
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d));
	double t_1 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -1.35e+79) {
		tmp = t_1;
	} else if (d <= -1.04e-134) {
		tmp = t_0;
	} else if (d <= 1.06e-137) {
		tmp = (a / c) + (b / (c / (d / c)));
	} else if (d <= 8.4e+15) {
		tmp = t_0;
	} else if (d <= 1.08e+136) {
		tmp = b * (1.0 / Math.hypot(c, d));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d))
	t_1 = (b / d) + ((c / d) * (a / d))
	tmp = 0
	if d <= -1.35e+79:
		tmp = t_1
	elif d <= -1.04e-134:
		tmp = t_0
	elif d <= 1.06e-137:
		tmp = (a / c) + (b / (c / (d / c)))
	elif d <= 8.4e+15:
		tmp = t_0
	elif d <= 1.08e+136:
		tmp = b * (1.0 / math.hypot(c, d))
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(d * b) + Float64(a * c)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)))
	tmp = 0.0
	if (d <= -1.35e+79)
		tmp = t_1;
	elseif (d <= -1.04e-134)
		tmp = t_0;
	elseif (d <= 1.06e-137)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c / Float64(d / c))));
	elseif (d <= 8.4e+15)
		tmp = t_0;
	elseif (d <= 1.08e+136)
		tmp = Float64(b * Float64(1.0 / hypot(c, d)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((d * b) + (a * c)) / ((c * c) + (d * d));
	t_1 = (b / d) + ((c / d) * (a / d));
	tmp = 0.0;
	if (d <= -1.35e+79)
		tmp = t_1;
	elseif (d <= -1.04e-134)
		tmp = t_0;
	elseif (d <= 1.06e-137)
		tmp = (a / c) + (b / (c / (d / c)));
	elseif (d <= 8.4e+15)
		tmp = t_0;
	elseif (d <= 1.08e+136)
		tmp = b * (1.0 / hypot(c, d));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.35e+79], t$95$1, If[LessEqual[d, -1.04e-134], t$95$0, If[LessEqual[d, 1.06e-137], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8.4e+15], t$95$0, If[LessEqual[d, 1.08e+136], N[(b * N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1.04 \cdot 10^{-134}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 8.4 \cdot 10^{+15}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.08 \cdot 10^{+136}:\\
\;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.35e79 or 1.07999999999999994e136 < d

    1. Initial program 31.2%

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

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

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

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

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

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

    if -1.35e79 < d < -1.04000000000000002e-134 or 1.06000000000000005e-137 < d < 8.4e15

    1. Initial program 80.4%

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

    if -1.04000000000000002e-134 < d < 1.06000000000000005e-137

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.4e15 < d < 1.07999999999999994e136

    1. Initial program 51.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.35 \cdot 10^{+79}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.04 \cdot 10^{-134}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.06 \cdot 10^{-137}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{+15}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.08 \cdot 10^{+136}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 79.6% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 28.6%

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

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

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

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

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

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

    if -6.5000000000000001e73 < d < -2.84999999999999982e-136

    1. Initial program 77.7%

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

    if -2.84999999999999982e-136 < d < 9.1999999999999997e-20

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.1999999999999997e-20 < d

    1. Initial program 43.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.5 \cdot 10^{+73}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -2.85 \cdot 10^{-136}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 9.2 \cdot 10^{-20}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 79.8% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 28.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity28.6%

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

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

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

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

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

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

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

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

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

        \[\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-def46.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-rr46.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. Step-by-step derivation
      1. associate-*l/46.6%

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b + -1 \cdot \frac{a \cdot c}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Step-by-step derivation
      1. distribute-lft-out86.0%

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

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

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

    if -5.70000000000000004e76 < d < -1.3999999999999999e-137

    1. Initial program 77.7%

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

    if -1.3999999999999999e-137 < d < 1.25e-17

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.25e-17 < d

    1. Initial program 43.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.7 \cdot 10^{+76}:\\ \;\;\;\;\frac{\left(-b\right) - \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.4 \cdot 10^{-137}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{-17}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 59.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -34000000000:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.62 \cdot 10^{-68}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq -2.3 \cdot 10^{-70}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-232}:\\ \;\;\;\;\frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 0.00037:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -34000000000.0)
   (/ b d)
   (if (<= d -1.62e-68)
     (/ a c)
     (if (<= d -2.3e-70)
       (/ b d)
       (if (<= d -2.35e-232)
         (/ (* b (/ d c)) c)
         (if (<= d 0.00037) (/ a c) (/ b d)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -34000000000.0) {
		tmp = b / d;
	} else if (d <= -1.62e-68) {
		tmp = a / c;
	} else if (d <= -2.3e-70) {
		tmp = b / d;
	} else if (d <= -2.35e-232) {
		tmp = (b * (d / c)) / c;
	} else if (d <= 0.00037) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= (-34000000000.0d0)) then
        tmp = b / d
    else if (d <= (-1.62d-68)) then
        tmp = a / c
    else if (d <= (-2.3d-70)) then
        tmp = b / d
    else if (d <= (-2.35d-232)) then
        tmp = (b * (d / c)) / c
    else if (d <= 0.00037d0) then
        tmp = a / c
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -34000000000.0) {
		tmp = b / d;
	} else if (d <= -1.62e-68) {
		tmp = a / c;
	} else if (d <= -2.3e-70) {
		tmp = b / d;
	} else if (d <= -2.35e-232) {
		tmp = (b * (d / c)) / c;
	} else if (d <= 0.00037) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -34000000000.0:
		tmp = b / d
	elif d <= -1.62e-68:
		tmp = a / c
	elif d <= -2.3e-70:
		tmp = b / d
	elif d <= -2.35e-232:
		tmp = (b * (d / c)) / c
	elif d <= 0.00037:
		tmp = a / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -34000000000.0)
		tmp = Float64(b / d);
	elseif (d <= -1.62e-68)
		tmp = Float64(a / c);
	elseif (d <= -2.3e-70)
		tmp = Float64(b / d);
	elseif (d <= -2.35e-232)
		tmp = Float64(Float64(b * Float64(d / c)) / c);
	elseif (d <= 0.00037)
		tmp = Float64(a / c);
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -34000000000.0)
		tmp = b / d;
	elseif (d <= -1.62e-68)
		tmp = a / c;
	elseif (d <= -2.3e-70)
		tmp = b / d;
	elseif (d <= -2.35e-232)
		tmp = (b * (d / c)) / c;
	elseif (d <= 0.00037)
		tmp = a / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -34000000000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, -1.62e-68], N[(a / c), $MachinePrecision], If[LessEqual[d, -2.3e-70], N[(b / d), $MachinePrecision], If[LessEqual[d, -2.35e-232], N[(N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 0.00037], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -34000000000:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq -1.62 \cdot 10^{-68}:\\
\;\;\;\;\frac{a}{c}\\

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

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

\mathbf{elif}\;d \leq 0.00037:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.4e10 or -1.62000000000000005e-68 < d < -2.30000000000000001e-70 or 3.6999999999999999e-4 < d

    1. Initial program 41.5%

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

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

    if -3.4e10 < d < -1.62000000000000005e-68 or -2.35000000000000017e-232 < d < 3.6999999999999999e-4

    1. Initial program 71.3%

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

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

    if -2.30000000000000001e-70 < d < -2.35000000000000017e-232

    1. Initial program 85.2%

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

      \[\leadsto \frac{\color{blue}{b \cdot d}}{c \cdot c + d \cdot d} \]
    4. Taylor expanded in d around 0 54.7%

      \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2}}} \]
    5. Step-by-step derivation
      1. associate-*r/50.8%

        \[\leadsto \color{blue}{b \cdot \frac{d}{{c}^{2}}} \]
    6. Simplified50.8%

      \[\leadsto \color{blue}{b \cdot \frac{d}{{c}^{2}}} \]
    7. Step-by-step derivation
      1. associate-*r/54.7%

        \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2}}} \]
      2. unpow254.7%

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

        \[\leadsto \color{blue}{\frac{\frac{b \cdot d}{c}}{c}} \]
      4. associate-*l/54.5%

        \[\leadsto \frac{\color{blue}{\frac{b}{c} \cdot d}}{c} \]
      5. associate-/r/58.1%

        \[\leadsto \frac{\color{blue}{\frac{b}{\frac{c}{d}}}}{c} \]
      6. div-inv58.2%

        \[\leadsto \frac{\color{blue}{b \cdot \frac{1}{\frac{c}{d}}}}{c} \]
      7. clear-num58.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -34000000000:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.62 \cdot 10^{-68}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq -2.3 \cdot 10^{-70}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-232}:\\ \;\;\;\;\frac{b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 0.00037:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 79.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{if}\;d \leq -1.75 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -2.46 \cdot 10^{-135}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{-19}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ b d) (* (/ c d) (/ a d)))))
   (if (<= d -1.75e+78)
     t_0
     (if (<= d -2.46e-135)
       (/ (+ (* d b) (* a c)) (+ (* c c) (* d d)))
       (if (<= d 1.02e-19) (+ (/ a c) (/ b (/ c (/ d c)))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -1.75e+78) {
		tmp = t_0;
	} else if (d <= -2.46e-135) {
		tmp = ((d * b) + (a * c)) / ((c * c) + (d * d));
	} else if (d <= 1.02e-19) {
		tmp = (a / c) + (b / (c / (d / c)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (b / d) + ((c / d) * (a / d))
    if (d <= (-1.75d+78)) then
        tmp = t_0
    else if (d <= (-2.46d-135)) then
        tmp = ((d * b) + (a * c)) / ((c * c) + (d * d))
    else if (d <= 1.02d-19) then
        tmp = (a / c) + (b / (c / (d / c)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -1.75e+78) {
		tmp = t_0;
	} else if (d <= -2.46e-135) {
		tmp = ((d * b) + (a * c)) / ((c * c) + (d * d));
	} else if (d <= 1.02e-19) {
		tmp = (a / c) + (b / (c / (d / c)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / d) + ((c / d) * (a / d))
	tmp = 0
	if d <= -1.75e+78:
		tmp = t_0
	elif d <= -2.46e-135:
		tmp = ((d * b) + (a * c)) / ((c * c) + (d * d))
	elif d <= 1.02e-19:
		tmp = (a / c) + (b / (c / (d / c)))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)))
	tmp = 0.0
	if (d <= -1.75e+78)
		tmp = t_0;
	elseif (d <= -2.46e-135)
		tmp = Float64(Float64(Float64(d * b) + Float64(a * c)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1.02e-19)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c / Float64(d / c))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b / d) + ((c / d) * (a / d));
	tmp = 0.0;
	if (d <= -1.75e+78)
		tmp = t_0;
	elseif (d <= -2.46e-135)
		tmp = ((d * b) + (a * c)) / ((c * c) + (d * d));
	elseif (d <= 1.02e-19)
		tmp = (a / c) + (b / (c / (d / c)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.75e+78], t$95$0, If[LessEqual[d, -2.46e-135], N[(N[(N[(d * b), $MachinePrecision] + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.02e-19], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.7500000000000001e78 or 1.02000000000000004e-19 < d

    1. Initial program 37.2%

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

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

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

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

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

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

    if -1.7500000000000001e78 < d < -2.46e-135

    1. Initial program 77.7%

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

    if -2.46e-135 < d < 1.02000000000000004e-19

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.75 \cdot 10^{+78}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -2.46 \cdot 10^{-135}:\\ \;\;\;\;\frac{d \cdot b + a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{-19}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{c}{\frac{d}{c}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 71.2% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -240000000000 \lor \neg \left(d \leq 1.75 \cdot 10^{+16}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.4e11 or 1.75e16 < d

    1. Initial program 39.6%

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

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

    if -2.4e11 < d < 1.75e16

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 76.7% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -35000000000 \lor \neg \left(d \leq 7 \cdot 10^{-17}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.5e10 or 7.0000000000000003e-17 < d

    1. Initial program 41.1%

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

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

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

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

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

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

    if -3.5e10 < d < 7.0000000000000003e-17

    1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 64.1% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.2e9 or 6.5000000000000003e-9 < d

    1. Initial program 40.6%

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

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

    if -8.2e9 < d < 6.5000000000000003e-9

    1. Initial program 74.4%

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

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

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

Alternative 16: 43.0% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq 2.05 \cdot 10^{+134}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d) :precision binary64 (if (<= d 2.05e+134) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= 2.05e+134) {
		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 <= 2.05d+134) 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 <= 2.05e+134) {
		tmp = a / c;
	} else {
		tmp = a / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= 2.05e+134:
		tmp = a / c
	else:
		tmp = a / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= 2.05e+134)
		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 <= 2.05e+134)
		tmp = a / c;
	else
		tmp = a / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, 2.05e+134], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 62.5%

      \[\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}} \]

    if 2.0500000000000002e134 < d

    1. Initial program 35.5%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/35.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-sqrt35.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-frac35.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-udef35.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. +-commutative35.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-def35.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-def35.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-udef35.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. +-commutative35.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-def62.6%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{b + \frac{a}{\frac{d}{c}}}}{\mathsf{hypot}\left(c, d\right)} \]
    10. Taylor expanded in d around 0 22.4%

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

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

Alternative 17: 42.5% 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 57.5%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification33.7%

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