Complex division, real part

Percentage Accurate: 61.8% → 77.7%
Time: 11.2s
Alternatives: 9
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 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 61.8% 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: 77.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -1.7 \cdot 10^{+93}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -7.6 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 5.6 \cdot 10^{-160}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{+147}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq 2 \cdot 10^{+166}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\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
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -1.7e+93)
     (/ (- (/ (- b) (/ c d)) a) (hypot c d))
     (if (<= c -7.6e-142)
       t_0
       (if (<= c 5.6e-160)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 7.2e-43)
           t_0
           (if (<= c 2.7e+147)
             (+ (/ b d) (* (/ c d) (/ a d)))
             (if (<= c 2e+166)
               (/ (+ a (/ b (/ c d))) (hypot c d))
               (* (/ c (hypot c d)) (/ a (hypot c d)))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.7e+93) {
		tmp = ((-b / (c / d)) - a) / hypot(c, d);
	} else if (c <= -7.6e-142) {
		tmp = t_0;
	} else if (c <= 5.6e-160) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 7.2e-43) {
		tmp = t_0;
	} else if (c <= 2.7e+147) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= 2e+166) {
		tmp = (a + (b / (c / d))) / hypot(c, d);
	} else {
		tmp = (c / hypot(c, d)) * (a / hypot(c, d));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.7e+93) {
		tmp = ((-b / (c / d)) - a) / Math.hypot(c, d);
	} else if (c <= -7.6e-142) {
		tmp = t_0;
	} else if (c <= 5.6e-160) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 7.2e-43) {
		tmp = t_0;
	} else if (c <= 2.7e+147) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= 2e+166) {
		tmp = (a + (b / (c / d))) / Math.hypot(c, d);
	} else {
		tmp = (c / Math.hypot(c, d)) * (a / Math.hypot(c, d));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.7e+93:
		tmp = ((-b / (c / d)) - a) / math.hypot(c, d)
	elif c <= -7.6e-142:
		tmp = t_0
	elif c <= 5.6e-160:
		tmp = (b / d) + (a / (d * (d / c)))
	elif c <= 7.2e-43:
		tmp = t_0
	elif c <= 2.7e+147:
		tmp = (b / d) + ((c / d) * (a / d))
	elif c <= 2e+166:
		tmp = (a + (b / (c / d))) / math.hypot(c, d)
	else:
		tmp = (c / math.hypot(c, d)) * (a / math.hypot(c, d))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -1.7e+93)
		tmp = Float64(Float64(Float64(Float64(-b) / Float64(c / d)) - a) / hypot(c, d));
	elseif (c <= -7.6e-142)
		tmp = t_0;
	elseif (c <= 5.6e-160)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 7.2e-43)
		tmp = t_0;
	elseif (c <= 2.7e+147)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	elseif (c <= 2e+166)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / hypot(c, d));
	else
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -1.7e+93)
		tmp = ((-b / (c / d)) - a) / hypot(c, d);
	elseif (c <= -7.6e-142)
		tmp = t_0;
	elseif (c <= 5.6e-160)
		tmp = (b / d) + (a / (d * (d / c)));
	elseif (c <= 7.2e-43)
		tmp = t_0;
	elseif (c <= 2.7e+147)
		tmp = (b / d) + ((c / d) * (a / d));
	elseif (c <= 2e+166)
		tmp = (a + (b / (c / d))) / hypot(c, d);
	else
		tmp = (c / hypot(c, d)) * (a / hypot(c, d));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.7e+93], N[(N[(N[((-b) / N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -7.6e-142], t$95$0, If[LessEqual[c, 5.6e-160], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.2e-43], t$95$0, If[LessEqual[c, 2.7e+147], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2e+166], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $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}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -1.7 \cdot 10^{+93}:\\
\;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -7.6 \cdot 10^{-142}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 7.2 \cdot 10^{-43}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 2 \cdot 10^{+166}:\\
\;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\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 6 regimes
  2. if c < -1.7e93

    1. Initial program 29.6%

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

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

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

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

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

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

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

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

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

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

      \[\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. neg-mul-180.8%

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

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

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

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

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

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

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

    if -1.7e93 < c < -7.59999999999999944e-142 or 5.60000000000000032e-160 < c < 7.1999999999999998e-43

    1. Initial program 85.5%

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

    if -7.59999999999999944e-142 < c < 5.60000000000000032e-160

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{\frac{c}{d}}}} \]
    10. Step-by-step derivation
      1. associate-/r/93.1%

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

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

    if 7.1999999999999998e-43 < c < 2.69999999999999998e147

    1. Initial program 52.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.69999999999999998e147 < c < 1.99999999999999988e166

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt26.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-frac26.1%

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

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

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

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

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

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

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

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

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

    if 1.99999999999999988e166 < c

    1. Initial program 27.6%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.7 \cdot 10^{+93}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -7.6 \cdot 10^{-142}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 5.6 \cdot 10^{-160}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{-43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{+147}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq 2 \cdot 10^{+166}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\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 2: 85.1% 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(a, c, b \cdot d\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 a c (* b d)) (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(a, c, (b * d)) / 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(a, c, Float64(b * d)) / 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[(a * c + N[(b * d), $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(a, c, b \cdot d\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.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-identity77.5%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt77.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-frac77.6%

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

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

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

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

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

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

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

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

    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.7%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}} \]
    7. Applied egg-rr55.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 simplification84.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(a, c, b \cdot d\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: 81.4% 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.55 \cdot 10^{+94}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq -1.25 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.52 \cdot 10^{-158}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{+23}:\\ \;\;\;\;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 -2.55e+94)
     (+ (/ a c) (/ b (* c (/ c d))))
     (if (<= c -1.25e-142)
       t_0
       (if (<= c 1.52e-158)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 8.6e+23) 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 <= -2.55e+94) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (c <= -1.25e-142) {
		tmp = t_0;
	} else if (c <= 1.52e-158) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 8.6e+23) {
		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 <= -2.55e+94) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (c <= -1.25e-142) {
		tmp = t_0;
	} else if (c <= 1.52e-158) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 8.6e+23) {
		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 <= -2.55e+94:
		tmp = (a / c) + (b / (c * (c / d)))
	elif c <= -1.25e-142:
		tmp = t_0
	elif c <= 1.52e-158:
		tmp = (b / d) + (a / (d * (d / c)))
	elif c <= 8.6e+23:
		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 <= -2.55e+94)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (c <= -1.25e-142)
		tmp = t_0;
	elseif (c <= 1.52e-158)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 8.6e+23)
		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 <= -2.55e+94)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (c <= -1.25e-142)
		tmp = t_0;
	elseif (c <= 1.52e-158)
		tmp = (b / d) + (a / (d * (d / c)));
	elseif (c <= 8.6e+23)
		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, -2.55e+94], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.25e-142], t$95$0, If[LessEqual[c, 1.52e-158], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.6e+23], 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 -2.55 \cdot 10^{+94}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\

\mathbf{elif}\;c \leq -1.25 \cdot 10^{-142}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 8.6 \cdot 10^{+23}:\\
\;\;\;\;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 < -2.5500000000000002e94

    1. Initial program 29.6%

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

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

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

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

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

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

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

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

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

    if -2.5500000000000002e94 < c < -1.2500000000000001e-142 or 1.52e-158 < c < 8.5999999999999997e23

    1. Initial program 82.2%

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

    if -1.2500000000000001e-142 < c < 1.52e-158

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{\frac{c}{d}}}} \]
    10. Step-by-step derivation
      1. associate-/r/93.1%

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

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

    if 8.5999999999999997e23 < c

    1. Initial program 35.5%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt35.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-frac35.5%

        \[\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-def35.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-def35.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-def51.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-rr51.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. associate-*l/51.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.55 \cdot 10^{+94}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq -1.25 \cdot 10^{-142}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.52 \cdot 10^{-158}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{+23}:\\ \;\;\;\;\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 4: 82.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -1.9 \cdot 10^{+93}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -7.5 \cdot 10^{-140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.5 \cdot 10^{-158}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 8.8 \cdot 10^{+23}:\\ \;\;\;\;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.9e+93)
     (/ (- (/ (- b) (/ c d)) a) (hypot c d))
     (if (<= c -7.5e-140)
       t_0
       (if (<= c 3.5e-158)
         (+ (/ b d) (/ a (* d (/ d c))))
         (if (<= c 8.8e+23) 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.9e+93) {
		tmp = ((-b / (c / d)) - a) / hypot(c, d);
	} else if (c <= -7.5e-140) {
		tmp = t_0;
	} else if (c <= 3.5e-158) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 8.8e+23) {
		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.9e+93) {
		tmp = ((-b / (c / d)) - a) / Math.hypot(c, d);
	} else if (c <= -7.5e-140) {
		tmp = t_0;
	} else if (c <= 3.5e-158) {
		tmp = (b / d) + (a / (d * (d / c)));
	} else if (c <= 8.8e+23) {
		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.9e+93:
		tmp = ((-b / (c / d)) - a) / math.hypot(c, d)
	elif c <= -7.5e-140:
		tmp = t_0
	elif c <= 3.5e-158:
		tmp = (b / d) + (a / (d * (d / c)))
	elif c <= 8.8e+23:
		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.9e+93)
		tmp = Float64(Float64(Float64(Float64(-b) / Float64(c / d)) - a) / hypot(c, d));
	elseif (c <= -7.5e-140)
		tmp = t_0;
	elseif (c <= 3.5e-158)
		tmp = Float64(Float64(b / d) + Float64(a / Float64(d * Float64(d / c))));
	elseif (c <= 8.8e+23)
		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.9e+93)
		tmp = ((-b / (c / d)) - a) / hypot(c, d);
	elseif (c <= -7.5e-140)
		tmp = t_0;
	elseif (c <= 3.5e-158)
		tmp = (b / d) + (a / (d * (d / c)));
	elseif (c <= 8.8e+23)
		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.9e+93], N[(N[(N[((-b) / N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -7.5e-140], t$95$0, If[LessEqual[c, 3.5e-158], N[(N[(b / d), $MachinePrecision] + N[(a / N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.8e+23], 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.9 \cdot 10^{+93}:\\
\;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -7.5 \cdot 10^{-140}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 8.8 \cdot 10^{+23}:\\
\;\;\;\;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.8999999999999999e93

    1. Initial program 29.6%

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

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

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

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

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

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

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

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

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

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

      \[\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. neg-mul-180.8%

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

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

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

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

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

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

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

    if -1.8999999999999999e93 < c < -7.4999999999999998e-140 or 3.50000000000000012e-158 < c < 8.80000000000000034e23

    1. Initial program 82.2%

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

    if -7.4999999999999998e-140 < c < 3.50000000000000012e-158

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{\frac{c}{d}}}} \]
    10. Step-by-step derivation
      1. associate-/r/93.1%

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

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

    if 8.80000000000000034e23 < c

    1. Initial program 35.5%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt35.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-frac35.5%

        \[\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-def35.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-def35.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-def51.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-rr51.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. associate-*l/51.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.9 \cdot 10^{+93}:\\ \;\;\;\;\frac{\frac{-b}{\frac{c}{d}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -7.5 \cdot 10^{-140}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.5 \cdot 10^{-158}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d \cdot \frac{d}{c}}\\ \mathbf{elif}\;c \leq 8.8 \cdot 10^{+23}:\\ \;\;\;\;\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: 82.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{if}\;d \leq -5.5 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-128}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{-106}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{+110}:\\ \;\;\;\;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 (+ (/ b d) (* (/ c d) (/ a d)))))
   (if (<= d -5.5e+64)
     t_1
     (if (<= d -2.5e-128)
       t_0
       (if (<= d 3.9e-106)
         (+ (/ a c) (/ b (* c (/ c d))))
         (if (<= d 4.2e+110) 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 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -5.5e+64) {
		tmp = t_1;
	} else if (d <= -2.5e-128) {
		tmp = t_0;
	} else if (d <= 3.9e-106) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 4.2e+110) {
		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 = (b / d) + ((c / d) * (a / d))
    if (d <= (-5.5d+64)) then
        tmp = t_1
    else if (d <= (-2.5d-128)) then
        tmp = t_0
    else if (d <= 3.9d-106) then
        tmp = (a / c) + (b / (c * (c / d)))
    else if (d <= 4.2d+110) 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 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -5.5e+64) {
		tmp = t_1;
	} else if (d <= -2.5e-128) {
		tmp = t_0;
	} else if (d <= 3.9e-106) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 4.2e+110) {
		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 = (b / d) + ((c / d) * (a / d))
	tmp = 0
	if d <= -5.5e+64:
		tmp = t_1
	elif d <= -2.5e-128:
		tmp = t_0
	elif d <= 3.9e-106:
		tmp = (a / c) + (b / (c * (c / d)))
	elif d <= 4.2e+110:
		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(b / d) + Float64(Float64(c / d) * Float64(a / d)))
	tmp = 0.0
	if (d <= -5.5e+64)
		tmp = t_1;
	elseif (d <= -2.5e-128)
		tmp = t_0;
	elseif (d <= 3.9e-106)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (d <= 4.2e+110)
		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 = (b / d) + ((c / d) * (a / d));
	tmp = 0.0;
	if (d <= -5.5e+64)
		tmp = t_1;
	elseif (d <= -2.5e-128)
		tmp = t_0;
	elseif (d <= 3.9e-106)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (d <= 4.2e+110)
		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[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.5e+64], t$95$1, If[LessEqual[d, -2.5e-128], t$95$0, If[LessEqual[d, 3.9e-106], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+110], 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{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -5.5 \cdot 10^{+64}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq -2.5 \cdot 10^{-128}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 4.2 \cdot 10^{+110}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.4999999999999996e64 or 4.2000000000000003e110 < d

    1. Initial program 28.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.4999999999999996e64 < d < -2.5000000000000001e-128 or 3.9000000000000001e-106 < d < 4.2000000000000003e110

    1. Initial program 82.2%

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

    if -2.5000000000000001e-128 < d < 3.9000000000000001e-106

    1. Initial program 66.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.5 \cdot 10^{+64}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-128}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{-106}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{+110}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 70.4% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.6499999999999999e-19 or 1.0500000000000001e-9 < d

    1. Initial program 42.5%

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

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

    if -1.6499999999999999e-19 < d < 1.0500000000000001e-9

    1. Initial program 72.2%

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

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

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

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

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

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

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

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

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

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

Alternative 7: 76.1% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.50000000000000015e-19 or 6e-10 < d

    1. Initial program 42.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.50000000000000015e-19 < d < 6e-10

    1. Initial program 72.2%

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

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

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

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

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

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

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

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

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

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

Alternative 8: 63.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.6 \cdot 10^{-30} \lor \neg \left(d \leq 2.1 \cdot 10^{-75}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.6e-30 or 2.1000000000000001e-75 < d

    1. Initial program 47.0%

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

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

    if -1.6e-30 < d < 2.1000000000000001e-75

    1. Initial program 69.6%

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

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

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

Alternative 9: 42.9% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification44.6%

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