Complex division, real part

Percentage Accurate: 61.6% → 82.6%
Time: 10.5s
Alternatives: 12
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 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.6% 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.6% accurate, 0.1× speedup?

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

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

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

\mathbf{elif}\;d \leq 3.1 \cdot 10^{-71}:\\
\;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{c}}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -3.55000000000000001e74

    1. Initial program 41.6%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified41.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
    5. Taylor expanded in d around inf 86.8%

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{{\left(\frac{d}{c}\right)}^{-1}}}{d} \]
    9. Applied egg-rr93.4%

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
    11. Simplified93.4%

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

    if -3.55000000000000001e74 < d < -2.4999999999999999e-67

    1. Initial program 89.6%

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

    if -2.4999999999999999e-67 < d < 3.10000000000000002e-71

    1. Initial program 78.2%

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

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

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

      \[\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
    5. Taylor expanded in c around inf 93.6%

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

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

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

        \[\leadsto \frac{a + \color{blue}{\left(d \cdot b\right) \cdot \frac{1}{c}}}{c} \]
    9. Applied egg-rr93.6%

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

    if 3.10000000000000002e-71 < d < 1.6499999999999999e77

    1. Initial program 88.6%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified88.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

    if 1.6499999999999999e77 < d

    1. Initial program 54.1%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 93.8%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.55 \cdot 10^{+74}:\\ \;\;\;\;\frac{b + a \cdot \frac{1}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{-71}:\\ \;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{c}}{c}\\ \mathbf{elif}\;d \leq 1.65 \cdot 10^{+77}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.1% 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^{+241}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(c, a, b \cdot d\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{1}{\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+241)
   (/ (/ 1.0 (hypot c d)) (/ (hypot c d) (fma c a (* b d))))
   (/ (+ b (* a (/ 1.0 (/ 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+241) {
		tmp = (1.0 / hypot(c, d)) / (hypot(c, d) / fma(c, a, (b * d)));
	} else {
		tmp = (b + (a * (1.0 / (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+241)
		tmp = Float64(Float64(1.0 / hypot(c, d)) / Float64(hypot(c, d) / fma(c, a, Float64(b * d))));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(1.0 / 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+241], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(1.0 / N[(d / c), $MachinePrecision]), $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^{+241}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(c, a, b \cdot d\right)}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{1}{\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.0000000000000001e241

    1. Initial program 82.3%

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

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

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

      \[\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
    5. Step-by-step derivation
      1. *-un-lft-identity82.3%

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

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

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

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

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

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

        \[\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)}} \]
      8. fma-define82.2%

        \[\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}}} \]
      9. hypot-define96.2%

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e241 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 23.2%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 63.3%

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

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

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
    11. Simplified72.6%

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

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

Alternative 3: 85.1% 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^{+241}:\\ \;\;\;\;\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{1}{\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+241)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (/ (+ b (* a (/ 1.0 (/ 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+241) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (b + (a * (1.0 / (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+241)
		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(1.0 / 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+241], 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[(1.0 / N[(d / c), $MachinePrecision]), $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^{+241}:\\
\;\;\;\;\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{1}{\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.0000000000000001e241

    1. Initial program 82.3%

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

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

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

      \[\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
    5. Step-by-step derivation
      1. *-un-lft-identity82.3%

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

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

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

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

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

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

        \[\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)}} \]
      8. fma-define82.2%

        \[\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}}} \]
      9. hypot-define96.2%

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

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

    if 2.0000000000000001e241 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 23.2%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 63.3%

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

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

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
    11. Simplified72.6%

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

Alternative 4: 82.6% 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}\\ \mathbf{if}\;d \leq -3.5 \cdot 10^{+74}:\\ \;\;\;\;\frac{b + a \cdot \frac{1}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-67}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-71}:\\ \;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{c}}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+77}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -3.5e+74)
     (/ (+ b (* a (/ 1.0 (/ d c)))) d)
     (if (<= d -2.5e-67)
       t_0
       (if (<= d 5.5e-71)
         (/ (+ a (* (* b d) (/ 1.0 c))) c)
         (if (<= d 2.9e+77) t_0 (/ (+ b (* c (/ a d))) d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -3.5e+74) {
		tmp = (b + (a * (1.0 / (d / c)))) / d;
	} else if (d <= -2.5e-67) {
		tmp = t_0;
	} else if (d <= 5.5e-71) {
		tmp = (a + ((b * d) * (1.0 / c))) / c;
	} else if (d <= 2.9e+77) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-3.5d+74)) then
        tmp = (b + (a * (1.0d0 / (d / c)))) / d
    else if (d <= (-2.5d-67)) then
        tmp = t_0
    else if (d <= 5.5d-71) then
        tmp = (a + ((b * d) * (1.0d0 / c))) / c
    else if (d <= 2.9d+77) then
        tmp = t_0
    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 t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -3.5e+74) {
		tmp = (b + (a * (1.0 / (d / c)))) / d;
	} else if (d <= -2.5e-67) {
		tmp = t_0;
	} else if (d <= 5.5e-71) {
		tmp = (a + ((b * d) * (1.0 / c))) / c;
	} else if (d <= 2.9e+77) {
		tmp = t_0;
	} else {
		tmp = (b + (c * (a / d))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -3.5e+74:
		tmp = (b + (a * (1.0 / (d / c)))) / d
	elif d <= -2.5e-67:
		tmp = t_0
	elif d <= 5.5e-71:
		tmp = (a + ((b * d) * (1.0 / c))) / c
	elif d <= 2.9e+77:
		tmp = t_0
	else:
		tmp = (b + (c * (a / d))) / d
	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)))
	tmp = 0.0
	if (d <= -3.5e+74)
		tmp = Float64(Float64(b + Float64(a * Float64(1.0 / Float64(d / c)))) / d);
	elseif (d <= -2.5e-67)
		tmp = t_0;
	elseif (d <= 5.5e-71)
		tmp = Float64(Float64(a + Float64(Float64(b * d) * Float64(1.0 / c))) / c);
	elseif (d <= 2.9e+77)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(c * Float64(a / d))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -3.5e+74)
		tmp = (b + (a * (1.0 / (d / c)))) / d;
	elseif (d <= -2.5e-67)
		tmp = t_0;
	elseif (d <= 5.5e-71)
		tmp = (a + ((b * d) * (1.0 / c))) / c;
	elseif (d <= 2.9e+77)
		tmp = t_0;
	else
		tmp = (b + (c * (a / d))) / d;
	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]}, If[LessEqual[d, -3.5e+74], N[(N[(b + N[(a * N[(1.0 / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.5e-67], t$95$0, If[LessEqual[d, 5.5e-71], N[(N[(a + N[(N[(b * d), $MachinePrecision] * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.9e+77], t$95$0, N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -2.5 \cdot 10^{-67}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 5.5 \cdot 10^{-71}:\\
\;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{c}}{c}\\

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

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


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

    1. Initial program 41.6%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified41.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
    5. Taylor expanded in d around inf 86.8%

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{{\left(\frac{d}{c}\right)}^{-1}}}{d} \]
    9. Applied egg-rr93.4%

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
    11. Simplified93.4%

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

    if -3.50000000000000014e74 < d < -2.4999999999999999e-67 or 5.4999999999999997e-71 < d < 2.9000000000000002e77

    1. Initial program 89.1%

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

    if -2.4999999999999999e-67 < d < 5.4999999999999997e-71

    1. Initial program 78.2%

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

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

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

      \[\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
    5. Taylor expanded in c around inf 93.6%

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

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

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

        \[\leadsto \frac{a + \color{blue}{\left(d \cdot b\right) \cdot \frac{1}{c}}}{c} \]
    9. Applied egg-rr93.6%

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

    if 2.9000000000000002e77 < d

    1. Initial program 54.1%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 93.8%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.5 \cdot 10^{+74}:\\ \;\;\;\;\frac{b + a \cdot \frac{1}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-67}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-71}:\\ \;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{c}}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+77}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.2% accurate, 0.7× speedup?

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

\mathbf{elif}\;d \leq 7.5 \cdot 10^{-24}:\\
\;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{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 < -2.8999999999999999e-58

    1. Initial program 60.7%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 76.4%

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

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

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

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

        \[\leadsto \frac{b + a \cdot \color{blue}{{\left(\frac{d}{c}\right)}^{-1}}}{d} \]
    9. Applied egg-rr80.4%

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

        \[\leadsto \frac{b + a \cdot \color{blue}{\frac{1}{\frac{d}{c}}}}{d} \]
    11. Simplified80.4%

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

    if -2.8999999999999999e-58 < d < 7.50000000000000007e-24

    1. Initial program 78.6%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified78.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
    5. Taylor expanded in c around inf 90.8%

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

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

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

        \[\leadsto \frac{a + \color{blue}{\left(d \cdot b\right) \cdot \frac{1}{c}}}{c} \]
    9. Applied egg-rr90.8%

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

    if 7.50000000000000007e-24 < d

    1. Initial program 66.1%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 86.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.9 \cdot 10^{-58}:\\ \;\;\;\;\frac{b + a \cdot \frac{1}{\frac{d}{c}}}{d}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-24}:\\ \;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 77.2% accurate, 0.7× speedup?

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

\mathbf{elif}\;d \leq 10^{-32}:\\
\;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{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 < -2.6999999999999999e-58

    1. Initial program 60.7%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 76.4%

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

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

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

    if -2.6999999999999999e-58 < d < 1.00000000000000006e-32

    1. Initial program 78.6%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified78.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
    5. Taylor expanded in c around inf 90.8%

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

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

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

        \[\leadsto \frac{a + \color{blue}{\left(d \cdot b\right) \cdot \frac{1}{c}}}{c} \]
    9. Applied egg-rr90.8%

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

    if 1.00000000000000006e-32 < d

    1. Initial program 66.1%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 86.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{-58}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 10^{-32}:\\ \;\;\;\;\frac{a + \left(b \cdot d\right) \cdot \frac{1}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 77.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{-64} \lor \neg \left(d \leq 2.55 \cdot 10^{-24}\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 -2.7e-64) (not (<= d 2.55e-24)))
   (/ (+ b (* a (/ c d))) d)
   (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -2.7e-64) || !(d <= 2.55e-24)) {
		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 <= (-2.7d-64)) .or. (.not. (d <= 2.55d-24))) 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 <= -2.7e-64) || !(d <= 2.55e-24)) {
		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 <= -2.7e-64) or not (d <= 2.55e-24):
		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 <= -2.7e-64) || !(d <= 2.55e-24))
		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 <= -2.7e-64) || ~((d <= 2.55e-24)))
		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, -2.7e-64], N[Not[LessEqual[d, 2.55e-24]], $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 -2.7 \cdot 10^{-64} \lor \neg \left(d \leq 2.55 \cdot 10^{-24}\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 < -2.69999999999999986e-64 or 2.55000000000000013e-24 < d

    1. Initial program 63.4%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 81.1%

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

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

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

    if -2.69999999999999986e-64 < d < 2.55000000000000013e-24

    1. Initial program 78.6%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified78.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
    5. Taylor expanded in c around inf 90.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{-64} \lor \neg \left(d \leq 2.55 \cdot 10^{-24}\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 8: 70.8% accurate, 0.8× speedup?

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

    1. Initial program 62.9%

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

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

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

      \[\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
    5. Taylor expanded in c around 0 70.7%

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

    if -2.8999999999999999e-58 < d < 3.4999999999999998e-10

    1. Initial program 79.0%

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

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

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

      \[\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
    5. Taylor expanded in c around inf 90.1%

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

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

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

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

Alternative 9: 70.6% accurate, 0.8× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.8999999999999999e-58 or 8.9999999999999995e-14 < d

    1. Initial program 62.9%

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

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

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

      \[\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
    5. Taylor expanded in c around 0 70.7%

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

    if -2.8999999999999999e-58 < d < 8.9999999999999995e-14

    1. Initial program 79.0%

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

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

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

      \[\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
    5. Step-by-step derivation
      1. *-un-lft-identity79.0%

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

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

        \[\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)}}} \]
      4. times-frac79.0%

        \[\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)}}} \]
      5. fma-define79.0%

        \[\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)}} \]
      6. hypot-define79.0%

        \[\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)}} \]
      7. fma-define79.0%

        \[\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)}} \]
      8. fma-define79.0%

        \[\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}}} \]
      9. hypot-define88.6%

        \[\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)}} \]
    6. Applied egg-rr88.6%

      \[\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)}} \]
    7. Taylor expanded in c around inf 90.1%

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

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

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

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

Alternative 10: 77.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{-59}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{-33}:\\ \;\;\;\;\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 -2e-59)
   (/ (+ b (* a (/ c d))) d)
   (if (<= d 4.5e-33) (/ (+ a (/ (* b d) c)) c) (/ (+ b (* c (/ a d))) d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -2e-59) {
		tmp = (b + (a * (c / d))) / d;
	} else if (d <= 4.5e-33) {
		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 <= (-2d-59)) then
        tmp = (b + (a * (c / d))) / d
    else if (d <= 4.5d-33) 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 <= -2e-59) {
		tmp = (b + (a * (c / d))) / d;
	} else if (d <= 4.5e-33) {
		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 <= -2e-59:
		tmp = (b + (a * (c / d))) / d
	elif d <= 4.5e-33:
		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 <= -2e-59)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (d <= 4.5e-33)
		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 <= -2e-59)
		tmp = (b + (a * (c / d))) / d;
	elseif (d <= 4.5e-33)
		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, -2e-59], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 4.5e-33], 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 -2 \cdot 10^{-59}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

\mathbf{elif}\;d \leq 4.5 \cdot 10^{-33}:\\
\;\;\;\;\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 < -2.0000000000000001e-59

    1. Initial program 60.7%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 76.4%

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

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

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

    if -2.0000000000000001e-59 < d < 4.49999999999999991e-33

    1. Initial program 78.6%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified78.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
    5. Taylor expanded in c around inf 90.8%

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

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

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

    if 4.49999999999999991e-33 < d

    1. Initial program 66.1%

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

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

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

      \[\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
    5. Taylor expanded in d around inf 86.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{-59}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{-33}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 63.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{-59} \lor \neg \left(d \leq 1.8 \cdot 10^{-17}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.0000000000000001e-59 or 1.79999999999999997e-17 < d

    1. Initial program 63.1%

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

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

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

      \[\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
    5. Taylor expanded in c around 0 70.2%

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

    if -2.0000000000000001e-59 < d < 1.79999999999999997e-17

    1. Initial program 78.8%

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

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

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

      \[\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
    5. Taylor expanded in c around inf 72.6%

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

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

Alternative 12: 43.0% 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 70.1%

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

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

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

    \[\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
  5. Taylor expanded in c around inf 39.9%

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  6. 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 2024152 
(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))))