Complex division, real part

Percentage Accurate: 61.5% → 82.8%
Time: 8.9s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 61.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: 82.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{if}\;d \leq -6.1 \cdot 10^{+88}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{-55}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{-107}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{+28}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ b (* a (/ c d))) d)))
   (if (<= d -6.1e+88)
     t_0
     (if (<= d -1.95e-55)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (if (<= d 1.95e-107)
         (/ (+ a (/ b (/ c d))) c)
         (if (<= d 3e+28) (/ (fma a c (* b d)) (fma c c (* d d))) t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -6.1e+88) {
		tmp = t_0;
	} else if (d <= -1.95e-55) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 1.95e-107) {
		tmp = (a + (b / (c / d))) / c;
	} else if (d <= 3e+28) {
		tmp = fma(a, c, (b * d)) / fma(c, c, (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d)
	tmp = 0.0
	if (d <= -6.1e+88)
		tmp = t_0;
	elseif (d <= -1.95e-55)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1.95e-107)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c);
	elseif (d <= 3e+28)
		tmp = Float64(fma(a, c, Float64(b * d)) / fma(c, c, Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -6.1e+88], t$95$0, If[LessEqual[d, -1.95e-55], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.95e-107], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3e+28], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -6.0999999999999998e88 or 3.0000000000000001e28 < d

    1. Initial program 44.2%

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

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

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

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

    if -6.0999999999999998e88 < d < -1.95e-55

    1. Initial program 89.4%

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

    if -1.95e-55 < d < 1.95e-107

    1. Initial program 72.4%

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

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

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

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

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

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

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

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

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

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

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

    if 1.95e-107 < d < 3.0000000000000001e28

    1. Initial program 91.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.1 \cdot 10^{+88}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{-55}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{-107}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{+28}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

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

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


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

    1. Initial program 80.5%

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

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

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

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

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

        \[\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-define95.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-rr95.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 1e189 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 25.7%

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

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

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

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

Alternative 3: 84.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot c + b \cdot d\\ \mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 10^{+189}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))))
   (if (<= (/ t_0 (+ (* c c) (* d d))) 1e+189)
     (* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
     (/ (+ b (* a (/ c d))) d))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if ((t_0 / ((c * c) + (d * d))) <= 1e+189) {
		tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
	} else {
		tmp = (b + (a * (c / d))) / d;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if ((t_0 / ((c * c) + (d * d))) <= 1e+189) {
		tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
	} else {
		tmp = (b + (a * (c / d))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a * c) + (b * d)
	tmp = 0
	if (t_0 / ((c * c) + (d * d))) <= 1e+189:
		tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d))
	else:
		tmp = (b + (a * (c / d))) / d
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) + Float64(b * d))
	tmp = 0.0
	if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= 1e+189)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d)));
	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 = (a * c) + (b * d);
	tmp = 0.0;
	if ((t_0 / ((c * c) + (d * d))) <= 1e+189)
		tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
	else
		tmp = (b + (a * (c / d))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+189], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq 10^{+189}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t\_0}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 80.5%

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

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

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

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

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

        \[\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-define95.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-rr95.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)}} \]
    5. Step-by-step derivation
      1. fma-define95.5%

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

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

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

    if 1e189 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 25.7%

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

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

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

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

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

Alternative 4: 77.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a + b \cdot \frac{d}{c}}{c}\\ t_1 := \frac{b + a \cdot \frac{c}{d}}{d}\\ t_2 := \frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{if}\;d \leq -2.1 \cdot 10^{+44}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-105}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{-47}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d \leq 3.7 \cdot 10^{+37}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{+121}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+121}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ a (* b (/ d c))) c))
        (t_1 (/ (+ b (* a (/ c d))) d))
        (t_2 (/ (+ b (/ (* a c) d)) d)))
   (if (<= d -2.1e+44)
     t_1
     (if (<= d 3.2e-105)
       t_0
       (if (<= d 1.25e-47)
         t_2
         (if (<= d 3.7e+37)
           t_0
           (if (<= d 1.85e+121) t_2 (if (<= d 1.9e+121) (/ a c) t_1))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a + (b * (d / c))) / c;
	double t_1 = (b + (a * (c / d))) / d;
	double t_2 = (b + ((a * c) / d)) / d;
	double tmp;
	if (d <= -2.1e+44) {
		tmp = t_1;
	} else if (d <= 3.2e-105) {
		tmp = t_0;
	} else if (d <= 1.25e-47) {
		tmp = t_2;
	} else if (d <= 3.7e+37) {
		tmp = t_0;
	} else if (d <= 1.85e+121) {
		tmp = t_2;
	} else if (d <= 1.9e+121) {
		tmp = a / c;
	} 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) :: t_2
    real(8) :: tmp
    t_0 = (a + (b * (d / c))) / c
    t_1 = (b + (a * (c / d))) / d
    t_2 = (b + ((a * c) / d)) / d
    if (d <= (-2.1d+44)) then
        tmp = t_1
    else if (d <= 3.2d-105) then
        tmp = t_0
    else if (d <= 1.25d-47) then
        tmp = t_2
    else if (d <= 3.7d+37) then
        tmp = t_0
    else if (d <= 1.85d+121) then
        tmp = t_2
    else if (d <= 1.9d+121) then
        tmp = a / c
    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 = (a + (b * (d / c))) / c;
	double t_1 = (b + (a * (c / d))) / d;
	double t_2 = (b + ((a * c) / d)) / d;
	double tmp;
	if (d <= -2.1e+44) {
		tmp = t_1;
	} else if (d <= 3.2e-105) {
		tmp = t_0;
	} else if (d <= 1.25e-47) {
		tmp = t_2;
	} else if (d <= 3.7e+37) {
		tmp = t_0;
	} else if (d <= 1.85e+121) {
		tmp = t_2;
	} else if (d <= 1.9e+121) {
		tmp = a / c;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a + (b * (d / c))) / c
	t_1 = (b + (a * (c / d))) / d
	t_2 = (b + ((a * c) / d)) / d
	tmp = 0
	if d <= -2.1e+44:
		tmp = t_1
	elif d <= 3.2e-105:
		tmp = t_0
	elif d <= 1.25e-47:
		tmp = t_2
	elif d <= 3.7e+37:
		tmp = t_0
	elif d <= 1.85e+121:
		tmp = t_2
	elif d <= 1.9e+121:
		tmp = a / c
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a + Float64(b * Float64(d / c))) / c)
	t_1 = Float64(Float64(b + Float64(a * Float64(c / d))) / d)
	t_2 = Float64(Float64(b + Float64(Float64(a * c) / d)) / d)
	tmp = 0.0
	if (d <= -2.1e+44)
		tmp = t_1;
	elseif (d <= 3.2e-105)
		tmp = t_0;
	elseif (d <= 1.25e-47)
		tmp = t_2;
	elseif (d <= 3.7e+37)
		tmp = t_0;
	elseif (d <= 1.85e+121)
		tmp = t_2;
	elseif (d <= 1.9e+121)
		tmp = Float64(a / c);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a + (b * (d / c))) / c;
	t_1 = (b + (a * (c / d))) / d;
	t_2 = (b + ((a * c) / d)) / d;
	tmp = 0.0;
	if (d <= -2.1e+44)
		tmp = t_1;
	elseif (d <= 3.2e-105)
		tmp = t_0;
	elseif (d <= 1.25e-47)
		tmp = t_2;
	elseif (d <= 3.7e+37)
		tmp = t_0;
	elseif (d <= 1.85e+121)
		tmp = t_2;
	elseif (d <= 1.9e+121)
		tmp = a / c;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$2 = N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.1e+44], t$95$1, If[LessEqual[d, 3.2e-105], t$95$0, If[LessEqual[d, 1.25e-47], t$95$2, If[LessEqual[d, 3.7e+37], t$95$0, If[LessEqual[d, 1.85e+121], t$95$2, If[LessEqual[d, 1.9e+121], N[(a / c), $MachinePrecision], t$95$1]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq 3.2 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 1.25 \cdot 10^{-47}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;d \leq 3.7 \cdot 10^{+37}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 1.85 \cdot 10^{+121}:\\
\;\;\;\;t\_2\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.09999999999999987e44 or 1.9e121 < d

    1. Initial program 46.3%

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

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

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

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

    if -2.09999999999999987e44 < d < 3.19999999999999981e-105 or 1.25000000000000003e-47 < d < 3.6999999999999999e37

    1. Initial program 77.4%

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

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

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

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

    if 3.19999999999999981e-105 < d < 1.25000000000000003e-47 or 3.6999999999999999e37 < d < 1.85000000000000006e121

    1. Initial program 79.8%

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

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

    if 1.85000000000000006e121 < d < 1.9e121

    1. Initial program 5.3%

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

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

Alternative 5: 82.9% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;d \leq -9.8 \cdot 10^{-53}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 3 \cdot 10^{+28}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.1999999999999998e92 or 3.0000000000000001e28 < d

    1. Initial program 44.2%

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

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

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

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

    if -5.1999999999999998e92 < d < -9.79999999999999926e-53 or 2.02e-109 < d < 3.0000000000000001e28

    1. Initial program 90.6%

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

    if -9.79999999999999926e-53 < d < 2.02e-109

    1. Initial program 72.4%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+92}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -9.8 \cdot 10^{-53}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.02 \cdot 10^{-109}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{+28}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 62.3% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5 \cdot 10^{+110} \lor \neg \left(c \leq -1.15 \cdot 10^{+40}\right) \land \left(c \leq -4.5 \cdot 10^{+38} \lor \neg \left(c \leq 2.05 \cdot 10^{-8} \lor \neg \left(c \leq 8 \cdot 10^{+133}\right) \land c \leq 2.6 \cdot 10^{+151}\right)\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.99999999999999978e110 or -1.14999999999999997e40 < c < -4.4999999999999998e38 or 2.05000000000000016e-8 < c < 8.0000000000000002e133 or 2.60000000000000013e151 < c

    1. Initial program 60.4%

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

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

    if -4.99999999999999978e110 < c < -1.14999999999999997e40 or -4.4999999999999998e38 < c < 2.05000000000000016e-8 or 8.0000000000000002e133 < c < 2.60000000000000013e151

    1. Initial program 68.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5 \cdot 10^{+110} \lor \neg \left(c \leq -1.15 \cdot 10^{+40}\right) \land \left(c \leq -4.5 \cdot 10^{+38} \lor \neg \left(c \leq 2.05 \cdot 10^{-8} \lor \neg \left(c \leq 8 \cdot 10^{+133}\right) \land c \leq 2.6 \cdot 10^{+151}\right)\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 72.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+31} \lor \neg \left(d \leq 1.35 \cdot 10^{-76}\right) \land \left(d \leq 1.95 \cdot 10^{-44} \lor \neg \left(d \leq 2.3 \cdot 10^{+37}\right)\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+31)
         (and (not (<= d 1.35e-76)) (or (<= d 1.95e-44) (not (<= d 2.3e+37)))))
   (/ b d)
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.2e+31) || (!(d <= 1.35e-76) && ((d <= 1.95e-44) || !(d <= 2.3e+37)))) {
		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+31)) .or. (.not. (d <= 1.35d-76)) .and. (d <= 1.95d-44) .or. (.not. (d <= 2.3d+37))) 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+31) || (!(d <= 1.35e-76) && ((d <= 1.95e-44) || !(d <= 2.3e+37)))) {
		tmp = b / d;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.2e+31) or (not (d <= 1.35e-76) and ((d <= 1.95e-44) or not (d <= 2.3e+37))):
		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+31) || (!(d <= 1.35e-76) && ((d <= 1.95e-44) || !(d <= 2.3e+37))))
		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+31) || (~((d <= 1.35e-76)) && ((d <= 1.95e-44) || ~((d <= 2.3e+37)))))
		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+31], And[N[Not[LessEqual[d, 1.35e-76]], $MachinePrecision], Or[LessEqual[d, 1.95e-44], N[Not[LessEqual[d, 2.3e+37]], $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^{+31} \lor \neg \left(d \leq 1.35 \cdot 10^{-76}\right) \land \left(d \leq 1.95 \cdot 10^{-44} \lor \neg \left(d \leq 2.3 \cdot 10^{+37}\right)\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.19999999999999991e31 or 1.35e-76 < d < 1.9500000000000001e-44 or 2.30000000000000002e37 < d

    1. Initial program 51.0%

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

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

    if -1.19999999999999991e31 < d < 1.35e-76 or 1.9500000000000001e-44 < d < 2.30000000000000002e37

    1. Initial program 78.6%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+31} \lor \neg \left(d \leq 1.35 \cdot 10^{-76}\right) \land \left(d \leq 1.95 \cdot 10^{-44} \lor \neg \left(d \leq 2.3 \cdot 10^{+37}\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 77.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{if}\;d \leq -2.1 \cdot 10^{+44}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{-43} \lor \neg \left(d \leq 1.38 \cdot 10^{-40}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ b (* a (/ c d))) d)))
   (if (<= d -2.1e+44)
     t_0
     (if (<= d 3.2e-105)
       (/ (+ a (* b (/ d c))) c)
       (if (or (<= d 2.5e-43) (not (<= d 1.38e-40))) t_0 (/ a c))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -2.1e+44) {
		tmp = t_0;
	} else if (d <= 3.2e-105) {
		tmp = (a + (b * (d / c))) / c;
	} else if ((d <= 2.5e-43) || !(d <= 1.38e-40)) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = (b + (a * (c / d))) / d
    if (d <= (-2.1d+44)) then
        tmp = t_0
    else if (d <= 3.2d-105) then
        tmp = (a + (b * (d / c))) / c
    else if ((d <= 2.5d-43) .or. (.not. (d <= 1.38d-40))) then
        tmp = t_0
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -2.1e+44) {
		tmp = t_0;
	} else if (d <= 3.2e-105) {
		tmp = (a + (b * (d / c))) / c;
	} else if ((d <= 2.5e-43) || !(d <= 1.38e-40)) {
		tmp = t_0;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b + (a * (c / d))) / d
	tmp = 0
	if d <= -2.1e+44:
		tmp = t_0
	elif d <= 3.2e-105:
		tmp = (a + (b * (d / c))) / c
	elif (d <= 2.5e-43) or not (d <= 1.38e-40):
		tmp = t_0
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d)
	tmp = 0.0
	if (d <= -2.1e+44)
		tmp = t_0;
	elseif (d <= 3.2e-105)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	elseif ((d <= 2.5e-43) || !(d <= 1.38e-40))
		tmp = t_0;
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b + (a * (c / d))) / d;
	tmp = 0.0;
	if (d <= -2.1e+44)
		tmp = t_0;
	elseif (d <= 3.2e-105)
		tmp = (a + (b * (d / c))) / c;
	elseif ((d <= 2.5e-43) || ~((d <= 1.38e-40)))
		tmp = t_0;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.1e+44], t$95$0, If[LessEqual[d, 3.2e-105], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[d, 2.5e-43], N[Not[LessEqual[d, 1.38e-40]], $MachinePrecision]], t$95$0, N[(a / c), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq 2.5 \cdot 10^{-43} \lor \neg \left(d \leq 1.38 \cdot 10^{-40}\right):\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.09999999999999987e44 or 3.19999999999999981e-105 < d < 2.50000000000000009e-43 or 1.37999999999999996e-40 < d

    1. Initial program 58.4%

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

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

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

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

    if -2.09999999999999987e44 < d < 3.19999999999999981e-105

    1. Initial program 74.8%

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

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

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

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

    if 2.50000000000000009e-43 < d < 1.37999999999999996e-40

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{+44}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{-43} \lor \neg \left(d \leq 1.38 \cdot 10^{-40}\right):\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 77.3% accurate, 0.5× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.30000000000000004e44 or 1.17999999999999993e-39 < d

    1. Initial program 53.7%

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

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

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

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

    if -2.30000000000000004e44 < d < 2.90000000000000003e-105

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

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

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

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

    if 2.90000000000000003e-105 < d < 1.35e-46

    1. Initial program 99.6%

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

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

    if 1.35e-46 < d < 1.17999999999999993e-39

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{+44}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{-105}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{-46}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{-39}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 77.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{if}\;d \leq -2.1 \cdot 10^{+44}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 1.15 \cdot 10^{-50}:\\ \;\;\;\;\frac{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 (/ (+ b (* a (/ c d))) d)))
   (if (<= d -2.1e+44)
     t_0
     (if (<= d 3.2e-105)
       (/ (+ a (/ b (/ c d))) c)
       (if (<= d 1.15e-50) (/ (* b d) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -2.1e+44) {
		tmp = t_0;
	} else if (d <= 3.2e-105) {
		tmp = (a + (b / (c / d))) / c;
	} else if (d <= 1.15e-50) {
		tmp = (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 = (b + (a * (c / d))) / d
    if (d <= (-2.1d+44)) then
        tmp = t_0
    else if (d <= 3.2d-105) then
        tmp = (a + (b / (c / d))) / c
    else if (d <= 1.15d-50) then
        tmp = (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 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -2.1e+44) {
		tmp = t_0;
	} else if (d <= 3.2e-105) {
		tmp = (a + (b / (c / d))) / c;
	} else if (d <= 1.15e-50) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b + (a * (c / d))) / d
	tmp = 0
	if d <= -2.1e+44:
		tmp = t_0
	elif d <= 3.2e-105:
		tmp = (a + (b / (c / d))) / c
	elif d <= 1.15e-50:
		tmp = (b * d) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d)
	tmp = 0.0
	if (d <= -2.1e+44)
		tmp = t_0;
	elseif (d <= 3.2e-105)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c);
	elseif (d <= 1.15e-50)
		tmp = Float64(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 = (b + (a * (c / d))) / d;
	tmp = 0.0;
	if (d <= -2.1e+44)
		tmp = t_0;
	elseif (d <= 3.2e-105)
		tmp = (a + (b / (c / d))) / c;
	elseif (d <= 1.15e-50)
		tmp = (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[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.1e+44], t$95$0, If[LessEqual[d, 3.2e-105], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.15e-50], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq 1.15 \cdot 10^{-50}:\\
\;\;\;\;\frac{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 d < -2.09999999999999987e44 or 1.1500000000000001e-50 < d

    1. Initial program 55.1%

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

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

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

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

    if -2.09999999999999987e44 < d < 3.19999999999999981e-105

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

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

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

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

    if 3.19999999999999981e-105 < d < 1.1500000000000001e-50

    1. Initial program 99.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{+44}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-105}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 1.15 \cdot 10^{-50}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 76.1% accurate, 0.8× speedup?

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

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

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

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


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

    1. Initial program 53.9%

      \[\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*88.3%

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

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

    if -1.16000000000000009e125 < c < 7.0000000000000001e-67

    1. Initial program 69.2%

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

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

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

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

    if 7.0000000000000001e-67 < c

    1. Initial program 64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.16 \cdot 10^{+125}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 7 \cdot 10^{-67}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 43.1% 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 65.7%

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

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

Developer target: 99.4% 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 2024103 
(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))))