Complex division, real part

Percentage Accurate: 61.4% → 80.3%
Time: 11.0s
Alternatives: 11
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 61.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: 80.3% accurate, 0.1× speedup?

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

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

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

\mathbf{elif}\;d \leq -1.7 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 9.5 \cdot 10^{-87}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 6.5 \cdot 10^{+78}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -4.6000000000000001e107

    1. Initial program 37.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.6000000000000001e107 < d < -1.28e84

    1. Initial program 23.7%

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

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

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

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

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

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

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

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

    if -1.28e84 < d < -1.7000000000000001e-35 or 9.5e-87 < d < 6.50000000000000036e78

    1. Initial program 87.5%

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

    if -1.7000000000000001e-35 < d < 9.5e-87

    1. Initial program 68.5%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity83.0%

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

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

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

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

    if 6.50000000000000036e78 < d

    1. Initial program 42.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.6 \cdot 10^{+107}:\\ \;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.28 \cdot 10^{+84}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;d \leq -1.7 \cdot 10^{-35}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-87}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+78}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{\frac{{d}^{2}}{c}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 84.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{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{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (a / c) + ((d / c) * (b / c));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(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[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{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{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\


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

    1. Initial program 74.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-identity74.9%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Applied egg-rr93.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 +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 0.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 78.7% accurate, 0.1× speedup?

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

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

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

\mathbf{elif}\;d \leq 60000000:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.2e84 or 6e7 < d

    1. Initial program 46.9%

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

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

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

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

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

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

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

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

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

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

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

    if -1.2e84 < d < -2.1e-35

    1. Initial program 88.4%

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

    if -2.1e-35 < d < 6e7

    1. Initial program 69.8%

      \[\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}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.8%

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

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

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

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

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

Alternative 4: 76.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{if}\;c \leq -3.4 \cdot 10^{-51}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-121}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{\frac{{d}^{2}}{c}}\\ \mathbf{elif}\;c \leq 2.75 \cdot 10^{+43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ a c) (/ (* d (/ b c)) c))))
   (if (<= c -3.4e-51)
     t_0
     (if (<= c 8e-121)
       (+ (/ b d) (/ a (/ (pow d 2.0) c)))
       (if (<= c 2.75e+43) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + ((d * (b / c)) / c);
	double tmp;
	if (c <= -3.4e-51) {
		tmp = t_0;
	} else if (c <= 8e-121) {
		tmp = (b / d) + (a / (pow(d, 2.0) / c));
	} else if (c <= 2.75e+43) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	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) + ((d * (b / c)) / c)
    if (c <= (-3.4d-51)) then
        tmp = t_0
    else if (c <= 8d-121) then
        tmp = (b / d) + (a / ((d ** 2.0d0) / c))
    else if (c <= 2.75d+43) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + ((d * (b / c)) / c);
	double tmp;
	if (c <= -3.4e-51) {
		tmp = t_0;
	} else if (c <= 8e-121) {
		tmp = (b / d) + (a / (Math.pow(d, 2.0) / c));
	} else if (c <= 2.75e+43) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a / c) + ((d * (b / c)) / c)
	tmp = 0
	if c <= -3.4e-51:
		tmp = t_0
	elif c <= 8e-121:
		tmp = (b / d) + (a / (math.pow(d, 2.0) / c))
	elif c <= 2.75e+43:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c))
	tmp = 0.0
	if (c <= -3.4e-51)
		tmp = t_0;
	elseif (c <= 8e-121)
		tmp = Float64(Float64(b / d) + Float64(a / Float64((d ^ 2.0) / c)));
	elseif (c <= 2.75e+43)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a / c) + ((d * (b / c)) / c);
	tmp = 0.0;
	if (c <= -3.4e-51)
		tmp = t_0;
	elseif (c <= 8e-121)
		tmp = (b / d) + (a / ((d ^ 2.0) / c));
	elseif (c <= 2.75e+43)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.4e-51], t$95$0, If[LessEqual[c, 8e-121], N[(N[(b / d), $MachinePrecision] + N[(a / N[(N[Power[d, 2.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.75e+43], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.40000000000000003e-51 or 2.74999999999999995e43 < c

    1. Initial program 51.8%

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

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

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

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

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

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

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

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

    if -3.40000000000000003e-51 < c < 7.9999999999999998e-121

    1. Initial program 71.9%

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

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

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

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

    if 7.9999999999999998e-121 < c < 2.74999999999999995e43

    1. Initial program 90.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.4 \cdot 10^{-51}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-121}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{\frac{{d}^{2}}{c}}\\ \mathbf{elif}\;c \leq 2.75 \cdot 10^{+43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 72.4% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.4 \cdot 10^{+108}:\\
\;\;\;\;\frac{b}{d}\\

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

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

\mathbf{elif}\;d \leq 29000000:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.40000000000000019e108 or 2.9e7 < d

    1. Initial program 48.4%

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

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

    if -2.40000000000000019e108 < d < -9.2000000000000001e58

    1. Initial program 49.1%

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

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

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

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

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

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

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

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

    if -9.2000000000000001e58 < d < -7.20000000000000038e-35

    1. Initial program 90.4%

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

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

    if -7.20000000000000038e-35 < d < 2.9e7

    1. Initial program 69.8%

      \[\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}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.4 \cdot 10^{+108}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -9.2 \cdot 10^{+58}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;d \leq -7.2 \cdot 10^{-35}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 29000000:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 71.8% accurate, 0.5× speedup?

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

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

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

\mathbf{elif}\;d \leq -2.5 \cdot 10^{-34}:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;d \leq 2600:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.6500000000000001e108 or 2600 < d

    1. Initial program 48.4%

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

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

    if -1.6500000000000001e108 < d < -8.9999999999999996e58 or -2.5000000000000001e-34 < d < 2600

    1. Initial program 68.2%

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

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

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

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

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

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

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

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

    if -8.9999999999999996e58 < d < -2.5000000000000001e-34

    1. Initial program 90.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.65 \cdot 10^{+108}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -9 \cdot 10^{+58}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-34}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2600:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 76.5% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.65 \cdot 10^{+118} \lor \neg \left(c \leq 6.4 \cdot 10^{+42}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.65e118 or 6.40000000000000004e42 < c

    1. Initial program 44.3%

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

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

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

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

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

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

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

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

    if -1.65e118 < c < 6.40000000000000004e42

    1. Initial program 75.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification81.0%

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

Alternative 8: 71.3% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5.3e107 or 8.5e11 < d

    1. Initial program 48.4%

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

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

    if -5.3e107 < d < 8.5e11

    1. Initial program 71.1%

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

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

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

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

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

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

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

Alternative 9: 71.7% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.35000000000000001e109 or 1.25e7 < d

    1. Initial program 48.4%

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

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

    if -1.35000000000000001e109 < d < 1.25e7

    1. Initial program 71.1%

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

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

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

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

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

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

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

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

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

Alternative 10: 64.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.2 \cdot 10^{-35} \lor \neg \left(d \leq 12000000\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -9.1999999999999996e-35 or 1.2e7 < d

    1. Initial program 55.3%

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

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

    if -9.1999999999999996e-35 < d < 1.2e7

    1. Initial program 69.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.2 \cdot 10^{-35} \lor \neg \left(d \leq 12000000\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.6%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification49.7%

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

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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