Complex division, real part

Percentage Accurate: 60.7% → 84.6%
Time: 9.1s
Alternatives: 10
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 10 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: 60.7% accurate, 1.0× speedup?

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

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

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\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{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\


\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))) < +inf.0

    1. Initial program 77.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\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 +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 0.0%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt1.4%

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

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

        \[\leadsto \frac{d \cdot b}{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
      5. times-frac61.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.2% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 47.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-identity47.1%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
      5. times-frac47.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)}}} \]
      6. fma-define47.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)}} \]
      7. hypot-define47.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)}} \]
      8. fma-define47.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)}} \]
      9. fma-define47.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}}} \]
      10. hypot-define64.5%

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

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

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

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

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

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

    if -3.00000000000000011e45 < d < -2.2e-131

    1. Initial program 80.0%

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

    if -2.2e-131 < d < 2.20000000000000021e-65

    1. Initial program 76.0%

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

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

    if 2.20000000000000021e-65 < d

    1. Initial program 54.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 80.1% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 47.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-identity47.1%

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

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

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

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}} \]
      5. times-frac47.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)}}} \]
      6. fma-define47.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)}} \]
      7. hypot-define47.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)}} \]
      8. fma-define47.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)}} \]
      9. fma-define47.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}}} \]
      10. hypot-define64.5%

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

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

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

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

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

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

    if -1.3999999999999999e50 < d < -2e-131

    1. Initial program 80.0%

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

    if -2e-131 < d < 1.72000000000000005e-65

    1. Initial program 76.0%

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

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

    if 1.72000000000000005e-65 < d

    1. Initial program 54.3%

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

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

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

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

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

Alternative 4: 80.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{if}\;d \leq -1.45 \cdot 10^{+85}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{-131}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{-65}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ b (* a (/ c d))) d)))
   (if (<= d -1.45e+85)
     t_0
     (if (<= d -1.95e-131)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (if (<= d 2.3e-65) (/ (+ a (/ (* b d) c)) c) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -1.45e+85) {
		tmp = t_0;
	} else if (d <= -1.95e-131) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 2.3e-65) {
		tmp = (a + ((b * d) / c)) / c;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (b + (a * (c / d))) / d
    if (d <= (-1.45d+85)) then
        tmp = t_0
    else if (d <= (-1.95d-131)) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
    else if (d <= 2.3d-65) then
        tmp = (a + ((b * d) / c)) / c
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b + (a * (c / d))) / d;
	double tmp;
	if (d <= -1.45e+85) {
		tmp = t_0;
	} else if (d <= -1.95e-131) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 2.3e-65) {
		tmp = (a + ((b * d) / c)) / c;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b + (a * (c / d))) / d
	tmp = 0
	if d <= -1.45e+85:
		tmp = t_0
	elif d <= -1.95e-131:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif d <= 2.3e-65:
		tmp = (a + ((b * d) / c)) / c
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b + Float64(a * Float64(c / d))) / d)
	tmp = 0.0
	if (d <= -1.45e+85)
		tmp = t_0;
	elseif (d <= -1.95e-131)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 2.3e-65)
		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b + (a * (c / d))) / d;
	tmp = 0.0;
	if (d <= -1.45e+85)
		tmp = t_0;
	elseif (d <= -1.95e-131)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (d <= 2.3e-65)
		tmp = (a + ((b * d) / c)) / c;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.45e+85], t$95$0, If[LessEqual[d, -1.95e-131], 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.3e-65], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.44999999999999999e85 or 2.3e-65 < d

    1. Initial program 49.3%

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

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

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

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

    if -1.44999999999999999e85 < d < -1.9500000000000001e-131

    1. Initial program 81.0%

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

    if -1.9500000000000001e-131 < d < 2.3e-65

    1. Initial program 76.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.45 \cdot 10^{+85}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{-131}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{-65}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.0% accurate, 0.8× speedup?

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

    1. Initial program 47.4%

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

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

    if -5.8000000000000004e44 < d < 9.99999999999999939e-12

    1. Initial program 79.0%

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

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

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

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

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

Alternative 6: 73.1% accurate, 0.8× speedup?

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

    1. Initial program 47.4%

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

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

    if -2.2999999999999998e41 < d < 2.0000000000000001e-18

    1. Initial program 79.0%

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

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

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

Alternative 7: 76.8% accurate, 0.8× speedup?

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

    1. Initial program 56.4%

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

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

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

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

    if -9.49999999999999946e-92 < d < 2.3e-65

    1. Initial program 76.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.5 \cdot 10^{-92} \lor \neg \left(d \leq 2.3 \cdot 10^{-65}\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: 63.1% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.3999999999999997e-93 or 1.15e-65 < d

    1. Initial program 56.4%

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

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

    if -6.3999999999999997e-93 < d < 1.15e-65

    1. Initial program 76.5%

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

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

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

Alternative 9: 43.0% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.1 \cdot 10^{+123}:\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.09999999999999994e123

    1. Initial program 41.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-identity41.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.09999999999999994e123 < d

    1. Initial program 68.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{+123}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 42.9% 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.8%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification42.7%

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

Developer target: 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 2024072 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

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