Complex division, imag part

Percentage Accurate: 62.0% → 85.2%
Time: 14.1s
Alternatives: 16
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 16 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: 85.2% 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, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \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 (* a (- d))) (hypot c d)))
   (fma
    (/ c (hypot c d))
    (/ b (hypot c d))
    (* a (/ d (- (pow (hypot c d) 2.0)))))))
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, (a * -d)) / hypot(c, d));
	} else {
		tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (d / -pow(hypot(c, d), 2.0))));
	}
	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(a * Float64(-d))) / hypot(c, d)));
	else
		tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(d / Float64(-(hypot(c, d) ^ 2.0)))));
	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[(a * (-d)), $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] + N[(a * N[(d / (-N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision])), $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, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\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)\\


\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)} \]
  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, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \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 2 \cdot 10^{+271}:\\ \;\;\;\;\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) 2e+271)
   (* (/ 1.0 (hypot c d)) (/ (fma b c (* a (- d))) (hypot c d)))
   (- (/ b c) (* (/ d c) (/ a c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 2e+271) {
		tmp = (1.0 / hypot(c, d)) * (fma(b, c, (a * -d)) / hypot(c, d));
	} else {
		tmp = (b / c) - ((d / c) * (a / c));
	}
	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))) <= 2e+271)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(a * Float64(-d))) / hypot(c, d)));
	else
		tmp = Float64(Float64(b / c) - Float64(Float64(d / c) * Float64(a / c)));
	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], 2e+271], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(a * (-d)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $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}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+271}:\\
\;\;\;\;\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)}\\

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


\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))) < 1.99999999999999991e271

    1. Initial program 81.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-identity81.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt81.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-frac81.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-define81.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-neg81.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-in81.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-define96.8%

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

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

    1. Initial program 15.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+271}:\\ \;\;\;\;\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.7% accurate, 0.0× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -3.6 \cdot 10^{+37}:\\
\;\;\;\;t\_0 \cdot \left(a - b \cdot \frac{c}{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 6.5 \cdot 10^{-125}:\\
\;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\

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

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


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

    1. Initial program 59.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.59999999999999998e37 < d < -8.0000000000000004e-193

    1. Initial program 86.2%

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

    if -8.0000000000000004e-193 < d < 6.4999999999999999e-125

    1. Initial program 72.7%

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

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

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

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

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

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

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

    if 6.4999999999999999e-125 < d < 8.19999999999999996e96

    1. Initial program 80.9%

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

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

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

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

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

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

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

      \[\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}}} \]

    if 8.19999999999999996e96 < d

    1. Initial program 33.9%

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

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

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

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

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

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

        \[\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-define62.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-rr62.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)}} \]
    5. Taylor expanded in c around 0 73.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - b \cdot \frac{c}{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 6.5 \cdot 10^{-125}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 8.2 \cdot 10^{+96}:\\ \;\;\;\;\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(c \cdot \frac{b}{d} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 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, a \cdot \left(-d\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 (* a (- d))) (/ 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, (a * -d)) * (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(a / Float64(-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(a * Float64(-d))) * 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[(a * (-d)), $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, a \cdot \left(-d\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. Taylor expanded in c around inf 89.3%

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

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

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

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

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

      \[\leadsto -1 \cdot \color{blue}{\left(\frac{1}{c} \cdot \frac{d \cdot a}{c}\right)} + \frac{b}{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, a \cdot \left(-d\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 5: 81.9% 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{1}{\mathsf{hypot}\left(c, d\right)}\\ t_2 := c \cdot \frac{b}{d}\\ \mathbf{if}\;d \leq -7.2 \cdot 10^{+37}:\\ \;\;\;\;t\_1 \cdot \left(a - t\_2\right)\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 8.5 \cdot 10^{-126}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+95}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \left(t\_2 - a\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
        (t_1 (/ 1.0 (hypot c d)))
        (t_2 (* c (/ b d))))
   (if (<= d -7.2e+37)
     (* t_1 (- a t_2))
     (if (<= d -8e-193)
       t_0
       (if (<= d 8.5e-126)
         (+ (/ b c) (* (/ (* a d) c) (/ -1.0 c)))
         (if (<= d 2.6e+95) t_0 (* t_1 (- t_2 a))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double t_1 = 1.0 / hypot(c, d);
	double t_2 = c * (b / d);
	double tmp;
	if (d <= -7.2e+37) {
		tmp = t_1 * (a - t_2);
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 8.5e-126) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 2.6e+95) {
		tmp = t_0;
	} else {
		tmp = t_1 * (t_2 - a);
	}
	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 = 1.0 / Math.hypot(c, d);
	double t_2 = c * (b / d);
	double tmp;
	if (d <= -7.2e+37) {
		tmp = t_1 * (a - t_2);
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 8.5e-126) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 2.6e+95) {
		tmp = t_0;
	} else {
		tmp = t_1 * (t_2 - a);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
	t_1 = 1.0 / math.hypot(c, d)
	t_2 = c * (b / d)
	tmp = 0
	if d <= -7.2e+37:
		tmp = t_1 * (a - t_2)
	elif d <= -8e-193:
		tmp = t_0
	elif d <= 8.5e-126:
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c))
	elif d <= 2.6e+95:
		tmp = t_0
	else:
		tmp = t_1 * (t_2 - a)
	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(1.0 / hypot(c, d))
	t_2 = Float64(c * Float64(b / d))
	tmp = 0.0
	if (d <= -7.2e+37)
		tmp = Float64(t_1 * Float64(a - t_2));
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 8.5e-126)
		tmp = Float64(Float64(b / c) + Float64(Float64(Float64(a * d) / c) * Float64(-1.0 / c)));
	elseif (d <= 2.6e+95)
		tmp = t_0;
	else
		tmp = Float64(t_1 * Float64(t_2 - a));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	t_1 = 1.0 / hypot(c, d);
	t_2 = c * (b / d);
	tmp = 0.0;
	if (d <= -7.2e+37)
		tmp = t_1 * (a - t_2);
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 8.5e-126)
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	elseif (d <= 2.6e+95)
		tmp = t_0;
	else
		tmp = t_1 * (t_2 - a);
	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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.2e+37], N[(t$95$1 * N[(a - t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8e-193], t$95$0, If[LessEqual[d, 8.5e-126], N[(N[(b / c), $MachinePrecision] + N[(N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.6e+95], t$95$0, N[(t$95$1 * N[(t$95$2 - a), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.6 \cdot 10^{+95}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \left(t\_2 - a\right)\\


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

    1. Initial program 59.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.19999999999999995e37 < d < -8.0000000000000004e-193 or 8.49999999999999938e-126 < d < 2.5999999999999999e95

    1. Initial program 83.2%

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

    if -8.0000000000000004e-193 < d < 8.49999999999999938e-126

    1. Initial program 72.2%

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

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

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

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

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

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

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

    if 2.5999999999999999e95 < d

    1. Initial program 33.9%

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

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

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

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

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

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

        \[\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-define62.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-rr62.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)}} \]
    5. Taylor expanded in c around 0 73.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - c \cdot \frac{b}{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 8.5 \cdot 10^{-126}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+95}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(c \cdot \frac{b}{d} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 81.7% 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{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;d \leq -7.2 \cdot 10^{+37}:\\ \;\;\;\;t\_1 \cdot \left(a - b \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;d \leq -7 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-126}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{+91}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \left(c \cdot \frac{b}{d} - a\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
        (t_1 (/ 1.0 (hypot c d))))
   (if (<= d -7.2e+37)
     (* t_1 (- a (* b (/ c d))))
     (if (<= d -7e-193)
       t_0
       (if (<= d 9.5e-126)
         (+ (/ b c) (* (/ (* a d) c) (/ -1.0 c)))
         (if (<= d 6e+91) t_0 (* t_1 (- (* c (/ b d)) a))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double t_1 = 1.0 / hypot(c, d);
	double tmp;
	if (d <= -7.2e+37) {
		tmp = t_1 * (a - (b * (c / d)));
	} else if (d <= -7e-193) {
		tmp = t_0;
	} else if (d <= 9.5e-126) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 6e+91) {
		tmp = t_0;
	} else {
		tmp = t_1 * ((c * (b / d)) - a);
	}
	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 = 1.0 / Math.hypot(c, d);
	double tmp;
	if (d <= -7.2e+37) {
		tmp = t_1 * (a - (b * (c / d)));
	} else if (d <= -7e-193) {
		tmp = t_0;
	} else if (d <= 9.5e-126) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 6e+91) {
		tmp = t_0;
	} else {
		tmp = t_1 * ((c * (b / d)) - a);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
	t_1 = 1.0 / math.hypot(c, d)
	tmp = 0
	if d <= -7.2e+37:
		tmp = t_1 * (a - (b * (c / d)))
	elif d <= -7e-193:
		tmp = t_0
	elif d <= 9.5e-126:
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c))
	elif d <= 6e+91:
		tmp = t_0
	else:
		tmp = t_1 * ((c * (b / d)) - a)
	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(1.0 / hypot(c, d))
	tmp = 0.0
	if (d <= -7.2e+37)
		tmp = Float64(t_1 * Float64(a - Float64(b * Float64(c / d))));
	elseif (d <= -7e-193)
		tmp = t_0;
	elseif (d <= 9.5e-126)
		tmp = Float64(Float64(b / c) + Float64(Float64(Float64(a * d) / c) * Float64(-1.0 / c)));
	elseif (d <= 6e+91)
		tmp = t_0;
	else
		tmp = Float64(t_1 * Float64(Float64(c * Float64(b / d)) - a));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	t_1 = 1.0 / hypot(c, d);
	tmp = 0.0;
	if (d <= -7.2e+37)
		tmp = t_1 * (a - (b * (c / d)));
	elseif (d <= -7e-193)
		tmp = t_0;
	elseif (d <= 9.5e-126)
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	elseif (d <= 6e+91)
		tmp = t_0;
	else
		tmp = t_1 * ((c * (b / d)) - a);
	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[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -7.2e+37], N[(t$95$1 * N[(a - N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -7e-193], t$95$0, If[LessEqual[d, 9.5e-126], N[(N[(b / c), $MachinePrecision] + N[(N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6e+91], t$95$0, N[(t$95$1 * N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -7 \cdot 10^{-193}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 6 \cdot 10^{+91}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 59.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.19999999999999995e37 < d < -7.00000000000000009e-193 or 9.5000000000000003e-126 < d < 6.00000000000000012e91

    1. Initial program 83.2%

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

    if -7.00000000000000009e-193 < d < 9.5000000000000003e-126

    1. Initial program 72.2%

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

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

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

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

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

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

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

    if 6.00000000000000012e91 < d

    1. Initial program 33.9%

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

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

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

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

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

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

        \[\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-define62.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-rr62.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)}} \]
    5. Taylor expanded in c around 0 73.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - b \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;d \leq -7 \cdot 10^{-193}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-126}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{+91}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(c \cdot \frac{b}{d} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 81.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}\\ \mathbf{if}\;d \leq -7.2 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - c \cdot \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{-125}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{+90}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;c \cdot \left(\frac{b}{d} \cdot \frac{1}{d}\right) - \frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
   (if (<= d -7.2e+37)
     (* (/ 1.0 (hypot c d)) (- a (* c (/ b d))))
     (if (<= d -8e-193)
       t_0
       (if (<= d 1.35e-125)
         (+ (/ b c) (* (/ (* a d) c) (/ -1.0 c)))
         (if (<= d 3.5e+90) t_0 (- (* c (* (/ b d) (/ 1.0 d))) (/ a 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 (d <= -7.2e+37) {
		tmp = (1.0 / hypot(c, d)) * (a - (c * (b / d)));
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 1.35e-125) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 3.5e+90) {
		tmp = t_0;
	} else {
		tmp = (c * ((b / d) * (1.0 / d))) - (a / d);
	}
	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 tmp;
	if (d <= -7.2e+37) {
		tmp = (1.0 / Math.hypot(c, d)) * (a - (c * (b / d)));
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 1.35e-125) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 3.5e+90) {
		tmp = t_0;
	} else {
		tmp = (c * ((b / d) * (1.0 / d))) - (a / d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -7.2e+37:
		tmp = (1.0 / math.hypot(c, d)) * (a - (c * (b / d)))
	elif d <= -8e-193:
		tmp = t_0
	elif d <= 1.35e-125:
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c))
	elif d <= 3.5e+90:
		tmp = t_0
	else:
		tmp = (c * ((b / d) * (1.0 / d))) - (a / 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 (d <= -7.2e+37)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(a - Float64(c * Float64(b / d))));
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 1.35e-125)
		tmp = Float64(Float64(b / c) + Float64(Float64(Float64(a * d) / c) * Float64(-1.0 / c)));
	elseif (d <= 3.5e+90)
		tmp = t_0;
	else
		tmp = Float64(Float64(c * Float64(Float64(b / d) * Float64(1.0 / d))) - Float64(a / d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -7.2e+37)
		tmp = (1.0 / hypot(c, d)) * (a - (c * (b / d)));
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 1.35e-125)
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	elseif (d <= 3.5e+90)
		tmp = t_0;
	else
		tmp = (c * ((b / d) * (1.0 / d))) - (a / d);
	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]}, If[LessEqual[d, -7.2e+37], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a - N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8e-193], t$95$0, If[LessEqual[d, 1.35e-125], N[(N[(b / c), $MachinePrecision] + N[(N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.5e+90], t$95$0, N[(N[(c * N[(N[(b / d), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $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}\;d \leq -7.2 \cdot 10^{+37}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - c \cdot \frac{b}{d}\right)\\

\mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 3.5 \cdot 10^{+90}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 59.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.19999999999999995e37 < d < -8.0000000000000004e-193 or 1.3499999999999999e-125 < d < 3.4999999999999998e90

    1. Initial program 83.2%

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

    if -8.0000000000000004e-193 < d < 1.3499999999999999e-125

    1. Initial program 72.2%

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

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

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

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

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

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

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

    if 3.4999999999999998e90 < d

    1. Initial program 33.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{+37}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a - c \cdot \frac{b}{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.35 \cdot 10^{-125}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{+90}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;c \cdot \left(\frac{b}{d} \cdot \frac{1}{d}\right) - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 80.0% 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}\\ \mathbf{if}\;d \leq -3 \cdot 10^{+28}:\\ \;\;\;\;c \cdot \frac{b}{{d}^{2}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{-125}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 7.2 \cdot 10^{+96}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;c \cdot \left(\frac{b}{d} \cdot \frac{1}{d}\right) - \frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
   (if (<= d -3e+28)
     (- (* c (/ b (pow d 2.0))) (/ a d))
     (if (<= d -8e-193)
       t_0
       (if (<= d 2.8e-125)
         (+ (/ b c) (* (/ (* a d) c) (/ -1.0 c)))
         (if (<= d 7.2e+96) t_0 (- (* c (* (/ b d) (/ 1.0 d))) (/ a 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 (d <= -3e+28) {
		tmp = (c * (b / pow(d, 2.0))) - (a / d);
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 2.8e-125) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 7.2e+96) {
		tmp = t_0;
	} else {
		tmp = (c * ((b / d) * (1.0 / d))) - (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) :: t_0
    real(8) :: tmp
    t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
    if (d <= (-3d+28)) then
        tmp = (c * (b / (d ** 2.0d0))) - (a / d)
    else if (d <= (-8d-193)) then
        tmp = t_0
    else if (d <= 2.8d-125) then
        tmp = (b / c) + (((a * d) / c) * ((-1.0d0) / c))
    else if (d <= 7.2d+96) then
        tmp = t_0
    else
        tmp = (c * ((b / d) * (1.0d0 / d))) - (a / d)
    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 tmp;
	if (d <= -3e+28) {
		tmp = (c * (b / Math.pow(d, 2.0))) - (a / d);
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 2.8e-125) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 7.2e+96) {
		tmp = t_0;
	} else {
		tmp = (c * ((b / d) * (1.0 / d))) - (a / d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -3e+28:
		tmp = (c * (b / math.pow(d, 2.0))) - (a / d)
	elif d <= -8e-193:
		tmp = t_0
	elif d <= 2.8e-125:
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c))
	elif d <= 7.2e+96:
		tmp = t_0
	else:
		tmp = (c * ((b / d) * (1.0 / d))) - (a / 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 (d <= -3e+28)
		tmp = Float64(Float64(c * Float64(b / (d ^ 2.0))) - Float64(a / d));
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 2.8e-125)
		tmp = Float64(Float64(b / c) + Float64(Float64(Float64(a * d) / c) * Float64(-1.0 / c)));
	elseif (d <= 7.2e+96)
		tmp = t_0;
	else
		tmp = Float64(Float64(c * Float64(Float64(b / d) * Float64(1.0 / d))) - Float64(a / d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -3e+28)
		tmp = (c * (b / (d ^ 2.0))) - (a / d);
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 2.8e-125)
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	elseif (d <= 7.2e+96)
		tmp = t_0;
	else
		tmp = (c * ((b / d) * (1.0 / d))) - (a / d);
	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]}, If[LessEqual[d, -3e+28], N[(N[(c * N[(b / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8e-193], t$95$0, If[LessEqual[d, 2.8e-125], N[(N[(b / c), $MachinePrecision] + N[(N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.2e+96], t$95$0, N[(N[(c * N[(N[(b / d), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $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}\;d \leq -3 \cdot 10^{+28}:\\
\;\;\;\;c \cdot \frac{b}{{d}^{2}} - \frac{a}{d}\\

\mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 7.2 \cdot 10^{+96}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 60.4%

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

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

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

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

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

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

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

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

    if -3.0000000000000001e28 < d < -8.0000000000000004e-193 or 2.8e-125 < d < 7.20000000000000026e96

    1. Initial program 83.1%

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

    if -8.0000000000000004e-193 < d < 2.8e-125

    1. Initial program 72.2%

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

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

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

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

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

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

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

    if 7.20000000000000026e96 < d

    1. Initial program 33.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 80.6% 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 := c \cdot \left(\frac{b}{d} \cdot \frac{1}{d}\right) - \frac{a}{d}\\ \mathbf{if}\;d \leq -3 \cdot 10^{+28}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 9.2 \cdot 10^{-126}:\\ \;\;\;\;\frac{b}{c} + \frac{a \cdot d}{c} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{+98}:\\ \;\;\;\;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 (* (/ b d) (/ 1.0 d))) (/ a d))))
   (if (<= d -3e+28)
     t_1
     (if (<= d -8e-193)
       t_0
       (if (<= d 9.2e-126)
         (+ (/ b c) (* (/ (* a d) c) (/ -1.0 c)))
         (if (<= d 2.2e+98) 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 * ((b / d) * (1.0 / d))) - (a / d);
	double tmp;
	if (d <= -3e+28) {
		tmp = t_1;
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 9.2e-126) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 2.2e+98) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
    t_1 = (c * ((b / d) * (1.0d0 / d))) - (a / d)
    if (d <= (-3d+28)) then
        tmp = t_1
    else if (d <= (-8d-193)) then
        tmp = t_0
    else if (d <= 9.2d-126) then
        tmp = (b / c) + (((a * d) / c) * ((-1.0d0) / c))
    else if (d <= 2.2d+98) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double t_1 = (c * ((b / d) * (1.0 / d))) - (a / d);
	double tmp;
	if (d <= -3e+28) {
		tmp = t_1;
	} else if (d <= -8e-193) {
		tmp = t_0;
	} else if (d <= 9.2e-126) {
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	} else if (d <= 2.2e+98) {
		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 * ((b / d) * (1.0 / d))) - (a / d)
	tmp = 0
	if d <= -3e+28:
		tmp = t_1
	elif d <= -8e-193:
		tmp = t_0
	elif d <= 9.2e-126:
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c))
	elif d <= 2.2e+98:
		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 * Float64(Float64(b / d) * Float64(1.0 / d))) - Float64(a / d))
	tmp = 0.0
	if (d <= -3e+28)
		tmp = t_1;
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 9.2e-126)
		tmp = Float64(Float64(b / c) + Float64(Float64(Float64(a * d) / c) * Float64(-1.0 / c)));
	elseif (d <= 2.2e+98)
		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 * ((b / d) * (1.0 / d))) - (a / d);
	tmp = 0.0;
	if (d <= -3e+28)
		tmp = t_1;
	elseif (d <= -8e-193)
		tmp = t_0;
	elseif (d <= 9.2e-126)
		tmp = (b / c) + (((a * d) / c) * (-1.0 / c));
	elseif (d <= 2.2e+98)
		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[(N[(b / d), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3e+28], t$95$1, If[LessEqual[d, -8e-193], t$95$0, If[LessEqual[d, 9.2e-126], N[(N[(b / c), $MachinePrecision] + N[(N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision] * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.2e+98], 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 := c \cdot \left(\frac{b}{d} \cdot \frac{1}{d}\right) - \frac{a}{d}\\
\mathbf{if}\;d \leq -3 \cdot 10^{+28}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -8 \cdot 10^{-193}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.2 \cdot 10^{+98}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.0000000000000001e28 or 2.20000000000000009e98 < d

    1. Initial program 47.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.0000000000000001e28 < d < -8.0000000000000004e-193 or 9.20000000000000043e-126 < d < 2.20000000000000009e98

    1. Initial program 83.1%

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

    if -8.0000000000000004e-193 < d < 9.20000000000000043e-126

    1. Initial program 72.2%

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

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

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

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

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

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

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

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

Alternative 10: 74.6% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -0.0179999999999999986 or 1.05999999999999993e-11 < c

    1. Initial program 52.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \frac{\color{blue}{d \cdot \frac{a}{c}}}{c} + \frac{b}{c} \]
    7. Applied egg-rr79.1%

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

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

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

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

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

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

    if -0.0179999999999999986 < c < 1.05999999999999993e-11

    1. Initial program 81.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 76.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -15000 \lor \neg \left(d \leq 1.8 \cdot 10^{-29}\right):\\
\;\;\;\;c \cdot \left(\frac{b}{d} \cdot \frac{1}{d}\right) - \frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -15000 or 1.79999999999999987e-29 < d

    1. Initial program 55.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if -15000 < d < 1.79999999999999987e-29

    1. Initial program 78.4%

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

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

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

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

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

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

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

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

Alternative 12: 69.0% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.3 \cdot 10^{-105} \lor \neg \left(c \leq 5.6 \cdot 10^{-37}\right):\\
\;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.2999999999999999e-105 or 5.6000000000000002e-37 < c

    1. Initial program 57.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.2999999999999999e-105 < c < 5.6000000000000002e-37

    1. Initial program 80.8%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified72.8%

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

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

Alternative 13: 69.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1 \cdot 10^{-102}:\\ \;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq 2.3 \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 -1e-102)
   (- (/ b c) (* d (/ (/ a c) c)))
   (if (<= c 2.3e-60) (/ a (- d)) (- (/ b c) (* (/ d c) (/ a c))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1e-102) {
		tmp = (b / c) - (d * ((a / c) / c));
	} else if (c <= 2.3e-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 <= (-1d-102)) then
        tmp = (b / c) - (d * ((a / c) / c))
    else if (c <= 2.3d-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 <= -1e-102) {
		tmp = (b / c) - (d * ((a / c) / c));
	} else if (c <= 2.3e-60) {
		tmp = a / -d;
	} else {
		tmp = (b / c) - ((d / c) * (a / c));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -1e-102:
		tmp = (b / c) - (d * ((a / c) / c))
	elif c <= 2.3e-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 <= -1e-102)
		tmp = Float64(Float64(b / c) - Float64(d * Float64(Float64(a / c) / c)));
	elseif (c <= 2.3e-60)
		tmp = Float64(a / Float64(-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 <= -1e-102)
		tmp = (b / c) - (d * ((a / c) / c));
	elseif (c <= 2.3e-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, -1e-102], N[(N[(b / c), $MachinePrecision] - N[(d * N[(N[(a / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.3e-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 \cdot 10^{-102}:\\
\;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\

\mathbf{elif}\;c \leq 2.3 \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 < -9.99999999999999933e-103

    1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto -1 \cdot \frac{\color{blue}{d \cdot \frac{a}{c}}}{c} + \frac{b}{c} \]
    7. Applied egg-rr70.5%

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

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

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

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

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

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

    if -9.99999999999999933e-103 < c < 2.3000000000000001e-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.3000000000000001e-60 < c

    1. Initial program 55.3%

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

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

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

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

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

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

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

Alternative 14: 62.9% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.9999999999999999e-82 or 2.5000000000000002e-6 < 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.9999999999999999e-82 < c < 2.5000000000000002e-6

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

Alternative 15: 45.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+161} \lor \neg \left(d \leq 1.65 \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 < -3.10000000000000007e161 or 1.65000000000000009e167 < d

    1. Initial program 37.4%

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

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

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

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

      \[\leadsto \frac{\color{blue}{a \cdot \left(-d\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-commutative37.7%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)} \]
      10. add-sqr-sqrt37.9%

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

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

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

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

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

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

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

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

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

    if -3.10000000000000007e161 < d < 1.65000000000000009e167

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

Alternative 16: 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. Taylor expanded in b around 0 44.0%

    \[\leadsto \frac{\color{blue}{-1 \cdot \left(a \cdot d\right)}}{c \cdot c + d \cdot d} \]
  4. Step-by-step derivation
    1. mul-1-neg44.0%

      \[\leadsto \frac{\color{blue}{-a \cdot d}}{c \cdot c + d \cdot d} \]
    2. distribute-rgt-neg-out44.0%

      \[\leadsto \frac{\color{blue}{a \cdot \left(-d\right)}}{c \cdot c + d \cdot d} \]
  5. Simplified44.0%

    \[\leadsto \frac{\color{blue}{a \cdot \left(-d\right)}}{c \cdot c + d \cdot d} \]
  6. Step-by-step derivation
    1. *-commutative44.0%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)} \]
    10. add-sqr-sqrt17.3%

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{a}{d} \]
  10. 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))))