Complex division, real part

Percentage Accurate: 61.5% → 84.8%
Time: 13.3s
Alternatives: 15
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 15 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.5% accurate, 1.0× speedup?

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

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

Alternative 1: 84.8% accurate, 0.1× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.0000000000000001e235

    1. Initial program 80.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      13. hypot-def97.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-rr97.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. Step-by-step derivation
      1. fma-def98.0%

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

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

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

    if 1.0000000000000001e235 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 14.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt31.7%

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt46.3%

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

        \[\leadsto \frac{b}{d} + \color{blue}{\left(-\frac{a}{\frac{d}{c}}\right)} \cdot \frac{1}{d} \]
      9. associate-/l*43.0%

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv43.0%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv43.0%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg43.0%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg43.0%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg46.3%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div46.3%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr64.1%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/65.7%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified65.7%

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

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

Alternative 2: 82.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -3.3 \cdot 10^{+81}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 7.6 \cdot 10^{-35}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 1.36 \cdot 10^{+101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -3.3e+81)
   (* (/ c (hypot c d)) (/ a (hypot c d)))
   (if (<= c -2.2e-105)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= c 7.6e-35)
       (/ (- (- b) (* a (/ c d))) (- d))
       (if (<= c 1.36e+101)
         (/ (fma a c (* b d)) (fma d d (* c c)))
         (* (/ 1.0 (hypot c d)) (+ a (* d (/ b c)))))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -3.3e+81) {
		tmp = (c / hypot(c, d)) * (a / hypot(c, d));
	} else if (c <= -2.2e-105) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (c <= 7.6e-35) {
		tmp = (-b - (a * (c / d))) / -d;
	} else if (c <= 1.36e+101) {
		tmp = fma(a, c, (b * d)) / fma(d, d, (c * c));
	} else {
		tmp = (1.0 / hypot(c, d)) * (a + (d * (b / c)));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -3.3e+81)
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d)));
	elseif (c <= -2.2e-105)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 7.6e-35)
		tmp = Float64(Float64(Float64(-b) - Float64(a * Float64(c / d))) / Float64(-d));
	elseif (c <= 1.36e+101)
		tmp = Float64(fma(a, c, Float64(b * d)) / fma(d, d, Float64(c * c)));
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(d * Float64(b / c))));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.3e+81], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.2e-105], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.6e-35], N[(N[((-b) - N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-d)), $MachinePrecision], If[LessEqual[c, 1.36e+101], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;c \leq 7.6 \cdot 10^{-35}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -3.3e81

    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 a around inf 46.3%

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

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

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

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

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

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

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

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

    if -3.3e81 < c < -2.20000000000000004e-105

    1. Initial program 89.6%

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

    if -2.20000000000000004e-105 < c < 7.6000000000000002e-35

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    if 7.6000000000000002e-35 < c < 1.35999999999999998e101

    1. Initial program 80.2%

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

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

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

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

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

    if 1.35999999999999998e101 < c

    1. Initial program 42.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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*80.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.3 \cdot 10^{+81}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 7.6 \cdot 10^{-35}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 1.36 \cdot 10^{+101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.6% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -1.15 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 7 \cdot 10^{-35}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

\mathbf{elif}\;c \leq 2.8 \cdot 10^{+103}:\\
\;\;\;\;t\_0\\

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


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

    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 a around inf 46.3%

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

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

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

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

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

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

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

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

    if -8.8000000000000005e82 < c < -1.15e-103 or 6.99999999999999992e-35 < c < 2.80000000000000008e103

    1. Initial program 85.1%

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

    if -1.15e-103 < c < 6.99999999999999992e-35

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    if 2.80000000000000008e103 < c

    1. Initial program 42.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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*80.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{+82}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.15 \cdot 10^{-103}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 7 \cdot 10^{-35}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 2.8 \cdot 10^{+103}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 81.9% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -5.5 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.25 \cdot 10^{-34}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

\mathbf{elif}\;c \leq 1.6 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 49.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.5999999999999999e83 < c < -5.50000000000000029e-105 or 1.2500000000000001e-34 < c < 1.6e104

    1. Initial program 85.1%

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

    if -5.50000000000000029e-105 < c < 1.2500000000000001e-34

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    if 1.6e104 < c

    1. Initial program 42.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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*80.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.6 \cdot 10^{+83}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{elif}\;c \leq -5.5 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-34}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{+104}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 83.1% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -3.1 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 10^{-34}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

\mathbf{elif}\;c \leq 1.66 \cdot 10^{+102}:\\
\;\;\;\;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 < -7.4999999999999999e82

    1. Initial program 49.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.4999999999999999e82 < c < -3.1000000000000001e-103 or 9.99999999999999928e-35 < c < 1.66e102

    1. Initial program 85.1%

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

    if -3.1000000000000001e-103 < c < 9.99999999999999928e-35

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    if 1.66e102 < c

    1. Initial program 42.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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*80.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+82}:\\ \;\;\;\;\left(a + d \cdot \frac{b}{c}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -3.1 \cdot 10^{-103}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 10^{-34}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 1.66 \cdot 10^{+102}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + d \cdot \frac{b}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 80.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{if}\;c \leq -4.3 \cdot 10^{+82}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -5.5 \cdot 10^{-105}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-34}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 4.4 \cdot 10^{+100}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (+ (/ a c) (* d (/ b (pow c 2.0))))))
   (if (<= c -4.3e+82)
     t_1
     (if (<= c -5.5e-105)
       t_0
       (if (<= c 1.25e-34)
         (/ (- (- b) (* a (/ c d))) (- d))
         (if (<= c 4.4e+100) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a / c) + (d * (b / pow(c, 2.0)));
	double tmp;
	if (c <= -4.3e+82) {
		tmp = t_1;
	} else if (c <= -5.5e-105) {
		tmp = t_0;
	} else if (c <= 1.25e-34) {
		tmp = (-b - (a * (c / d))) / -d;
	} else if (c <= 4.4e+100) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (a / c) + (d * (b / (c ** 2.0d0)))
    if (c <= (-4.3d+82)) then
        tmp = t_1
    else if (c <= (-5.5d-105)) then
        tmp = t_0
    else if (c <= 1.25d-34) then
        tmp = (-b - (a * (c / d))) / -d
    else if (c <= 4.4d+100) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a / c) + (d * (b / Math.pow(c, 2.0)));
	double tmp;
	if (c <= -4.3e+82) {
		tmp = t_1;
	} else if (c <= -5.5e-105) {
		tmp = t_0;
	} else if (c <= 1.25e-34) {
		tmp = (-b - (a * (c / d))) / -d;
	} else if (c <= 4.4e+100) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (a / c) + (d * (b / math.pow(c, 2.0)))
	tmp = 0
	if c <= -4.3e+82:
		tmp = t_1
	elif c <= -5.5e-105:
		tmp = t_0
	elif c <= 1.25e-34:
		tmp = (-b - (a * (c / d))) / -d
	elif c <= 4.4e+100:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(a / c) + Float64(d * Float64(b / (c ^ 2.0))))
	tmp = 0.0
	if (c <= -4.3e+82)
		tmp = t_1;
	elseif (c <= -5.5e-105)
		tmp = t_0;
	elseif (c <= 1.25e-34)
		tmp = Float64(Float64(Float64(-b) - Float64(a * Float64(c / d))) / Float64(-d));
	elseif (c <= 4.4e+100)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (a / c) + (d * (b / (c ^ 2.0)));
	tmp = 0.0;
	if (c <= -4.3e+82)
		tmp = t_1;
	elseif (c <= -5.5e-105)
		tmp = t_0;
	elseif (c <= 1.25e-34)
		tmp = (-b - (a * (c / d))) / -d;
	elseif (c <= 4.4e+100)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(d * N[(b / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.3e+82], t$95$1, If[LessEqual[c, -5.5e-105], t$95$0, If[LessEqual[c, 1.25e-34], N[(N[((-b) - N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-d)), $MachinePrecision], If[LessEqual[c, 4.4e+100], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -5.5 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.25 \cdot 10^{-34}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

\mathbf{elif}\;c \leq 4.4 \cdot 10^{+100}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.30000000000000015e82 or 4.4000000000000001e100 < c

    1. Initial program 46.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.30000000000000015e82 < c < -5.50000000000000029e-105 or 1.2500000000000001e-34 < c < 4.4000000000000001e100

    1. Initial program 85.1%

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

    if -5.50000000000000029e-105 < c < 1.2500000000000001e-34

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.3 \cdot 10^{+82}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{elif}\;c \leq -5.5 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-34}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 4.4 \cdot 10^{+100}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 79.7% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -3.9 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 6.8 \cdot 10^{-35}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

\mathbf{elif}\;c \leq 1.45 \cdot 10^{+118}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 39.9%

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

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

    if -4.50000000000000039e130 < c < -3.9000000000000002e-103 or 6.8000000000000005e-35 < c < 1.45000000000000008e118

    1. Initial program 84.6%

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

    if -3.9000000000000002e-103 < c < 6.8000000000000005e-35

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    if 1.45000000000000008e118 < c

    1. Initial program 36.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.5 \cdot 10^{+130}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -3.9 \cdot 10^{-103}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 6.8 \cdot 10^{-35}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{+118}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 79.7% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -6.2 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 6.5 \cdot 10^{-35}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

\mathbf{elif}\;c \leq 5 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 39.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.99999999999999925e125 < c < -6.2000000000000003e-103 or 6.4999999999999999e-35 < c < 4.9999999999999999e119

    1. Initial program 84.6%

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

    if -6.2000000000000003e-103 < c < 6.4999999999999999e-35

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    if 4.9999999999999999e119 < c

    1. Initial program 36.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1 \cdot 10^{+126}:\\ \;\;\;\;a \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -6.2 \cdot 10^{-103}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{-35}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 5 \cdot 10^{+119}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 79.5% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;c \leq -1.25 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.7 \cdot 10^{-34}:\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

\mathbf{elif}\;c \leq 1.1 \cdot 10^{+125}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.1e129 or 1.09999999999999995e125 < c

    1. Initial program 38.5%

      \[\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}{c}} \]

    if -1.1e129 < c < -1.24999999999999992e-103 or 1.7e-34 < c < 1.09999999999999995e125

    1. Initial program 84.6%

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

    if -1.24999999999999992e-103 < c < 1.7e-34

    1. Initial program 62.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{d}{c}}} \cdot \frac{1}{d} \]
      3. add-sqr-sqrt37.0%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{a \cdot a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      5. sqr-neg62.6%

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt63.8%

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

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

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv63.8%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv63.8%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg63.8%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg63.8%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg63.8%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div63.8%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr84.9%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/88.0%

        \[\leadsto \frac{\left(-b\right) - \color{blue}{a \cdot \frac{c}{d}}}{-d} \]
    11. Simplified88.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.1 \cdot 10^{+129}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -1.25 \cdot 10^{-103}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{-34}:\\ \;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\ \mathbf{elif}\;c \leq 1.1 \cdot 10^{+125}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 73.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5 \cdot 10^{+18}:\\
\;\;\;\;\frac{a}{c}\\

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

\mathbf{elif}\;c \leq 1.9 \cdot 10^{+104}:\\
\;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5e18 or 1.89999999999999984e104 < c

    1. Initial program 55.9%

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

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

    if -5e18 < c < 7.6000000000000002e-35

    1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

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

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

    if 7.6000000000000002e-35 < c < 1.89999999999999984e104

    1. Initial program 80.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5 \cdot 10^{+18}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 7.6 \cdot 10^{-35}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.9 \cdot 10^{+104}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 72.0% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.3 \cdot 10^{+18} \lor \neg \left(c \leq 1.9 \cdot 10^{-34}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.3e18 or 1.9000000000000001e-34 < c

    1. Initial program 61.9%

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

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

    if -2.3e18 < c < 1.9000000000000001e-34

    1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 70.0% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.5 \lor \neg \left(d \leq 4.8 \cdot 10^{-46}\right):\\
\;\;\;\;\frac{\left(-b\right) - a \cdot \frac{c}{d}}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.5 or 4.80000000000000027e-46 < d

    1. Initial program 53.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt57.9%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{-a}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      8. distribute-frac-neg57.9%

        \[\leadsto \frac{b}{d} + \color{blue}{\left(-\frac{a}{\frac{d}{c}}\right)} \cdot \frac{1}{d} \]
      9. associate-/l*56.3%

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv56.3%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv56.3%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg56.3%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg56.3%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg57.9%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div57.9%

        \[\leadsto \color{blue}{\frac{\left(-b\right) - \frac{-a}{\frac{d}{c}}}{-d}} \]
    9. Applied egg-rr79.4%

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

        \[\leadsto \frac{\left(-b\right) - \color{blue}{\frac{a \cdot c}{d}}}{-d} \]
      2. associate-*r/77.1%

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

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

    if -7.5 < d < 4.80000000000000027e-46

    1. Initial program 75.0%

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

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

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

Alternative 13: 70.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.5 \lor \neg \left(d \leq 110\right):\\
\;\;\;\;\frac{\left(-b\right) - c \cdot \frac{a}{d}}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.5 or 110 < d

    1. Initial program 52.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{\frac{d}{c}} \cdot \frac{1}{d} \]
      7. add-sqr-sqrt60.1%

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

        \[\leadsto \frac{b}{d} + \color{blue}{\left(-\frac{a}{\frac{d}{c}}\right)} \cdot \frac{1}{d} \]
      9. associate-/l*58.4%

        \[\leadsto \frac{b}{d} + \left(-\color{blue}{\frac{a \cdot c}{d}}\right) \cdot \frac{1}{d} \]
      10. cancel-sign-sub-inv58.4%

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a \cdot c}{d} \cdot \frac{1}{d}} \]
      11. div-inv58.4%

        \[\leadsto \frac{b}{d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{d}} \]
      12. frac-2neg58.4%

        \[\leadsto \color{blue}{\frac{-b}{-d}} - \frac{\frac{a \cdot c}{d}}{d} \]
      13. frac-2neg58.4%

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

        \[\leadsto \frac{-b}{-d} - \frac{-\color{blue}{\frac{a}{\frac{d}{c}}}}{-d} \]
      15. distribute-frac-neg60.1%

        \[\leadsto \frac{-b}{-d} - \frac{\color{blue}{\frac{-a}{\frac{d}{c}}}}{-d} \]
      16. sub-div60.1%

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

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

    if -6.5 < d < 110

    1. Initial program 75.2%

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

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

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

Alternative 14: 63.8% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.9999999999999994e84 or 470 < d

    1. Initial program 49.2%

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

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

    if -8.9999999999999994e84 < d < 470

    1. Initial program 75.4%

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

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

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

Alternative 15: 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 63.8%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification46.0%

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

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))