Complex division, real part

Percentage Accurate: 62.4% → 86.0%
Time: 8.9s
Alternatives: 8
Speedup: 1.3×

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 8 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.4% 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.0% 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 5 \cdot 10^{+299}:\\ \;\;\;\;\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{-1}{c} \cdot \left(\left(-a\right) - \frac{b}{\frac{c}{d}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+299)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (* (/ -1.0 c) (- (- a) (/ b (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+299) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (-1.0 / c) * (-a - (b / (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))) <= 5e+299)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(-1.0 / c) * Float64(Float64(-a) - Float64(b / Float64(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], 5e+299], 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[(-1.0 / c), $MachinePrecision] * N[((-a) - N[(b / N[(c / d), $MachinePrecision]), $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 5 \cdot 10^{+299}:\\
\;\;\;\;\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{-1}{c} \cdot \left(\left(-a\right) - \frac{b}{\frac{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))) < 5.0000000000000003e299

    1. Initial program 76.4%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def76.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-def76.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-def96.9%

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

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

    if 5.0000000000000003e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 12.6%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt12.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-frac12.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-def12.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-def12.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-def18.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)}} \]
    3. Applied egg-rr18.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)}} \]
    4. Taylor expanded in c around -inf 30.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+299}:\\ \;\;\;\;\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{-1}{c} \cdot \left(\left(-a\right) - \frac{b}{\frac{c}{d}}\right)\\ \end{array} \]

Alternative 2: 78.8% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq 6 \cdot 10^{-175}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 7.2 \cdot 10^{+68}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 44.3%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def77.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)}} \]
    3. Applied egg-rr77.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)}} \]
    4. Taylor expanded in d around -inf 85.6%

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

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

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

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

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

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

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

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

    if -2.59999999999999997e34 < d < 6e-175 or 7.99999999999999952e39 < d < 7.1999999999999998e68

    1. Initial program 64.4%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac64.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-def64.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-def64.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-def77.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)}} \]
    3. Applied egg-rr77.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)}} \]
    4. Taylor expanded in c around inf 46.3%

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

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

    if 6e-175 < d < 7.99999999999999952e39

    1. Initial program 83.2%

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

    if 7.1999999999999998e68 < d

    1. Initial program 48.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.6 \cdot 10^{+34}:\\ \;\;\;\;\left(b + \frac{a}{\frac{d}{c}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{-175}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+39}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{+68}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \end{array} \]

Alternative 3: 77.8% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d \leq 6 \cdot 10^{-175}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.4 \cdot 10^{+69}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.19999999999999993e34 or 1.39999999999999991e69 < d

    1. Initial program 46.2%

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

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

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

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

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

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

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

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

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

    if -1.19999999999999993e34 < d < 6e-175 or 7.99999999999999952e39 < d < 1.39999999999999991e69

    1. Initial program 64.4%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac64.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-def64.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-def64.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-def77.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)}} \]
    3. Applied egg-rr77.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)}} \]
    4. Taylor expanded in c around inf 46.3%

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

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

    if 6e-175 < d < 7.99999999999999952e39

    1. Initial program 83.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+34}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{-175}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+39}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{+69}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \end{array} \]

Alternative 4: 73.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -8 \cdot 10^{+33} \lor \neg \left(d \leq 5400000000000 \lor \neg \left(d \leq 7.5 \cdot 10^{+38}\right) \land d \leq 10^{+69}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.9999999999999996e33 or 5.4e12 < d < 7.4999999999999999e38 or 1.0000000000000001e69 < d

    1. Initial program 51.8%

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

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

    if -7.9999999999999996e33 < d < 5.4e12 or 7.4999999999999999e38 < d < 1.0000000000000001e69

    1. Initial program 69.0%

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

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

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

        \[\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-def69.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-def69.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-def80.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)}} \]
    3. Applied egg-rr80.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)}} \]
    4. Taylor expanded in c around inf 41.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8 \cdot 10^{+33} \lor \neg \left(d \leq 5400000000000 \lor \neg \left(d \leq 7.5 \cdot 10^{+38}\right) \land d \leq 10^{+69}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \end{array} \]

Alternative 5: 76.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.2 \cdot 10^{+33} \lor \neg \left(d \leq 8 \cdot 10^{-5}\right) \land \left(d \leq 8 \cdot 10^{+39} \lor \neg \left(d \leq 7.2 \cdot 10^{+68}\right)\right):\\
\;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.2e33 or 8.00000000000000065e-5 < d < 7.99999999999999952e39 or 7.1999999999999998e68 < d

    1. Initial program 52.7%

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

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

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

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

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

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

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

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

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

    if -6.2e33 < d < 8.00000000000000065e-5 or 7.99999999999999952e39 < d < 7.1999999999999998e68

    1. Initial program 68.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.2 \cdot 10^{+33} \lor \neg \left(d \leq 8 \cdot 10^{-5}\right) \land \left(d \leq 8 \cdot 10^{+39} \lor \neg \left(d \leq 7.2 \cdot 10^{+68}\right)\right):\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \end{array} \]

Alternative 6: 76.7% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.2 \cdot 10^{-89} \lor \neg \left(c \leq 6.3 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b}{\frac{c}{d}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.20000000000000012e-89 or 6.3000000000000004e-18 < c

    1. Initial program 53.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.20000000000000012e-89 < c < 6.3000000000000004e-18

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.2 \cdot 10^{-89} \lor \neg \left(c \leq 6.3 \cdot 10^{-18}\right):\\ \;\;\;\;\frac{-1}{c} \cdot \left(\left(-a\right) - \frac{b}{\frac{c}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \end{array} \]

Alternative 7: 63.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3.1 \cdot 10^{+34} \lor \neg \left(d \leq 1850000000000 \lor \neg \left(d \leq 8 \cdot 10^{+39}\right) \land d \leq 1.05 \cdot 10^{+70}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -3.1e+34)
         (not
          (or (<= d 1850000000000.0)
              (and (not (<= d 8e+39)) (<= d 1.05e+70)))))
   (/ b d)
   (/ a c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -3.1e+34) || !((d <= 1850000000000.0) || (!(d <= 8e+39) && (d <= 1.05e+70)))) {
		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 <= (-3.1d+34)) .or. (.not. (d <= 1850000000000.0d0) .or. (.not. (d <= 8d+39)) .and. (d <= 1.05d+70))) 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 <= -3.1e+34) || !((d <= 1850000000000.0) || (!(d <= 8e+39) && (d <= 1.05e+70)))) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -3.1e+34) or not ((d <= 1850000000000.0) or (not (d <= 8e+39) and (d <= 1.05e+70))):
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -3.1e+34) || !((d <= 1850000000000.0) || (!(d <= 8e+39) && (d <= 1.05e+70))))
		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 <= -3.1e+34) || ~(((d <= 1850000000000.0) || (~((d <= 8e+39)) && (d <= 1.05e+70)))))
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.1e+34], N[Not[Or[LessEqual[d, 1850000000000.0], And[N[Not[LessEqual[d, 8e+39]], $MachinePrecision], LessEqual[d, 1.05e+70]]]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+34} \lor \neg \left(d \leq 1850000000000 \lor \neg \left(d \leq 8 \cdot 10^{+39}\right) \land d \leq 1.05 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.09999999999999977e34 or 1.85e12 < d < 7.99999999999999952e39 or 1.05000000000000004e70 < d

    1. Initial program 51.8%

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

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

    if -3.09999999999999977e34 < d < 1.85e12 or 7.99999999999999952e39 < d < 1.05000000000000004e70

    1. Initial program 69.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.1 \cdot 10^{+34} \lor \neg \left(d \leq 1850000000000 \lor \neg \left(d \leq 8 \cdot 10^{+39}\right) \land d \leq 1.05 \cdot 10^{+70}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 8: 43.0% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification47.4%

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

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 2023332 
(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))))