Complex division, real part

Percentage Accurate: 62.5% → 86.1%
Time: 9.3s
Alternatives: 11
Speedup: 0.8×

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

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

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

Alternative 1: 86.1% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+278}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+279}:\\ \;\;\;\;\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= t_0 -2e+278)
     (/ (+ a (* b (/ d c))) c)
     (if (<= t_0 2e+279)
       (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
       (/ (+ b (* a (/ c d))) d)))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (t_0 <= -2e+278) {
		tmp = (a + (b * (d / c))) / c;
	} else if (t_0 <= 2e+279) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (b + (a * (c / d))) / 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 (t_0 <= -2e+278)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	elseif (t_0 <= 2e+279)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	end
	return 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[t$95$0, -2e+278], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[t$95$0, 2e+279], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+279}:\\
\;\;\;\;\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)}\\

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


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

    1. Initial program 38.6%

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

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

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

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

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

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

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

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

    if -1.99999999999999993e278 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.00000000000000012e279

    1. Initial program 82.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-identity82.9%

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

        \[\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-define82.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-define99.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-rr99.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)}} \]

    if 2.00000000000000012e279 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 11.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq -2 \cdot 10^{+278}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+279}:\\ \;\;\;\;\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 84.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := a \cdot \frac{c}{d}\\ \mathbf{if}\;d \leq -3.6 \cdot 10^{+113}:\\ \;\;\;\;\frac{b + t\_1}{d}\\ \mathbf{elif}\;d \leq -9 \cdot 10^{-101}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-129}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 8.7 \cdot 10^{+89}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \left(\left(t\_1 - a \cdot {\left(\frac{c}{d}\right)}^{3}\right) - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\ \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))))
   (if (<= d -3.6e+113)
     (/ (+ b t_1) d)
     (if (<= d -9e-101)
       t_0
       (if (<= d 1.5e-129)
         (/ (+ a (* b (/ d c))) c)
         (if (<= d 8.7e+89)
           t_0
           (/
            (+ b (- (- t_1 (* a (pow (/ c d) 3.0))) (* b (pow (/ c d) 2.0))))
            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 = a * (c / d);
	double tmp;
	if (d <= -3.6e+113) {
		tmp = (b + t_1) / d;
	} else if (d <= -9e-101) {
		tmp = t_0;
	} else if (d <= 1.5e-129) {
		tmp = (a + (b * (d / c))) / c;
	} else if (d <= 8.7e+89) {
		tmp = t_0;
	} else {
		tmp = (b + ((t_1 - (a * pow((c / d), 3.0))) - (b * pow((c / d), 2.0)))) / 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = a * (c / d)
    if (d <= (-3.6d+113)) then
        tmp = (b + t_1) / d
    else if (d <= (-9d-101)) then
        tmp = t_0
    else if (d <= 1.5d-129) then
        tmp = (a + (b * (d / c))) / c
    else if (d <= 8.7d+89) then
        tmp = t_0
    else
        tmp = (b + ((t_1 - (a * ((c / d) ** 3.0d0))) - (b * ((c / d) ** 2.0d0)))) / d
    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);
	double tmp;
	if (d <= -3.6e+113) {
		tmp = (b + t_1) / d;
	} else if (d <= -9e-101) {
		tmp = t_0;
	} else if (d <= 1.5e-129) {
		tmp = (a + (b * (d / c))) / c;
	} else if (d <= 8.7e+89) {
		tmp = t_0;
	} else {
		tmp = (b + ((t_1 - (a * Math.pow((c / d), 3.0))) - (b * Math.pow((c / d), 2.0)))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = a * (c / d)
	tmp = 0
	if d <= -3.6e+113:
		tmp = (b + t_1) / d
	elif d <= -9e-101:
		tmp = t_0
	elif d <= 1.5e-129:
		tmp = (a + (b * (d / c))) / c
	elif d <= 8.7e+89:
		tmp = t_0
	else:
		tmp = (b + ((t_1 - (a * math.pow((c / d), 3.0))) - (b * math.pow((c / d), 2.0)))) / 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(a * Float64(c / d))
	tmp = 0.0
	if (d <= -3.6e+113)
		tmp = Float64(Float64(b + t_1) / d);
	elseif (d <= -9e-101)
		tmp = t_0;
	elseif (d <= 1.5e-129)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	elseif (d <= 8.7e+89)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(Float64(t_1 - Float64(a * (Float64(c / d) ^ 3.0))) - Float64(b * (Float64(c / d) ^ 2.0)))) / 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 = a * (c / d);
	tmp = 0.0;
	if (d <= -3.6e+113)
		tmp = (b + t_1) / d;
	elseif (d <= -9e-101)
		tmp = t_0;
	elseif (d <= 1.5e-129)
		tmp = (a + (b * (d / c))) / c;
	elseif (d <= 8.7e+89)
		tmp = t_0;
	else
		tmp = (b + ((t_1 - (a * ((c / d) ^ 3.0))) - (b * ((c / d) ^ 2.0)))) / 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[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.6e+113], N[(N[(b + t$95$1), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -9e-101], t$95$0, If[LessEqual[d, 1.5e-129], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 8.7e+89], t$95$0, N[(N[(b + N[(N[(t$95$1 - N[(a * N[Power[N[(c / d), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(b * N[Power[N[(c / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -9 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 8.7 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{b + \left(\left(t\_1 - a \cdot {\left(\frac{c}{d}\right)}^{3}\right) - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\


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

    1. Initial program 26.9%

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

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

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

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

    if -3.59999999999999992e113 < d < -8.9999999999999997e-101 or 1.4999999999999999e-129 < d < 8.70000000000000019e89

    1. Initial program 87.8%

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

    if -8.9999999999999997e-101 < d < 1.4999999999999999e-129

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

    if 8.70000000000000019e89 < d

    1. Initial program 27.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-identity27.5%

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+113}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -9 \cdot 10^{-101}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-129}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 8.7 \cdot 10^{+89}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \left(\left(a \cdot \frac{c}{d} - a \cdot {\left(\frac{c}{d}\right)}^{3}\right) - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 84.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}\;d \leq -8.2 \cdot 10^{+118}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -4.7 \cdot 10^{-101}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{-131}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{+70}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
       (if (<= d -8.2e+118)
         (/ (+ b (* a (/ c d))) d)
         (if (<= d -4.7e-101)
           t_0
           (if (<= d 1.85e-131)
             (/ (+ a (* b (/ d c))) c)
             (if (<= d 1.5e+70) t_0 (/ (+ b (/ a (/ 1.0 (/ c d)))) 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 (d <= -8.2e+118) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= -4.7e-101) {
    		tmp = t_0;
    	} else if (d <= 1.85e-131) {
    		tmp = (a + (b * (d / c))) / c;
    	} else if (d <= 1.5e+70) {
    		tmp = t_0;
    	} else {
    		tmp = (b + (a / (1.0 / (c / d)))) / d;
    	}
    	return tmp;
    }
    
    real(8) function code(a, b, c, d)
        real(8), intent (in) :: a
        real(8), intent (in) :: b
        real(8), intent (in) :: c
        real(8), intent (in) :: d
        real(8) :: t_0
        real(8) :: tmp
        t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
        if (d <= (-8.2d+118)) then
            tmp = (b + (a * (c / d))) / d
        else if (d <= (-4.7d-101)) then
            tmp = t_0
        else if (d <= 1.85d-131) then
            tmp = (a + (b * (d / c))) / c
        else if (d <= 1.5d+70) then
            tmp = t_0
        else
            tmp = (b + (a / (1.0d0 / (c / d)))) / d
        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 (d <= -8.2e+118) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= -4.7e-101) {
    		tmp = t_0;
    	} else if (d <= 1.85e-131) {
    		tmp = (a + (b * (d / c))) / c;
    	} else if (d <= 1.5e+70) {
    		tmp = t_0;
    	} else {
    		tmp = (b + (a / (1.0 / (c / d)))) / d;
    	}
    	return tmp;
    }
    
    def code(a, b, c, d):
    	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    	tmp = 0
    	if d <= -8.2e+118:
    		tmp = (b + (a * (c / d))) / d
    	elif d <= -4.7e-101:
    		tmp = t_0
    	elif d <= 1.85e-131:
    		tmp = (a + (b * (d / c))) / c
    	elif d <= 1.5e+70:
    		tmp = t_0
    	else:
    		tmp = (b + (a / (1.0 / (c / d)))) / 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 (d <= -8.2e+118)
    		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
    	elseif (d <= -4.7e-101)
    		tmp = t_0;
    	elseif (d <= 1.85e-131)
    		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
    	elseif (d <= 1.5e+70)
    		tmp = t_0;
    	else
    		tmp = Float64(Float64(b + Float64(a / Float64(1.0 / Float64(c / d)))) / 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 (d <= -8.2e+118)
    		tmp = (b + (a * (c / d))) / d;
    	elseif (d <= -4.7e-101)
    		tmp = t_0;
    	elseif (d <= 1.85e-131)
    		tmp = (a + (b * (d / c))) / c;
    	elseif (d <= 1.5e+70)
    		tmp = t_0;
    	else
    		tmp = (b + (a / (1.0 / (c / d)))) / 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[d, -8.2e+118], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -4.7e-101], t$95$0, If[LessEqual[d, 1.85e-131], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.5e+70], t$95$0, N[(N[(b + N[(a / N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
    \mathbf{if}\;d \leq -8.2 \cdot 10^{+118}:\\
    \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
    
    \mathbf{elif}\;d \leq -4.7 \cdot 10^{-101}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;d \leq 1.85 \cdot 10^{-131}:\\
    \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
    
    \mathbf{elif}\;d \leq 1.5 \cdot 10^{+70}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if d < -8.1999999999999994e118

      1. Initial program 26.9%

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

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

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

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

      if -8.1999999999999994e118 < d < -4.6999999999999999e-101 or 1.8500000000000001e-131 < d < 1.49999999999999988e70

      1. Initial program 88.8%

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

      if -4.6999999999999999e-101 < d < 1.8500000000000001e-131

      1. Initial program 72.5%

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

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

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

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

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

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

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

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

      if 1.49999999999999988e70 < d

      1. Initial program 27.0%

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

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

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

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

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

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

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

          \[\leadsto \frac{b + \frac{a}{\color{blue}{\frac{1}{\frac{c}{d}}}}}{d} \]
        2. inv-pow86.8%

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

        \[\leadsto \frac{b + \frac{a}{\color{blue}{{\left(\frac{c}{d}\right)}^{-1}}}}{d} \]
      10. Step-by-step derivation
        1. unpow-186.8%

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.2 \cdot 10^{+118}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -4.7 \cdot 10^{-101}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{-131}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{+70}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 4: 76.9% accurate, 0.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{-76}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+47}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (if (<= d -4.5e-98)
       (/ (+ b (* a (/ c d))) d)
       (if (<= d 2.5e-76)
         (/ (+ a (* b (/ d c))) c)
         (if (<= d 3.6e+47)
           (/ (* b d) (+ (* c c) (* d d)))
           (/ (+ b (/ a (/ 1.0 (/ c d)))) d)))))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -4.5e-98) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 2.5e-76) {
    		tmp = (a + (b * (d / c))) / c;
    	} else if (d <= 3.6e+47) {
    		tmp = (b * d) / ((c * c) + (d * d));
    	} else {
    		tmp = (b + (a / (1.0 / (c / d)))) / d;
    	}
    	return tmp;
    }
    
    real(8) function code(a, b, c, d)
        real(8), intent (in) :: a
        real(8), intent (in) :: b
        real(8), intent (in) :: c
        real(8), intent (in) :: d
        real(8) :: tmp
        if (d <= (-4.5d-98)) then
            tmp = (b + (a * (c / d))) / d
        else if (d <= 2.5d-76) then
            tmp = (a + (b * (d / c))) / c
        else if (d <= 3.6d+47) then
            tmp = (b * d) / ((c * c) + (d * d))
        else
            tmp = (b + (a / (1.0d0 / (c / d)))) / d
        end if
        code = tmp
    end function
    
    public static double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -4.5e-98) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 2.5e-76) {
    		tmp = (a + (b * (d / c))) / c;
    	} else if (d <= 3.6e+47) {
    		tmp = (b * d) / ((c * c) + (d * d));
    	} else {
    		tmp = (b + (a / (1.0 / (c / d)))) / d;
    	}
    	return tmp;
    }
    
    def code(a, b, c, d):
    	tmp = 0
    	if d <= -4.5e-98:
    		tmp = (b + (a * (c / d))) / d
    	elif d <= 2.5e-76:
    		tmp = (a + (b * (d / c))) / c
    	elif d <= 3.6e+47:
    		tmp = (b * d) / ((c * c) + (d * d))
    	else:
    		tmp = (b + (a / (1.0 / (c / d)))) / d
    	return tmp
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if (d <= -4.5e-98)
    		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
    	elseif (d <= 2.5e-76)
    		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
    	elseif (d <= 3.6e+47)
    		tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d)));
    	else
    		tmp = Float64(Float64(b + Float64(a / Float64(1.0 / Float64(c / d)))) / d);
    	end
    	return tmp
    end
    
    function tmp_2 = code(a, b, c, d)
    	tmp = 0.0;
    	if (d <= -4.5e-98)
    		tmp = (b + (a * (c / d))) / d;
    	elseif (d <= 2.5e-76)
    		tmp = (a + (b * (d / c))) / c;
    	elseif (d <= 3.6e+47)
    		tmp = (b * d) / ((c * c) + (d * d));
    	else
    		tmp = (b + (a / (1.0 / (c / d)))) / d;
    	end
    	tmp_2 = tmp;
    end
    
    code[a_, b_, c_, d_] := If[LessEqual[d, -4.5e-98], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.5e-76], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.6e+47], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\
    \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
    
    \mathbf{elif}\;d \leq 2.5 \cdot 10^{-76}:\\
    \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
    
    \mathbf{elif}\;d \leq 3.6 \cdot 10^{+47}:\\
    \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if d < -4.49999999999999997e-98

      1. Initial program 61.2%

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

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

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

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

      if -4.49999999999999997e-98 < d < 2.4999999999999999e-76

      1. Initial program 74.0%

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

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

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

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

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c} \]
      5. Simplified87.9%

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

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

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

      if 2.4999999999999999e-76 < d < 3.60000000000000008e47

      1. Initial program 84.4%

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

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

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

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

      if 3.60000000000000008e47 < d

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

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

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

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

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

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

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

          \[\leadsto \frac{b + \frac{a}{\color{blue}{\frac{1}{\frac{c}{d}}}}}{d} \]
        2. inv-pow85.6%

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

        \[\leadsto \frac{b + \frac{a}{\color{blue}{{\left(\frac{c}{d}\right)}^{-1}}}}{d} \]
      10. Step-by-step derivation
        1. unpow-185.6%

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{-76}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+47}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{1}{\frac{c}{d}}}}{d}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 5: 76.9% accurate, 0.6× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{-77}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 10^{+48}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (if (<= d -4.5e-98)
       (/ (+ b (* a (/ c d))) d)
       (if (<= d 1.55e-77)
         (/ (+ a (* b (/ d c))) c)
         (if (<= d 1e+48)
           (/ (* b d) (+ (* c c) (* d d)))
           (/ (+ b (/ a (/ d c))) d)))))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -4.5e-98) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 1.55e-77) {
    		tmp = (a + (b * (d / c))) / c;
    	} else if (d <= 1e+48) {
    		tmp = (b * d) / ((c * c) + (d * d));
    	} else {
    		tmp = (b + (a / (d / 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 <= (-4.5d-98)) then
            tmp = (b + (a * (c / d))) / d
        else if (d <= 1.55d-77) then
            tmp = (a + (b * (d / c))) / c
        else if (d <= 1d+48) then
            tmp = (b * d) / ((c * c) + (d * d))
        else
            tmp = (b + (a / (d / c))) / d
        end if
        code = tmp
    end function
    
    public static double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -4.5e-98) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 1.55e-77) {
    		tmp = (a + (b * (d / c))) / c;
    	} else if (d <= 1e+48) {
    		tmp = (b * d) / ((c * c) + (d * d));
    	} else {
    		tmp = (b + (a / (d / c))) / d;
    	}
    	return tmp;
    }
    
    def code(a, b, c, d):
    	tmp = 0
    	if d <= -4.5e-98:
    		tmp = (b + (a * (c / d))) / d
    	elif d <= 1.55e-77:
    		tmp = (a + (b * (d / c))) / c
    	elif d <= 1e+48:
    		tmp = (b * d) / ((c * c) + (d * d))
    	else:
    		tmp = (b + (a / (d / c))) / d
    	return tmp
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if (d <= -4.5e-98)
    		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
    	elseif (d <= 1.55e-77)
    		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
    	elseif (d <= 1e+48)
    		tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d)));
    	else
    		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
    	end
    	return tmp
    end
    
    function tmp_2 = code(a, b, c, d)
    	tmp = 0.0;
    	if (d <= -4.5e-98)
    		tmp = (b + (a * (c / d))) / d;
    	elseif (d <= 1.55e-77)
    		tmp = (a + (b * (d / c))) / c;
    	elseif (d <= 1e+48)
    		tmp = (b * d) / ((c * c) + (d * d));
    	else
    		tmp = (b + (a / (d / c))) / d;
    	end
    	tmp_2 = tmp;
    end
    
    code[a_, b_, c_, d_] := If[LessEqual[d, -4.5e-98], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.55e-77], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1e+48], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\
    \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
    
    \mathbf{elif}\;d \leq 1.55 \cdot 10^{-77}:\\
    \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
    
    \mathbf{elif}\;d \leq 10^{+48}:\\
    \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 4 regimes
    2. if d < -4.49999999999999997e-98

      1. Initial program 61.2%

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

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

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

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

      if -4.49999999999999997e-98 < d < 1.55000000000000004e-77

      1. Initial program 74.0%

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

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

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

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

          \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c} \]
      5. Simplified87.9%

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

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

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

      if 1.55000000000000004e-77 < d < 1.00000000000000004e48

      1. Initial program 84.4%

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

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

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

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

      if 1.00000000000000004e48 < d

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{-77}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 10^{+48}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 6: 77.3% accurate, 0.8× speedup?

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

      1. Initial program 49.9%

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

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

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

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

      if -4.49999999999999997e-98 < d < 6.7999999999999997e50

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

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

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

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

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

    Alternative 7: 73.0% accurate, 0.8× speedup?

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

      1. Initial program 41.6%

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

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

      if -4.99999999999999999e-15 < d < 3.7000000000000002e54

      1. Initial program 78.7%

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

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

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

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

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

    Alternative 8: 77.4% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3.3 \cdot 10^{-99}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+50}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (if (<= d -3.3e-99)
       (/ (+ b (* a (/ c d))) d)
       (if (<= d 5.6e+50) (/ (+ a (* b (/ d c))) c) (/ (+ b (/ a (/ d c))) d))))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -3.3e-99) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 5.6e+50) {
    		tmp = (a + (b * (d / c))) / c;
    	} else {
    		tmp = (b + (a / (d / 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.3d-99)) then
            tmp = (b + (a * (c / d))) / d
        else if (d <= 5.6d+50) then
            tmp = (a + (b * (d / c))) / c
        else
            tmp = (b + (a / (d / 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.3e-99) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 5.6e+50) {
    		tmp = (a + (b * (d / c))) / c;
    	} else {
    		tmp = (b + (a / (d / c))) / d;
    	}
    	return tmp;
    }
    
    def code(a, b, c, d):
    	tmp = 0
    	if d <= -3.3e-99:
    		tmp = (b + (a * (c / d))) / d
    	elif d <= 5.6e+50:
    		tmp = (a + (b * (d / c))) / c
    	else:
    		tmp = (b + (a / (d / c))) / d
    	return tmp
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if (d <= -3.3e-99)
    		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
    	elseif (d <= 5.6e+50)
    		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
    	else
    		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
    	end
    	return tmp
    end
    
    function tmp_2 = code(a, b, c, d)
    	tmp = 0.0;
    	if (d <= -3.3e-99)
    		tmp = (b + (a * (c / d))) / d;
    	elseif (d <= 5.6e+50)
    		tmp = (a + (b * (d / c))) / c;
    	else
    		tmp = (b + (a / (d / c))) / d;
    	end
    	tmp_2 = tmp;
    end
    
    code[a_, b_, c_, d_] := If[LessEqual[d, -3.3e-99], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 5.6e+50], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d \leq -3.3 \cdot 10^{-99}:\\
    \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
    
    \mathbf{elif}\;d \leq 5.6 \cdot 10^{+50}:\\
    \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d < -3.29999999999999986e-99

      1. Initial program 61.2%

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

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

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

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

      if -3.29999999999999986e-99 < d < 5.5999999999999996e50

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

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

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

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

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

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

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

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

      if 5.5999999999999996e50 < d

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.3 \cdot 10^{-99}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+50}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 9: 77.3% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.8 \cdot 10^{-99}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+47}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (if (<= d -7.8e-99)
       (/ (+ b (* a (/ c d))) d)
       (if (<= d 2.6e+47) (/ (+ a (/ (* b d) c)) c) (/ (+ b (/ a (/ d c))) d))))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -7.8e-99) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 2.6e+47) {
    		tmp = (a + ((b * d) / c)) / c;
    	} else {
    		tmp = (b + (a / (d / 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 <= (-7.8d-99)) then
            tmp = (b + (a * (c / d))) / d
        else if (d <= 2.6d+47) then
            tmp = (a + ((b * d) / c)) / c
        else
            tmp = (b + (a / (d / c))) / d
        end if
        code = tmp
    end function
    
    public static double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -7.8e-99) {
    		tmp = (b + (a * (c / d))) / d;
    	} else if (d <= 2.6e+47) {
    		tmp = (a + ((b * d) / c)) / c;
    	} else {
    		tmp = (b + (a / (d / c))) / d;
    	}
    	return tmp;
    }
    
    def code(a, b, c, d):
    	tmp = 0
    	if d <= -7.8e-99:
    		tmp = (b + (a * (c / d))) / d
    	elif d <= 2.6e+47:
    		tmp = (a + ((b * d) / c)) / c
    	else:
    		tmp = (b + (a / (d / c))) / d
    	return tmp
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if (d <= -7.8e-99)
    		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
    	elseif (d <= 2.6e+47)
    		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
    	else
    		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
    	end
    	return tmp
    end
    
    function tmp_2 = code(a, b, c, d)
    	tmp = 0.0;
    	if (d <= -7.8e-99)
    		tmp = (b + (a * (c / d))) / d;
    	elseif (d <= 2.6e+47)
    		tmp = (a + ((b * d) / c)) / c;
    	else
    		tmp = (b + (a / (d / c))) / d;
    	end
    	tmp_2 = tmp;
    end
    
    code[a_, b_, c_, d_] := If[LessEqual[d, -7.8e-99], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.6e+47], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d \leq -7.8 \cdot 10^{-99}:\\
    \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
    
    \mathbf{elif}\;d \leq 2.6 \cdot 10^{+47}:\\
    \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d < -7.79999999999999975e-99

      1. Initial program 61.2%

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

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

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

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

      if -7.79999999999999975e-99 < d < 2.60000000000000003e47

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

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

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

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

      if 2.60000000000000003e47 < d

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.8 \cdot 10^{-99}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+47}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 10: 62.2% accurate, 1.1× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.45 \cdot 10^{-99} \lor \neg \left(d \leq 3.45 \cdot 10^{-71}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (if (or (<= d -1.45e-99) (not (<= d 3.45e-71))) (/ b d) (/ a c)))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if ((d <= -1.45e-99) || !(d <= 3.45e-71)) {
    		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.45d-99)) .or. (.not. (d <= 3.45d-71))) 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.45e-99) || !(d <= 3.45e-71)) {
    		tmp = b / d;
    	} else {
    		tmp = a / c;
    	}
    	return tmp;
    }
    
    def code(a, b, c, d):
    	tmp = 0
    	if (d <= -1.45e-99) or not (d <= 3.45e-71):
    		tmp = b / d
    	else:
    		tmp = a / c
    	return tmp
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if ((d <= -1.45e-99) || !(d <= 3.45e-71))
    		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.45e-99) || ~((d <= 3.45e-71)))
    		tmp = b / d;
    	else
    		tmp = a / c;
    	end
    	tmp_2 = tmp;
    end
    
    code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.45e-99], N[Not[LessEqual[d, 3.45e-71]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d \leq -1.45 \cdot 10^{-99} \lor \neg \left(d \leq 3.45 \cdot 10^{-71}\right):\\
    \;\;\;\;\frac{b}{d}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{a}{c}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if d < -1.44999999999999993e-99 or 3.4500000000000002e-71 < d

      1. Initial program 54.8%

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

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

      if -1.44999999999999993e-99 < d < 3.4500000000000002e-71

      1. Initial program 74.8%

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

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

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

    Alternative 11: 42.1% 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 62.9%

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

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

    Developer Target 1: 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 2024191 
    (FPCore (a b c d)
      :name "Complex division, real part"
      :precision binary64
    
      :alt
      (! :herbie-platform default (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))))