Complex division, real part

Percentage Accurate: 61.7% → 84.1%
Time: 8.3s
Alternatives: 14
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 14 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 84.1% accurate, 0.0× speedup?

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

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

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


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

    1. Initial program 81.0%

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

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

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

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

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

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

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

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

    if 2.00000000000000003e306 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 5.6%

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}} \cdot \sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}}} \]
      2. sqrt-div4.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{b}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}} \]
      4. hypot-udef10.2%

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

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

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

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

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

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

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

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

Alternative 2: 80.8% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -3 \cdot 10^{-130}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.05 \cdot 10^{+25}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.5999999999999999e46 or 1.05e25 < d

    1. Initial program 45.3%

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

      \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    3. Step-by-step derivation
      1. add-sqr-sqrt28.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}} \cdot \sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}}} \]
      2. sqrt-div20.5%

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

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

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

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

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

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

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

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

    if -3.5999999999999999e46 < d < -2.99999999999999986e-130 or 4.70000000000000027e-139 < d < 1.05e25

    1. Initial program 90.0%

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

    if -2.99999999999999986e-130 < d < 4.70000000000000027e-139

    1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+46}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3 \cdot 10^{-130}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.7 \cdot 10^{-139}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{+25}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 80.8% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -3.05 \cdot 10^{-130}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 2.65 \cdot 10^{+24}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -7.5000000000000006e48 or 2.6499999999999999e24 < d

    1. Initial program 45.3%

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

      \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    3. Step-by-step derivation
      1. add-sqr-sqrt28.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}} \cdot \sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}}} \]
      2. sqrt-div20.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.5000000000000006e48 < d < -3.04999999999999998e-130 or 2.7999999999999999e-139 < d < 2.6499999999999999e24

    1. Initial program 90.0%

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

    if -3.04999999999999998e-130 < d < 2.7999999999999999e-139

    1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{+48}:\\ \;\;\;\;\frac{\frac{b}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}\\ \mathbf{elif}\;d \leq -3.05 \cdot 10^{-130}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{-139}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;d \leq 2.65 \cdot 10^{+24}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{d}}\\ \end{array} \]

Alternative 4: 82.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -1.3 \cdot 10^{+68}:\\ \;\;\;\;\left(b + \frac{c}{\frac{d}{a}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-126}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 4.7 \cdot 10^{-139}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{+79}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -1.3e+68)
     (* (+ b (/ c (/ d a))) (/ -1.0 (hypot c d)))
     (if (<= d -2.35e-126)
       t_0
       (if (<= d 4.7e-139)
         (* (/ 1.0 c) (+ a (/ d (/ c b))))
         (if (<= d 4.4e+79) t_0 (+ (/ b d) (* (/ c 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 (d <= -1.3e+68) {
		tmp = (b + (c / (d / a))) * (-1.0 / hypot(c, d));
	} else if (d <= -2.35e-126) {
		tmp = t_0;
	} else if (d <= 4.7e-139) {
		tmp = (1.0 / c) * (a + (d / (c / b)));
	} else if (d <= 4.4e+79) {
		tmp = t_0;
	} else {
		tmp = (b / d) + ((c / d) * (a / d));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.3e+68) {
		tmp = (b + (c / (d / a))) * (-1.0 / Math.hypot(c, d));
	} else if (d <= -2.35e-126) {
		tmp = t_0;
	} else if (d <= 4.7e-139) {
		tmp = (1.0 / c) * (a + (d / (c / b)));
	} else if (d <= 4.4e+79) {
		tmp = t_0;
	} else {
		tmp = (b / d) + ((c / d) * (a / d));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.3e+68:
		tmp = (b + (c / (d / a))) * (-1.0 / math.hypot(c, d))
	elif d <= -2.35e-126:
		tmp = t_0
	elif d <= 4.7e-139:
		tmp = (1.0 / c) * (a + (d / (c / b)))
	elif d <= 4.4e+79:
		tmp = t_0
	else:
		tmp = (b / d) + ((c / 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 (d <= -1.3e+68)
		tmp = Float64(Float64(b + Float64(c / Float64(d / a))) * Float64(-1.0 / hypot(c, d)));
	elseif (d <= -2.35e-126)
		tmp = t_0;
	elseif (d <= 4.7e-139)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(d / Float64(c / b))));
	elseif (d <= 4.4e+79)
		tmp = t_0;
	else
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -1.3e+68)
		tmp = (b + (c / (d / a))) * (-1.0 / hypot(c, d));
	elseif (d <= -2.35e-126)
		tmp = t_0;
	elseif (d <= 4.7e-139)
		tmp = (1.0 / c) * (a + (d / (c / b)));
	elseif (d <= 4.4e+79)
		tmp = t_0;
	else
		tmp = (b / d) + ((c / d) * (a / d));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.3e+68], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.35e-126], t$95$0, If[LessEqual[d, 4.7e-139], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.4e+79], t$95$0, N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -2.35 \cdot 10^{-126}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 4.4 \cdot 10^{+79}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 46.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.2999999999999999e68 < d < -2.35000000000000009e-126 or 4.70000000000000027e-139 < d < 4.3999999999999998e79

    1. Initial program 83.6%

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

    if -2.35000000000000009e-126 < d < 4.70000000000000027e-139

    1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

    if 4.3999999999999998e79 < d

    1. Initial program 37.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{+68}:\\ \;\;\;\;\left(b + \frac{c}{\frac{d}{a}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-126}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.7 \cdot 10^{-139}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{+79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 5: 82.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -9.2 \cdot 10^{-129}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.5 \cdot 10^{+81}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.1000000000000002e71 or 1.49999999999999999e81 < d

    1. Initial program 42.4%

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

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

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

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

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

    if -4.1000000000000002e71 < d < -9.1999999999999998e-129 or 3.1999999999999999e-139 < d < 1.49999999999999999e81

    1. Initial program 83.6%

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

    if -9.1999999999999998e-129 < d < 3.1999999999999999e-139

    1. Initial program 74.2%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.1 \cdot 10^{+71}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -9.2 \cdot 10^{-129}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-139}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{+81}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 6: 76.5% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.6000000000000004e-13

    1. Initial program 52.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.6000000000000004e-13 < c < 1.65e-31

    1. Initial program 72.9%

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

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

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

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

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

    if 1.65e-31 < c

    1. Initial program 58.9%

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{{\left(\frac{\frac{c \cdot c}{b}}{d}\right)}^{-1}} \]
      3. associate-/l*75.9%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{1}{\frac{\frac{c}{\frac{b}{c}}}{d}}} \]
      2. associate-/l/77.2%

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c}{d \cdot \frac{b}{c}}}} \]
      3. *-rgt-identity77.2%

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\frac{c}{d} \cdot \color{blue}{\left(\frac{1}{b} \cdot c\right)}} \]
      6. associate-*l/77.3%

        \[\leadsto \frac{a}{c} + \frac{1}{\frac{c}{d} \cdot \color{blue}{\frac{1 \cdot c}{b}}} \]
      7. *-lft-identity77.3%

        \[\leadsto \frac{a}{c} + \frac{1}{\frac{c}{d} \cdot \frac{\color{blue}{c}}{b}} \]
    8. Simplified77.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.6 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{-31}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{\frac{c}{b} \cdot \frac{c}{d}}\\ \end{array} \]

Alternative 7: 70.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.5 \cdot 10^{-13} \lor \neg \left(c \leq 4.4 \cdot 10^{-32}\right):\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.49999999999999979e-13 or 4.4e-32 < c

    1. Initial program 55.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.49999999999999979e-13 < c < 4.4e-32

    1. Initial program 72.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{-13} \lor \neg \left(c \leq 4.4 \cdot 10^{-32}\right):\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 8: 70.2% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;c \leq 2.65 \cdot 10^{-33}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.1000000000000002e-13

    1. Initial program 52.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.1000000000000002e-13 < c < 2.64999999999999984e-33

    1. Initial program 72.9%

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

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

    if 2.64999999999999984e-33 < c

    1. Initial program 58.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.1 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;c \leq 2.65 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]

Alternative 9: 76.6% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.70000000000000011e-13

    1. Initial program 52.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.70000000000000011e-13 < c < 1.65e-31

    1. Initial program 72.9%

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

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

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

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

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

    if 1.65e-31 < c

    1. Initial program 58.9%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.7 \cdot 10^{-13}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{d}{\frac{c}{b}}\right)\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{-31}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]

Alternative 10: 63.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.6 \cdot 10^{-13}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 1.45 \cdot 10^{-30}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq 1.9 \cdot 10^{-5}:\\
\;\;\;\;b \cdot \frac{\frac{d}{c}}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.6000000000000004e-13 or 1.5e15 < c

    1. Initial program 53.3%

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

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

    if -5.6000000000000004e-13 < c < 1.44999999999999995e-30 or 1.9000000000000001e-5 < c < 1.5e15

    1. Initial program 72.5%

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

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

    if 1.44999999999999995e-30 < c < 1.9000000000000001e-5

    1. Initial program 99.5%

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

      \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    3. Step-by-step derivation
      1. add-sqr-sqrt49.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}} \cdot \sqrt{\frac{d \cdot b}{c \cdot c + d \cdot d}}} \]
      2. sqrt-div49.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.6 \cdot 10^{-13}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{-30}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 1.9 \cdot 10^{-5}:\\ \;\;\;\;b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+15}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 11: 63.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.2 \cdot 10^{-13}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 1.45 \cdot 10^{-30}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq 3.4 \cdot 10^{-6}:\\
\;\;\;\;\frac{d}{c} \cdot \frac{b}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.2e-13 or 3.7e15 < c

    1. Initial program 53.3%

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

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

    if -3.2e-13 < c < 1.44999999999999995e-30 or 3.40000000000000006e-6 < c < 3.7e15

    1. Initial program 72.5%

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

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

    if 1.44999999999999995e-30 < c < 3.40000000000000006e-6

    1. Initial program 99.5%

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

      \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    3. Taylor expanded in c around inf 83.5%

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

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

      \[\leadsto \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
    6. Step-by-step derivation
      1. times-frac83.0%

        \[\leadsto \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    7. Applied egg-rr83.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{-13}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{-30}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 3.4 \cdot 10^{-6}:\\ \;\;\;\;\frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{+15}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 12: 63.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6 \cdot 10^{-13}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 1.45 \cdot 10^{-30}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;c \leq 3.4 \cdot 10^{-6}:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.99999999999999968e-13 or 4.4e15 < c

    1. Initial program 53.3%

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

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

    if -5.99999999999999968e-13 < c < 1.44999999999999995e-30 or 3.40000000000000006e-6 < c < 4.4e15

    1. Initial program 72.5%

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

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

    if 1.44999999999999995e-30 < c < 3.40000000000000006e-6

    1. Initial program 99.5%

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

      \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    3. Taylor expanded in c around inf 83.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6 \cdot 10^{-13}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{-30}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 3.4 \cdot 10^{-6}:\\ \;\;\;\;\frac{b \cdot d}{c \cdot c}\\ \mathbf{elif}\;c \leq 4.4 \cdot 10^{+15}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 13: 64.4% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.9 \cdot 10^{-13}:\\
\;\;\;\;\frac{a}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.8999999999999998e-13 or 2e15 < c

    1. Initial program 53.3%

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

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

    if -2.8999999999999998e-13 < c < 2e15

    1. Initial program 73.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.9 \cdot 10^{-13}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 2 \cdot 10^{+15}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 14: 42.3% accurate, 5.0× speedup?

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

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 63.9%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification40.5%

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

Developer target: 99.4% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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