Complex division, real part

Percentage Accurate: 61.7% → 85.4%
Time: 8.4s
Alternatives: 8
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 61.7% accurate, 1.0× speedup?

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

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

Alternative 1: 85.4% accurate, 0.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+264}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.00000000000000009e264

    1. Initial program 76.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000009e264 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 16.9%

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

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

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

      \[\leadsto \color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in b around 0 57.7%

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

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

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{c} \]
    8. Simplified68.0%

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

Alternative 2: 80.9% accurate, 0.5× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.9000000000000003e-14 or 5.00000000000000029e83 < c

    1. Initial program 47.1%

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

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

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

      \[\leadsto \color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in b around 0 76.6%

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

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

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{c} \]
    8. Simplified82.2%

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

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

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

    if -2.9000000000000003e-14 < c < 1.12e-150

    1. Initial program 69.6%

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

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

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

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

    if 1.12e-150 < c < 5.00000000000000029e83

    1. Initial program 86.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification86.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.9 \cdot 10^{-14}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;c \leq 1.12 \cdot 10^{-150}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 5 \cdot 10^{+83}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 70.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2500000 \lor \neg \left(d \leq 2 \cdot 10^{-61} \lor \neg \left(d \leq 7.8 \cdot 10^{+112}\right) \land d \leq 1.02 \cdot 10^{+133}\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 -2500000.0)
         (not (or (<= d 2e-61) (and (not (<= d 7.8e+112)) (<= d 1.02e+133)))))
   (/ b d)
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -2500000.0) || !((d <= 2e-61) || (!(d <= 7.8e+112) && (d <= 1.02e+133)))) {
		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 <= (-2500000.0d0)) .or. (.not. (d <= 2d-61) .or. (.not. (d <= 7.8d+112)) .and. (d <= 1.02d+133))) 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 <= -2500000.0) || !((d <= 2e-61) || (!(d <= 7.8e+112) && (d <= 1.02e+133)))) {
		tmp = b / d;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -2500000.0) or not ((d <= 2e-61) or (not (d <= 7.8e+112) and (d <= 1.02e+133))):
		tmp = b / d
	else:
		tmp = (a + (b * (d / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -2500000.0) || !((d <= 2e-61) || (!(d <= 7.8e+112) && (d <= 1.02e+133))))
		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 <= -2500000.0) || ~(((d <= 2e-61) || (~((d <= 7.8e+112)) && (d <= 1.02e+133)))))
		tmp = b / d;
	else
		tmp = (a + (b * (d / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2500000.0], N[Not[Or[LessEqual[d, 2e-61], And[N[Not[LessEqual[d, 7.8e+112]], $MachinePrecision], LessEqual[d, 1.02e+133]]]], $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 -2500000 \lor \neg \left(d \leq 2 \cdot 10^{-61} \lor \neg \left(d \leq 7.8 \cdot 10^{+112}\right) \land d \leq 1.02 \cdot 10^{+133}\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 < -2.5e6 or 2.0000000000000001e-61 < d < 7.79999999999999937e112 or 1.02e133 < d

    1. Initial program 59.4%

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

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

    if -2.5e6 < d < 2.0000000000000001e-61 or 7.79999999999999937e112 < d < 1.02e133

    1. Initial program 67.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2500000 \lor \neg \left(d \leq 2 \cdot 10^{-61} \lor \neg \left(d \leq 7.8 \cdot 10^{+112}\right) \land d \leq 1.02 \cdot 10^{+133}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 70.9% accurate, 0.5× speedup?

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

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

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

\mathbf{elif}\;d \leq 5 \cdot 10^{+115} \lor \neg \left(d \leq 5.4 \cdot 10^{+135}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3e6 or 2.0000000000000001e-61 < d < 5.00000000000000008e115 or 5.3999999999999997e135 < d

    1. Initial program 59.4%

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

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

    if -3e6 < d < 2.0000000000000001e-61

    1. Initial program 70.7%

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

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

    if 5.00000000000000008e115 < d < 5.3999999999999997e135

    1. Initial program 34.7%

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

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

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

      \[\leadsto \color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in b around 0 45.6%

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

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

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

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

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

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

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

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

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

Alternative 5: 70.9% accurate, 0.5× speedup?

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

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

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

\mathbf{elif}\;d \leq 9 \cdot 10^{+114} \lor \neg \left(d \leq 1.05 \cdot 10^{+133}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -9e4 or 1.8999999999999999e-61 < d < 9.0000000000000001e114 or 1.05e133 < d

    1. Initial program 59.4%

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

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

    if -9e4 < d < 1.8999999999999999e-61

    1. Initial program 70.7%

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

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

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

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

    if 9.0000000000000001e114 < d < 1.05e133

    1. Initial program 34.7%

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

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

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

      \[\leadsto \color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in b around 0 45.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -90000:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{-61}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+114} \lor \neg \left(d \leq 1.05 \cdot 10^{+133}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 77.8% accurate, 0.8× speedup?

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

    1. Initial program 55.9%

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

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

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

      \[\leadsto \color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in b around 0 73.3%

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

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

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{c} \]
    8. Simplified77.0%

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

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

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

    if -2.2000000000000001e-14 < c < 1.02e-57

    1. Initial program 71.6%

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

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

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

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

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

Alternative 7: 63.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -46000 \lor \neg \left(d \leq 9.2 \cdot 10^{-62}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -46000 or 9.20000000000000002e-62 < d

    1. Initial program 57.9%

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

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

    if -46000 < d < 9.20000000000000002e-62

    1. Initial program 70.7%

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

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

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

Alternative 8: 43.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 63.3%

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

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

Developer target: 99.5% 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 2024118 
(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))))