Complex division, real part

Percentage Accurate: 61.9% → 85.0%
Time: 9.6s
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: 61.9% 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.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;t_0 \leq 10^{+298}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + c \cdot \left(\frac{1}{d} \cdot \frac{a}{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 (<= t_0 (- INFINITY))
     (* (/ 1.0 c) (+ a (/ b (/ c d))))
     (if (<= t_0 1e+298)
       (/ (/ (fma b d (* a c)) (hypot c d)) (hypot c d))
       (+ (/ b d) (* c (* (/ 1.0 d) (/ a 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 (t_0 <= -((double) INFINITY)) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (t_0 <= 1e+298) {
		tmp = (fma(b, d, (a * c)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (b / d) + (c * ((1.0 / d) * (a / 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 (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif (t_0 <= 1e+298)
		tmp = Float64(Float64(fma(b, d, Float64(a * c)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(1.0 / d) * Float64(a / 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[t$95$0, (-Infinity)], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+298], N[(N[(N[(b * d + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(1.0 / d), $MachinePrecision] * N[(a / 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}\;t_0 \leq -\infty:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\

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

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


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

    1. Initial program 56.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-identity56.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999996e297

    1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999996e297 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 8.3%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/48.6%

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

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

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

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

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

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

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

Alternative 2: 84.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot c + b \cdot d\\ t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;t_1 \leq 10^{+298}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + c \cdot \left(\frac{1}{d} \cdot \frac{a}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))) (t_1 (/ t_0 (+ (* c c) (* d d)))))
   (if (<= t_1 (- INFINITY))
     (* (/ 1.0 c) (+ a (/ b (/ c d))))
     (if (<= t_1 1e+298)
       (* (/ 1.0 (hypot c d)) (/ t_0 (hypot c d)))
       (+ (/ b d) (* c (* (/ 1.0 d) (/ a d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double t_1 = t_0 / ((c * c) + (d * d));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (t_1 <= 1e+298) {
		tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
	} else {
		tmp = (b / d) + (c * ((1.0 / 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 t_1 = t_0 / ((c * c) + (d * d));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (t_1 <= 1e+298) {
		tmp = (1.0 / Math.hypot(c, d)) * (t_0 / Math.hypot(c, d));
	} else {
		tmp = (b / d) + (c * ((1.0 / d) * (a / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a * c) + (b * d)
	t_1 = t_0 / ((c * c) + (d * d))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	elif t_1 <= 1e+298:
		tmp = (1.0 / math.hypot(c, d)) * (t_0 / math.hypot(c, d))
	else:
		tmp = (b / d) + (c * ((1.0 / d) * (a / d)))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) + Float64(b * d))
	t_1 = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif (t_1 <= 1e+298)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(t_0 / hypot(c, d)));
	else
		tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(1.0 / d) * Float64(a / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a * c) + (b * d);
	t_1 = t_0 / ((c * c) + (d * d));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = (1.0 / c) * (a + (b / (c / d)));
	elseif (t_1 <= 1e+298)
		tmp = (1.0 / hypot(c, d)) * (t_0 / hypot(c, d));
	else
		tmp = (b / d) + (c * ((1.0 / 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]}, Block[{t$95$1 = N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+298], 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[(b / d), $MachinePrecision] + N[(c * N[(N[(1.0 / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\

\mathbf{elif}\;t_1 \leq 10^{+298}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 56.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-identity56.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 9.9999999999999996e297

    1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 8.3%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/48.6%

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

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

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

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

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

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

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

Alternative 3: 77.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;d \leq -2.6 \cdot 10^{+92}:\\ \;\;\;\;\frac{b}{d} + c \cdot \left(\frac{1}{d} \cdot \frac{a}{d}\right)\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{-87}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.62 \cdot 10^{-12}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ c (hypot c d)) (/ a (hypot c d)))))
   (if (<= d -2.6e+92)
     (+ (/ b d) (* c (* (/ 1.0 d) (/ a d))))
     (if (<= d -3.6e-69)
       t_0
       (if (<= d 4.2e-87)
         (* (/ 1.0 c) (+ a (/ b (/ c d))))
         (if (<= d 1.62e-12)
           (/ (+ (* a c) (* b d)) (fma d d (* c c)))
           (if (<= d 3.4e+61) t_0 (/ (+ b (/ a (/ d c))) (hypot c d)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c / hypot(c, d)) * (a / hypot(c, d));
	double tmp;
	if (d <= -2.6e+92) {
		tmp = (b / d) + (c * ((1.0 / d) * (a / d)));
	} else if (d <= -3.6e-69) {
		tmp = t_0;
	} else if (d <= 4.2e-87) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 1.62e-12) {
		tmp = ((a * c) + (b * d)) / fma(d, d, (c * c));
	} else if (d <= 3.4e+61) {
		tmp = t_0;
	} else {
		tmp = (b + (a / (d / c))) / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d)))
	tmp = 0.0
	if (d <= -2.6e+92)
		tmp = Float64(Float64(b / d) + Float64(c * Float64(Float64(1.0 / d) * Float64(a / d))));
	elseif (d <= -3.6e-69)
		tmp = t_0;
	elseif (d <= 4.2e-87)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif (d <= 1.62e-12)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / fma(d, d, Float64(c * c)));
	elseif (d <= 3.4e+61)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.6e+92], N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(1.0 / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.6e-69], t$95$0, If[LessEqual[d, 4.2e-87], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.62e-12], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.4e+61], t$95$0, N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -3.6 \cdot 10^{-69}:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;d \leq 3.4 \cdot 10^{+61}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 37.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/72.7%

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

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

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

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

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

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

    if -2.5999999999999999e92 < d < -3.60000000000000018e-69 or 1.62e-12 < d < 3.40000000000000026e61

    1. Initial program 66.5%

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

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

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

      \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt56.5%

        \[\leadsto \frac{c \cdot a}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. hypot-udef56.5%

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

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

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

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

    if -3.60000000000000018e-69 < d < 4.20000000000000014e-87

    1. Initial program 68.9%

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

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

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

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      10. fma-udef68.9%

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

        \[\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}}} \]
      12. hypot-def79.4%

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

      \[\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 inf 50.9%

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

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

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

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

    if 4.20000000000000014e-87 < d < 1.62e-12

    1. Initial program 82.3%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-def82.3%

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

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

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

    if 3.40000000000000026e61 < d

    1. Initial program 46.3%

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

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

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

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      10. fma-udef46.3%

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

        \[\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}}} \]
      12. hypot-def61.1%

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

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

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

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

        \[\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)} \]
      4. fma-def61.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.6 \cdot 10^{+92}:\\ \;\;\;\;\frac{b}{d} + c \cdot \left(\frac{1}{d} \cdot \frac{a}{d}\right)\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-69}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{-87}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.62 \cdot 10^{-12}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{+61}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 79.3% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 37.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/72.7%

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

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

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

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

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

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

    if -4.79999999999999966e91 < d < 2.0500000000000001e-88

    1. Initial program 69.6%

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

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

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

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      10. fma-udef69.6%

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

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

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

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

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

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

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

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

    if 2.0500000000000001e-88 < d < 2.2e45

    1. Initial program 72.9%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. fma-def73.0%

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

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

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

    if 2.2e45 < d

    1. Initial program 46.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      11. +-commutative46.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}}} \]
      12. hypot-def60.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 79.3% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 37.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/72.7%

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

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

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

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

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

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

    if -4.79999999999999966e91 < d < 3.99999999999999974e-88

    1. Initial program 69.6%

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

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

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

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      10. fma-udef69.6%

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

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

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

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

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

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

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

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

    if 3.99999999999999974e-88 < d < 2.2e45

    1. Initial program 72.9%

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

    if 2.2e45 < d

    1. Initial program 46.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \]
      11. +-commutative46.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}}} \]
      12. hypot-def60.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{d} + c \cdot \left(\frac{1}{d} \cdot \frac{a}{d}\right)\\ \mathbf{if}\;d \leq -4.8 \cdot 10^{+91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 4.6 \cdot 10^{-88}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{+43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ b d) (* c (* (/ 1.0 d) (/ a d))))))
   (if (<= d -4.8e+91)
     t_0
     (if (<= d 4.6e-88)
       (* (/ 1.0 c) (+ a (/ b (/ c d))))
       (if (<= d 1.55e+43) (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + (c * ((1.0 / d) * (a / d)));
	double tmp;
	if (d <= -4.8e+91) {
		tmp = t_0;
	} else if (d <= 4.6e-88) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 1.55e+43) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (b / d) + (c * ((1.0d0 / d) * (a / d)))
    if (d <= (-4.8d+91)) then
        tmp = t_0
    else if (d <= 4.6d-88) then
        tmp = (1.0d0 / c) * (a + (b / (c / d)))
    else if (d <= 1.55d+43) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + (c * ((1.0 / d) * (a / d)));
	double tmp;
	if (d <= -4.8e+91) {
		tmp = t_0;
	} else if (d <= 4.6e-88) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else if (d <= 1.55e+43) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / d) + (c * ((1.0 / d) * (a / d)))
	tmp = 0
	if d <= -4.8e+91:
		tmp = t_0
	elif d <= 4.6e-88:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	elif d <= 1.55e+43:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b / d) + Float64(c * Float64(Float64(1.0 / d) * Float64(a / d))))
	tmp = 0.0
	if (d <= -4.8e+91)
		tmp = t_0;
	elseif (d <= 4.6e-88)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	elseif (d <= 1.55e+43)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b / d) + (c * ((1.0 / d) * (a / d)));
	tmp = 0.0;
	if (d <= -4.8e+91)
		tmp = t_0;
	elseif (d <= 4.6e-88)
		tmp = (1.0 / c) * (a + (b / (c / d)));
	elseif (d <= 1.55e+43)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(c * N[(N[(1.0 / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.8e+91], t$95$0, If[LessEqual[d, 4.6e-88], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.55e+43], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b}{d} + c \cdot \left(\frac{1}{d} \cdot \frac{a}{d}\right)\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{+91}:\\
\;\;\;\;t_0\\

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

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.79999999999999966e91 or 1.5500000000000001e43 < d

    1. Initial program 42.0%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/77.1%

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

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

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

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

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

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

    if -4.79999999999999966e91 < d < 4.59999999999999972e-88

    1. Initial program 69.6%

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

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

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

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

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

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

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

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

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

        \[\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(d, d, c \cdot c\right)}} \]
      10. fma-udef69.6%

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

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

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

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

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

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

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

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

    if 4.59999999999999972e-88 < d < 1.5500000000000001e43

    1. Initial program 72.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification80.8%

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

Alternative 7: 77.0% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.2 \cdot 10^{+91} \lor \neg \left(d \leq 1.3 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{b}{d} + c \cdot \left(\frac{1}{d} \cdot \frac{a}{d}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.19999999999999995e91 or 1.3000000000000001e43 < d

    1. Initial program 42.0%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/77.1%

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

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

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

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

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

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

    if -6.19999999999999995e91 < d < 1.3000000000000001e43

    1. Initial program 70.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      12. hypot-def82.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-rr82.3%

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

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

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

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

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

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

Alternative 8: 73.2% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.09999999999999986e92 or 8.0000000000000007e44 < d

    1. Initial program 42.0%

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

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

    if -2.09999999999999986e92 < d < 8.0000000000000007e44

    1. Initial program 70.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      12. hypot-def82.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-rr82.3%

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

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

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

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

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

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

Alternative 9: 63.0% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -5 \cdot 10^{+91} \lor \neg \left(d \leq 1.15 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5.0000000000000002e91 or 1.1500000000000001e43 < d

    1. Initial program 42.0%

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

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

    if -5.0000000000000002e91 < d < 1.1500000000000001e43

    1. Initial program 70.4%

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

      \[\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 -5 \cdot 10^{+91} \lor \neg \left(d \leq 1.15 \cdot 10^{+43}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 42.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 58.2%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification44.3%

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

Developer target: 99.2% 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 2024010 
(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))))