Complex division, real part

Percentage Accurate: 61.6% → 85.7%
Time: 8.0s
Alternatives: 12
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 12 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.6% 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: 85.7% accurate, 0.0× speedup?

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

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


\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))) < 4.99999999999999993e306

    1. Initial program 76.8%

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

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

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

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

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

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

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

        \[\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)} \]
    5. Applied egg-rr96.7%

      \[\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 4.99999999999999993e306 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 9.1%

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

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

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

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

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

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

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

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

Alternative 2: 78.6% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.4 \cdot 10^{+89}:\\
\;\;\;\;\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{a}}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -5.4e89

    1. Initial program 31.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.4e89 < c < -4.39999999999999995e-71

    1. Initial program 84.9%

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

    if -4.39999999999999995e-71 < c < 2.8500000000000002e24

    1. Initial program 67.7%

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

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

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

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

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

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

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

    if 2.8500000000000002e24 < c

    1. Initial program 48.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.4 \cdot 10^{+89}:\\ \;\;\;\;\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{a}}\\ \mathbf{elif}\;c \leq -4.4 \cdot 10^{-71}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.85 \cdot 10^{+24}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]

Alternative 3: 79.2% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.34999999999999986e95

    1. Initial program 31.2%

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

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

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

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

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

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

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

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

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

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

    if -2.34999999999999986e95 < c < -3.79999999999999992e-71

    1. Initial program 80.8%

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

    if -3.79999999999999992e-71 < c < 4.4999999999999997e28

    1. Initial program 67.7%

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

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

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

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

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

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

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

    if 4.4999999999999997e28 < c

    1. Initial program 48.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.35 \cdot 10^{+95}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c \cdot \frac{c}{b}}\\ \mathbf{elif}\;c \leq -3.8 \cdot 10^{-71}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{+28}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]

Alternative 4: 62.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{+45}:\\
\;\;\;\;\frac{a}{c}\\

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

\mathbf{elif}\;c \leq 1.65 \cdot 10^{-91}:\\
\;\;\;\;\frac{1}{\frac{d}{c} \cdot \frac{d}{a}}\\

\mathbf{elif}\;c \leq 1.65 \cdot 10^{+26}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.5000000000000001e45 or 1.64999999999999997e26 < c

    1. Initial program 45.4%

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

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

    if -5.5000000000000001e45 < c < 2.75000000000000012e-129 or 1.65000000000000006e-91 < c < 1.64999999999999997e26

    1. Initial program 69.3%

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

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

    if 2.75000000000000012e-129 < c < 1.65000000000000006e-91

    1. Initial program 80.9%

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

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

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d}} \]
    5. Taylor expanded in a around inf 61.1%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{d \cdot d}{c \cdot a}}} \]
      2. inv-pow60.9%

        \[\leadsto \color{blue}{{\left(\frac{d \cdot d}{c \cdot a}\right)}^{-1}} \]
      3. *-commutative60.9%

        \[\leadsto {\left(\frac{d \cdot d}{\color{blue}{a \cdot c}}\right)}^{-1} \]
      4. times-frac71.4%

        \[\leadsto {\color{blue}{\left(\frac{d}{a} \cdot \frac{d}{c}\right)}}^{-1} \]
    7. Applied egg-rr71.4%

      \[\leadsto \color{blue}{{\left(\frac{d}{a} \cdot \frac{d}{c}\right)}^{-1}} \]
    8. Step-by-step derivation
      1. unpow-171.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{d}{a} \cdot \frac{d}{c}}} \]
      2. *-commutative71.4%

        \[\leadsto \frac{1}{\color{blue}{\frac{d}{c} \cdot \frac{d}{a}}} \]
    9. Simplified71.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{+45}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 2.75 \cdot 10^{-129}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{-91}:\\ \;\;\;\;\frac{1}{\frac{d}{c} \cdot \frac{d}{a}}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{+26}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 5: 68.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{+52} \lor \neg \left(d \leq 1.85 \cdot 10^{+168}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.9999999999999999e52 or 1.85000000000000005e168 < d

    1. Initial program 39.2%

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

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

    if -8.9999999999999999e52 < d < 1.85000000000000005e168

    1. Initial program 67.4%

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

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

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

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

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

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

Alternative 6: 69.2% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.09999999999999999e53 or 1.85000000000000005e168 < d

    1. Initial program 39.2%

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

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

    if -1.09999999999999999e53 < d < 1.85000000000000005e168

    1. Initial program 67.4%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.1 \cdot 10^{+53}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{+168}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 7: 75.9% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -6.00000000000000021e45

    1. Initial program 41.9%

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{c} \cdot \frac{d}{c}} \]
      2. clear-num75.0%

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

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

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

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

    if -6.00000000000000021e45 < c < 1.8499999999999999e25

    1. Initial program 70.1%

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

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

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

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

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

    if 1.8499999999999999e25 < c

    1. Initial program 48.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6 \cdot 10^{+45}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c \cdot \frac{c}{b}}\\ \mathbf{elif}\;c \leq 1.85 \cdot 10^{+25}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]

Alternative 8: 76.3% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.5000000000000001e45

    1. Initial program 41.9%

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{c} \cdot \frac{d}{c}} \]
      2. clear-num75.0%

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

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

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

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

    if -5.5000000000000001e45 < c < 1e27

    1. Initial program 70.1%

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

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

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

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

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

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

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

    if 1e27 < c

    1. Initial program 48.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{+45}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c \cdot \frac{c}{b}}\\ \mathbf{elif}\;c \leq 10^{+27}:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]

Alternative 9: 76.8% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -6.19999999999999975e45

    1. Initial program 41.9%

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{c} \cdot \frac{d}{c}} \]
      2. clear-num75.0%

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

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

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

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

    if -6.19999999999999975e45 < c < 3.20000000000000029e26

    1. Initial program 70.1%

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

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

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

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

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

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

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

    if 3.20000000000000029e26 < c

    1. Initial program 48.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{+45}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c \cdot \frac{c}{b}}\\ \mathbf{elif}\;c \leq 3.2 \cdot 10^{+26}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]

Alternative 10: 62.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{+45}:\\
\;\;\;\;\frac{a}{c}\\

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

\mathbf{elif}\;c \leq 6.5 \cdot 10^{-85}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{a}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.5000000000000001e45 or 7.6000000000000003e24 < c

    1. Initial program 45.4%

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

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

    if -5.5000000000000001e45 < c < 9.5000000000000006e-129 or 6.5e-85 < c < 7.6000000000000003e24

    1. Initial program 69.3%

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

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

    if 9.5000000000000006e-129 < c < 6.5e-85

    1. Initial program 80.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{b \cdot \left(d \cdot d\right) + d \cdot \left(a \cdot c\right)}{d \cdot \left(d \cdot d\right)}} \]
    6. Applied egg-rr37.0%

      \[\leadsto \color{blue}{\frac{b \cdot \left(d \cdot d\right) + d \cdot \left(a \cdot c\right)}{d \cdot \left(d \cdot d\right)}} \]
    7. Taylor expanded in b around 0 61.1%

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

        \[\leadsto \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac71.1%

        \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    9. Simplified71.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{+45}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 9.5 \cdot 10^{-129}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{-85}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq 7.6 \cdot 10^{+24}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 11: 62.8% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{+45}:\\
\;\;\;\;\frac{a}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.5000000000000001e45 or 1.79999999999999992e24 < c

    1. Initial program 45.4%

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

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

    if -5.5000000000000001e45 < c < 1.79999999999999992e24

    1. Initial program 70.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{+45}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{+24}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 12: 42.4% 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 58.0%

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

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

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

Developer target: 99.2% 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 2023192 
(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))))