Complex division, real part

Percentage Accurate: 61.6% → 89.7%
Time: 13.9s
Alternatives: 13
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 13 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.6% 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: 89.7% accurate, 0.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -9.2000000000000006e132

    1. Initial program 41.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.2000000000000006e132 < c < 4.3000000000000001e98

    1. Initial program 69.4%

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

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

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

      \[\leadsto \frac{\color{blue}{d \cdot \left(b + a \cdot \frac{c}{d}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative63.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.3000000000000001e98 < c

    1. Initial program 38.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 82.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+77}:\\ \;\;\;\;\frac{\left(-b\right) - c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-65}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 5.3 \cdot 10^{+100}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.55e+77)
   (/ (- (- b) (* c (/ a d))) (hypot c d))
   (if (<= d -1.45e-65)
     (/ (+ (* d b) (* c a)) (+ (* c c) (* d d)))
     (if (<= d 1.5e-67)
       (/ (+ a (/ (* d b) c)) c)
       (if (<= d 5.3e+100)
         (/ (fma a c (* d b)) (fma c c (* d d)))
         (* (/ d (hypot d c)) (/ b (hypot d c))))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.55e+77) {
		tmp = (-b - (c * (a / d))) / hypot(c, d);
	} else if (d <= -1.45e-65) {
		tmp = ((d * b) + (c * a)) / ((c * c) + (d * d));
	} else if (d <= 1.5e-67) {
		tmp = (a + ((d * b) / c)) / c;
	} else if (d <= 5.3e+100) {
		tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
	} else {
		tmp = (d / hypot(d, c)) * (b / hypot(d, c));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.55e+77)
		tmp = Float64(Float64(Float64(-b) - Float64(c * Float64(a / d))) / hypot(c, d));
	elseif (d <= -1.45e-65)
		tmp = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1.5e-67)
		tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c);
	elseif (d <= 5.3e+100)
		tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d)));
	else
		tmp = Float64(Float64(d / hypot(d, c)) * Float64(b / hypot(d, c)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.55e+77], N[(N[((-b) - N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.45e-65], N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.5e-67], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.3e+100], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

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

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

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


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

    1. Initial program 44.6%

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

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

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

      \[\leadsto \frac{\color{blue}{d \cdot \left(b + a \cdot \frac{c}{d}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative42.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.54999999999999999e77 < d < -1.4499999999999999e-65

    1. Initial program 91.9%

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

    if -1.4499999999999999e-65 < d < 1.50000000000000016e-67

    1. Initial program 61.5%

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

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

    if 1.50000000000000016e-67 < d < 5.2999999999999998e100

    1. Initial program 81.1%

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

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

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

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

    if 5.2999999999999998e100 < d

    1. Initial program 31.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+77}:\\ \;\;\;\;\frac{\left(-b\right) - c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-65}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 5.3 \cdot 10^{+100}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.3% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -1.2 \cdot 10^{-65}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.25 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 44.6%

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

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

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

      \[\leadsto \frac{\color{blue}{d \cdot \left(b + a \cdot \frac{c}{d}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative42.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.79999999999999979e76 < d < -1.2000000000000001e-65 or 1.1000000000000001e-67 < d < 2.2499999999999999e104

    1. Initial program 86.1%

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

    if -1.2000000000000001e-65 < d < 1.1000000000000001e-67

    1. Initial program 61.5%

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

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

    if 2.2499999999999999e104 < d

    1. Initial program 31.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.8 \cdot 10^{+76}:\\ \;\;\;\;\frac{\left(-b\right) - c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.2 \cdot 10^{-65}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.1 \cdot 10^{-67}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 2.25 \cdot 10^{+104}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 90.3% accurate, 0.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -7.8999999999999997e-22

    1. Initial program 60.6%

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

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

        \[\leadsto \frac{d \cdot \left(b + \color{blue}{a \cdot \frac{c}{d}}\right)}{c \cdot c + d \cdot d} \]
    5. Simplified58.0%

      \[\leadsto \frac{\color{blue}{d \cdot \left(b + a \cdot \frac{c}{d}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative58.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.8999999999999997e-22 < d < 1.74999999999999992e-116

    1. Initial program 65.3%

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

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

    if 1.74999999999999992e-116 < d

    1. Initial program 58.2%

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

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

        \[\leadsto \frac{d \cdot \left(b + \color{blue}{a \cdot \frac{c}{d}}\right)}{c \cdot c + d \cdot d} \]
    5. Simplified55.9%

      \[\leadsto \frac{\color{blue}{d \cdot \left(b + a \cdot \frac{c}{d}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative55.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 90.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.8 \cdot 10^{-22} \lor \neg \left(d \leq 10^{-116}\right):\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -7.8e-22) (not (<= d 1e-116)))
   (* (/ (+ b (* c (/ a d))) (hypot c d)) (/ d (hypot c d)))
   (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -7.8e-22) || !(d <= 1e-116)) {
		tmp = ((b + (c * (a / d))) / hypot(c, d)) * (d / hypot(c, d));
	} else {
		tmp = (a + ((d * b) / c)) / c;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -7.8e-22) || !(d <= 1e-116)) {
		tmp = ((b + (c * (a / d))) / Math.hypot(c, d)) * (d / Math.hypot(c, d));
	} else {
		tmp = (a + ((d * b) / c)) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -7.8e-22) or not (d <= 1e-116):
		tmp = ((b + (c * (a / d))) / math.hypot(c, d)) * (d / math.hypot(c, d))
	else:
		tmp = (a + ((d * b) / c)) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -7.8e-22) || !(d <= 1e-116))
		tmp = Float64(Float64(Float64(b + Float64(c * Float64(a / d))) / hypot(c, d)) * Float64(d / hypot(c, d)));
	else
		tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -7.8e-22) || ~((d <= 1e-116)))
		tmp = ((b + (c * (a / d))) / hypot(c, d)) * (d / hypot(c, d));
	else
		tmp = (a + ((d * b) / c)) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.8e-22], N[Not[LessEqual[d, 1e-116]], $MachinePrecision]], N[(N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.79999999999999996e-22 or 9.9999999999999999e-117 < d

    1. Initial program 59.3%

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

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

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

      \[\leadsto \frac{\color{blue}{d \cdot \left(b + a \cdot \frac{c}{d}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative56.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.79999999999999996e-22 < d < 9.9999999999999999e-117

    1. Initial program 65.3%

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

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

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

Alternative 6: 82.9% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -5 \cdot 10^{-26}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.9 \cdot 10^{+67}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.25000000000000006e95

    1. Initial program 38.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.25000000000000006e95 < c < -5.00000000000000019e-26 or 1.2499999999999999e-72 < c < 1.9000000000000001e67

    1. Initial program 81.7%

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

    if -5.00000000000000019e-26 < c < 1.2499999999999999e-72

    1. Initial program 69.6%

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

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

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

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

    if 1.9000000000000001e67 < c

    1. Initial program 45.3%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.25 \cdot 10^{+95}:\\ \;\;\;\;\left(a + b \cdot \frac{d}{c}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -5 \cdot 10^{-26}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-72}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.9 \cdot 10^{+67}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + b \cdot \frac{d}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 82.7% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -5 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 2.35 \cdot 10^{+67}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -9.4999999999999998e94

    1. Initial program 38.6%

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

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

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

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

    if -9.4999999999999998e94 < c < -5.0000000000000002e-27 or 1.9999999999999999e-72 < c < 2.35000000000000009e67

    1. Initial program 81.7%

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

    if -5.0000000000000002e-27 < c < 1.9999999999999999e-72

    1. Initial program 69.6%

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

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

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

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

    if 2.35000000000000009e67 < c

    1. Initial program 45.3%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -9.5 \cdot 10^{+94}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -5 \cdot 10^{-27}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2 \cdot 10^{-72}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.35 \cdot 10^{+67}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + b \cdot \frac{d}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 82.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{if}\;c \leq -4.6 \cdot 10^{+95}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -4.8 \cdot 10^{-27}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{-74}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{+74}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* c c) (* d d))))
        (t_1 (/ (+ a (* b (/ d c))) c)))
   (if (<= c -4.6e+95)
     t_1
     (if (<= c -4.8e-27)
       t_0
       (if (<= c 4.5e-74)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 5.8e+74) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double t_1 = (a + (b * (d / c))) / c;
	double tmp;
	if (c <= -4.6e+95) {
		tmp = t_1;
	} else if (c <= -4.8e-27) {
		tmp = t_0;
	} else if (c <= 4.5e-74) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 5.8e+74) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d))
    t_1 = (a + (b * (d / c))) / c
    if (c <= (-4.6d+95)) then
        tmp = t_1
    else if (c <= (-4.8d-27)) then
        tmp = t_0
    else if (c <= 4.5d-74) then
        tmp = (b + (a * (c / d))) / d
    else if (c <= 5.8d+74) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double t_1 = (a + (b * (d / c))) / c;
	double tmp;
	if (c <= -4.6e+95) {
		tmp = t_1;
	} else if (c <= -4.8e-27) {
		tmp = t_0;
	} else if (c <= 4.5e-74) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 5.8e+74) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d))
	t_1 = (a + (b * (d / c))) / c
	tmp = 0
	if c <= -4.6e+95:
		tmp = t_1
	elif c <= -4.8e-27:
		tmp = t_0
	elif c <= 4.5e-74:
		tmp = (b + (a * (c / d))) / d
	elif c <= 5.8e+74:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c)
	tmp = 0.0
	if (c <= -4.6e+95)
		tmp = t_1;
	elseif (c <= -4.8e-27)
		tmp = t_0;
	elseif (c <= 4.5e-74)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 5.8e+74)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	t_1 = (a + (b * (d / c))) / c;
	tmp = 0.0;
	if (c <= -4.6e+95)
		tmp = t_1;
	elseif (c <= -4.8e-27)
		tmp = t_0;
	elseif (c <= 4.5e-74)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 5.8e+74)
		tmp = t_0;
	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[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.6e+95], t$95$1, If[LessEqual[c, -4.8e-27], t$95$0, If[LessEqual[c, 4.5e-74], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.8e+74], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.8 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 5.8 \cdot 10^{+74}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.59999999999999994e95 or 5.8000000000000005e74 < c

    1. Initial program 41.2%

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

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

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

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

    if -4.59999999999999994e95 < c < -4.80000000000000004e-27 or 4.4999999999999999e-74 < c < 5.8000000000000005e74

    1. Initial program 80.5%

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

    if -4.80000000000000004e-27 < c < 4.4999999999999999e-74

    1. Initial program 69.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.6 \cdot 10^{+95}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -4.8 \cdot 10^{-27}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{-74}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{+74}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 70.4% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.2 \cdot 10^{+101} \lor \neg \left(d \leq 1.1 \cdot 10^{+15}\right) \land \left(d \leq 1.7 \cdot 10^{+73} \lor \neg \left(d \leq 3.5 \cdot 10^{+170}\right)\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.1999999999999999e101 or 1.1e15 < d < 1.7000000000000001e73 or 3.50000000000000005e170 < d

    1. Initial program 51.5%

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

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

    if -8.1999999999999999e101 < d < 1.1e15 or 1.7000000000000001e73 < d < 3.50000000000000005e170

    1. Initial program 67.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.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.2 \cdot 10^{+101} \lor \neg \left(d \leq 1.1 \cdot 10^{+15}\right) \land \left(d \leq 1.7 \cdot 10^{+73} \lor \neg \left(d \leq 3.5 \cdot 10^{+170}\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 70.1% accurate, 0.5× speedup?

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

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

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

\mathbf{elif}\;d \leq 1.35 \cdot 10^{+73} \lor \neg \left(d \leq 3.5 \cdot 10^{+170}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.69999999999999971e101 or 9.6e13 < d < 1.35e73 or 3.50000000000000005e170 < d

    1. Initial program 51.5%

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

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

    if -4.69999999999999971e101 < d < 9.6e13

    1. Initial program 69.6%

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

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

    if 1.35e73 < d < 3.50000000000000005e170

    1. Initial program 44.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.7 \cdot 10^{+101}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 96000000000000:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{+73} \lor \neg \left(d \leq 3.5 \cdot 10^{+170}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 78.1% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.95 \cdot 10^{-23} \lor \neg \left(c \leq 9.8 \cdot 10^{+45}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.95e-23 or 9.8000000000000004e45 < c

    1. Initial program 49.6%

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

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

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

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

    if -1.95e-23 < c < 9.8000000000000004e45

    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 d around inf 84.3%

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

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

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

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

Alternative 12: 63.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.8 \cdot 10^{-39} \lor \neg \left(c \leq 2.75 \cdot 10^{+42}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.79999999999999975e-39 or 2.75000000000000001e42 < c

    1. Initial program 49.7%

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

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

    if -5.79999999999999975e-39 < c < 2.75000000000000001e42

    1. Initial program 71.9%

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

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

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

Alternative 13: 43.0% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Add Preprocessing

Developer target: 99.4% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024101 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (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))))