Complex division, real part

Percentage Accurate: 61.7% → 84.8%
Time: 11.6s
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.7% 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: 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{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
   (* (/ c (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (c / hypot(c, d)) * (a / hypot(c, d));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 80.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-define94.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-rr94.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)}} \]
    5. Step-by-step derivation
      1. associate-*l/95.0%

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

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

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

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

    1. Initial program 0.0%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot a}}{{c}^{2} + {d}^{2}} \]
      2. rem-square-sqrt1.1%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{c \cdot a}{{\color{blue}{\left(\sqrt{c \cdot c + d \cdot d}\right)}}^{2}} \]
      11. unpow21.1%

        \[\leadsto \frac{c \cdot a}{{\left(\sqrt{\color{blue}{{c}^{2}} + d \cdot d}\right)}^{2}} \]
      12. unpow21.1%

        \[\leadsto \frac{c \cdot a}{{\left(\sqrt{{c}^{2} + \color{blue}{{d}^{2}}}\right)}^{2}} \]
      13. +-commutative1.1%

        \[\leadsto \frac{c \cdot a}{{\left(\sqrt{\color{blue}{{d}^{2} + {c}^{2}}}\right)}^{2}} \]
      14. unpow21.1%

        \[\leadsto \frac{c \cdot a}{{\left(\sqrt{\color{blue}{d \cdot d} + {c}^{2}}\right)}^{2}} \]
      15. unpow21.1%

        \[\leadsto \frac{c \cdot a}{{\left(\sqrt{d \cdot d + \color{blue}{c \cdot c}}\right)}^{2}} \]
      16. hypot-define1.1%

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

      \[\leadsto \color{blue}{\frac{c \cdot a}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}} \]
    6. Step-by-step derivation
      1. hypot-undefine1.1%

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

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

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

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

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

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

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

Alternative 2: 80.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -170:\\ \;\;\;\;\frac{\left(-b\right) - c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.85 \cdot 10^{+76}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -170.0)
   (/ (- (- b) (* c (/ a d))) (hypot c d))
   (if (<= d 1.05e-24)
     (+ (/ a c) (/ (/ (* b d) c) c))
     (if (<= d 2.85e+76)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (* (/ 1.0 (hypot c d)) (+ b (* a (/ c d))))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -170.0) {
		tmp = (-b - (c * (a / d))) / hypot(c, d);
	} else if (d <= 1.05e-24) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 2.85e+76) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = (1.0 / hypot(c, d)) * (b + (a * (c / d)));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -170.0) {
		tmp = (-b - (c * (a / d))) / Math.hypot(c, d);
	} else if (d <= 1.05e-24) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 2.85e+76) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * (b + (a * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -170.0:
		tmp = (-b - (c * (a / d))) / math.hypot(c, d)
	elif d <= 1.05e-24:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 2.85e+76:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = (1.0 / math.hypot(c, d)) * (b + (a * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -170.0)
		tmp = Float64(Float64(Float64(-b) - Float64(c * Float64(a / d))) / hypot(c, d));
	elseif (d <= 1.05e-24)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 2.85e+76)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(a * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -170.0)
		tmp = (-b - (c * (a / d))) / hypot(c, d);
	elseif (d <= 1.05e-24)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 2.85e+76)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = (1.0 / hypot(c, d)) * (b + (a * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -170.0], N[(N[((-b) - N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.05e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.85e+76], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 50.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. frac-2neg71.0%

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

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

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

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

    if -170 < d < 1.05e-24

    1. Initial program 69.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.2%

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

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

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

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

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

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

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

    if 1.05e-24 < d < 2.85000000000000002e76

    1. Initial program 94.4%

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

    if 2.85000000000000002e76 < d

    1. Initial program 53.8%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt53.8%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -170:\\ \;\;\;\;\frac{\left(-b\right) - c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.85 \cdot 10^{+76}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.0% accurate, 0.1× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + t\_0 \cdot \frac{1}{d}\\


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

    1. Initial program 50.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. frac-2neg71.0%

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

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

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

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

    if -26000 < d < 9.99999999999999924e-25

    1. Initial program 69.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.2%

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

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

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

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

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

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

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

    if 9.99999999999999924e-25 < d < 7.00000000000000001e91

    1. Initial program 94.9%

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

    if 7.00000000000000001e91 < d

    1. Initial program 52.0%

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

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

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

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

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

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

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

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

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

Alternative 4: 80.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{d} + \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\ \mathbf{if}\;d \leq -1150:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 4 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 7.3 \cdot 10^{+90}:\\ \;\;\;\;\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 (+ (/ b d) (* (* c (/ a d)) (/ 1.0 d)))))
   (if (<= d -1150.0)
     t_0
     (if (<= d 4e-24)
       (+ (/ a c) (/ (/ (* b d) c) c))
       (if (<= d 7.3e+90) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c * (a / d)) * (1.0 / d));
	double tmp;
	if (d <= -1150.0) {
		tmp = t_0;
	} else if (d <= 4e-24) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 7.3e+90) {
		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 = (b / d) + ((c * (a / d)) * (1.0d0 / d))
    if (d <= (-1150.0d0)) then
        tmp = t_0
    else if (d <= 4d-24) then
        tmp = (a / c) + (((b * d) / c) / c)
    else if (d <= 7.3d+90) 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 = (b / d) + ((c * (a / d)) * (1.0 / d));
	double tmp;
	if (d <= -1150.0) {
		tmp = t_0;
	} else if (d <= 4e-24) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else if (d <= 7.3e+90) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / d) + ((c * (a / d)) * (1.0 / d))
	tmp = 0
	if d <= -1150.0:
		tmp = t_0
	elif d <= 4e-24:
		tmp = (a / c) + (((b * d) / c) / c)
	elif d <= 7.3e+90:
		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(b / d) + Float64(Float64(c * Float64(a / d)) * Float64(1.0 / d)))
	tmp = 0.0
	if (d <= -1150.0)
		tmp = t_0;
	elseif (d <= 4e-24)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	elseif (d <= 7.3e+90)
		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 = (b / d) + ((c * (a / d)) * (1.0 / d));
	tmp = 0.0;
	if (d <= -1150.0)
		tmp = t_0;
	elseif (d <= 4e-24)
		tmp = (a / c) + (((b * d) / c) / c);
	elseif (d <= 7.3e+90)
		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[(b / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1150.0], t$95$0, If[LessEqual[d, 4e-24], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.3e+90], 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{b}{d} + \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\
\mathbf{if}\;d \leq -1150:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 7.3 \cdot 10^{+90}:\\
\;\;\;\;\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 d < -1150 or 7.29999999999999995e90 < d

    1. Initial program 50.9%

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

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

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

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

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

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

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

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

    if -1150 < d < 3.99999999999999969e-24

    1. Initial program 69.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.2%

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

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

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

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

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

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

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

    if 3.99999999999999969e-24 < d < 7.29999999999999995e90

    1. Initial program 94.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1150:\\ \;\;\;\;\frac{b}{d} + \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\ \mathbf{elif}\;d \leq 4 \cdot 10^{-24}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 7.3 \cdot 10^{+90}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 79.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -145000 \lor \neg \left(d \leq 0.0145\right):\\
\;\;\;\;\frac{b}{d} + \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -145000 or 0.0145000000000000007 < d

    1. Initial program 56.0%

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

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

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

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

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

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

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

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

    if -145000 < d < 0.0145000000000000007

    1. Initial program 70.3%

      \[\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. associate-/l*76.8%

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

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

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

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

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

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

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

Alternative 6: 74.2% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -82000 or 1.9e21 < d

    1. Initial program 55.0%

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

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

    if -82000 < d < 1.9e21

    1. Initial program 70.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-identity70.9%

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      4. add-sqr-sqrt70.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 79.6% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -40000 \lor \neg \left(d \leq 6.4\right):\\
\;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4e4 or 6.4000000000000004 < d

    1. Initial program 56.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d} + \color{blue}{b \cdot \frac{1}{d}} \]
      4. distribute-rgt-out79.8%

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

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

    if -4e4 < d < 6.4000000000000004

    1. Initial program 70.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-identity70.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 79.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -82000 \lor \neg \left(d \leq 380\right):\\
\;\;\;\;\left(b + c \cdot \frac{a}{d}\right) \cdot \frac{1}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -82000 or 380 < d

    1. Initial program 56.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(c \cdot \frac{a}{d}\right) \cdot \frac{1}{d} + \color{blue}{b \cdot \frac{1}{d}} \]
      4. distribute-rgt-out79.8%

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

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

    if -82000 < d < 380

    1. Initial program 70.3%

      \[\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. associate-/l*76.8%

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

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

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

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

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

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

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

Alternative 9: 65.5% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5e4 or 4.3e20 < d

    1. Initial program 55.0%

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

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

    if -5e4 < d < 4.3e20

    1. Initial program 70.9%

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

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

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

Alternative 10: 43.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq 2 \cdot 10^{+218}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d) :precision binary64 (if (<= d 2e+218) (/ a c) (/ a d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= 2e+218) {
		tmp = a / c;
	} else {
		tmp = a / 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 <= 2d+218) then
        tmp = a / c
    else
        tmp = a / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= 2e+218) {
		tmp = a / c;
	} else {
		tmp = a / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= 2e+218:
		tmp = a / c
	else:
		tmp = a / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= 2e+218)
		tmp = Float64(a / c);
	else
		tmp = Float64(a / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= 2e+218)
		tmp = a / c;
	else
		tmp = a / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, 2e+218], N[(a / c), $MachinePrecision], N[(a / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq 2 \cdot 10^{+218}:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 2.00000000000000017e218

    1. Initial program 63.4%

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

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

    if 2.00000000000000017e218 < d

    1. Initial program 57.1%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. Taylor expanded in c around -inf 39.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 2 \cdot 10^{+218}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 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.8%

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

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

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

Developer target: 99.4% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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