Complex division, real part

Percentage Accurate: 61.9% → 86.9%
Time: 10.3s
Alternatives: 9
Speedup: 0.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 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: 86.9% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\ t_1 := \frac{1}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{if}\;d \leq -6.9 \cdot 10^{+149}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \left(t\_1 \cdot \left(a \cdot t\_1\right)\right)\right)\\ \mathbf{elif}\;d \leq -5.5 \cdot 10^{-82}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-87}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+155}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0
         (fma
          b
          (/ d (pow (hypot d c) 2.0))
          (* c (/ (/ a (hypot d c)) (hypot d c)))))
        (t_1 (/ 1.0 (hypot d c))))
   (if (<= d -6.9e+149)
     (fma b (/ 1.0 d) (* c (* t_1 (* a t_1))))
     (if (<= d -5.5e-82)
       t_0
       (if (<= d 1.2e-87)
         (/ (+ a (* b (/ d c))) c)
         (if (<= d 2.9e+155) t_0 (/ (+ b (* c (/ a d))) d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(b, (d / pow(hypot(d, c), 2.0)), (c * ((a / hypot(d, c)) / hypot(d, c))));
	double t_1 = 1.0 / hypot(d, c);
	double tmp;
	if (d <= -6.9e+149) {
		tmp = fma(b, (1.0 / d), (c * (t_1 * (a * t_1))));
	} else if (d <= -5.5e-82) {
		tmp = t_0;
	} else if (d <= 1.2e-87) {
		tmp = (a + (b * (d / c))) / c;
	} else if (d <= 2.9e+155) {
		tmp = t_0;
	} else {
		tmp = (b + (c * (a / d))) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(b, Float64(d / (hypot(d, c) ^ 2.0)), Float64(c * Float64(Float64(a / hypot(d, c)) / hypot(d, c))))
	t_1 = Float64(1.0 / hypot(d, c))
	tmp = 0.0
	if (d <= -6.9e+149)
		tmp = fma(b, Float64(1.0 / d), Float64(c * Float64(t_1 * Float64(a * t_1))));
	elseif (d <= -5.5e-82)
		tmp = t_0;
	elseif (d <= 1.2e-87)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	elseif (d <= 2.9e+155)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(d / N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(c * N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -6.9e+149], N[(b * N[(1.0 / d), $MachinePrecision] + N[(c * N[(t$95$1 * N[(a * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.5e-82], t$95$0, If[LessEqual[d, 1.2e-87], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.9e+155], t$95$0, N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\
t_1 := \frac{1}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -6.9 \cdot 10^{+149}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \left(t\_1 \cdot \left(a \cdot t\_1\right)\right)\right)\\

\mathbf{elif}\;d \leq -5.5 \cdot 10^{-82}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.9 \cdot 10^{+155}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 35.9%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{d}{{c}^{2} + {d}^{2}}, \frac{a \cdot c}{{c}^{2} + {d}^{2}}\right)} \]
    5. Simplified37.3%

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \color{blue}{\frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}}\right) \]
    10. Step-by-step derivation
      1. div-inv44.9%

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

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

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

      \[\leadsto \mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \color{blue}{\left(a \cdot \left(\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\right)\right)}\right) \]
    12. Step-by-step derivation
      1. associate-*r*44.9%

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

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

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

    if -6.9000000000000004e149 < d < -5.4999999999999998e-82 or 1.2e-87 < d < 2.8999999999999999e155

    1. Initial program 74.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{\color{blue}{\frac{a}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)}\right) \]
    9. Simplified89.7%

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

    if -5.4999999999999998e-82 < d < 1.2e-87

    1. Initial program 66.8%

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

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

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

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

    if 2.8999999999999999e155 < d

    1. Initial program 22.6%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.9 \cdot 10^{+149}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \left(\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \left(a \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\right)\right)\right)\\ \mathbf{elif}\;d \leq -5.5 \cdot 10^{-82}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-87}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+155}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.7% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(b, \frac{1}{d}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\ t_1 := {\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}\\ \mathbf{if}\;d \leq -1.02 \cdot 10^{-69}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-88}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 7 \cdot 10^{+105}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{d}{t\_1}, c \cdot \frac{a}{t\_1}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma b (/ 1.0 d) (* c (/ (/ a (hypot d c)) (hypot d c)))))
        (t_1 (pow (hypot d c) 2.0)))
   (if (<= d -1.02e-69)
     t_0
     (if (<= d 5.5e-88)
       (/ (+ a (* b (/ d c))) c)
       (if (<= d 7e+105) (fma b (/ d t_1) (* c (/ a t_1))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(b, (1.0 / d), (c * ((a / hypot(d, c)) / hypot(d, c))));
	double t_1 = pow(hypot(d, c), 2.0);
	double tmp;
	if (d <= -1.02e-69) {
		tmp = t_0;
	} else if (d <= 5.5e-88) {
		tmp = (a + (b * (d / c))) / c;
	} else if (d <= 7e+105) {
		tmp = fma(b, (d / t_1), (c * (a / t_1)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(b, Float64(1.0 / d), Float64(c * Float64(Float64(a / hypot(d, c)) / hypot(d, c))))
	t_1 = hypot(d, c) ^ 2.0
	tmp = 0.0
	if (d <= -1.02e-69)
		tmp = t_0;
	elseif (d <= 5.5e-88)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	elseif (d <= 7e+105)
		tmp = fma(b, Float64(d / t_1), Float64(c * Float64(a / t_1)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(1.0 / d), $MachinePrecision] + N[(c * N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[d, -1.02e-69], t$95$0, If[LessEqual[d, 5.5e-88], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7e+105], N[(b * N[(d / t$95$1), $MachinePrecision] + N[(c * N[(a / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, \frac{1}{d}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\
t_1 := {\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}\\
\mathbf{if}\;d \leq -1.02 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 7 \cdot 10^{+105}:\\
\;\;\;\;\mathsf{fma}\left(b, \frac{d}{t\_1}, c \cdot \frac{a}{t\_1}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.02000000000000005e-69 or 6.99999999999999982e105 < d

    1. Initial program 49.5%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{d}{{c}^{2} + {d}^{2}}, \frac{a \cdot c}{{c}^{2} + {d}^{2}}\right)} \]
    5. Simplified52.3%

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

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

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

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

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

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

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

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

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

    if -1.02000000000000005e-69 < d < 5.49999999999999971e-88

    1. Initial program 66.8%

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

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

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

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

    if 5.49999999999999971e-88 < d < 6.99999999999999982e105

    1. Initial program 71.2%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{d}{{c}^{2} + {d}^{2}}, \frac{a \cdot c}{{c}^{2} + {d}^{2}}\right)} \]
    5. Simplified85.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{a}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 79.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{-82} \lor \neg \left(d \leq 1.15 \cdot 10^{-16}\right):\\ \;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -4.8e-82) (not (<= d 1.15e-16)))
   (fma b (/ 1.0 d) (* c (/ (/ a (hypot d c)) (hypot d c))))
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -4.8e-82) || !(d <= 1.15e-16)) {
		tmp = fma(b, (1.0 / d), (c * ((a / hypot(d, c)) / hypot(d, c))));
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -4.8e-82) || !(d <= 1.15e-16))
		tmp = fma(b, Float64(1.0 / d), Float64(c * Float64(Float64(a / hypot(d, c)) / hypot(d, c))));
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -4.8e-82], N[Not[LessEqual[d, 1.15e-16]], $MachinePrecision]], N[(b * N[(1.0 / d), $MachinePrecision] + N[(c * N[(N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{-82} \lor \neg \left(d \leq 1.15 \cdot 10^{-16}\right):\\
\;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.80000000000000017e-82 or 1.15e-16 < d

    1. Initial program 52.8%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{d}{{c}^{2} + {d}^{2}}, \frac{a \cdot c}{{c}^{2} + {d}^{2}}\right)} \]
    5. Simplified58.3%

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{d}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}, c \cdot \frac{\color{blue}{\frac{a}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)}\right) \]
    9. Simplified63.6%

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

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

    if -4.80000000000000017e-82 < d < 1.15e-16

    1. Initial program 67.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{-82} \lor \neg \left(d \leq 1.15 \cdot 10^{-16}\right):\\ \;\;\;\;\mathsf{fma}\left(b, \frac{1}{d}, c \cdot \frac{\frac{a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.8% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;d \leq -2.4 \cdot 10^{-79}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 3.5 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 49.5%

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

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

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

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

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

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

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

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

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

    if -8.8e67 < d < -2.40000000000000006e-79 or 7.50000000000000041e-88 < d < 3.50000000000000011e102

    1. Initial program 76.5%

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

    if -2.40000000000000006e-79 < d < 7.50000000000000041e-88

    1. Initial program 66.8%

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

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

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

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

    if 3.50000000000000011e102 < d

    1. Initial program 29.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.8 \cdot 10^{+67}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq -2.4 \cdot 10^{-79}:\\ \;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-88}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{+102}:\\ \;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.5% accurate, 0.8× speedup?

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

    1. Initial program 49.3%

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

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

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

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

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

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

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

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

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

    if -2.2e6 < d < 1.8000000000000001e-15

    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 88.4%

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

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

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

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

Alternative 6: 78.0% accurate, 0.8× speedup?

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

    1. Initial program 49.3%

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

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

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

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

    if -4.9e5 < d < 1.76e-15

    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 88.4%

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

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

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

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

Alternative 7: 72.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+48} \lor \neg \left(d \leq 3.1 \cdot 10^{+125}\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.05e+48) (not (<= d 3.1e+125)))
   (/ b d)
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.05e+48) || !(d <= 3.1e+125)) {
		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.05d+48)) .or. (.not. (d <= 3.1d+125))) 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.05e+48) || !(d <= 3.1e+125)) {
		tmp = b / d;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.05e+48) or not (d <= 3.1e+125):
		tmp = b / d
	else:
		tmp = (a + (b * (d / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1.05e+48) || !(d <= 3.1e+125))
		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.05e+48) || ~((d <= 3.1e+125)))
		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.05e+48], N[Not[LessEqual[d, 3.1e+125]], $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.05 \cdot 10^{+48} \lor \neg \left(d \leq 3.1 \cdot 10^{+125}\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.0499999999999999e48 or 3.1e125 < d

    1. Initial program 42.1%

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

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

    if -1.0499999999999999e48 < d < 3.1e125

    1. Initial program 69.7%

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

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

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

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

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

Alternative 8: 61.8% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8e3 or 5.0000000000000004e127 < d

    1. Initial program 45.0%

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

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

    if -8e3 < d < 5.0000000000000004e127

    1. Initial program 69.0%

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

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

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

Alternative 9: 42.9% 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 59.2%

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

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

Developer Target 1: 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 2024131 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (! :herbie-platform default (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))))