Complex division, real part

Percentage Accurate: 62.4% → 85.7%
Time: 7.2s
Alternatives: 10
Speedup: 2.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: 62.4% 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.7% 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{\frac{t_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))))
   (if (<= (/ t_0 (+ (* c c) (* d d))) INFINITY)
     (/ (/ t_0 (hypot c d)) (hypot c d))
     (+ (/ b d) (* (/ c d) (/ a 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 = (t_0 / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (b / d) + ((c / d) * (a / 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 = (t_0 / Math.hypot(c, d)) / Math.hypot(c, d);
	} else {
		tmp = (b / d) + ((c / d) * (a / 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 = (t_0 / math.hypot(c, d)) / math.hypot(c, d)
	else:
		tmp = (b / d) + ((c / d) * (a / 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(t_0 / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / 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 = (t_0 / hypot(c, d)) / hypot(c, d);
	else
		tmp = (b / d) + ((c / d) * (a / 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[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $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{\frac{t_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 77.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{b \cdot d + a \cdot c}}{\mathsf{hypot}\left(c, 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. Taylor expanded in c around 0 45.3%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 2: 83.1% 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}\;c \leq -1.46 \cdot 10^{+85}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-159}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.45 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -1.46e+85)
     (+ (/ a c) (/ (* d (/ b c)) c))
     (if (<= c -9e-46)
       t_0
       (if (<= c 2.6e-159)
         (+ (/ b d) (/ (* a (/ c d)) d))
         (if (<= c 2.45e+36)
           t_0
           (* (/ 1.0 (hypot c d)) (+ a (/ d (/ c b))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.46e+85) {
		tmp = (a / c) + ((d * (b / c)) / c);
	} else if (c <= -9e-46) {
		tmp = t_0;
	} else if (c <= 2.6e-159) {
		tmp = (b / d) + ((a * (c / d)) / d);
	} else if (c <= 2.45e+36) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b)));
	}
	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 (c <= -1.46e+85) {
		tmp = (a / c) + ((d * (b / c)) / c);
	} else if (c <= -9e-46) {
		tmp = t_0;
	} else if (c <= 2.6e-159) {
		tmp = (b / d) + ((a * (c / d)) / d);
	} else if (c <= 2.45e+36) {
		tmp = t_0;
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * (a + (d / (c / b)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.46e+85:
		tmp = (a / c) + ((d * (b / c)) / c)
	elif c <= -9e-46:
		tmp = t_0
	elif c <= 2.6e-159:
		tmp = (b / d) + ((a * (c / d)) / d)
	elif c <= 2.45e+36:
		tmp = t_0
	else:
		tmp = (1.0 / math.hypot(c, d)) * (a + (d / (c / b)))
	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 (c <= -1.46e+85)
		tmp = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c));
	elseif (c <= -9e-46)
		tmp = t_0;
	elseif (c <= 2.6e-159)
		tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d));
	elseif (c <= 2.45e+36)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a + Float64(d / Float64(c / b))));
	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 (c <= -1.46e+85)
		tmp = (a / c) + ((d * (b / c)) / c);
	elseif (c <= -9e-46)
		tmp = t_0;
	elseif (c <= 2.6e-159)
		tmp = (b / d) + ((a * (c / d)) / d);
	elseif (c <= 2.45e+36)
		tmp = t_0;
	else
		tmp = (1.0 / hypot(c, d)) * (a + (d / (c / b)));
	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[c, -1.46e+85], N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -9e-46], t$95$0, If[LessEqual[c, 2.6e-159], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.45e+36], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a + N[(d / N[(c / b), $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}\;c \leq -1.46 \cdot 10^{+85}:\\
\;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\

\mathbf{elif}\;c \leq -9 \cdot 10^{-46}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 2.45 \cdot 10^{+36}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.46e85

    1. Initial program 41.5%

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

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

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

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

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

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

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

    if -1.46e85 < c < -9.00000000000000001e-46 or 2.5999999999999998e-159 < c < 2.4499999999999999e36

    1. Initial program 90.0%

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

    if -9.00000000000000001e-46 < c < 2.5999999999999998e-159

    1. Initial program 63.0%

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

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

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

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

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

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

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

    if 2.4499999999999999e36 < c

    1. Initial program 43.4%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def62.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)}} \]
    3. Applied egg-rr62.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)}} \]
    4. Taylor expanded in c around inf 78.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.46 \cdot 10^{+85}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-46}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-159}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.45 \cdot 10^{+36}:\\ \;\;\;\;\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(a + \frac{d}{\frac{c}{b}}\right)\\ \end{array} \]

Alternative 3: 82.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{if}\;c \leq -2.15 \cdot 10^{+85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -1.15 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{-159}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{+34}:\\ \;\;\;\;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 (+ (/ a c) (/ (* d (/ b c)) c))))
   (if (<= c -2.15e+85)
     t_1
     (if (<= c -1.15e-45)
       t_0
       (if (<= c 4.5e-159)
         (+ (/ b d) (/ (* a (/ c d)) d))
         (if (<= c 1.2e+34) 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 = (a / c) + ((d * (b / c)) / c);
	double tmp;
	if (c <= -2.15e+85) {
		tmp = t_1;
	} else if (c <= -1.15e-45) {
		tmp = t_0;
	} else if (c <= 4.5e-159) {
		tmp = (b / d) + ((a * (c / d)) / d);
	} else if (c <= 1.2e+34) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (a / c) + ((d * (b / c)) / c)
    if (c <= (-2.15d+85)) then
        tmp = t_1
    else if (c <= (-1.15d-45)) then
        tmp = t_0
    else if (c <= 4.5d-159) then
        tmp = (b / d) + ((a * (c / d)) / d)
    else if (c <= 1.2d+34) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a / c) + ((d * (b / c)) / c);
	double tmp;
	if (c <= -2.15e+85) {
		tmp = t_1;
	} else if (c <= -1.15e-45) {
		tmp = t_0;
	} else if (c <= 4.5e-159) {
		tmp = (b / d) + ((a * (c / d)) / d);
	} else if (c <= 1.2e+34) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (a / c) + ((d * (b / c)) / c)
	tmp = 0
	if c <= -2.15e+85:
		tmp = t_1
	elif c <= -1.15e-45:
		tmp = t_0
	elif c <= 4.5e-159:
		tmp = (b / d) + ((a * (c / d)) / d)
	elif c <= 1.2e+34:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(a / c) + Float64(Float64(d * Float64(b / c)) / c))
	tmp = 0.0
	if (c <= -2.15e+85)
		tmp = t_1;
	elseif (c <= -1.15e-45)
		tmp = t_0;
	elseif (c <= 4.5e-159)
		tmp = Float64(Float64(b / d) + Float64(Float64(a * Float64(c / d)) / d));
	elseif (c <= 1.2e+34)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (a / c) + ((d * (b / c)) / c);
	tmp = 0.0;
	if (c <= -2.15e+85)
		tmp = t_1;
	elseif (c <= -1.15e-45)
		tmp = t_0;
	elseif (c <= 4.5e-159)
		tmp = (b / d) + ((a * (c / d)) / d);
	elseif (c <= 1.2e+34)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.15e+85], t$95$1, If[LessEqual[c, -1.15e-45], t$95$0, If[LessEqual[c, 4.5e-159], N[(N[(b / d), $MachinePrecision] + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.2e+34], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -1.15 \cdot 10^{-45}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.2 \cdot 10^{+34}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.15e85 or 1.19999999999999993e34 < c

    1. Initial program 42.4%

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

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

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

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

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

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

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

    if -2.15e85 < c < -1.14999999999999996e-45 or 4.49999999999999989e-159 < c < 1.19999999999999993e34

    1. Initial program 90.0%

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

    if -1.14999999999999996e-45 < c < 4.49999999999999989e-159

    1. Initial program 63.0%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.15 \cdot 10^{+85}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;c \leq -1.15 \cdot 10^{-45}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{-159}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{+34}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]

Alternative 4: 74.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{+36} \lor \neg \left(d \leq 1.05 \cdot 10^{+33}\right):\\
\;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.7999999999999999e36 or 1.05e33 < d

    1. Initial program 47.1%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{d}^{2} + {c}^{2}}{d}}} \]
      3. unpow241.7%

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

        \[\leadsto \frac{b}{\frac{d \cdot d + \color{blue}{c \cdot c}}{d}} \]
      5. +-commutative41.7%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c + d \cdot d}}{d}} \]
      6. fma-udef41.7%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt41.7%

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

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

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

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

        \[\leadsto \frac{b}{\frac{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}}{d}} \]
      6. *-un-lft-identity41.7%

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

        \[\leadsto \frac{b}{\color{blue}{\frac{\mathsf{hypot}\left(c, d\right)}{1} \cdot \frac{\mathsf{hypot}\left(c, d\right)}{d}}} \]
      8. /-rgt-identity73.5%

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

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

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

        \[\leadsto \frac{b}{\color{blue}{d + \frac{{c}^{2}}{d}}} \]
      2. unpow264.1%

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      3. associate-*r/73.5%

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

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

    if -1.7999999999999999e36 < d < 1.05e33

    1. Initial program 73.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.8 \cdot 10^{+36} \lor \neg \left(d \leq 1.05 \cdot 10^{+33}\right):\\ \;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \end{array} \]

Alternative 5: 74.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+36} \lor \neg \left(d \leq 3.8 \cdot 10^{+33}\right):\\
\;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.02000000000000003e36 or 3.80000000000000002e33 < d

    1. Initial program 47.1%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{d}^{2} + {c}^{2}}{d}}} \]
      3. unpow241.7%

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

        \[\leadsto \frac{b}{\frac{d \cdot d + \color{blue}{c \cdot c}}{d}} \]
      5. +-commutative41.7%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c + d \cdot d}}{d}} \]
      6. fma-udef41.7%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt41.7%

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

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

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

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

        \[\leadsto \frac{b}{\frac{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}}{d}} \]
      6. *-un-lft-identity41.7%

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

        \[\leadsto \frac{b}{\color{blue}{\frac{\mathsf{hypot}\left(c, d\right)}{1} \cdot \frac{\mathsf{hypot}\left(c, d\right)}{d}}} \]
      8. /-rgt-identity73.5%

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

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

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

        \[\leadsto \frac{b}{\color{blue}{d + \frac{{c}^{2}}{d}}} \]
      2. unpow264.1%

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      3. associate-*r/73.5%

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

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

    if -1.02000000000000003e36 < d < 3.80000000000000002e33

    1. Initial program 73.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.02 \cdot 10^{+36} \lor \neg \left(d \leq 3.8 \cdot 10^{+33}\right):\\ \;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \end{array} \]

Alternative 6: 77.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+18} \lor \neg \left(d \leq 7 \cdot 10^{+26}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5e18 or 6.9999999999999998e26 < d

    1. Initial program 48.9%

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

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

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac79.2%

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

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

    if -5e18 < d < 6.9999999999999998e26

    1. Initial program 73.4%

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

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

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

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

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

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

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

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

Alternative 7: 76.9% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 55.3%

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

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

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

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

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

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

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

    if -4.1e18 < d < 7.49999999999999941e26

    1. Initial program 73.4%

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

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

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

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

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

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

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

    if 7.49999999999999941e26 < d

    1. Initial program 44.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.1 \cdot 10^{+18}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+26}:\\ \;\;\;\;\frac{a}{c} + \frac{d \cdot \frac{b}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 8: 67.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.45 \cdot 10^{+96} \lor \neg \left(c \leq 8 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.44999999999999989e96 or 8.0000000000000006e-18 < c

    1. Initial program 47.6%

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

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

    if -1.44999999999999989e96 < c < 8.0000000000000006e-18

    1. Initial program 73.2%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{d}^{2} + {c}^{2}}{d}}} \]
      3. unpow251.3%

        \[\leadsto \frac{b}{\frac{\color{blue}{d \cdot d} + {c}^{2}}{d}} \]
      4. unpow251.3%

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

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c + d \cdot d}}{d}} \]
      6. fma-udef51.3%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt51.3%

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

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

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

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

        \[\leadsto \frac{b}{\frac{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}}{d}} \]
      6. *-un-lft-identity51.3%

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

        \[\leadsto \frac{b}{\color{blue}{\frac{\mathsf{hypot}\left(c, d\right)}{1} \cdot \frac{\mathsf{hypot}\left(c, d\right)}{d}}} \]
      8. /-rgt-identity69.8%

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

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

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

        \[\leadsto \frac{b}{\color{blue}{d + \frac{{c}^{2}}{d}}} \]
      2. unpow268.2%

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      3. associate-*r/69.8%

        \[\leadsto \frac{b}{d + \color{blue}{c \cdot \frac{c}{d}}} \]
    9. Simplified69.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{+96} \lor \neg \left(c \leq 8 \cdot 10^{-18}\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Alternative 9: 64.0% accurate, 2.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.3e39 or 7.6000000000000004e26 < d

    1. Initial program 47.6%

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

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

    if -1.3e39 < d < 7.6000000000000004e26

    1. Initial program 74.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{+39}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 7.6 \cdot 10^{+26}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 10: 43.7% 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 61.8%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification42.8%

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

Developer target: 99.4% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023230 
(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))))