Complex division, real part

Percentage Accurate: 62.5% → 84.8%
Time: 10.1s
Alternatives: 7
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 7 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: 62.5% accurate, 1.0× speedup?

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

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

Alternative 1: 84.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -1.35 \cdot 10^{+68}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -3 \cdot 10^{-118}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 3.1 \cdot 10^{-32}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\ \;\;\;\;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 (* (/ 1.0 (hypot c d)) (/ (fma a c (* d b)) (hypot c d)))))
   (if (<= c -1.35e+68)
     (/ (+ a (* d (/ b c))) (- (hypot c d)))
     (if (<= c -3e-118)
       t_0
       (if (<= c 3.1e-32)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 4.3e+107) t_0 (/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (1.0 / hypot(c, d)) * (fma(a, c, (d * b)) / hypot(c, d));
	double tmp;
	if (c <= -1.35e+68) {
		tmp = (a + (d * (b / c))) / -hypot(c, d);
	} else if (c <= -3e-118) {
		tmp = t_0;
	} else if (c <= 3.1e-32) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 4.3e+107) {
		tmp = t_0;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(d * b)) / hypot(c, d)))
	tmp = 0.0
	if (c <= -1.35e+68)
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / Float64(-hypot(c, d)));
	elseif (c <= -3e-118)
		tmp = t_0;
	elseif (c <= 3.1e-32)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 4.3e+107)
		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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.35e+68], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -3e-118], t$95$0, If[LessEqual[c, 3.1e-32], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.3e+107], 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{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -1.35 \cdot 10^{+68}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -3 \cdot 10^{-118}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 52.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.34999999999999995e68 < c < -3.00000000000000018e-118 or 3.10000000000000011e-32 < c < 4.3e107

    1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.00000000000000018e-118 < c < 3.10000000000000011e-32

    1. Initial program 64.1%

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

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

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

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

    if 4.3e107 < c

    1. Initial program 27.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.35 \cdot 10^{+68}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -3 \cdot 10^{-118}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 3.1 \cdot 10^{-32}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -5.3 \cdot 10^{+70}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.5 \cdot 10^{-139}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 0.00046:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\ \;\;\;\;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 (/ (+ (* d b) (* c a)) (+ (* c c) (* d d)))))
   (if (<= c -5.3e+70)
     (/ (+ a (* d (/ b c))) (- (hypot c d)))
     (if (<= c -8.5e-139)
       t_0
       (if (<= c 0.00046)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 4.3e+107) t_0 (/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -5.3e+70) {
		tmp = (a + (d * (b / c))) / -hypot(c, d);
	} else if (c <= -8.5e-139) {
		tmp = t_0;
	} else if (c <= 0.00046) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 4.3e+107) {
		tmp = t_0;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -5.3e+70) {
		tmp = (a + (d * (b / c))) / -Math.hypot(c, d);
	} else if (c <= -8.5e-139) {
		tmp = t_0;
	} else if (c <= 0.00046) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 4.3e+107) {
		tmp = t_0;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -5.3e+70:
		tmp = (a + (d * (b / c))) / -math.hypot(c, d)
	elif c <= -8.5e-139:
		tmp = t_0
	elif c <= 0.00046:
		tmp = (b + (a * (c / d))) / d
	elif c <= 4.3e+107:
		tmp = t_0
	else:
		tmp = (a + (b * (d / c))) / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -5.3e+70)
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / Float64(-hypot(c, d)));
	elseif (c <= -8.5e-139)
		tmp = t_0;
	elseif (c <= 0.00046)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 4.3e+107)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -5.3e+70)
		tmp = (a + (d * (b / c))) / -hypot(c, d);
	elseif (c <= -8.5e-139)
		tmp = t_0;
	elseif (c <= 0.00046)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 4.3e+107)
		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[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.3e+70], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -8.5e-139], t$95$0, If[LessEqual[c, 0.00046], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.3e+107], 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{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -5.3 \cdot 10^{+70}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -8.5 \cdot 10^{-139}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 0.00046:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

\mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 50.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.3e70 < c < -8.5000000000000003e-139 or 4.6000000000000001e-4 < c < 4.3e107

    1. Initial program 86.3%

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

    if -8.5000000000000003e-139 < c < 4.6000000000000001e-4

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

      \[\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}} \]

    if 4.3e107 < c

    1. Initial program 27.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.3 \cdot 10^{+70}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -8.5 \cdot 10^{-139}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 0.00046:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{+107}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{if}\;c \leq -1.16 \cdot 10^{+128}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -3.2 \cdot 10^{-123}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 0.00045:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{+107}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* c c) (* d d))))
        (t_1 (/ (+ a (* b (/ d c))) c)))
   (if (<= c -1.16e+128)
     t_1
     (if (<= c -3.2e-123)
       t_0
       (if (<= c 0.00045)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 5.2e+107) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double t_1 = (a + (b * (d / c))) / c;
	double tmp;
	if (c <= -1.16e+128) {
		tmp = t_1;
	} else if (c <= -3.2e-123) {
		tmp = t_0;
	} else if (c <= 0.00045) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 5.2e+107) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 = ((d * b) + (c * a)) / ((c * c) + (d * d))
    t_1 = (a + (b * (d / c))) / c
    if (c <= (-1.16d+128)) then
        tmp = t_1
    else if (c <= (-3.2d-123)) then
        tmp = t_0
    else if (c <= 0.00045d0) then
        tmp = (b + (a * (c / d))) / d
    else if (c <= 5.2d+107) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double t_1 = (a + (b * (d / c))) / c;
	double tmp;
	if (c <= -1.16e+128) {
		tmp = t_1;
	} else if (c <= -3.2e-123) {
		tmp = t_0;
	} else if (c <= 0.00045) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 5.2e+107) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d))
	t_1 = (a + (b * (d / c))) / c
	tmp = 0
	if c <= -1.16e+128:
		tmp = t_1
	elif c <= -3.2e-123:
		tmp = t_0
	elif c <= 0.00045:
		tmp = (b + (a * (c / d))) / d
	elif c <= 5.2e+107:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c)
	tmp = 0.0
	if (c <= -1.16e+128)
		tmp = t_1;
	elseif (c <= -3.2e-123)
		tmp = t_0;
	elseif (c <= 0.00045)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 5.2e+107)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	t_1 = (a + (b * (d / c))) / c;
	tmp = 0.0;
	if (c <= -1.16e+128)
		tmp = t_1;
	elseif (c <= -3.2e-123)
		tmp = t_0;
	elseif (c <= 0.00045)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 5.2e+107)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.16e+128], t$95$1, If[LessEqual[c, -3.2e-123], t$95$0, If[LessEqual[c, 0.00045], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.2e+107], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -3.2 \cdot 10^{-123}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 0.00045:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

\mathbf{elif}\;c \leq 5.2 \cdot 10^{+107}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.1600000000000001e128 or 5.2000000000000002e107 < c

    1. Initial program 28.0%

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

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

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

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

    if -1.1600000000000001e128 < c < -3.19999999999999979e-123 or 4.4999999999999999e-4 < c < 5.2000000000000002e107

    1. Initial program 85.8%

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

    if -3.19999999999999979e-123 < c < 4.4999999999999999e-4

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

      \[\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}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.16 \cdot 10^{+128}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -3.2 \cdot 10^{-123}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 0.00045:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{+107}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 71.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+90} \lor \neg \left(d \leq 6.8 \cdot 10^{+27}\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.2e+90) (not (<= d 6.8e+27)))
   (/ b d)
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.2e+90) || !(d <= 6.8e+27)) {
		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.2d+90)) .or. (.not. (d <= 6.8d+27))) 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.2e+90) || !(d <= 6.8e+27)) {
		tmp = b / d;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.2e+90) or not (d <= 6.8e+27):
		tmp = b / d
	else:
		tmp = (a + (b * (d / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1.2e+90) || !(d <= 6.8e+27))
		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.2e+90) || ~((d <= 6.8e+27)))
		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.2e+90], N[Not[LessEqual[d, 6.8e+27]], $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.2 \cdot 10^{+90} \lor \neg \left(d \leq 6.8 \cdot 10^{+27}\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.20000000000000005e90 or 6.8e27 < d

    1. Initial program 44.7%

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

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

    if -1.20000000000000005e90 < d < 6.8e27

    1. Initial program 72.5%

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

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

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

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

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

Alternative 5: 77.9% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.7199999999999999e-20 or 800 < c

    1. Initial program 54.4%

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

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

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

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

    if -1.7199999999999999e-20 < c < 800

    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 d around inf 84.9%

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

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

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

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

Alternative 6: 63.3% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.25e20 or 2.45e19 < d

    1. Initial program 45.2%

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

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

    if -1.25e20 < d < 2.45e19

    1. Initial program 75.7%

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

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

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

Alternative 7: 42.2% 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 61.0%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification46.6%

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

Developer target: 99.2% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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