Complex division, real part

Percentage Accurate: 62.0% → 83.0%
Time: 11.8s
Alternatives: 11
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 11 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: 62.0% 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: 83.0% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\

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

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

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


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

    1. Initial program 33.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.05999999999999999e102 < c < -2.29999999999999985e-164

    1. Initial program 83.0%

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

    if -2.29999999999999985e-164 < c < 1.05e-105

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d} \cdot \left(b + \color{blue}{\frac{c}{d}} \cdot a\right) \]
    10. Applied egg-rr92.1%

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

    if 1.05e-105 < c < 6.6e78

    1. Initial program 81.5%

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

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

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

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

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

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

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

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

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

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

    if 6.6e78 < c

    1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.06 \cdot 10^{+102}:\\ \;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 6.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.3% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (/ (/ (fma b d (* a c)) (hypot c d)) (hypot c d))
   (* (/ c (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (fma(b, d, (a * c)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (c / hypot(c, d)) * (a / hypot(c, d));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(fma(b, d, Float64(a * c)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(N[(b * d + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 77.9%

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

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

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

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

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

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

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

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

        \[\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. *-commutative93.8%

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

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

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

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

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

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

    if +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.8% 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 -3.7 \cdot 10^{+59}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 3.3 \cdot 10^{-106}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{+78}:\\ \;\;\;\;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 -3.7e+59)
     t_1
     (if (<= c -2.3e-164)
       t_0
       (if (<= c 3.3e-106)
         (* (/ 1.0 d) (+ b (* a (/ c d))))
         (if (<= c 1.45e+78) 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 <= -3.7e+59) {
		tmp = t_1;
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 3.3e-106) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 1.45e+78) {
		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 <= (-3.7d+59)) then
        tmp = t_1
    else if (c <= (-2.3d-164)) then
        tmp = t_0
    else if (c <= 3.3d-106) then
        tmp = (1.0d0 / d) * (b + (a * (c / d)))
    else if (c <= 1.45d+78) 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 <= -3.7e+59) {
		tmp = t_1;
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 3.3e-106) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 1.45e+78) {
		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 <= -3.7e+59:
		tmp = t_1
	elif c <= -2.3e-164:
		tmp = t_0
	elif c <= 3.3e-106:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	elif c <= 1.45e+78:
		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 <= -3.7e+59)
		tmp = t_1;
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 3.3e-106)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	elseif (c <= 1.45e+78)
		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 <= -3.7e+59)
		tmp = t_1;
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 3.3e-106)
		tmp = (1.0 / d) * (b + (a * (c / d)));
	elseif (c <= 1.45e+78)
		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, -3.7e+59], t$95$1, If[LessEqual[c, -2.3e-164], t$95$0, If[LessEqual[c, 3.3e-106], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.45e+78], 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 -3.7 \cdot 10^{+59}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.69999999999999997e59 or 1.45000000000000008e78 < c

    1. Initial program 41.7%

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

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

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

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

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

    if -3.69999999999999997e59 < c < -2.29999999999999985e-164 or 3.30000000000000016e-106 < c < 1.45000000000000008e78

    1. Initial program 83.6%

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

    if -2.29999999999999985e-164 < c < 3.30000000000000016e-106

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d} \cdot \left(b + \color{blue}{\frac{c}{d}} \cdot a\right) \]
    10. Applied egg-rr92.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.7 \cdot 10^{+59}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.3 \cdot 10^{-106}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{+78}:\\ \;\;\;\;\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 4: 81.3% 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.05 \cdot 10^{+60}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{+78}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -1.05e+60)
     (+ (/ a c) (* d (/ b (pow c 2.0))))
     (if (<= c -2.3e-164)
       t_0
       (if (<= c 1.45e-105)
         (* (/ 1.0 d) (+ b (* a (/ c d))))
         (if (<= c 6.2e+78) t_0 (/ (+ a (/ b (/ c d))) (hypot c d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.05e+60) {
		tmp = (a / c) + (d * (b / pow(c, 2.0)));
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 1.45e-105) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 6.2e+78) {
		tmp = t_0;
	} else {
		tmp = (a + (b / (c / d))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.05e+60) {
		tmp = (a / c) + (d * (b / Math.pow(c, 2.0)));
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 1.45e-105) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 6.2e+78) {
		tmp = t_0;
	} else {
		tmp = (a + (b / (c / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.05e+60:
		tmp = (a / c) + (d * (b / math.pow(c, 2.0)))
	elif c <= -2.3e-164:
		tmp = t_0
	elif c <= 1.45e-105:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	elif c <= 6.2e+78:
		tmp = t_0
	else:
		tmp = (a + (b / (c / d))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -1.05e+60)
		tmp = Float64(Float64(a / c) + Float64(d * Float64(b / (c ^ 2.0))));
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 1.45e-105)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	elseif (c <= 6.2e+78)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -1.05e+60)
		tmp = (a / c) + (d * (b / (c ^ 2.0)));
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 1.45e-105)
		tmp = (1.0 / d) * (b + (a * (c / d)));
	elseif (c <= 6.2e+78)
		tmp = t_0;
	else
		tmp = (a + (b / (c / d))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.05e+60], N[(N[(a / c), $MachinePrecision] + N[(d * N[(b / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.3e-164], t$95$0, If[LessEqual[c, 1.45e-105], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.2e+78], t$95$0, N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 6.2 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 42.2%

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

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

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

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

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

    if -1.0500000000000001e60 < c < -2.29999999999999985e-164 or 1.45000000000000002e-105 < c < 6.2e78

    1. Initial program 83.6%

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

    if -2.29999999999999985e-164 < c < 1.45000000000000002e-105

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d} \cdot \left(b + \color{blue}{\frac{c}{d}} \cdot a\right) \]
    10. Applied egg-rr92.1%

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

    if 6.2e78 < c

    1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.05 \cdot 10^{+60}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{+78}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\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 := \frac{b}{\frac{c}{d}}\\ \mathbf{if}\;c \leq -2.2 \cdot 10^{+102}:\\ \;\;\;\;\frac{\left(-a\right) - t\_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{-106}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{+78}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + t\_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))) (t_1 (/ b (/ c d))))
   (if (<= c -2.2e+102)
     (/ (- (- a) t_1) (hypot c d))
     (if (<= c -2.3e-164)
       t_0
       (if (<= c 3.9e-106)
         (* (/ 1.0 d) (+ b (* a (/ c d))))
         (if (<= c 4.2e+78) t_0 (/ (+ a t_1) (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 t_1 = b / (c / d);
	double tmp;
	if (c <= -2.2e+102) {
		tmp = (-a - t_1) / hypot(c, d);
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 3.9e-106) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 4.2e+78) {
		tmp = t_0;
	} else {
		tmp = (a + t_1) / 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 t_1 = b / (c / d);
	double tmp;
	if (c <= -2.2e+102) {
		tmp = (-a - t_1) / Math.hypot(c, d);
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 3.9e-106) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 4.2e+78) {
		tmp = t_0;
	} else {
		tmp = (a + t_1) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = b / (c / d)
	tmp = 0
	if c <= -2.2e+102:
		tmp = (-a - t_1) / math.hypot(c, d)
	elif c <= -2.3e-164:
		tmp = t_0
	elif c <= 3.9e-106:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	elif c <= 4.2e+78:
		tmp = t_0
	else:
		tmp = (a + t_1) / 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)))
	t_1 = Float64(b / Float64(c / d))
	tmp = 0.0
	if (c <= -2.2e+102)
		tmp = Float64(Float64(Float64(-a) - t_1) / hypot(c, d));
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 3.9e-106)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	elseif (c <= 4.2e+78)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + t_1) / 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));
	t_1 = b / (c / d);
	tmp = 0.0;
	if (c <= -2.2e+102)
		tmp = (-a - t_1) / hypot(c, d);
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 3.9e-106)
		tmp = (1.0 / d) * (b + (a * (c / d)));
	elseif (c <= 4.2e+78)
		tmp = t_0;
	else
		tmp = (a + t_1) / 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]}, Block[{t$95$1 = N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.2e+102], N[(N[((-a) - t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.3e-164], t$95$0, If[LessEqual[c, 3.9e-106], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.2e+78], t$95$0, N[(N[(a + t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 4.2 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 33.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.20000000000000007e102 < c < -2.29999999999999985e-164 or 3.9000000000000001e-106 < c < 4.2000000000000002e78

    1. Initial program 82.5%

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

    if -2.29999999999999985e-164 < c < 3.9000000000000001e-106

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d} \cdot \left(b + \color{blue}{\frac{c}{d}} \cdot a\right) \]
    10. Applied egg-rr92.1%

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

    if 4.2000000000000002e78 < c

    1. Initial program 41.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.2 \cdot 10^{+102}:\\ \;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{-106}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{+78}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 79.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -2.15 \cdot 10^{+102}:\\ \;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{-105}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{+153}:\\ \;\;\;\;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 -2.15e+102)
     (/ (- a) (hypot c d))
     (if (<= c -2.3e-164)
       t_0
       (if (<= c 1.75e-105)
         (* (/ 1.0 d) (+ b (* a (/ c d))))
         (if (<= c 1.05e+153) 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 <= -2.15e+102) {
		tmp = -a / hypot(c, d);
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 1.75e-105) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 1.05e+153) {
		tmp = t_0;
	} else {
		tmp = a / 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 <= -2.15e+102) {
		tmp = -a / Math.hypot(c, d);
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 1.75e-105) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 1.05e+153) {
		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 <= -2.15e+102:
		tmp = -a / math.hypot(c, d)
	elif c <= -2.3e-164:
		tmp = t_0
	elif c <= 1.75e-105:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	elif c <= 1.05e+153:
		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 <= -2.15e+102)
		tmp = Float64(Float64(-a) / hypot(c, d));
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 1.75e-105)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	elseif (c <= 1.05e+153)
		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 <= -2.15e+102)
		tmp = -a / hypot(c, d);
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 1.75e-105)
		tmp = (1.0 / d) * (b + (a * (c / d)));
	elseif (c <= 1.05e+153)
		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, -2.15e+102], N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.3e-164], t$95$0, If[LessEqual[c, 1.75e-105], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.05e+153], 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 -2.15 \cdot 10^{+102}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.05 \cdot 10^{+153}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 33.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.15e102 < c < -2.29999999999999985e-164 or 1.75e-105 < c < 1.05000000000000008e153

    1. Initial program 81.2%

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

    if -2.29999999999999985e-164 < c < 1.75e-105

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d} \cdot \left(b + \color{blue}{\frac{c}{d}} \cdot a\right) \]
    10. Applied egg-rr92.1%

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

    if 1.05000000000000008e153 < c

    1. Initial program 29.2%

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

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

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

Alternative 7: 79.1% 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 -2.1 \cdot 10^{+102}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 3 \cdot 10^{-106}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{+151}:\\ \;\;\;\;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 -2.1e+102)
     (/ a c)
     (if (<= c -2.3e-164)
       t_0
       (if (<= c 3e-106)
         (* (/ 1.0 d) (+ b (* a (/ c d))))
         (if (<= c 9.2e+151) 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 <= -2.1e+102) {
		tmp = a / c;
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 3e-106) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 9.2e+151) {
		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 <= (-2.1d+102)) then
        tmp = a / c
    else if (c <= (-2.3d-164)) then
        tmp = t_0
    else if (c <= 3d-106) then
        tmp = (1.0d0 / d) * (b + (a * (c / d)))
    else if (c <= 9.2d+151) 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 <= -2.1e+102) {
		tmp = a / c;
	} else if (c <= -2.3e-164) {
		tmp = t_0;
	} else if (c <= 3e-106) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 9.2e+151) {
		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 <= -2.1e+102:
		tmp = a / c
	elif c <= -2.3e-164:
		tmp = t_0
	elif c <= 3e-106:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	elif c <= 9.2e+151:
		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 <= -2.1e+102)
		tmp = Float64(a / c);
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 3e-106)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	elseif (c <= 9.2e+151)
		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 <= -2.1e+102)
		tmp = a / c;
	elseif (c <= -2.3e-164)
		tmp = t_0;
	elseif (c <= 3e-106)
		tmp = (1.0 / d) * (b + (a * (c / d)));
	elseif (c <= 9.2e+151)
		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, -2.1e+102], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.3e-164], t$95$0, If[LessEqual[c, 3e-106], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.2e+151], 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 -2.1 \cdot 10^{+102}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 9.2 \cdot 10^{+151}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.10000000000000001e102 or 9.2000000000000003e151 < c

    1. Initial program 31.4%

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

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

    if -2.10000000000000001e102 < c < -2.29999999999999985e-164 or 3.00000000000000019e-106 < c < 9.2000000000000003e151

    1. Initial program 81.2%

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

    if -2.29999999999999985e-164 < c < 3.00000000000000019e-106

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d} \cdot \left(b + \color{blue}{\frac{c}{d}} \cdot a\right) \]
    10. Applied egg-rr92.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.1 \cdot 10^{+102}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-164}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{-106}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{+151}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 70.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{if}\;c \leq -1.35 \cdot 10^{-27}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 6 \cdot 10^{-101}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{+42}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{+77}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ 1.0 d) (+ b (* a (/ c d))))))
   (if (<= c -1.35e-27)
     (/ a c)
     (if (<= c 6e-101)
       t_0
       (if (<= c 8.6e+42)
         (/ (* a c) (+ (* c c) (* d d)))
         (if (<= c 2.1e+77) t_0 (/ a c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (1.0 / d) * (b + (a * (c / d)));
	double tmp;
	if (c <= -1.35e-27) {
		tmp = a / c;
	} else if (c <= 6e-101) {
		tmp = t_0;
	} else if (c <= 8.6e+42) {
		tmp = (a * c) / ((c * c) + (d * d));
	} else if (c <= 2.1e+77) {
		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 = (1.0d0 / d) * (b + (a * (c / d)))
    if (c <= (-1.35d-27)) then
        tmp = a / c
    else if (c <= 6d-101) then
        tmp = t_0
    else if (c <= 8.6d+42) then
        tmp = (a * c) / ((c * c) + (d * d))
    else if (c <= 2.1d+77) 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 = (1.0 / d) * (b + (a * (c / d)));
	double tmp;
	if (c <= -1.35e-27) {
		tmp = a / c;
	} else if (c <= 6e-101) {
		tmp = t_0;
	} else if (c <= 8.6e+42) {
		tmp = (a * c) / ((c * c) + (d * d));
	} else if (c <= 2.1e+77) {
		tmp = t_0;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (1.0 / d) * (b + (a * (c / d)))
	tmp = 0
	if c <= -1.35e-27:
		tmp = a / c
	elif c <= 6e-101:
		tmp = t_0
	elif c <= 8.6e+42:
		tmp = (a * c) / ((c * c) + (d * d))
	elif c <= 2.1e+77:
		tmp = t_0
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))))
	tmp = 0.0
	if (c <= -1.35e-27)
		tmp = Float64(a / c);
	elseif (c <= 6e-101)
		tmp = t_0;
	elseif (c <= 8.6e+42)
		tmp = Float64(Float64(a * c) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 2.1e+77)
		tmp = t_0;
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (1.0 / d) * (b + (a * (c / d)));
	tmp = 0.0;
	if (c <= -1.35e-27)
		tmp = a / c;
	elseif (c <= 6e-101)
		tmp = t_0;
	elseif (c <= 8.6e+42)
		tmp = (a * c) / ((c * c) + (d * d));
	elseif (c <= 2.1e+77)
		tmp = t_0;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.35e-27], N[(a / c), $MachinePrecision], If[LessEqual[c, 6e-101], t$95$0, If[LessEqual[c, 8.6e+42], N[(N[(a * c), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.1e+77], t$95$0, N[(a / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq 6 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 2.1 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.34999999999999994e-27 or 2.0999999999999999e77 < c

    1. Initial program 47.8%

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

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

    if -1.34999999999999994e-27 < c < 6.0000000000000006e-101 or 8.5999999999999996e42 < c < 2.0999999999999999e77

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.0000000000000006e-101 < c < 8.5999999999999996e42

    1. Initial program 85.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.35 \cdot 10^{-27}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 6 \cdot 10^{-101}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{+42}:\\ \;\;\;\;\frac{a \cdot c}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{+77}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 71.3% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{-32} \lor \neg \left(c \leq 2.65 \cdot 10^{+78}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.50000000000000024e-32 or 2.64999999999999981e78 < c

    1. Initial program 47.8%

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

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

    if -5.50000000000000024e-32 < c < 2.64999999999999981e78

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 62.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.7 \cdot 10^{-27} \lor \neg \left(c \leq 2.05 \cdot 10^{+77}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.69999999999999989e-27 or 2.05e77 < c

    1. Initial program 47.8%

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

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

    if -2.69999999999999989e-27 < c < 2.05e77

    1. Initial program 74.4%

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

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

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

Alternative 11: 42.2% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification43.1%

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

Developer target: 99.4% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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