Complex division, real part

Percentage Accurate: 61.0% → 84.9%
Time: 11.1s
Alternatives: 14
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 14 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 84.9% 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^{+223}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+223)
   (/ (/ (fma c a (* b d)) (hypot c d)) (hypot c d))
   (/ (+ b (/ a (/ d c))) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+223) {
		tmp = (fma(c, a, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (b + (a / (d / c))) / 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))) <= 2e+223)
		tmp = Float64(Float64(fma(c, a, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / 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], 2e+223], N[(N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $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 2 \cdot 10^{+223}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{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))) < 2.00000000000000009e223

    1. Initial program 79.9%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt79.9%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define79.8%

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

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

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

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

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

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

        \[\leadsto \frac{\frac{\color{blue}{a \cdot c + b \cdot d}}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} \]
      4. *-commutative96.3%

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

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

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

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

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

    1. Initial program 17.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{b + \color{blue}{\frac{1 \cdot a}{\frac{1}{c} \cdot d}}}{d} \]
      3. *-un-lft-identity68.9%

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

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

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

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

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

Alternative 2: 80.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -9 \cdot 10^{+63}:\\ \;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-114}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1850000000000:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{1}{\frac{c}{d}}, a\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -9e+63)
   (/ (+ b (- (* a (/ c d)) (* b (pow (/ c d) 2.0)))) d)
   (if (<= d -1.15e-114)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 1850000000000.0)
       (/ (fma b (/ 1.0 (/ c d)) a) c)
       (/ (+ b (* c (/ a d))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -9e+63) {
		tmp = (b + ((a * (c / d)) - (b * pow((c / d), 2.0)))) / d;
	} else if (d <= -1.15e-114) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 1850000000000.0) {
		tmp = fma(b, (1.0 / (c / d)), a) / c;
	} else {
		tmp = (b + (c * (a / d))) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -9e+63)
		tmp = Float64(Float64(b + Float64(Float64(a * Float64(c / d)) - Float64(b * (Float64(c / d) ^ 2.0)))) / d);
	elseif (d <= -1.15e-114)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1850000000000.0)
		tmp = Float64(fma(b, Float64(1.0 / Float64(c / d)), a) / c);
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -9e+63], N[(N[(b + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] - N[(b * N[Power[N[(c / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.15e-114], 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, 1850000000000.0], N[(N[(b * N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{+63}:\\
\;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\

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

\mathbf{elif}\;d \leq 1850000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{1}{\frac{c}{d}}, a\right)}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 36.9%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt36.9%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define36.9%

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

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

        \[\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-rr54.0%

      \[\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. add-sqr-sqrt53.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b + \left(-1 \cdot \frac{b \cdot {c}^{2}}{{d}^{2}} + \frac{a \cdot c}{d}\right)}{d}} \]
    8. Step-by-step derivation
      1. +-commutative65.0%

        \[\leadsto \frac{b + \color{blue}{\left(\frac{a \cdot c}{d} + -1 \cdot \frac{b \cdot {c}^{2}}{{d}^{2}}\right)}}{d} \]
      2. associate-/l*65.0%

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

        \[\leadsto \frac{b + \left(\color{blue}{\frac{c}{d} \cdot a} + -1 \cdot \frac{b \cdot {c}^{2}}{{d}^{2}}\right)}{d} \]
      4. mul-1-neg65.0%

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

        \[\leadsto \frac{b + \color{blue}{\left(\frac{c}{d} \cdot a - \frac{b \cdot {c}^{2}}{{d}^{2}}\right)}}{d} \]
      6. *-commutative65.0%

        \[\leadsto \frac{b + \left(\color{blue}{a \cdot \frac{c}{d}} - \frac{b \cdot {c}^{2}}{{d}^{2}}\right)}{d} \]
      7. associate-/l*68.6%

        \[\leadsto \frac{b + \left(a \cdot \frac{c}{d} - \color{blue}{b \cdot \frac{{c}^{2}}{{d}^{2}}}\right)}{d} \]
      8. unpow268.6%

        \[\leadsto \frac{b + \left(a \cdot \frac{c}{d} - b \cdot \frac{\color{blue}{c \cdot c}}{{d}^{2}}\right)}{d} \]
      9. unpow268.6%

        \[\leadsto \frac{b + \left(a \cdot \frac{c}{d} - b \cdot \frac{c \cdot c}{\color{blue}{d \cdot d}}\right)}{d} \]
      10. times-frac83.0%

        \[\leadsto \frac{b + \left(a \cdot \frac{c}{d} - b \cdot \color{blue}{\left(\frac{c}{d} \cdot \frac{c}{d}\right)}\right)}{d} \]
      11. unpow283.0%

        \[\leadsto \frac{b + \left(a \cdot \frac{c}{d} - b \cdot \color{blue}{{\left(\frac{c}{d}\right)}^{2}}\right)}{d} \]
    9. Simplified83.0%

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

    if -9.00000000000000034e63 < d < -1.15e-114

    1. Initial program 81.3%

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

    if -1.15e-114 < d < 1.85e12

    1. Initial program 75.7%

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

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

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

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

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

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

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

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

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

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

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

    if 1.85e12 < d

    1. Initial program 54.1%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define54.1%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} \]
    7. Taylor expanded in c around 0 82.4%

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

        \[\leadsto \frac{b + \frac{\color{blue}{c \cdot a}}{d}}{d} \]
      2. *-un-lft-identity78.9%

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

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

      \[\leadsto \frac{b + \color{blue}{\frac{c}{1} \cdot \frac{a}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification86.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9 \cdot 10^{+63}:\\ \;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-114}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1850000000000:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{1}{\frac{c}{d}}, a\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -8.2 \cdot 10^{+63}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -3 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 10000000000000:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{1}{\frac{c}{d}}, a\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -8.2e+63)
   (/ (+ b (* a (/ c d))) d)
   (if (<= d -3e-113)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 10000000000000.0)
       (/ (fma b (/ 1.0 (/ c d)) a) c)
       (/ (+ b (* c (/ a d))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -8.2e+63) {
		tmp = (b + (a * (c / d))) / d;
	} else if (d <= -3e-113) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 10000000000000.0) {
		tmp = fma(b, (1.0 / (c / d)), a) / c;
	} else {
		tmp = (b + (c * (a / d))) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -8.2e+63)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (d <= -3e-113)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 10000000000000.0)
		tmp = Float64(fma(b, Float64(1.0 / Float64(c / d)), a) / c);
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -8.2e+63], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3e-113], 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, 10000000000000.0], N[(N[(b * N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq 10000000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{1}{\frac{c}{d}}, a\right)}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b + c \cdot \frac{a}{d}}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 36.9%

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

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

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

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

    if -8.19999999999999985e63 < d < -3.0000000000000001e-113

    1. Initial program 81.3%

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

    if -3.0000000000000001e-113 < d < 1e13

    1. Initial program 75.7%

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

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

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

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

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

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

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

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

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

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

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

    if 1e13 < d

    1. Initial program 54.1%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define54.1%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}} \]
    7. Taylor expanded in c around 0 82.4%

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

        \[\leadsto \frac{b + \frac{\color{blue}{c \cdot a}}{d}}{d} \]
      2. *-un-lft-identity78.9%

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

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

      \[\leadsto \frac{b + \color{blue}{\frac{c}{1} \cdot \frac{a}{d}}}{\mathsf{hypot}\left(c, d\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification86.4%

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

Alternative 4: 80.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{+63}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-118}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{+14}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{1}{\frac{c}{d}}, a\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -7.2e+63)
   (/ (+ b (* a (/ c d))) d)
   (if (<= d -2.5e-118)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 2.5e+14)
       (/ (fma b (/ 1.0 (/ c d)) a) c)
       (/ (+ b (* c (/ a d))) d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -7.2e+63) {
		tmp = (b + (a * (c / d))) / d;
	} else if (d <= -2.5e-118) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 2.5e+14) {
		tmp = fma(b, (1.0 / (c / d)), a) / c;
	} else {
		tmp = (b + (c * (a / d))) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -7.2e+63)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (d <= -2.5e-118)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 2.5e+14)
		tmp = Float64(fma(b, Float64(1.0 / Float64(c / d)), a) / c);
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -7.2e+63], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.5e-118], 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, 2.5e+14], N[(N[(b * N[(1.0 / N[(c / d), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 36.9%

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

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

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

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

    if -7.19999999999999998e63 < d < -2.50000000000000007e-118

    1. Initial program 81.3%

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

    if -2.50000000000000007e-118 < d < 2.5e14

    1. Initial program 75.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2.5e14 < d

    1. Initial program 54.1%

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

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

        \[\leadsto \frac{b + \frac{\color{blue}{c \cdot a}}{d}}{d} \]
      2. *-un-lft-identity78.9%

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

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

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

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

Alternative 5: 80.7% accurate, 0.6× speedup?

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

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

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

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

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


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

    1. Initial program 36.9%

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

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

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

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

    if -1.62e63 < d < -4.99999999999999993e-119

    1. Initial program 81.3%

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

    if -4.99999999999999993e-119 < d < 7e12

    1. Initial program 75.7%

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

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

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

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

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

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

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

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

    if 7e12 < d

    1. Initial program 54.1%

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

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

        \[\leadsto \frac{b + \frac{\color{blue}{c \cdot a}}{d}}{d} \]
      2. *-un-lft-identity78.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.62 \cdot 10^{+63}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-119}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 7000000000000:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 60.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -6 \cdot 10^{-75}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 2.1 \cdot 10^{-14}:\\
\;\;\;\;\frac{b \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.9999999999999997e-75 or 2.0999999999999999e-14 < d

    1. Initial program 54.2%

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

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

    if -5.9999999999999997e-75 < d < 8.80000000000000018e-179

    1. Initial program 71.1%

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

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

    if 8.80000000000000018e-179 < d < 2.0999999999999999e-14

    1. Initial program 84.1%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    6. Taylor expanded in b around inf 62.2%

      \[\leadsto \frac{\color{blue}{\frac{b \cdot d}{c}}}{c} \]
    7. Step-by-step derivation
      1. associate-*r/62.3%

        \[\leadsto \frac{\color{blue}{b \cdot \frac{d}{c}}}{c} \]
    8. Simplified62.3%

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

Alternative 7: 59.9% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{-74}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 4.4 \cdot 10^{-14}:\\
\;\;\;\;\frac{d}{c} \cdot \frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.70000000000000018e-74 or 4.4000000000000002e-14 < d

    1. Initial program 54.2%

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

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

    if -2.70000000000000018e-74 < d < 4.0000000000000001e-180

    1. Initial program 71.1%

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

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

    if 4.0000000000000001e-180 < d < 4.4000000000000002e-14

    1. Initial program 84.1%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    6. Taylor expanded in b around inf 62.2%

      \[\leadsto \frac{\color{blue}{\frac{b \cdot d}{c}}}{c} \]
    7. Step-by-step derivation
      1. associate-/l/57.1%

        \[\leadsto \color{blue}{\frac{b \cdot d}{c \cdot c}} \]
      2. *-commutative57.1%

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c} \]
      3. times-frac57.5%

        \[\leadsto \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    8. Applied egg-rr57.5%

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

Alternative 8: 61.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.05 \cdot 10^{-75}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 8.5 \cdot 10^{-14}:\\
\;\;\;\;d \cdot \frac{\frac{b}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.05000000000000001e-75 or 8.50000000000000038e-14 < d

    1. Initial program 54.2%

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

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

    if -2.05000000000000001e-75 < d < 2.30000000000000003e-132

    1. Initial program 73.6%

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

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

    if 2.30000000000000003e-132 < d < 8.50000000000000038e-14

    1. Initial program 84.6%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    6. Taylor expanded in b around inf 62.6%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot \frac{b}{c}}}{c} \]
    8. Applied egg-rr62.6%

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

        \[\leadsto \color{blue}{d \cdot \frac{\frac{b}{c}}{c}} \]
    10. Applied egg-rr62.7%

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

Alternative 9: 78.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -68000000 \lor \neg \left(d \leq 38000000000\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.8e7 or 3.8e10 < d

    1. Initial program 49.4%

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

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

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

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

    if -6.8e7 < d < 3.8e10

    1. Initial program 76.8%

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

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

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

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

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

Alternative 10: 73.0% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.3e7 or 6.4e15 < d

    1. Initial program 49.4%

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

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

    if -1.3e7 < d < 6.4e15

    1. Initial program 76.8%

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

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

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

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

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

Alternative 11: 78.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -48000000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.8e7

    1. Initial program 45.8%

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

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

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

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

    if -4.8e7 < d < 1.4e12

    1. Initial program 76.8%

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

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

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

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

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

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

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

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

    if 1.4e12 < d

    1. Initial program 54.1%

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

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

        \[\leadsto \frac{b + \frac{\color{blue}{c \cdot a}}{d}}{d} \]
      2. *-un-lft-identity78.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -48000000:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 1400000000000:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 78.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -56000000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.6e7

    1. Initial program 45.8%

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

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

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

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

    if -5.6e7 < d < 1.6e10

    1. Initial program 76.8%

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

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

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

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

    if 1.6e10 < d

    1. Initial program 54.1%

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

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

        \[\leadsto \frac{b + \frac{\color{blue}{c \cdot a}}{d}}{d} \]
      2. *-un-lft-identity78.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -56000000:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 16000000000:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 63.5% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.64999999999999994e-74 or 0.25 < d

    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 0 65.5%

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

    if -2.64999999999999994e-74 < d < 0.25

    1. Initial program 75.3%

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

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

Alternative 14: 42.6% 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.2%

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

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

Developer Target 1: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))