Complex division, real part

Percentage Accurate: 61.9% → 81.5%
Time: 9.1s
Alternatives: 8
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

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

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot a + b \cdot d\\ \mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\ \;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}\\ \mathbf{elif}\;c \leq -1.55 \cdot 10^{+77}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq -5.2:\\ \;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 10^{-120}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\ \;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c a) (* b d))))
   (if (<= c -2.4e+103)
     (/ 1.0 (/ c (fma b (/ d c) a)))
     (if (<= c -1.55e+77)
       (/ (+ b (* a (/ c d))) d)
       (if (<= c -5.2)
         (/ t_0 (+ (* c c) (* d d)))
         (if (<= c 1e-120)
           (/ (+ b (/ a (/ d c))) d)
           (if (<= c 8.2e+92)
             (/ t_0 (fma c c (* d d)))
             (/ (+ a (* b (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * a) + (b * d);
	double tmp;
	if (c <= -2.4e+103) {
		tmp = 1.0 / (c / fma(b, (d / c), a));
	} else if (c <= -1.55e+77) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= -5.2) {
		tmp = t_0 / ((c * c) + (d * d));
	} else if (c <= 1e-120) {
		tmp = (b + (a / (d / c))) / d;
	} else if (c <= 8.2e+92) {
		tmp = t_0 / fma(c, c, (d * d));
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c * a) + Float64(b * d))
	tmp = 0.0
	if (c <= -2.4e+103)
		tmp = Float64(1.0 / Float64(c / fma(b, Float64(d / c), a)));
	elseif (c <= -1.55e+77)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= -5.2)
		tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 1e-120)
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
	elseif (c <= 8.2e+92)
		tmp = Float64(t_0 / fma(c, c, Float64(d * d)));
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.4e+103], N[(1.0 / N[(c / N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.55e+77], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -5.2], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1e-120], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.2e+92], N[(t$95$0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;c \leq -5.2:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\

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

\mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\
\;\;\;\;\frac{t\_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if c < -2.3999999999999998e103

    1. Initial program 35.6%

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

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

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

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

        \[\leadsto \frac{a + b \cdot \color{blue}{\frac{1}{\frac{c}{d}}}}{c} \]
      2. un-div-inv92.9%

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{c}{a + \frac{b}{\frac{c}{d}}}}} \]
      2. inv-pow92.9%

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

        \[\leadsto {\left(\frac{c}{\color{blue}{\frac{b}{\frac{c}{d}} + a}}\right)}^{-1} \]
      4. associate-/r/93.0%

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

        \[\leadsto {\left(\frac{c}{\color{blue}{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}}\right)}^{-1} \]
    9. Applied egg-rr93.0%

      \[\leadsto \color{blue}{{\left(\frac{c}{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}\right)}^{-1}} \]
    10. Step-by-step derivation
      1. unpow-193.0%

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

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

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

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

        \[\leadsto \frac{1}{\frac{c}{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}} \]
    11. Simplified92.9%

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

    if -2.3999999999999998e103 < c < -1.54999999999999999e77

    1. Initial program 30.8%

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

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

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

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

    if -1.54999999999999999e77 < c < -5.20000000000000018

    1. Initial program 87.0%

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

    if -5.20000000000000018 < c < 9.99999999999999979e-121

    1. Initial program 61.0%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999979e-121 < c < 8.20000000000000047e92

    1. Initial program 82.6%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-define82.6%

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

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

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

    if 8.20000000000000047e92 < c

    1. Initial program 30.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\ \;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}\\ \mathbf{elif}\;c \leq -1.55 \cdot 10^{+77}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq -5.2:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 10^{-120}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\ \;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}\\ \mathbf{elif}\;c \leq -1.55 \cdot 10^{+77}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq -7.8:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-119}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -2.4e+103)
     (/ 1.0 (/ c (fma b (/ d c) a)))
     (if (<= c -1.55e+77)
       (/ (+ b (* a (/ c d))) d)
       (if (<= c -7.8)
         t_0
         (if (<= c 1.2e-119)
           (/ (+ b (/ a (/ d c))) d)
           (if (<= c 8.5e+92) t_0 (/ (+ a (* b (/ d c))) c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * a) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -2.4e+103) {
		tmp = 1.0 / (c / fma(b, (d / c), a));
	} else if (c <= -1.55e+77) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= -7.8) {
		tmp = t_0;
	} else if (c <= 1.2e-119) {
		tmp = (b + (a / (d / c))) / d;
	} else if (c <= 8.5e+92) {
		tmp = t_0;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -2.4e+103)
		tmp = Float64(1.0 / Float64(c / fma(b, Float64(d / c), a)));
	elseif (c <= -1.55e+77)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= -7.8)
		tmp = t_0;
	elseif (c <= 1.2e-119)
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
	elseif (c <= 8.5e+92)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.4e+103], N[(1.0 / N[(c / N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.55e+77], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -7.8], t$95$0, If[LessEqual[c, 1.2e-119], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.5e+92], t$95$0, N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;c \leq -7.8:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 8.5 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -2.3999999999999998e103

    1. Initial program 35.6%

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

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

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

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

        \[\leadsto \frac{a + b \cdot \color{blue}{\frac{1}{\frac{c}{d}}}}{c} \]
      2. un-div-inv92.9%

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{c}{a + \frac{b}{\frac{c}{d}}}}} \]
      2. inv-pow92.9%

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

        \[\leadsto {\left(\frac{c}{\color{blue}{\frac{b}{\frac{c}{d}} + a}}\right)}^{-1} \]
      4. associate-/r/93.0%

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

        \[\leadsto {\left(\frac{c}{\color{blue}{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}}\right)}^{-1} \]
    9. Applied egg-rr93.0%

      \[\leadsto \color{blue}{{\left(\frac{c}{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}\right)}^{-1}} \]
    10. Step-by-step derivation
      1. unpow-193.0%

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

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

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

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

        \[\leadsto \frac{1}{\frac{c}{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}} \]
    11. Simplified92.9%

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

    if -2.3999999999999998e103 < c < -1.54999999999999999e77

    1. Initial program 30.8%

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

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

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

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

    if -1.54999999999999999e77 < c < -7.79999999999999982 or 1.20000000000000004e-119 < c < 8.5000000000000001e92

    1. Initial program 83.6%

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

    if -7.79999999999999982 < c < 1.20000000000000004e-119

    1. Initial program 61.0%

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

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

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

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

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

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

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

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

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

    if 8.5000000000000001e92 < c

    1. Initial program 30.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\ \;\;\;\;\frac{1}{\frac{c}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}\\ \mathbf{elif}\;c \leq -1.55 \cdot 10^{+77}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq -7.8:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-119}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{+92}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a + b \cdot \frac{d}{c}}{c}\\ t_1 := \frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -1.12 \cdot 10^{+77}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq -16.5:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-119}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ a (* b (/ d c))) c))
        (t_1 (/ (+ (* c a) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -2.4e+103)
     t_0
     (if (<= c -1.12e+77)
       (/ (+ b (* a (/ c d))) d)
       (if (<= c -16.5)
         t_1
         (if (<= c 1.05e-119)
           (/ (+ b (/ a (/ d c))) d)
           (if (<= c 8.2e+92) t_1 t_0)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a + (b * (d / c))) / c;
	double t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -2.4e+103) {
		tmp = t_0;
	} else if (c <= -1.12e+77) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= -16.5) {
		tmp = t_1;
	} else if (c <= 1.05e-119) {
		tmp = (b + (a / (d / c))) / d;
	} else if (c <= 8.2e+92) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (a + (b * (d / c))) / c
    t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d))
    if (c <= (-2.4d+103)) then
        tmp = t_0
    else if (c <= (-1.12d+77)) then
        tmp = (b + (a * (c / d))) / d
    else if (c <= (-16.5d0)) then
        tmp = t_1
    else if (c <= 1.05d-119) then
        tmp = (b + (a / (d / c))) / d
    else if (c <= 8.2d+92) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (a + (b * (d / c))) / c;
	double t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -2.4e+103) {
		tmp = t_0;
	} else if (c <= -1.12e+77) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= -16.5) {
		tmp = t_1;
	} else if (c <= 1.05e-119) {
		tmp = (b + (a / (d / c))) / d;
	} else if (c <= 8.2e+92) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a + (b * (d / c))) / c
	t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -2.4e+103:
		tmp = t_0
	elif c <= -1.12e+77:
		tmp = (b + (a * (c / d))) / d
	elif c <= -16.5:
		tmp = t_1
	elif c <= 1.05e-119:
		tmp = (b + (a / (d / c))) / d
	elif c <= 8.2e+92:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a + Float64(b * Float64(d / c))) / c)
	t_1 = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -2.4e+103)
		tmp = t_0;
	elseif (c <= -1.12e+77)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= -16.5)
		tmp = t_1;
	elseif (c <= 1.05e-119)
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
	elseif (c <= 8.2e+92)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a + (b * (d / c))) / c;
	t_1 = ((c * a) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -2.4e+103)
		tmp = t_0;
	elseif (c <= -1.12e+77)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= -16.5)
		tmp = t_1;
	elseif (c <= 1.05e-119)
		tmp = (b + (a / (d / c))) / d;
	elseif (c <= 8.2e+92)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.4e+103], t$95$0, If[LessEqual[c, -1.12e+77], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, -16.5], t$95$1, If[LessEqual[c, 1.05e-119], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.2e+92], t$95$1, t$95$0]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;c \leq -16.5:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.3999999999999998e103 or 8.20000000000000047e92 < c

    1. Initial program 32.7%

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

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

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

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

    if -2.3999999999999998e103 < c < -1.1199999999999999e77

    1. Initial program 30.8%

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

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

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

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

    if -1.1199999999999999e77 < c < -16.5 or 1.05e-119 < c < 8.20000000000000047e92

    1. Initial program 83.6%

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

    if -16.5 < c < 1.05e-119

    1. Initial program 61.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{+103}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -1.12 \cdot 10^{+77}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq -16.5:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-119}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;c \leq 8.2 \cdot 10^{+92}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{if}\;d \leq -9.6 \cdot 10^{+83}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{-37}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-70} \lor \neg \left(d \leq 1.9 \cdot 10^{-10}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ b (* a (/ c d))) d)))
   (if (<= d -9.6e+83)
     t_0
     (if (<= d -1.9e-37)
       (/ (+ a (/ b (/ c d))) c)
       (if (or (<= d -1.75e-70) (not (<= d 1.9e-10)))
         t_0
         (/ (+ a (/ (* b d) c)) c))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -9.6e+83) {
		tmp = t_0;
	} else if (d <= -1.9e-37) {
		tmp = (a + (b / (c / d))) / c;
	} else if ((d <= -1.75e-70) || !(d <= 1.9e-10)) {
		tmp = t_0;
	} else {
		tmp = (a + ((b * d) / c)) / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (b + (a * (c / d))) / d
    if (d <= (-9.6d+83)) then
        tmp = t_0
    else if (d <= (-1.9d-37)) then
        tmp = (a + (b / (c / d))) / c
    else if ((d <= (-1.75d-70)) .or. (.not. (d <= 1.9d-10))) then
        tmp = t_0
    else
        tmp = (a + ((b * d) / c)) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -9.6e+83) {
		tmp = t_0;
	} else if (d <= -1.9e-37) {
		tmp = (a + (b / (c / d))) / c;
	} else if ((d <= -1.75e-70) || !(d <= 1.9e-10)) {
		tmp = t_0;
	} else {
		tmp = (a + ((b * d) / c)) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b + (a * (c / d))) / d
	tmp = 0
	if d <= -9.6e+83:
		tmp = t_0
	elif d <= -1.9e-37:
		tmp = (a + (b / (c / d))) / c
	elif (d <= -1.75e-70) or not (d <= 1.9e-10):
		tmp = t_0
	else:
		tmp = (a + ((b * d) / c)) / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d)
	tmp = 0.0
	if (d <= -9.6e+83)
		tmp = t_0;
	elseif (d <= -1.9e-37)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c);
	elseif ((d <= -1.75e-70) || !(d <= 1.9e-10))
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b + (a * (c / d))) / d;
	tmp = 0.0;
	if (d <= -9.6e+83)
		tmp = t_0;
	elseif (d <= -1.9e-37)
		tmp = (a + (b / (c / d))) / c;
	elseif ((d <= -1.75e-70) || ~((d <= 1.9e-10)))
		tmp = t_0;
	else
		tmp = (a + ((b * d) / c)) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -9.6e+83], t$95$0, If[LessEqual[d, -1.9e-37], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, -1.75e-70], N[Not[LessEqual[d, 1.9e-10]], $MachinePrecision]], t$95$0, N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq -1.75 \cdot 10^{-70} \lor \neg \left(d \leq 1.9 \cdot 10^{-10}\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -9.59999999999999965e83 or -1.9000000000000002e-37 < d < -1.74999999999999987e-70 or 1.8999999999999999e-10 < d

    1. Initial program 43.1%

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

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

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

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

    if -9.59999999999999965e83 < d < -1.9000000000000002e-37

    1. Initial program 63.6%

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

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

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

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

        \[\leadsto \frac{a + b \cdot \color{blue}{\frac{1}{\frac{c}{d}}}}{c} \]
      2. un-div-inv64.9%

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

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

    if -1.74999999999999987e-70 < d < 1.8999999999999999e-10

    1. Initial program 69.8%

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

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

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

Alternative 5: 76.5% accurate, 0.5× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.0600000000000001e85 or 1.85000000000000007e-10 < d

    1. Initial program 39.1%

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

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

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

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

    if -1.0600000000000001e85 < d < -1.80000000000000004e-37

    1. Initial program 63.6%

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

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

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

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

        \[\leadsto \frac{a + b \cdot \color{blue}{\frac{1}{\frac{c}{d}}}}{c} \]
      2. un-div-inv64.9%

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

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

    if -1.80000000000000004e-37 < d < -4.99999999999999998e-71

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

    if -4.99999999999999998e-71 < d < 1.85000000000000007e-10

    1. Initial program 69.8%

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

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

Alternative 6: 72.0% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.6 \cdot 10^{+87} \lor \neg \left(d \leq 5 \cdot 10^{+93}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.6e87 or 5.0000000000000001e93 < d

    1. Initial program 32.7%

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

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

    if -1.6e87 < d < 5.0000000000000001e93

    1. Initial program 68.6%

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

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

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

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

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

Alternative 7: 62.6% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.00000000000000023e84 or 1.7600000000000001e-10 < d

    1. Initial program 39.1%

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

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

    if -4.00000000000000023e84 < d < 1.7600000000000001e-10

    1. Initial program 70.7%

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

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

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

Alternative 8: 41.8% 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 56.8%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Add Preprocessing

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024084 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (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))))