Complex division, imag part

Percentage Accurate: 61.8% → 85.7%
Time: 9.7s
Alternatives: 13
Speedup: 1.8×

Specification

?
\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 61.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 85.7% accurate, 0.1× speedup?

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

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

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


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

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

Alternative 2: 82.1% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -3.7 \cdot 10^{-124}:\\
\;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;d \leq 5.7 \cdot 10^{-114}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\

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

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


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

    1. Initial program 43.9%

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

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

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

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

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

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

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

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

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

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

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

    if -3.2e20 < d < -3.6999999999999999e-124

    1. Initial program 79.3%

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

    if -3.6999999999999999e-124 < d < 5.6999999999999997e-114

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/92.0%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\color{blue}{c \cdot \frac{c}{d}}}\right) \]
      6. *-commutative92.0%

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg90.9%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/82.6%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative82.6%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub90.9%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative92.9%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified92.9%

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

    if 5.6999999999999997e-114 < d < 2.50000000000000009e61

    1. Initial program 89.7%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. clear-num89.6%

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

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

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

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

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

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

    if 2.50000000000000009e61 < d

    1. Initial program 53.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.2 \cdot 10^{+20}:\\ \;\;\;\;\frac{a - \frac{b \cdot c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.7 \cdot 10^{-124}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.7 \cdot 10^{-114}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{+61}:\\ \;\;\;\;\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 83.0% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -7.5 \cdot 10^{-118}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{t_0}\\

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

\mathbf{elif}\;d \leq 1.5 \cdot 10^{+57}:\\
\;\;\;\;\frac{b \cdot c}{t_0} - \frac{a \cdot d}{t_0}\\

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


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

    1. Initial program 43.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.8e20 < d < -7.49999999999999978e-118

    1. Initial program 79.3%

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

    if -7.49999999999999978e-118 < d < 1.44999999999999996e-112

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/92.0%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\color{blue}{c \cdot \frac{c}{d}}}\right) \]
      6. *-commutative92.0%

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg90.9%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/82.6%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative82.6%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub90.9%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative92.9%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified92.9%

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

    if 1.44999999999999996e-112 < d < 1.5e57

    1. Initial program 89.7%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-a \cdot d}}{{d}^{2} + {c}^{2}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]
      4. distribute-rgt-neg-out89.7%

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

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

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

        \[\leadsto \frac{a \cdot \left(-d\right)}{d \cdot d + c \cdot c} + \frac{c \cdot b}{\color{blue}{d \cdot d} + {c}^{2}} \]
      8. unpow289.7%

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

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

    if 1.5e57 < d

    1. Initial program 53.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+20}:\\ \;\;\;\;\frac{a - \frac{c}{\frac{d}{b}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{-118}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-112}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{+57}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 4: 82.0% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -4.3 \cdot 10^{-124}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{t_0}\\

\mathbf{elif}\;d \leq 1.3 \cdot 10^{-114}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\

\mathbf{elif}\;d \leq 9 \cdot 10^{+57}:\\
\;\;\;\;\frac{b \cdot c}{t_0} - \frac{a \cdot d}{t_0}\\

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


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

    1. Initial program 43.9%

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

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

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

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

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

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

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

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

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

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

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

    if -5.8e20 < d < -4.3e-124

    1. Initial program 79.3%

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

    if -4.3e-124 < d < 1.30000000000000007e-114

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/92.0%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\color{blue}{c \cdot \frac{c}{d}}}\right) \]
      6. *-commutative92.0%

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg90.9%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/82.6%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative82.6%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub90.9%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative92.9%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified92.9%

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

    if 1.30000000000000007e-114 < d < 8.99999999999999991e57

    1. Initial program 89.7%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-a \cdot d}}{{d}^{2} + {c}^{2}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]
      4. distribute-rgt-neg-out89.7%

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

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

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

        \[\leadsto \frac{a \cdot \left(-d\right)}{d \cdot d + c \cdot c} + \frac{c \cdot b}{\color{blue}{d \cdot d} + {c}^{2}} \]
      8. unpow289.7%

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

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

    if 8.99999999999999991e57 < d

    1. Initial program 53.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+20}:\\ \;\;\;\;\frac{a - \frac{b \cdot c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -4.3 \cdot 10^{-124}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.3 \cdot 10^{-114}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+57}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 5: 82.9% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -3.3 \cdot 10^{-121}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{t_0}\\

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

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

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


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

    1. Initial program 43.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.9e20 < d < -3.3000000000000001e-121

    1. Initial program 79.3%

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

    if -3.3000000000000001e-121 < d < 1.44999999999999996e-112

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/92.0%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\color{blue}{c \cdot \frac{c}{d}}}\right) \]
      6. *-commutative92.0%

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg90.9%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/82.6%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative82.6%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub90.9%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative92.9%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified92.9%

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

    if 1.44999999999999996e-112 < d < 2.29999999999999984e62

    1. Initial program 89.7%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-a \cdot d}}{{d}^{2} + {c}^{2}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]
      4. distribute-rgt-neg-out89.7%

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

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

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

        \[\leadsto \frac{a \cdot \left(-d\right)}{d \cdot d + c \cdot c} + \frac{c \cdot b}{\color{blue}{d \cdot d} + {c}^{2}} \]
      8. unpow289.7%

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

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

    if 2.29999999999999984e62 < d

    1. Initial program 53.2%

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

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

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

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

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

        \[\leadsto \frac{c \cdot b}{\color{blue}{d \cdot d}} - \frac{a}{d} \]
      5. times-frac82.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.9 \cdot 10^{+20}:\\ \;\;\;\;\frac{a - \frac{c}{\frac{d}{b}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.3 \cdot 10^{-121}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-112}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+62}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]

Alternative 6: 82.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -5.8 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-122}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{t_0}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-106}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{+58}:\\ \;\;\;\;\frac{b \cdot c}{t_0} - \frac{a \cdot d}{t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d))) (t_1 (- (* (/ c d) (/ b d)) (/ a d))))
   (if (<= d -5.8e+20)
     t_1
     (if (<= d -1.75e-122)
       (/ (- (* b c) (* a d)) t_0)
       (if (<= d 1.5e-106)
         (/ (- b (/ (* a d) c)) c)
         (if (<= d 1.4e+58) (- (/ (* b c) t_0) (/ (* a d) t_0)) t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -5.8e+20) {
		tmp = t_1;
	} else if (d <= -1.75e-122) {
		tmp = ((b * c) - (a * d)) / t_0;
	} else if (d <= 1.5e-106) {
		tmp = (b - ((a * d) / c)) / c;
	} else if (d <= 1.4e+58) {
		tmp = ((b * c) / t_0) - ((a * d) / 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 = (c * c) + (d * d)
    t_1 = ((c / d) * (b / d)) - (a / d)
    if (d <= (-5.8d+20)) then
        tmp = t_1
    else if (d <= (-1.75d-122)) then
        tmp = ((b * c) - (a * d)) / t_0
    else if (d <= 1.5d-106) then
        tmp = (b - ((a * d) / c)) / c
    else if (d <= 1.4d+58) then
        tmp = ((b * c) / t_0) - ((a * d) / 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 = (c * c) + (d * d);
	double t_1 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -5.8e+20) {
		tmp = t_1;
	} else if (d <= -1.75e-122) {
		tmp = ((b * c) - (a * d)) / t_0;
	} else if (d <= 1.5e-106) {
		tmp = (b - ((a * d) / c)) / c;
	} else if (d <= 1.4e+58) {
		tmp = ((b * c) / t_0) - ((a * d) / t_0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (c * c) + (d * d)
	t_1 = ((c / d) * (b / d)) - (a / d)
	tmp = 0
	if d <= -5.8e+20:
		tmp = t_1
	elif d <= -1.75e-122:
		tmp = ((b * c) - (a * d)) / t_0
	elif d <= 1.5e-106:
		tmp = (b - ((a * d) / c)) / c
	elif d <= 1.4e+58:
		tmp = ((b * c) / t_0) - ((a * d) / t_0)
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	t_1 = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d))
	tmp = 0.0
	if (d <= -5.8e+20)
		tmp = t_1;
	elseif (d <= -1.75e-122)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / t_0);
	elseif (d <= 1.5e-106)
		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
	elseif (d <= 1.4e+58)
		tmp = Float64(Float64(Float64(b * c) / t_0) - Float64(Float64(a * d) / t_0));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (c * c) + (d * d);
	t_1 = ((c / d) * (b / d)) - (a / d);
	tmp = 0.0;
	if (d <= -5.8e+20)
		tmp = t_1;
	elseif (d <= -1.75e-122)
		tmp = ((b * c) - (a * d)) / t_0;
	elseif (d <= 1.5e-106)
		tmp = (b - ((a * d) / c)) / c;
	elseif (d <= 1.4e+58)
		tmp = ((b * c) / t_0) - ((a * d) / t_0);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.8e+20], t$95$1, If[LessEqual[d, -1.75e-122], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[d, 1.5e-106], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.4e+58], N[(N[(N[(b * c), $MachinePrecision] / t$95$0), $MachinePrecision] - N[(N[(a * d), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1.75 \cdot 10^{-122}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{t_0}\\

\mathbf{elif}\;d \leq 1.5 \cdot 10^{-106}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -5.8e20 or 1.3999999999999999e58 < d

    1. Initial program 48.3%

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

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

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

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

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

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

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

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

    if -5.8e20 < d < -1.7500000000000001e-122

    1. Initial program 79.3%

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

    if -1.7500000000000001e-122 < d < 1.50000000000000009e-106

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/92.0%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\color{blue}{c \cdot \frac{c}{d}}}\right) \]
      6. *-commutative92.0%

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg90.9%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/82.6%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative82.6%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub90.9%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative92.9%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified92.9%

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

    if 1.50000000000000009e-106 < d < 1.3999999999999999e58

    1. Initial program 89.7%

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

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

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

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

        \[\leadsto \frac{\color{blue}{-a \cdot d}}{{d}^{2} + {c}^{2}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]
      4. distribute-rgt-neg-out89.7%

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

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

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

        \[\leadsto \frac{a \cdot \left(-d\right)}{d \cdot d + c \cdot c} + \frac{c \cdot b}{\color{blue}{d \cdot d} + {c}^{2}} \]
      8. unpow289.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+20}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-122}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-106}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{+58}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]

Alternative 7: 82.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -5.8 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-116}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.1 \cdot 10^{-113}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+57}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
        (t_1 (- (* (/ c d) (/ b d)) (/ a d))))
   (if (<= d -5.8e+20)
     t_1
     (if (<= d -2e-116)
       t_0
       (if (<= d 1.1e-113)
         (/ (- b (/ (* a d) c)) c)
         (if (<= d 9e+57) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double t_1 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -5.8e+20) {
		tmp = t_1;
	} else if (d <= -2e-116) {
		tmp = t_0;
	} else if (d <= 1.1e-113) {
		tmp = (b - ((a * d) / c)) / c;
	} else if (d <= 9e+57) {
		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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
    t_1 = ((c / d) * (b / d)) - (a / d)
    if (d <= (-5.8d+20)) then
        tmp = t_1
    else if (d <= (-2d-116)) then
        tmp = t_0
    else if (d <= 1.1d-113) then
        tmp = (b - ((a * d) / c)) / c
    else if (d <= 9d+57) 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 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double t_1 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -5.8e+20) {
		tmp = t_1;
	} else if (d <= -2e-116) {
		tmp = t_0;
	} else if (d <= 1.1e-113) {
		tmp = (b - ((a * d) / c)) / c;
	} else if (d <= 9e+57) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
	t_1 = ((c / d) * (b / d)) - (a / d)
	tmp = 0
	if d <= -5.8e+20:
		tmp = t_1
	elif d <= -2e-116:
		tmp = t_0
	elif d <= 1.1e-113:
		tmp = (b - ((a * d) / c)) / c
	elif d <= 9e+57:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d))
	tmp = 0.0
	if (d <= -5.8e+20)
		tmp = t_1;
	elseif (d <= -2e-116)
		tmp = t_0;
	elseif (d <= 1.1e-113)
		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
	elseif (d <= 9e+57)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	t_1 = ((c / d) * (b / d)) - (a / d);
	tmp = 0.0;
	if (d <= -5.8e+20)
		tmp = t_1;
	elseif (d <= -2e-116)
		tmp = t_0;
	elseif (d <= 1.1e-113)
		tmp = (b - ((a * d) / c)) / c;
	elseif (d <= 9e+57)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.8e+20], t$95$1, If[LessEqual[d, -2e-116], t$95$0, If[LessEqual[d, 1.1e-113], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 9e+57], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -2 \cdot 10^{-116}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.1 \cdot 10^{-113}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\

\mathbf{elif}\;d \leq 9 \cdot 10^{+57}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.8e20 or 8.99999999999999991e57 < d

    1. Initial program 48.3%

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

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

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

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

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

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

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

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

    if -5.8e20 < d < -2e-116 or 1.10000000000000002e-113 < d < 8.99999999999999991e57

    1. Initial program 84.5%

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

    if -2e-116 < d < 1.10000000000000002e-113

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/92.0%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\color{blue}{c \cdot \frac{c}{d}}}\right) \]
      6. *-commutative92.0%

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg90.9%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/82.6%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative82.6%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub90.9%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative92.9%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified92.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+20}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-116}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.1 \cdot 10^{-113}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 9 \cdot 10^{+57}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]

Alternative 8: 78.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{+21} \lor \neg \left(d \leq 2.5 \cdot 10^{-40}\right):\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.95e21 or 2.49999999999999982e-40 < d

    1. Initial program 54.0%

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

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

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

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

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

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

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

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

    if -1.95e21 < d < 2.49999999999999982e-40

    1. Initial program 75.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{a}{\frac{{c}^{2}}{d}}}\right) \]
      4. unpow278.3%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/82.2%

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

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg81.5%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/76.0%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative76.0%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub81.5%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative82.9%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified82.9%

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

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

Alternative 9: 71.8% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{+22} \lor \neg \left(d \leq 5.8 \cdot 10^{+31}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.7000000000000002e22 or 5.8000000000000001e31 < d

    1. Initial program 50.9%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/76.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-176.1%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified76.1%

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

    if -2.7000000000000002e22 < d < 5.8000000000000001e31

    1. Initial program 75.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b - \color{blue}{d \cdot \frac{a}{c}}}{c} \]
    8. Applied egg-rr78.3%

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

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

Alternative 10: 72.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{+23} \lor \neg \left(d \leq 6 \cdot 10^{+35}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.25e23 or 5.99999999999999981e35 < d

    1. Initial program 50.9%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/76.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-176.1%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified76.1%

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

    if -1.25e23 < d < 5.99999999999999981e35

    1. Initial program 75.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{a}{\frac{{c}^{2}}{d}}}\right) \]
      4. unpow274.0%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\frac{\color{blue}{c \cdot c}}{d}}\right) \]
      5. associate-*r/77.5%

        \[\leadsto \frac{b}{c} + \left(-\frac{a}{\color{blue}{c \cdot \frac{c}{d}}}\right) \]
      6. *-commutative77.5%

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

        \[\leadsto \frac{b}{c} + \left(-\color{blue}{\frac{\frac{a}{c}}{\frac{c}{d}}}\right) \]
      8. sub-neg78.2%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{\frac{a}{c}}{\frac{c}{d}}} \]
      9. associate-/r/73.3%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c}}{c} \cdot d} \]
      10. *-commutative73.3%

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{d \cdot \frac{a}{c}}{c}} \]
      12. div-sub78.3%

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

        \[\leadsto \frac{b - \color{blue}{\frac{d \cdot a}{c}}}{c} \]
      14. *-commutative79.6%

        \[\leadsto \frac{b - \frac{\color{blue}{a \cdot d}}{c}}{c} \]
    8. Simplified79.6%

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

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

Alternative 11: 63.1% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.9 \cdot 10^{+20} \lor \neg \left(d \leq 6.5 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5.9e20 or 6.49999999999999997e-8 < d

    1. Initial program 51.4%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    3. Step-by-step derivation
      1. associate-*r/74.7%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-174.7%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified74.7%

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

    if -5.9e20 < d < 6.49999999999999997e-8

    1. Initial program 76.3%

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

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

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

Alternative 12: 9.5% 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 64.5%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  6. Final simplification9.3%

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

Alternative 13: 41.5% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{b}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
	return b / 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 = b / c
end function
public static double code(double a, double b, double c, double d) {
	return b / c;
}
def code(a, b, c, d):
	return b / c
function code(a, b, c, d)
	return Float64(b / c)
end
function tmp = code(a, b, c, d)
	tmp = b / c;
end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}

\\
\frac{b}{c}
\end{array}
Derivation
  1. Initial program 64.5%

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

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  3. Final simplification43.3%

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

Developer target: 99.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \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))
   (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
   (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (-a + (b * (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(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(Float64(-a) + Float64(b * 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 = (b - (a * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (-a + (b * (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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * 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{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023200 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

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