Complex division, imag part

Percentage Accurate: 61.2% → 97.7%
Time: 10.5s
Alternatives: 10
Speedup: 0.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 10 alternatives:

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

Initial Program: 61.2% 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: 97.7% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* c (/ b (hypot c d))) (* d (/ a (hypot c d)))) (hypot c d)))
double code(double a, double b, double c, double d) {
	return ((c * (b / hypot(c, d))) - (d * (a / hypot(c, d)))) / hypot(c, d);
}
public static double code(double a, double b, double c, double d) {
	return ((c * (b / Math.hypot(c, d))) - (d * (a / Math.hypot(c, d)))) / Math.hypot(c, d);
}
def code(a, b, c, d):
	return ((c * (b / math.hypot(c, d))) - (d * (a / math.hypot(c, d)))) / math.hypot(c, d)
function code(a, b, c, d)
	return Float64(Float64(Float64(c * Float64(b / hypot(c, d))) - Float64(d * Float64(a / hypot(c, d)))) / hypot(c, d))
end
function tmp = code(a, b, c, d)
	tmp = ((c * (b / hypot(c, d))) - (d * (a / hypot(c, d)))) / hypot(c, d);
end
code[a_, b_, c_, d_] := N[(N[(N[(c * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(d * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{c \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} - d \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}
\end{array}
Derivation
  1. Initial program 66.5%

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
    2. add-sqr-sqrt66.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-frac66.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-define66.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-define78.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)}} \]
  4. Applied egg-rr78.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)}} \]
  5. Step-by-step derivation
    1. associate-*l/78.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-identity78.2%

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

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

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

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

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

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

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

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

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

Alternative 2: 85.4% accurate, 0.1× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - 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))) < 3.9999999999999997e261

    1. Initial program 83.6%

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

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

        \[\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-frac83.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-define83.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-define97.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)}} \]
    4. Applied egg-rr97.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)}} \]
    5. Step-by-step derivation
      1. associate-*l/97.3%

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

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

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

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

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

    if 3.9999999999999997e261 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 10.7%

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

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

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

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

        \[\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-define15.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)}} \]
    4. Applied egg-rr15.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)}} \]
    5. Taylor expanded in d around inf 48.7%

      \[\leadsto \color{blue}{\frac{-1 \cdot a + \frac{b \cdot c}{d}}{d}} \]
    6. Step-by-step derivation
      1. neg-mul-148.7%

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

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

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

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

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

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

Alternative 3: 83.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot b - d \cdot a\\ t_1 := c \cdot \frac{b}{d} - a\\ t_2 := c \cdot c + d \cdot d\\ \mathbf{if}\;d \leq -2.8 \cdot 10^{+49}:\\ \;\;\;\;\frac{t\_1}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-87}:\\ \;\;\;\;\frac{t\_0 + 2 \cdot \mathsf{fma}\left(a, -d, d \cdot a\right)}{t\_2}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{-158}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{+122}:\\ \;\;\;\;\frac{t\_0}{t\_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (- (* c b) (* d a)))
        (t_1 (- (* c (/ b d)) a))
        (t_2 (+ (* c c) (* d d))))
   (if (<= d -2.8e+49)
     (/ t_1 d)
     (if (<= d -1.15e-87)
       (/ (+ t_0 (* 2.0 (fma a (- d) (* d a)))) t_2)
       (if (<= d 1.9e-158)
         (/ (- b (* a (/ d c))) c)
         (if (<= d 5.2e+122) (/ t_0 t_2) (/ t_1 (hypot c d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * b) - (d * a);
	double t_1 = (c * (b / d)) - a;
	double t_2 = (c * c) + (d * d);
	double tmp;
	if (d <= -2.8e+49) {
		tmp = t_1 / d;
	} else if (d <= -1.15e-87) {
		tmp = (t_0 + (2.0 * fma(a, -d, (d * a)))) / t_2;
	} else if (d <= 1.9e-158) {
		tmp = (b - (a * (d / c))) / c;
	} else if (d <= 5.2e+122) {
		tmp = t_0 / t_2;
	} else {
		tmp = t_1 / hypot(c, d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c * b) - Float64(d * a))
	t_1 = Float64(Float64(c * Float64(b / d)) - a)
	t_2 = Float64(Float64(c * c) + Float64(d * d))
	tmp = 0.0
	if (d <= -2.8e+49)
		tmp = Float64(t_1 / d);
	elseif (d <= -1.15e-87)
		tmp = Float64(Float64(t_0 + Float64(2.0 * fma(a, Float64(-d), Float64(d * a)))) / t_2);
	elseif (d <= 1.9e-158)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif (d <= 5.2e+122)
		tmp = Float64(t_0 / t_2);
	else
		tmp = Float64(t_1 / hypot(c, d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.8e+49], N[(t$95$1 / d), $MachinePrecision], If[LessEqual[d, -1.15e-87], N[(N[(t$95$0 + N[(2.0 * N[(a * (-d) + N[(d * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], If[LessEqual[d, 1.9e-158], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.2e+122], N[(t$95$0 / t$95$2), $MachinePrecision], N[(t$95$1 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := c \cdot b - d \cdot a\\
t_1 := c \cdot \frac{b}{d} - a\\
t_2 := c \cdot c + d \cdot d\\
\mathbf{if}\;d \leq -2.8 \cdot 10^{+49}:\\
\;\;\;\;\frac{t\_1}{d}\\

\mathbf{elif}\;d \leq -1.15 \cdot 10^{-87}:\\
\;\;\;\;\frac{t\_0 + 2 \cdot \mathsf{fma}\left(a, -d, d \cdot a\right)}{t\_2}\\

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

\mathbf{elif}\;d \leq 5.2 \cdot 10^{+122}:\\
\;\;\;\;\frac{t\_0}{t\_2}\\

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


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

    1. Initial program 50.1%

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

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

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

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

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

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

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

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

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

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

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

    if -2.7999999999999998e49 < d < -1.1500000000000001e-87

    1. Initial program 91.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) + \left(\color{blue}{\left(\left(-d\right) \cdot a + a \cdot d\right)} + \mathsf{fma}\left(-d, a, d \cdot a\right)\right)}{c \cdot c + d \cdot d} \]
      10. distribute-lft-neg-in91.4%

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

        \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) + \left(\left(\left(-\color{blue}{a \cdot d}\right) + a \cdot d\right) + \mathsf{fma}\left(-d, a, d \cdot a\right)\right)}{c \cdot c + d \cdot d} \]
      12. distribute-rgt-neg-in91.4%

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

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

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

        \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) + \left(\mathsf{fma}\left(a, -d, a \cdot d\right) + \color{blue}{\left(\left(-d\right) \cdot a + a \cdot d\right)}\right)}{c \cdot c + d \cdot d} \]
      16. distribute-lft-neg-in91.4%

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

        \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) + \left(\mathsf{fma}\left(a, -d, a \cdot d\right) + \left(\left(-\color{blue}{a \cdot d}\right) + a \cdot d\right)\right)}{c \cdot c + d \cdot d} \]
      18. distribute-rgt-neg-in91.4%

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

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

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

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

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

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

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

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

    if -1.1500000000000001e-87 < d < 1.8999999999999999e-158

    1. Initial program 76.3%

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

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

        \[\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-frac76.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-define76.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-define85.4%

        \[\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)}} \]
    4. Applied egg-rr85.4%

      \[\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)}} \]
    5. Taylor expanded in c around inf 93.9%

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. mul-1-neg93.9%

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

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

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

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

    if 1.8999999999999999e-158 < d < 5.20000000000000015e122

    1. Initial program 85.9%

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

    if 5.20000000000000015e122 < d

    1. Initial program 37.3%

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

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

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

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

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

        \[\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)}} \]
    4. Applied egg-rr63.2%

      \[\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)}} \]
    5. Step-by-step derivation
      1. associate-*l/63.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-identity63.4%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.8 \cdot 10^{+49}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{-87}:\\ \;\;\;\;\frac{\left(c \cdot b - d \cdot a\right) + 2 \cdot \mathsf{fma}\left(a, -d, d \cdot a\right)}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{-158}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{+122}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 83.4% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -6.5 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 5 \cdot 10^{+123}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 50.9%

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

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

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

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

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

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

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

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

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

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

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

    if -3.09999999999999988e45 < d < -6.50000000000000006e-88 or 4.3e-159 < d < 4.99999999999999974e123

    1. Initial program 87.5%

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

    if -6.50000000000000006e-88 < d < 4.3e-159

    1. Initial program 76.3%

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

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

        \[\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-frac76.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-define76.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-define85.4%

        \[\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)}} \]
    4. Applied egg-rr85.4%

      \[\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)}} \]
    5. Taylor expanded in c around inf 93.9%

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. mul-1-neg93.9%

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

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

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

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

    if 4.99999999999999974e123 < d

    1. Initial program 37.3%

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

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

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

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

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

        \[\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)}} \]
    4. Applied egg-rr63.2%

      \[\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)}} \]
    5. Step-by-step derivation
      1. associate-*l/63.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-identity63.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 83.3% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;d \leq -3.5 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 6.5 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.49999999999999993e44 or 6.49999999999999963e122 < d

    1. Initial program 44.8%

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

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

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

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

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

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

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

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

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

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

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

    if -1.49999999999999993e44 < d < -3.50000000000000021e-86 or 1.75000000000000006e-158 < d < 6.49999999999999963e122

    1. Initial program 87.5%

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

    if -3.50000000000000021e-86 < d < 1.75000000000000006e-158

    1. Initial program 76.3%

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

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

        \[\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-frac76.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-define76.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-define85.4%

        \[\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)}} \]
    4. Applied egg-rr85.4%

      \[\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)}} \]
    5. Taylor expanded in c around inf 93.9%

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. mul-1-neg93.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{+44}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;d \leq -3.5 \cdot 10^{-86}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.75 \cdot 10^{-158}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+122}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 79.1% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0021 \lor \neg \left(d \leq 1.4 \cdot 10^{-24}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -0.00209999999999999987 or 1.4000000000000001e-24 < d

    1. Initial program 54.7%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d}}{d}} - \frac{a}{d} \]
      6. div-sub75.0%

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

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

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

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

    if -0.00209999999999999987 < d < 1.4000000000000001e-24

    1. Initial program 81.4%

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

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

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

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

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

        \[\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)}} \]
    4. Applied egg-rr87.5%

      \[\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)}} \]
    5. Taylor expanded in c around inf 84.3%

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

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

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

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

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

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

Alternative 7: 78.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.95 \cdot 10^{-14} \lor \neg \left(d \leq 1.26 \cdot 10^{-23}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.9499999999999999e-14 or 1.25999999999999996e-23 < d

    1. Initial program 55.3%

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

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

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

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

        \[\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-define70.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)}} \]
    4. Applied egg-rr70.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)}} \]
    5. Taylor expanded in d around inf 74.7%

      \[\leadsto \color{blue}{\frac{-1 \cdot a + \frac{b \cdot c}{d}}{d}} \]
    6. Step-by-step derivation
      1. neg-mul-174.7%

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

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

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

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

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

    if -1.9499999999999999e-14 < d < 1.25999999999999996e-23

    1. Initial program 81.0%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt81.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-frac80.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-define81.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-define87.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)}} \]
    4. Applied egg-rr87.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)}} \]
    5. Taylor expanded in c around inf 84.8%

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. mul-1-neg84.8%

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

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

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

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

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

Alternative 8: 7.1% accurate, 1.2× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 7.8000000000000004e-283

    1. Initial program 66.7%

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

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

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

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

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

        \[\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)}} \]
    4. Applied egg-rr77.1%

      \[\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)}} \]
    5. Taylor expanded in c around -inf 31.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{b}{d} - \frac{a}{c}} \]
    10. Simplified8.8%

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

    if 7.8000000000000004e-283 < d

    1. Initial program 66.2%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt66.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-frac66.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-define66.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-define78.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)}} \]
    4. Applied egg-rr78.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)}} \]
    5. Taylor expanded in c around -inf 33.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{a}{c} - \frac{b}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 53.9% accurate, 1.7× speedup?

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

\\
\frac{b - a \cdot \frac{d}{c}}{c}
\end{array}
Derivation
  1. Initial program 66.5%

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
    2. add-sqr-sqrt66.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-frac66.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-define66.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-define78.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)}} \]
  4. Applied egg-rr78.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)}} \]
  5. Taylor expanded in c around inf 48.3%

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

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

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

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

    \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
  8. Add Preprocessing

Alternative 10: 7.2% accurate, 2.1× speedup?

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

\\
\frac{a}{c} - \frac{b}{d}
\end{array}
Derivation
  1. Initial program 66.5%

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

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
    2. add-sqr-sqrt66.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-frac66.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-define66.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-define78.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)}} \]
  4. Applied egg-rr78.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)}} \]
  5. Taylor expanded in c around -inf 32.4%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{a}{c} - \frac{b}{d}} \]
  10. Simplified7.5%

    \[\leadsto \color{blue}{\frac{a}{c} - \frac{b}{d}} \]
  11. Add Preprocessing

Developer Target 1: 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 2024179 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :alt
  (! :herbie-platform default (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))))