Complex division, imag part

Percentage Accurate: 62.0% → 97.4%
Time: 14.6s
Alternatives: 11
Speedup: 1.1×

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 11 alternatives:

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

Initial Program: 62.0% 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.4% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{+222} \lor \neg \left(t\_0 \leq 2 \cdot 10^{+271}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{\frac{d}{-\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
   (if (or (<= t_0 -5e+222) (not (<= t_0 2e+271)))
     (fma
      (/ c (hypot c d))
      (/ b (hypot c d))
      (* a (/ (/ d (- (hypot d c))) (hypot d c))))
     (* (/ 1.0 (hypot c d)) (/ (fma b c (* d (- a))) (hypot c d))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double tmp;
	if ((t_0 <= -5e+222) || !(t_0 <= 2e+271)) {
		tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * ((d / -hypot(d, c)) / hypot(d, c))));
	} else {
		tmp = (1.0 / hypot(c, d)) * (fma(b, c, (d * -a)) / hypot(c, d));
	}
	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)))
	tmp = 0.0
	if ((t_0 <= -5e+222) || !(t_0 <= 2e+271))
		tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(d / Float64(-hypot(d, c))) / hypot(d, c))));
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(d * Float64(-a))) / hypot(c, d)));
	end
	return 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]}, If[Or[LessEqual[t$95$0, -5e+222], N[Not[LessEqual[t$95$0, 2e+271]], $MachinePrecision]], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(d / (-N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision])), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{+222} \lor \neg \left(t\_0 \leq 2 \cdot 10^{+271}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{\frac{d}{-\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\right)\\

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


\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))) < -5.00000000000000023e222 or 1.99999999999999991e271 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 33.3%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt24.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000023e222 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.99999999999999991e271

    1. Initial program 82.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-identity82.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt82.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-frac82.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-define82.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. fma-neg82.3%

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

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

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

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

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

Alternative 2: 85.5% accurate, 0.0× speedup?

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

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

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


\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 80.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-identity80.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt80.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-frac80.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-define80.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. fma-neg80.2%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\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. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub0.0%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{b \cdot \frac{c}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
    8. Step-by-step derivation
      1. associate-*r/1.0%

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{d \cdot d + {c}^{2}}}{b \cdot c}} \]
      4. add-sqr-sqrt1.0%

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

        \[\leadsto \frac{1}{\frac{\sqrt{d \cdot d + \color{blue}{c \cdot c}} \cdot \sqrt{d \cdot d + {c}^{2}}}{b \cdot c}} \]
      6. hypot-undefine1.0%

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}}{b \cdot c}}} \]
    10. Step-by-step derivation
      1. clear-num1.0%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{{\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}} \]
      3. unpow21.0%

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

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

        \[\leadsto \frac{c \cdot b}{\sqrt{d \cdot d + c \cdot c} \cdot \color{blue}{\sqrt{d \cdot d + c \cdot c}}} \]
      6. add-sqr-sqrt1.0%

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

        \[\leadsto \frac{c \cdot b}{\color{blue}{c \cdot c + d \cdot d}} \]
      8. add-sqr-sqrt1.0%

        \[\leadsto \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      9. hypot-undefine1.0%

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

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

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

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

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

Alternative 3: 83.6% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \mathbf{if}\;d \leq -3.1 \cdot 10^{-21}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-124}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+56}:\\ \;\;\;\;\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma (/ c (hypot c d)) (/ b (hypot c d)) (/ (- a) d))))
   (if (<= d -3.1e-21)
     t_0
     (if (<= d -8e-193)
       (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
       (if (<= d 1.2e-124)
         (+ (/ b c) (* (/ (* a d) c) (/ -1.0 c)))
         (if (<= d 3.6e+56)
           (* (fma b c (* d (- a))) (/ 1.0 (pow (hypot c d) 2.0)))
           t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma((c / hypot(c, d)), (b / hypot(c, d)), (-a / d));
	double tmp;
	if (d <= -3.1e-21) {
		tmp = t_0;
	} else if (d <= -8e-193) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (d <= 1.2e-124) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 3.6e+56) {
		tmp = fma(b, c, (d * -a)) * (1.0 / pow(hypot(c, d), 2.0));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(Float64(-a) / d))
	tmp = 0.0
	if (d <= -3.1e-21)
		tmp = t_0;
	elseif (d <= -8e-193)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 1.2e-124)
		tmp = Float64(Float64(b / c) + Float64(Float64(Float64(a * d) / c) * Float64(-1.0 / c)));
	elseif (d <= 3.6e+56)
		tmp = Float64(fma(b, c, Float64(d * Float64(-a))) * Float64(1.0 / (hypot(c, d) ^ 2.0)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.1e-21], t$95$0, If[LessEqual[d, -8e-193], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.2e-124], N[(N[(b / c), $MachinePrecision] + N[(N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.6e+56], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq 1.2 \cdot 10^{-124}:\\
\;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\

\mathbf{elif}\;d \leq 3.6 \cdot 10^{+56}:\\
\;\;\;\;\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -3.0999999999999998e-21 or 3.59999999999999998e56 < d

    1. Initial program 50.5%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt50.5%

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

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

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

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

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

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

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

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

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

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

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

    if -3.0999999999999998e-21 < d < -8.0000000000000004e-193

    1. Initial program 85.9%

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

    if -8.0000000000000004e-193 < d < 1.19999999999999996e-124

    1. Initial program 72.7%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt63.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{1}{c} \cdot \frac{d \cdot a}{c}} \]
      4. *-commutative92.6%

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

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

    if 1.19999999999999996e-124 < d < 3.59999999999999998e56

    1. Initial program 85.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.1 \cdot 10^{-21}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-124}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+56}:\\ \;\;\;\;\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 75.3% accurate, 0.1× 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}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -6.8 \cdot 10^{+32}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq 2.05 \cdot 10^{-233}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{-204}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{+141}:\\ \;\;\;\;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 (hypot c d)) (/ b (hypot c d)))))
   (if (<= c -6.8e+32)
     t_1
     (if (<= c 2.05e-233)
       t_0
       (if (<= c 6.2e-204) (/ (- a) d) (if (<= c 5.2e+141) 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 / hypot(c, d)) * (b / hypot(c, d));
	double tmp;
	if (c <= -6.8e+32) {
		tmp = t_1;
	} else if (c <= 2.05e-233) {
		tmp = t_0;
	} else if (c <= 6.2e-204) {
		tmp = -a / d;
	} else if (c <= 5.2e+141) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
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 / Math.hypot(c, d)) * (b / Math.hypot(c, d));
	double tmp;
	if (c <= -6.8e+32) {
		tmp = t_1;
	} else if (c <= 2.05e-233) {
		tmp = t_0;
	} else if (c <= 6.2e-204) {
		tmp = -a / d;
	} else if (c <= 5.2e+141) {
		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 / math.hypot(c, d)) * (b / math.hypot(c, d))
	tmp = 0
	if c <= -6.8e+32:
		tmp = t_1
	elif c <= 2.05e-233:
		tmp = t_0
	elif c <= 6.2e-204:
		tmp = -a / d
	elif c <= 5.2e+141:
		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(c / hypot(c, d)) * Float64(b / hypot(c, d)))
	tmp = 0.0
	if (c <= -6.8e+32)
		tmp = t_1;
	elseif (c <= 2.05e-233)
		tmp = t_0;
	elseif (c <= 6.2e-204)
		tmp = Float64(Float64(-a) / d);
	elseif (c <= 5.2e+141)
		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 / hypot(c, d)) * (b / hypot(c, d));
	tmp = 0.0;
	if (c <= -6.8e+32)
		tmp = t_1;
	elseif (c <= 2.05e-233)
		tmp = t_0;
	elseif (c <= 6.2e-204)
		tmp = -a / d;
	elseif (c <= 5.2e+141)
		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[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -6.8e+32], t$95$1, If[LessEqual[c, 2.05e-233], t$95$0, If[LessEqual[c, 6.2e-204], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 5.2e+141], 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}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -6.8 \cdot 10^{+32}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq 2.05 \cdot 10^{-233}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 6.2 \cdot 10^{-204}:\\
\;\;\;\;\frac{-a}{d}\\

\mathbf{elif}\;c \leq 5.2 \cdot 10^{+141}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -6.79999999999999957e32 or 5.1999999999999999e141 < c

    1. Initial program 41.4%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt41.5%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg48.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{b \cdot \frac{c}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
    8. Step-by-step derivation
      1. associate-*r/37.7%

        \[\leadsto \color{blue}{\frac{b \cdot c}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. clear-num37.6%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{d \cdot d + {c}^{2}}}{b \cdot c}} \]
      4. add-sqr-sqrt37.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{c \cdot b}{\sqrt{d \cdot d + c \cdot c} \cdot \color{blue}{\sqrt{d \cdot d + c \cdot c}}} \]
      6. add-sqr-sqrt37.7%

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

        \[\leadsto \frac{c \cdot b}{\color{blue}{c \cdot c + d \cdot d}} \]
      8. add-sqr-sqrt37.7%

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

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

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

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

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

    if -6.79999999999999957e32 < c < 2.0500000000000002e-233 or 6.1999999999999998e-204 < c < 5.1999999999999999e141

    1. Initial program 83.4%

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

    if 2.0500000000000002e-233 < c < 6.1999999999999998e-204

    1. Initial program 46.4%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.8 \cdot 10^{+32}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 2.05 \cdot 10^{-233}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{-204}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{+141}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.3% accurate, 0.1× 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{b}{\mathsf{hypot}\left(c, d\right)}\\ t_2 := \frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\ \mathbf{if}\;c \leq -2 \cdot 10^{+31}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;c \leq -5.5 \cdot 10^{-189}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-188}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, t\_1, \frac{-a}{d}\right)\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{+141}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
        (t_1 (/ b (hypot c d)))
        (t_2 (* (/ c (hypot c d)) t_1)))
   (if (<= c -2e+31)
     t_2
     (if (<= c -5.5e-189)
       t_0
       (if (<= c 8e-188)
         (fma (/ c d) t_1 (/ (- a) d))
         (if (<= c 6.5e+141) t_0 t_2))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double t_1 = b / hypot(c, d);
	double t_2 = (c / hypot(c, d)) * t_1;
	double tmp;
	if (c <= -2e+31) {
		tmp = t_2;
	} else if (c <= -5.5e-189) {
		tmp = t_0;
	} else if (c <= 8e-188) {
		tmp = fma((c / d), t_1, (-a / d));
	} else if (c <= 6.5e+141) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	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(b / hypot(c, d))
	t_2 = Float64(Float64(c / hypot(c, d)) * t_1)
	tmp = 0.0
	if (c <= -2e+31)
		tmp = t_2;
	elseif (c <= -5.5e-189)
		tmp = t_0;
	elseif (c <= 8e-188)
		tmp = fma(Float64(c / d), t_1, Float64(Float64(-a) / d));
	elseif (c <= 6.5e+141)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return 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[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[c, -2e+31], t$95$2, If[LessEqual[c, -5.5e-189], t$95$0, If[LessEqual[c, 8e-188], N[(N[(c / d), $MachinePrecision] * t$95$1 + N[((-a) / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.5e+141], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
t_2 := \frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\
\mathbf{if}\;c \leq -2 \cdot 10^{+31}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;c \leq -5.5 \cdot 10^{-189}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 8 \cdot 10^{-188}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{d}, t\_1, \frac{-a}{d}\right)\\

\mathbf{elif}\;c \leq 6.5 \cdot 10^{+141}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.9999999999999999e31 or 6.50000000000000053e141 < c

    1. Initial program 41.4%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt41.5%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg48.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{b \cdot \frac{c}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
    8. Step-by-step derivation
      1. associate-*r/37.7%

        \[\leadsto \color{blue}{\frac{b \cdot c}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. clear-num37.6%

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

        \[\leadsto \frac{1}{\frac{\color{blue}{d \cdot d + {c}^{2}}}{b \cdot c}} \]
      4. add-sqr-sqrt37.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{c \cdot b}{\sqrt{d \cdot d + c \cdot c} \cdot \color{blue}{\sqrt{d \cdot d + c \cdot c}}} \]
      6. add-sqr-sqrt37.7%

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

        \[\leadsto \frac{c \cdot b}{\color{blue}{c \cdot c + d \cdot d}} \]
      8. add-sqr-sqrt37.7%

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

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

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

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

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

    if -1.9999999999999999e31 < c < -5.4999999999999999e-189 or 7.9999999999999996e-188 < c < 6.50000000000000053e141

    1. Initial program 84.8%

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

    if -5.4999999999999999e-189 < c < 7.9999999999999996e-188

    1. Initial program 75.2%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt64.8%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2 \cdot 10^{+31}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -5.5 \cdot 10^{-189}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-188}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{+141}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 77.4% accurate, 0.4× 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{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{if}\;c \leq -3.1 \cdot 10^{+54}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{-234}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-203}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 6.6 \cdot 10^{+139}:\\ \;\;\;\;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 (- (/ b c) (* (/ d c) (/ a c)))))
   (if (<= c -3.1e+54)
     t_1
     (if (<= c 2.7e-234)
       t_0
       (if (<= c 3.6e-203) (/ (- a) d) (if (<= c 6.6e+139) 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 = (b / c) - ((d / c) * (a / c));
	double tmp;
	if (c <= -3.1e+54) {
		tmp = t_1;
	} else if (c <= 2.7e-234) {
		tmp = t_0;
	} else if (c <= 3.6e-203) {
		tmp = -a / d;
	} else if (c <= 6.6e+139) {
		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 = (b / c) - ((d / c) * (a / c))
    if (c <= (-3.1d+54)) then
        tmp = t_1
    else if (c <= 2.7d-234) then
        tmp = t_0
    else if (c <= 3.6d-203) then
        tmp = -a / d
    else if (c <= 6.6d+139) 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 = (b / c) - ((d / c) * (a / c));
	double tmp;
	if (c <= -3.1e+54) {
		tmp = t_1;
	} else if (c <= 2.7e-234) {
		tmp = t_0;
	} else if (c <= 3.6e-203) {
		tmp = -a / d;
	} else if (c <= 6.6e+139) {
		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 = (b / c) - ((d / c) * (a / c))
	tmp = 0
	if c <= -3.1e+54:
		tmp = t_1
	elif c <= 2.7e-234:
		tmp = t_0
	elif c <= 3.6e-203:
		tmp = -a / d
	elif c <= 6.6e+139:
		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(b / c) - Float64(Float64(d / c) * Float64(a / c)))
	tmp = 0.0
	if (c <= -3.1e+54)
		tmp = t_1;
	elseif (c <= 2.7e-234)
		tmp = t_0;
	elseif (c <= 3.6e-203)
		tmp = Float64(Float64(-a) / d);
	elseif (c <= 6.6e+139)
		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 = (b / c) - ((d / c) * (a / c));
	tmp = 0.0;
	if (c <= -3.1e+54)
		tmp = t_1;
	elseif (c <= 2.7e-234)
		tmp = t_0;
	elseif (c <= 3.6e-203)
		tmp = -a / d;
	elseif (c <= 6.6e+139)
		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[(b / c), $MachinePrecision] - N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.1e+54], t$95$1, If[LessEqual[c, 2.7e-234], t$95$0, If[LessEqual[c, 3.6e-203], N[((-a) / d), $MachinePrecision], If[LessEqual[c, 6.6e+139], 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{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\
\mathbf{if}\;c \leq -3.1 \cdot 10^{+54}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq 2.7 \cdot 10^{-234}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 3.6 \cdot 10^{-203}:\\
\;\;\;\;\frac{-a}{d}\\

\mathbf{elif}\;c \leq 6.6 \cdot 10^{+139}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.0999999999999999e54 or 6.6000000000000003e139 < c

    1. Initial program 40.0%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt40.0%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg47.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.0999999999999999e54 < c < 2.7000000000000002e-234 or 3.59999999999999979e-203 < c < 6.6000000000000003e139

    1. Initial program 82.9%

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

    if 2.7000000000000002e-234 < c < 3.59999999999999979e-203

    1. Initial program 46.4%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.1 \cdot 10^{+54}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{elif}\;c \leq 2.7 \cdot 10^{-234}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-203}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 6.6 \cdot 10^{+139}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 69.7% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.12 \cdot 10^{-107} \lor \neg \left(c \leq 3.5 \cdot 10^{-62}\right):\\
\;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.12e-107 or 3.5000000000000001e-62 < c

    1. Initial program 59.1%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt59.1%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.12e-107 < c < 3.5000000000000001e-62

    1. Initial program 79.8%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified74.3%

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

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

Alternative 8: 68.9% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;c \leq 2.15 \cdot 10^{-60}:\\
\;\;\;\;\frac{-a}{d}\\

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


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

    1. Initial program 62.1%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt62.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{1}{c} \cdot \frac{d \cdot a}{c}} \]
      4. *-commutative72.8%

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

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

    if -1.10000000000000006e-107 < c < 2.15e-60

    1. Initial program 79.8%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified74.3%

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

    if 2.15e-60 < c

    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. div-sub55.3%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt55.3%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg57.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.1 \cdot 10^{-107}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-60}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 62.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{-82} \lor \neg \left(c \leq 1.12 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.6e-82 or 1.12e-7 < c

    1. Initial program 55.2%

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

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

    if -2.6e-82 < c < 1.12e-7

    1. Initial program 81.7%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified69.6%

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

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

Alternative 10: 45.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.22 \cdot 10^{+154} \lor \neg \left(d \leq 6.2 \cdot 10^{+167}\right):\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.22e154 or 6.1999999999999999e167 < d

    1. Initial program 37.4%

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

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

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

        \[\leadsto \frac{\frac{\color{blue}{{\left(b \cdot c\right)}^{2}} - \left(-a \cdot d\right) \cdot \left(-a \cdot d\right)}{b \cdot c - \left(-a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      4. distribute-rgt-neg-in22.9%

        \[\leadsto \frac{\frac{{\left(b \cdot c\right)}^{2} - \color{blue}{\left(a \cdot \left(-d\right)\right)} \cdot \left(-a \cdot d\right)}{b \cdot c - \left(-a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      5. distribute-rgt-neg-in22.9%

        \[\leadsto \frac{\frac{{\left(b \cdot c\right)}^{2} - \left(a \cdot \left(-d\right)\right) \cdot \color{blue}{\left(a \cdot \left(-d\right)\right)}}{b \cdot c - \left(-a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      6. distribute-rgt-neg-in22.9%

        \[\leadsto \frac{\frac{{\left(b \cdot c\right)}^{2} - \left(a \cdot \left(-d\right)\right) \cdot \left(a \cdot \left(-d\right)\right)}{b \cdot c - \color{blue}{a \cdot \left(-d\right)}}}{c \cdot c + d \cdot d} \]
    4. Applied egg-rr22.9%

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

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

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

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

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

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

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

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

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

    if -1.22e154 < d < 6.1999999999999999e167

    1. Initial program 76.5%

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

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

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

Alternative 11: 10.9% accurate, 5.0× speedup?

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

\\
\frac{a}{d}
\end{array}
Derivation
  1. Initial program 67.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{a}{d}} \]
  12. Final simplification11.5%

    \[\leadsto \frac{a}{d} \]
  13. Add Preprocessing

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

  :alt
  (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))))