Complex division, real part

Percentage Accurate: 70.1% → 89.6%
Time: 20.4s
Alternatives: 9
Speedup: 2.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

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

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+27}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-143}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{-115}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 19500:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.55e+27)
   (+ (/ b d) (/ c (/ (* d d) a)))
   (if (<= d -8e-143)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 4.5e-115)
       (* (/ 1.0 c) (+ a (/ (* b d) c)))
       (if (<= d 19500.0)
         (/ (fma a c (* b d)) (fma c c (* d d)))
         (+ (/ b d) (/ (* a c) (* d d))))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.55e+27) {
		tmp = (b / d) + (c / ((d * d) / a));
	} else if (d <= -8e-143) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 4.5e-115) {
		tmp = (1.0 / c) * (a + ((b * d) / c));
	} else if (d <= 19500.0) {
		tmp = fma(a, c, (b * d)) / fma(c, c, (d * d));
	} else {
		tmp = (b / d) + ((a * c) / (d * d));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.55e+27)
		tmp = Float64(Float64(b / d) + Float64(c / Float64(Float64(d * d) / a)));
	elseif (d <= -8e-143)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 4.5e-115)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c)));
	elseif (d <= 19500.0)
		tmp = Float64(fma(a, c, Float64(b * d)) / fma(c, c, Float64(d * d)));
	else
		tmp = Float64(Float64(b / d) + Float64(Float64(a * c) / Float64(d * d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.55e+27], N[(N[(b / d), $MachinePrecision] + N[(c / N[(N[(d * d), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8e-143], 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.5e-115], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 19500.0], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.55 \cdot 10^{+27}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{-115}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\

\mathbf{elif}\;d \leq 19500:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

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


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

    1. Initial program 72.7%

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

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

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

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

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

    if -1.54999999999999998e27 < d < -7.9999999999999996e-143

    1. Initial program 87.4%

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

    if -7.9999999999999996e-143 < d < 4.50000000000000023e-115

    1. Initial program 70.1%

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

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

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

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

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

        \[\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-def85.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)}} \]
    3. Applied egg-rr85.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)}} \]
    4. Taylor expanded in c around inf 49.0%

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

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

    if 4.50000000000000023e-115 < d < 19500

    1. Initial program 87.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-def87.9%

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

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

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

    if 19500 < d

    1. Initial program 73.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+27}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-143}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{-115}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 19500:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\ \end{array} \]

Alternative 2: 88.2% 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 \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\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)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (/ (* a (/ c (hypot c d))) (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 = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (a * (c / hypot(c, d))) / 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(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(a * Float64(c / hypot(c, d))) / 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[(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 * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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 \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\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 84.5%

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

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

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

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

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

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

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

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

    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. Taylor expanded in a around inf 1.8%

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

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

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

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

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

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

        \[\leadsto \frac{c}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \cdot a \]
    4. Simplified3.6%

      \[\leadsto \color{blue}{\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot a} \]
    5. Step-by-step derivation
      1. *-un-lft-identity3.6%

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

        \[\leadsto \frac{1 \cdot c}{\color{blue}{c \cdot c + d \cdot d}} \cdot a \]
      3. add-sqr-sqrt3.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot a}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.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 \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 89.6% accurate, 0.6× 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 -1.55 \cdot 10^{+27}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-115}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 21000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -1.55e+27)
     (+ (/ b d) (/ c (/ (* d d) a)))
     (if (<= d -1e-142)
       t_0
       (if (<= d 6.8e-115)
         (* (/ 1.0 c) (+ a (/ (* b d) c)))
         (if (<= d 21000.0) t_0 (+ (/ b d) (/ (* a c) (* d d)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.55e+27) {
		tmp = (b / d) + (c / ((d * d) / a));
	} else if (d <= -1e-142) {
		tmp = t_0;
	} else if (d <= 6.8e-115) {
		tmp = (1.0 / c) * (a + ((b * d) / c));
	} else if (d <= 21000.0) {
		tmp = t_0;
	} else {
		tmp = (b / d) + ((a * c) / (d * d));
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-1.55d+27)) then
        tmp = (b / d) + (c / ((d * d) / a))
    else if (d <= (-1d-142)) then
        tmp = t_0
    else if (d <= 6.8d-115) then
        tmp = (1.0d0 / c) * (a + ((b * d) / c))
    else if (d <= 21000.0d0) then
        tmp = t_0
    else
        tmp = (b / d) + ((a * c) / (d * d))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.55e+27) {
		tmp = (b / d) + (c / ((d * d) / a));
	} else if (d <= -1e-142) {
		tmp = t_0;
	} else if (d <= 6.8e-115) {
		tmp = (1.0 / c) * (a + ((b * d) / c));
	} else if (d <= 21000.0) {
		tmp = t_0;
	} else {
		tmp = (b / d) + ((a * c) / (d * d));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.55e+27:
		tmp = (b / d) + (c / ((d * d) / a))
	elif d <= -1e-142:
		tmp = t_0
	elif d <= 6.8e-115:
		tmp = (1.0 / c) * (a + ((b * d) / c))
	elif d <= 21000.0:
		tmp = t_0
	else:
		tmp = (b / d) + ((a * c) / (d * d))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -1.55e+27)
		tmp = Float64(Float64(b / d) + Float64(c / Float64(Float64(d * d) / a)));
	elseif (d <= -1e-142)
		tmp = t_0;
	elseif (d <= 6.8e-115)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c)));
	elseif (d <= 21000.0)
		tmp = t_0;
	else
		tmp = Float64(Float64(b / d) + Float64(Float64(a * c) / Float64(d * d)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -1.55e+27)
		tmp = (b / d) + (c / ((d * d) / a));
	elseif (d <= -1e-142)
		tmp = t_0;
	elseif (d <= 6.8e-115)
		tmp = (1.0 / c) * (a + ((b * d) / c));
	elseif (d <= 21000.0)
		tmp = t_0;
	else
		tmp = (b / d) + ((a * c) / (d * d));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.55e+27], N[(N[(b / d), $MachinePrecision] + N[(c / N[(N[(d * d), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e-142], t$95$0, If[LessEqual[d, 6.8e-115], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 21000.0], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] / N[(d * d), $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 -1.55 \cdot 10^{+27}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\

\mathbf{elif}\;d \leq -1 \cdot 10^{-142}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 6.8 \cdot 10^{-115}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\

\mathbf{elif}\;d \leq 21000:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 72.7%

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

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

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

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

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

    if -1.54999999999999998e27 < d < -1e-142 or 6.7999999999999996e-115 < d < 21000

    1. Initial program 87.5%

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

    if -1e-142 < d < 6.7999999999999996e-115

    1. Initial program 70.1%

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

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

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

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

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

        \[\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-def85.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)}} \]
    3. Applied egg-rr85.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)}} \]
    4. Taylor expanded in c around inf 49.0%

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

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

    if 21000 < d

    1. Initial program 73.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+27}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-142}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-115}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;d \leq 21000:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\ \end{array} \]

Alternative 4: 83.4% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.79999999999999997e-8 or 1.30000000000000004 < c

    1. Initial program 68.9%

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

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

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

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

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

    if -4.79999999999999997e-8 < c < 1.30000000000000004

    1. Initial program 79.0%

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

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

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

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

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

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

Alternative 5: 83.5% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.2999999999999998e-8 or 2.34999999999999993e-4 < c

    1. Initial program 68.9%

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

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

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

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

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

    if -5.2999999999999998e-8 < c < 2.34999999999999993e-4

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

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

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

Alternative 6: 82.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -8200000000000:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 70000000:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -8200000000000.0)
   (/ b d)
   (if (<= d 70000000.0) (* (/ 1.0 c) (+ a (/ (* b d) c))) (/ b d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -8200000000000.0) {
		tmp = b / d;
	} else if (d <= 70000000.0) {
		tmp = (1.0 / c) * (a + ((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 <= (-8200000000000.0d0)) then
        tmp = b / d
    else if (d <= 70000000.0d0) then
        tmp = (1.0d0 / c) * (a + ((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 <= -8200000000000.0) {
		tmp = b / d;
	} else if (d <= 70000000.0) {
		tmp = (1.0 / c) * (a + ((b * d) / c));
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -8200000000000.0:
		tmp = b / d
	elif d <= 70000000.0:
		tmp = (1.0 / c) * (a + ((b * d) / c))
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -8200000000000.0)
		tmp = Float64(b / d);
	elseif (d <= 70000000.0)
		tmp = Float64(Float64(1.0 / c) * Float64(a + 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 <= -8200000000000.0)
		tmp = b / d;
	elseif (d <= 70000000.0)
		tmp = (1.0 / c) * (a + ((b * d) / c));
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -8200000000000.0], N[(b / d), $MachinePrecision], If[LessEqual[d, 70000000.0], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -8200000000000:\\
\;\;\;\;\frac{b}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.2e12 or 7e7 < d

    1. Initial program 73.0%

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

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

    if -8.2e12 < d < 7e7

    1. Initial program 76.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8200000000000:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 70000000:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 7: 84.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -45:\\
\;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\

\mathbf{elif}\;d \leq 1.12 \cdot 10^{-79}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\

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


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

    1. Initial program 74.5%

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

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

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

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

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

    if -45 < d < 1.11999999999999996e-79

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

    if 1.11999999999999996e-79 < d

    1. Initial program 77.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -45:\\ \;\;\;\;\frac{b}{d} + \frac{c}{\frac{d \cdot d}{a}}\\ \mathbf{elif}\;d \leq 1.12 \cdot 10^{-79}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot c}{d \cdot d}\\ \end{array} \]

Alternative 8: 70.2% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.3 \cdot 10^{-30}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 12.6:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.29999999999999984e-30 or 12.5999999999999996 < c

    1. Initial program 70.9%

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

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

    if -2.29999999999999984e-30 < c < 12.5999999999999996

    1. Initial program 78.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.3 \cdot 10^{-30}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 12.6:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 9: 43.6% 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 75.6%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification40.6%

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

Developer target: 99.1% 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 2023278 
(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))))