Complex division, real part

Percentage Accurate: 61.5% → 85.0%
Time: 11.3s
Alternatives: 13
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 13 alternatives:

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

Initial Program: 61.5% accurate, 1.0× speedup?

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

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

Alternative 1: 85.0% accurate, 0.1× speedup?

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d}} \]
      3. fma-define78.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-sqrt78.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-frac78.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-define78.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-define78.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-define78.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-define78.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-define96.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-rr96.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. Step-by-step derivation
      1. fma-define96.3%

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

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

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

    if +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.3%

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

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

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

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

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

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

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

    \[\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{a \cdot c + b \cdot d}{\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: 81.2% accurate, 0.1× 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 -9.5 \cdot 10^{+151}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -6 \cdot 10^{-49}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{-139}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -9.5e+151)
     (* (/ d (hypot c d)) (/ b (hypot c d)))
     (if (<= d -6e-49)
       t_0
       (if (<= d 7.2e-139)
         (+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
         (if (<= d 2.4e+92)
           t_0
           (* (/ 1.0 (hypot c d)) (+ b (* a (/ c 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 <= -9.5e+151) {
		tmp = (d / hypot(c, d)) * (b / hypot(c, d));
	} else if (d <= -6e-49) {
		tmp = t_0;
	} else if (d <= 7.2e-139) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.4e+92) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * (b + (a * (c / d)));
	}
	return tmp;
}
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 <= -9.5e+151) {
		tmp = (d / Math.hypot(c, d)) * (b / Math.hypot(c, d));
	} else if (d <= -6e-49) {
		tmp = t_0;
	} else if (d <= 7.2e-139) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.4e+92) {
		tmp = t_0;
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * (b + (a * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -9.5e+151:
		tmp = (d / math.hypot(c, d)) * (b / math.hypot(c, d))
	elif d <= -6e-49:
		tmp = t_0
	elif d <= 7.2e-139:
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c))
	elif d <= 2.4e+92:
		tmp = t_0
	else:
		tmp = (1.0 / math.hypot(c, d)) * (b + (a * (c / 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 <= -9.5e+151)
		tmp = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, d)));
	elseif (d <= -6e-49)
		tmp = t_0;
	elseif (d <= 7.2e-139)
		tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c)));
	elseif (d <= 2.4e+92)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(a * Float64(c / 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 <= -9.5e+151)
		tmp = (d / hypot(c, d)) * (b / hypot(c, d));
	elseif (d <= -6e-49)
		tmp = t_0;
	elseif (d <= 7.2e-139)
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	elseif (d <= 2.4e+92)
		tmp = t_0;
	else
		tmp = (1.0 / hypot(c, d)) * (b + (a * (c / 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, -9.5e+151], N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -6e-49], t$95$0, If[LessEqual[d, 7.2e-139], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.4e+92], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -9.5 \cdot 10^{+151}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -6 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 7.2 \cdot 10^{-139}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 2.4 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 32.0%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt32.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-undefine32.4%

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

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

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

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

    if -9.5000000000000001e151 < d < -6e-49 or 7.20000000000000007e-139 < d < 2.40000000000000005e92

    1. Initial program 82.7%

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

    if -6e-49 < d < 7.20000000000000007e-139

    1. Initial program 73.0%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.5%

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

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

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

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

    if 2.40000000000000005e92 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-define62.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-rr62.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 c around 0 88.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.5 \cdot 10^{+151}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -6 \cdot 10^{-49}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{-139}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.9% accurate, 0.1× 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.6 \cdot 10^{+80}:\\ \;\;\;\;\mathsf{fma}\left(c, \frac{1}{d} \cdot \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -5.7 \cdot 10^{-49}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-140}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \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.6e+80)
     (fma c (* (/ 1.0 d) (/ a d)) (/ b d))
     (if (<= d -5.7e-49)
       t_0
       (if (<= d 1.4e-140)
         (+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
         (if (<= d 1.7e+92)
           t_0
           (* (/ 1.0 (hypot c d)) (+ b (* a (/ c 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.6e+80) {
		tmp = fma(c, ((1.0 / d) * (a / d)), (b / d));
	} else if (d <= -5.7e-49) {
		tmp = t_0;
	} else if (d <= 1.4e-140) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 1.7e+92) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * (b + (a * (c / 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.6e+80)
		tmp = fma(c, Float64(Float64(1.0 / d) * Float64(a / d)), Float64(b / d));
	elseif (d <= -5.7e-49)
		tmp = t_0;
	elseif (d <= 1.4e-140)
		tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c)));
	elseif (d <= 1.7e+92)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(b + Float64(a * Float64(c / d))));
	end
	return 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.6e+80], N[(c * N[(N[(1.0 / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5.7e-49], t$95$0, If[LessEqual[d, 1.4e-140], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.7e+92], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.6 \cdot 10^{+80}:\\
\;\;\;\;\mathsf{fma}\left(c, \frac{1}{d} \cdot \frac{a}{d}, \frac{b}{d}\right)\\

\mathbf{elif}\;d \leq -5.7 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 1.4 \cdot 10^{-140}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 1.7 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 45.5%

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

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

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

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

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

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

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

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

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

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

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

    if -3.59999999999999995e80 < d < -5.7000000000000003e-49 or 1.4000000000000001e-140 < d < 1.6999999999999999e92

    1. Initial program 81.6%

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

    if -5.7000000000000003e-49 < d < 1.4000000000000001e-140

    1. Initial program 73.0%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.5%

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

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

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

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

    if 1.6999999999999999e92 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-define62.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-rr62.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 c around 0 88.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+80}:\\ \;\;\;\;\mathsf{fma}\left(c, \frac{1}{d} \cdot \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -5.7 \cdot 10^{-49}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-140}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.2% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -6.2 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 4.6 \cdot 10^{-138}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 2.15 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\


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

    1. Initial program 45.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-define63.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-rr63.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)}} \]
    5. Taylor expanded in d around -inf 73.6%

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

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

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

      \[\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 -7.20000000000000028e82 < d < -6.2e-49 or 4.5999999999999998e-138 < d < 2.1499999999999999e92

    1. Initial program 81.6%

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

    if -6.2e-49 < d < 4.5999999999999998e-138

    1. Initial program 73.0%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.5%

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

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

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

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

    if 2.1499999999999999e92 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      10. hypot-define62.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-rr62.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 c around 0 88.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{+82}:\\ \;\;\;\;\left(b + a \cdot \frac{c}{d}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -6.2 \cdot 10^{-49}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.6 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 81.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \mathsf{fma}\left(c, \frac{1}{d} \cdot \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{if}\;d \leq -3.8 \cdot 10^{+84}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -6.4 \cdot 10^{-49}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 3.8 \cdot 10^{-139}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (fma c (* (/ 1.0 d) (/ a d)) (/ b d))))
   (if (<= d -3.8e+84)
     t_1
     (if (<= d -6.4e-49)
       t_0
       (if (<= d 3.8e-139)
         (+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
         (if (<= d 2.15e+92) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = fma(c, ((1.0 / d) * (a / d)), (b / d));
	double tmp;
	if (d <= -3.8e+84) {
		tmp = t_1;
	} else if (d <= -6.4e-49) {
		tmp = t_0;
	} else if (d <= 3.8e-139) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.15e+92) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = fma(c, Float64(Float64(1.0 / d) * Float64(a / d)), Float64(b / d))
	tmp = 0.0
	if (d <= -3.8e+84)
		tmp = t_1;
	elseif (d <= -6.4e-49)
		tmp = t_0;
	elseif (d <= 3.8e-139)
		tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c)));
	elseif (d <= 2.15e+92)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(N[(1.0 / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.8e+84], t$95$1, If[LessEqual[d, -6.4e-49], t$95$0, If[LessEqual[d, 3.8e-139], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.15e+92], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \mathsf{fma}\left(c, \frac{1}{d} \cdot \frac{a}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -3.8 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -6.4 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 3.8 \cdot 10^{-139}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 2.15 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.8000000000000001e84 or 2.1499999999999999e92 < d

    1. Initial program 42.2%

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

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

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

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

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

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

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

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

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

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

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

    if -3.8000000000000001e84 < d < -6.40000000000000005e-49 or 3.80000000000000008e-139 < d < 2.1499999999999999e92

    1. Initial program 81.6%

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

    if -6.40000000000000005e-49 < d < 3.80000000000000008e-139

    1. Initial program 73.0%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.8 \cdot 10^{+84}:\\ \;\;\;\;\mathsf{fma}\left(c, \frac{1}{d} \cdot \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -6.4 \cdot 10^{-49}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.8 \cdot 10^{-139}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(c, \frac{1}{d} \cdot \frac{a}{d}, \frac{b}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 81.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \mathsf{fma}\left(c, \frac{\frac{a}{d}}{d}, \frac{b}{d}\right)\\ \mathbf{if}\;d \leq -4.4 \cdot 10^{+79}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-48}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 3.7 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.12 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (fma c (/ (/ a d) d) (/ b d))))
   (if (<= d -4.4e+79)
     t_1
     (if (<= d -1.75e-48)
       t_0
       (if (<= d 3.7e-138)
         (+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
         (if (<= d 2.12e+92) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = fma(c, ((a / d) / d), (b / d));
	double tmp;
	if (d <= -4.4e+79) {
		tmp = t_1;
	} else if (d <= -1.75e-48) {
		tmp = t_0;
	} else if (d <= 3.7e-138) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.12e+92) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = fma(c, Float64(Float64(a / d) / d), Float64(b / d))
	tmp = 0.0
	if (d <= -4.4e+79)
		tmp = t_1;
	elseif (d <= -1.75e-48)
		tmp = t_0;
	elseif (d <= 3.7e-138)
		tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c)));
	elseif (d <= 2.12e+92)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(c * N[(N[(a / d), $MachinePrecision] / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.4e+79], t$95$1, If[LessEqual[d, -1.75e-48], t$95$0, If[LessEqual[d, 3.7e-138], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.12e+92], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \mathsf{fma}\left(c, \frac{\frac{a}{d}}{d}, \frac{b}{d}\right)\\
\mathbf{if}\;d \leq -4.4 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -1.75 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 3.7 \cdot 10^{-138}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 2.12 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.3999999999999998e79 or 2.11999999999999999e92 < d

    1. Initial program 42.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.3999999999999998e79 < d < -1.74999999999999996e-48 or 3.69999999999999991e-138 < d < 2.11999999999999999e92

    1. Initial program 81.6%

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

    if -1.74999999999999996e-48 < d < 3.69999999999999991e-138

    1. Initial program 73.0%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.4 \cdot 10^{+79}:\\ \;\;\;\;\mathsf{fma}\left(c, \frac{\frac{a}{d}}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-48}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.7 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.12 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(c, \frac{\frac{a}{d}}{d}, \frac{b}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.6% accurate, 0.1× 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 -1.32 \cdot 10^{+154}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{-48}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.45 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{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 -1.32e+154)
     (* b (/ -1.0 (hypot c d)))
     (if (<= d -1.9e-48)
       t_0
       (if (<= d 2.6e-138)
         (+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
         (if (<= d 2.45e+92) t_0 (/ b 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 <= -1.32e+154) {
		tmp = b * (-1.0 / hypot(c, d));
	} else if (d <= -1.9e-48) {
		tmp = t_0;
	} else if (d <= 2.6e-138) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.45e+92) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
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 <= -1.32e+154) {
		tmp = b * (-1.0 / Math.hypot(c, d));
	} else if (d <= -1.9e-48) {
		tmp = t_0;
	} else if (d <= 2.6e-138) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.45e+92) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.32e+154:
		tmp = b * (-1.0 / math.hypot(c, d))
	elif d <= -1.9e-48:
		tmp = t_0
	elif d <= 2.6e-138:
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c))
	elif d <= 2.45e+92:
		tmp = t_0
	else:
		tmp = b / 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 <= -1.32e+154)
		tmp = Float64(b * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -1.9e-48)
		tmp = t_0;
	elseif (d <= 2.6e-138)
		tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c)));
	elseif (d <= 2.45e+92)
		tmp = t_0;
	else
		tmp = Float64(b / 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 <= -1.32e+154)
		tmp = b * (-1.0 / hypot(c, d));
	elseif (d <= -1.9e-48)
		tmp = t_0;
	elseif (d <= 2.6e-138)
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	elseif (d <= 2.45e+92)
		tmp = t_0;
	else
		tmp = b / 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, -1.32e+154], N[(b * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.9e-48], t$95$0, If[LessEqual[d, 2.6e-138], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.45e+92], t$95$0, N[(b / 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 -1.32 \cdot 10^{+154}:\\
\;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;d \leq -1.9 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 2.6 \cdot 10^{-138}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 2.45 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 32.0%

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

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

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

        \[\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-sqrt32.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)}}} \]
      5. times-frac32.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-define32.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-define32.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-define32.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-define32.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-define55.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-rr55.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)}} \]
    5. Taylor expanded in d around -inf 68.2%

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot b\right)} \]
    6. Step-by-step derivation
      1. mul-1-neg68.2%

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

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

    if -1.31999999999999998e154 < d < -1.90000000000000001e-48 or 2.6e-138 < d < 2.4500000000000001e92

    1. Initial program 82.7%

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

    if -1.90000000000000001e-48 < d < 2.6e-138

    1. Initial program 73.0%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.5%

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

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

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

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

    if 2.4500000000000001e92 < d

    1. Initial program 39.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.32 \cdot 10^{+154}:\\ \;\;\;\;b \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -1.9 \cdot 10^{-48}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-138}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.45 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 78.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 -2.6 \cdot 10^{+153}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -5.7 \cdot 10^{-49}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-137}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.55 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{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 -2.6e+153)
     (/ b d)
     (if (<= d -5.7e-49)
       t_0
       (if (<= d 5.5e-137)
         (+ (/ a c) (* (/ 1.0 c) (/ (* b d) c)))
         (if (<= d 2.55e+92) t_0 (/ b 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 <= -2.6e+153) {
		tmp = b / d;
	} else if (d <= -5.7e-49) {
		tmp = t_0;
	} else if (d <= 5.5e-137) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.55e+92) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-2.6d+153)) then
        tmp = b / d
    else if (d <= (-5.7d-49)) then
        tmp = t_0
    else if (d <= 5.5d-137) then
        tmp = (a / c) + ((1.0d0 / c) * ((b * d) / c))
    else if (d <= 2.55d+92) then
        tmp = t_0
    else
        tmp = b / 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 <= -2.6e+153) {
		tmp = b / d;
	} else if (d <= -5.7e-49) {
		tmp = t_0;
	} else if (d <= 5.5e-137) {
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	} else if (d <= 2.55e+92) {
		tmp = t_0;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -2.6e+153:
		tmp = b / d
	elif d <= -5.7e-49:
		tmp = t_0
	elif d <= 5.5e-137:
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c))
	elif d <= 2.55e+92:
		tmp = t_0
	else:
		tmp = b / 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 <= -2.6e+153)
		tmp = Float64(b / d);
	elseif (d <= -5.7e-49)
		tmp = t_0;
	elseif (d <= 5.5e-137)
		tmp = Float64(Float64(a / c) + Float64(Float64(1.0 / c) * Float64(Float64(b * d) / c)));
	elseif (d <= 2.55e+92)
		tmp = t_0;
	else
		tmp = Float64(b / 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 <= -2.6e+153)
		tmp = b / d;
	elseif (d <= -5.7e-49)
		tmp = t_0;
	elseif (d <= 5.5e-137)
		tmp = (a / c) + ((1.0 / c) * ((b * d) / c));
	elseif (d <= 2.55e+92)
		tmp = t_0;
	else
		tmp = b / 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, -2.6e+153], N[(b / d), $MachinePrecision], If[LessEqual[d, -5.7e-49], t$95$0, If[LessEqual[d, 5.5e-137], N[(N[(a / c), $MachinePrecision] + N[(N[(1.0 / c), $MachinePrecision] * N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.55e+92], t$95$0, N[(b / 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 -2.6 \cdot 10^{+153}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq -5.7 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 5.5 \cdot 10^{-137}:\\
\;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\

\mathbf{elif}\;d \leq 2.55 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.5999999999999999e153 or 2.5500000000000001e92 < d

    1. Initial program 36.6%

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

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

    if -2.5999999999999999e153 < d < -5.7000000000000003e-49 or 5.5000000000000003e-137 < d < 2.5500000000000001e92

    1. Initial program 82.7%

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

    if -5.7000000000000003e-49 < d < 5.5000000000000003e-137

    1. Initial program 73.0%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity81.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.6 \cdot 10^{+153}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -5.7 \cdot 10^{-49}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-137}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c} \cdot \frac{b \cdot d}{c}\\ \mathbf{elif}\;d \leq 2.55 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 71.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 135:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{\frac{c}{b}}}{c}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{+51}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{+92}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.5e+85)
   (/ b d)
   (if (<= d 135.0)
     (+ (/ a c) (/ (/ d (/ c b)) c))
     (if (<= d 3.2e+51)
       (/ (* b d) (+ (* c c) (* d d)))
       (if (<= d 3.1e+92) (+ (/ a c) (* (/ d c) (/ b c))) (/ b d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.5e+85) {
		tmp = b / d;
	} else if (d <= 135.0) {
		tmp = (a / c) + ((d / (c / b)) / c);
	} else if (d <= 3.2e+51) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 3.1e+92) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= (-1.5d+85)) then
        tmp = b / d
    else if (d <= 135.0d0) then
        tmp = (a / c) + ((d / (c / b)) / c)
    else if (d <= 3.2d+51) then
        tmp = (b * d) / ((c * c) + (d * d))
    else if (d <= 3.1d+92) then
        tmp = (a / c) + ((d / c) * (b / c))
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.5e+85) {
		tmp = b / d;
	} else if (d <= 135.0) {
		tmp = (a / c) + ((d / (c / b)) / c);
	} else if (d <= 3.2e+51) {
		tmp = (b * d) / ((c * c) + (d * d));
	} else if (d <= 3.1e+92) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -1.5e+85:
		tmp = b / d
	elif d <= 135.0:
		tmp = (a / c) + ((d / (c / b)) / c)
	elif d <= 3.2e+51:
		tmp = (b * d) / ((c * c) + (d * d))
	elif d <= 3.1e+92:
		tmp = (a / c) + ((d / c) * (b / c))
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.5e+85)
		tmp = Float64(b / d);
	elseif (d <= 135.0)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / Float64(c / b)) / c));
	elseif (d <= 3.2e+51)
		tmp = Float64(Float64(b * d) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 3.1e+92)
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -1.5e+85)
		tmp = b / d;
	elseif (d <= 135.0)
		tmp = (a / c) + ((d / (c / b)) / c);
	elseif (d <= 3.2e+51)
		tmp = (b * d) / ((c * c) + (d * d));
	elseif (d <= 3.1e+92)
		tmp = (a / c) + ((d / c) * (b / c));
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.5e+85], N[(b / d), $MachinePrecision], If[LessEqual[d, 135.0], N[(N[(a / c), $MachinePrecision] + N[(N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.2e+51], N[(N[(b * d), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.1e+92], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.5 \cdot 10^{+85}:\\
\;\;\;\;\frac{b}{d}\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.5e85 or 3.1000000000000002e92 < d

    1. Initial program 43.1%

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

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

    if -1.5e85 < d < 135

    1. Initial program 75.4%

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{d \cdot b}}{{c}^{2}} \]
      2. pow274.7%

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

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

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

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

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

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

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

    if 135 < d < 3.2000000000000002e51

    1. Initial program 92.8%

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

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

    if 3.2000000000000002e51 < d < 3.1000000000000002e92

    1. Initial program 35.2%

      \[\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} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. *-commutative48.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{+85}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 135:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{d}{\frac{c}{b}}}{c}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{+51}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{+92}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 71.3% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.79999999999999993e85 or 1350 < d

    1. Initial program 49.2%

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

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

    if -4.79999999999999993e85 < d < 1350

    1. Initial program 75.4%

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{d \cdot b}}{{c}^{2}} \]
      2. pow274.7%

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

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

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

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

Alternative 11: 71.8% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.5000000000000001e84 or 65000 < d

    1. Initial program 49.2%

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

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

    if -7.5000000000000001e84 < d < 65000

    1. Initial program 75.4%

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{d \cdot b}}{{c}^{2}} \]
      2. pow274.7%

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

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

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

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

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

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

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

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

Alternative 12: 63.8% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.00000000000000046e84 or 0.107999999999999999 < d

    1. Initial program 49.2%

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

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

    if -8.00000000000000046e84 < d < 0.107999999999999999

    1. Initial program 75.4%

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

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

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

Alternative 13: 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 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 46.0%

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification46.0%

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

  :herbie-target
  (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))))