Complex division, imag part

Percentage Accurate: 62.2% → 96.0%
Time: 12.1s
Alternatives: 15
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 15 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 96.0% accurate, 0.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\right) \]
  9. Add Preprocessing

Alternative 2: 87.2% accurate, 0.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{\frac{-d}{\frac{\mathsf{hypot}\left(c, d\right)}{a}}}{\mathsf{hypot}\left(c, d\right)}\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 79.8%

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

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

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

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

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

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

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

    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. sub-neg0.0%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      4. 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}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      5. times-frac1.6%

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

        \[\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)} \]
      7. hypot-def1.6%

        \[\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) \]
      8. hypot-def41.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 75.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ t_1 := \frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \mathbf{if}\;d \leq -5.7 \cdot 10^{+242}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\ \;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\ \mathbf{elif}\;d \leq -58000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{c} - d \cdot \frac{a}{{c}^{2}}\\ \mathbf{elif}\;d \leq -2.4 \cdot 10^{-69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-111}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{c}}\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{-164}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{a}{c \cdot \frac{c}{d}}, \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{+45}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- a) (fma c (/ c d) d)))
        (t_1 (- (/ c (/ (pow d 2.0) b)) (/ a d))))
   (if (<= d -5.7e+242)
     t_0
     (if (<= d -4.8e+192)
       (/ (/ (- c) d) (/ (hypot c d) b))
       (if (<= d -58000000000.0)
         t_1
         (if (<= d -4e-33)
           (- (/ b c) (* d (/ a (pow c 2.0))))
           (if (<= d -2.4e-69)
             t_0
             (if (<= d -4e-111)
               (/ b (* (hypot c d) (/ (hypot c d) c)))
               (if (<= d 4.4e-164)
                 (fma -1.0 (/ a (* c (/ c d))) (/ b c))
                 (if (<= d 5.5e+45)
                   (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
                   t_1))))))))))
double code(double a, double b, double c, double d) {
	double t_0 = -a / fma(c, (c / d), d);
	double t_1 = (c / (pow(d, 2.0) / b)) - (a / d);
	double tmp;
	if (d <= -5.7e+242) {
		tmp = t_0;
	} else if (d <= -4.8e+192) {
		tmp = (-c / d) / (hypot(c, d) / b);
	} else if (d <= -58000000000.0) {
		tmp = t_1;
	} else if (d <= -4e-33) {
		tmp = (b / c) - (d * (a / pow(c, 2.0)));
	} else if (d <= -2.4e-69) {
		tmp = t_0;
	} else if (d <= -4e-111) {
		tmp = b / (hypot(c, d) * (hypot(c, d) / c));
	} else if (d <= 4.4e-164) {
		tmp = fma(-1.0, (a / (c * (c / d))), (b / c));
	} else if (d <= 5.5e+45) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(-a) / fma(c, Float64(c / d), d))
	t_1 = Float64(Float64(c / Float64((d ^ 2.0) / b)) - Float64(a / d))
	tmp = 0.0
	if (d <= -5.7e+242)
		tmp = t_0;
	elseif (d <= -4.8e+192)
		tmp = Float64(Float64(Float64(-c) / d) / Float64(hypot(c, d) / b));
	elseif (d <= -58000000000.0)
		tmp = t_1;
	elseif (d <= -4e-33)
		tmp = Float64(Float64(b / c) - Float64(d * Float64(a / (c ^ 2.0))));
	elseif (d <= -2.4e-69)
		tmp = t_0;
	elseif (d <= -4e-111)
		tmp = Float64(b / Float64(hypot(c, d) * Float64(hypot(c, d) / c)));
	elseif (d <= 4.4e-164)
		tmp = fma(-1.0, Float64(a / Float64(c * Float64(c / d))), Float64(b / c));
	elseif (d <= 5.5e+45)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / N[(c * N[(c / d), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c / N[(N[Power[d, 2.0], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.7e+242], t$95$0, If[LessEqual[d, -4.8e+192], N[(N[((-c) / d), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -58000000000.0], t$95$1, If[LessEqual[d, -4e-33], N[(N[(b / c), $MachinePrecision] - N[(d * N[(a / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.4e-69], t$95$0, If[LessEqual[d, -4e-111], N[(b / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] * N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.4e-164], N[(-1.0 * N[(a / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.5e+45], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\
\;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\

\mathbf{elif}\;d \leq -58000000000:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d \leq -2.4 \cdot 10^{-69}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -4 \cdot 10^{-111}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{c}}\\

\mathbf{elif}\;d \leq 4.4 \cdot 10^{-164}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{a}{c \cdot \frac{c}{d}}, \frac{b}{c}\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 7 regimes
  2. if d < -5.7000000000000003e242 or -4.0000000000000002e-33 < d < -2.4000000000000001e-69

    1. Initial program 55.7%

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

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

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

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

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

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

        \[\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)} \]
      7. hypot-def55.9%

        \[\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) \]
      8. hypot-def65.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d + \frac{{c}^{2}}{d}}} \]
    9. Step-by-step derivation
      1. associate-*r/81.4%

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

        \[\leadsto \frac{\color{blue}{-a}}{d + \frac{{c}^{2}}{d}} \]
      3. +-commutative81.4%

        \[\leadsto \frac{-a}{\color{blue}{\frac{{c}^{2}}{d} + d}} \]
      4. unpow281.4%

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

        \[\leadsto \frac{-a}{\color{blue}{c \cdot \frac{c}{d}} + d} \]
      6. fma-udef90.6%

        \[\leadsto \frac{-a}{\color{blue}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}} \]
    10. Simplified90.6%

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

    if -5.7000000000000003e242 < d < -4.7999999999999996e192

    1. Initial program 36.7%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{{c}^{2} + {d}^{2}} \cdot c} \]
      3. +-commutative38.9%

        \[\leadsto \frac{b}{\color{blue}{{d}^{2} + {c}^{2}}} \cdot c \]
      4. unpow238.9%

        \[\leadsto \frac{b}{\color{blue}{d \cdot d} + {c}^{2}} \cdot c \]
      5. fma-def38.9%

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

      \[\leadsto \color{blue}{\frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)} \cdot c} \]
    6. Step-by-step derivation
      1. *-commutative38.9%

        \[\leadsto \color{blue}{c \cdot \frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. associate-*r/36.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.7999999999999996e192 < d < -5.8e10 or 5.5000000000000001e45 < d

    1. Initial program 45.7%

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

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

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

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

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

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

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

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

    if -5.8e10 < d < -4.0000000000000002e-33

    1. Initial program 46.3%

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{a}{\frac{{c}^{2}}{d}}} \]
      5. associate-/r/73.8%

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

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

    if -2.4000000000000001e-69 < d < -4.00000000000000035e-111

    1. Initial program 73.1%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{c \cdot \frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. associate-*r/73.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.00000000000000035e-111 < d < 4.39999999999999975e-164

    1. Initial program 76.7%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{a}{\frac{{c}^{2}}{d}}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. div-inv79.4%

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

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

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

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

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

    if 4.39999999999999975e-164 < d < 5.5000000000000001e45

    1. Initial program 90.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 7 regimes into one program.
  4. Final simplification87.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.7 \cdot 10^{+242}:\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\ \;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\ \mathbf{elif}\;d \leq -58000000000:\\ \;\;\;\;\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{c} - d \cdot \frac{a}{{c}^{2}}\\ \mathbf{elif}\;d \leq -2.4 \cdot 10^{-69}:\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-111}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{c}}\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{-164}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{a}{c \cdot \frac{c}{d}}, \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{+45}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 85.0% accurate, 0.1× speedup?

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

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

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


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

    1. Initial program 79.8%

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

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

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

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

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

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

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

    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. sub-neg0.0%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      4. 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}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      5. times-frac1.6%

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

        \[\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)} \]
      7. hypot-def1.6%

        \[\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) \]
      8. hypot-def41.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d + \frac{{c}^{2}}{d}}} \]
    9. Step-by-step derivation
      1. associate-*r/44.8%

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

        \[\leadsto \frac{\color{blue}{-a}}{d + \frac{{c}^{2}}{d}} \]
      3. +-commutative44.8%

        \[\leadsto \frac{-a}{\color{blue}{\frac{{c}^{2}}{d} + d}} \]
      4. unpow244.8%

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

        \[\leadsto \frac{-a}{\color{blue}{c \cdot \frac{c}{d}} + d} \]
      6. fma-udef57.0%

        \[\leadsto \frac{-a}{\color{blue}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}} \]
    10. Simplified57.0%

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

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

Alternative 5: 73.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -3.3 \cdot 10^{+34} \lor \neg \left(a \leq 8.5 \cdot 10^{-27}\right):\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= a -3.3e+34) (not (<= a 8.5e-27)))
   (/ (- a) (fma c (/ c d) d))
   (/ (/ b (hypot c d)) (/ (hypot c d) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((a <= -3.3e+34) || !(a <= 8.5e-27)) {
		tmp = -a / fma(c, (c / d), d);
	} else {
		tmp = (b / hypot(c, d)) / (hypot(c, d) / c);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((a <= -3.3e+34) || !(a <= 8.5e-27))
		tmp = Float64(Float64(-a) / fma(c, Float64(c / d), d));
	else
		tmp = Float64(Float64(b / hypot(c, d)) / Float64(hypot(c, d) / c));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[a, -3.3e+34], N[Not[LessEqual[a, 8.5e-27]], $MachinePrecision]], N[((-a) / N[(c * N[(c / d), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision], N[(N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.3 \cdot 10^{+34} \lor \neg \left(a \leq 8.5 \cdot 10^{-27}\right):\\
\;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -3.29999999999999988e34 or 8.50000000000000033e-27 < a

    1. Initial program 53.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      6. fma-def50.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)} \]
      7. hypot-def50.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) \]
      8. hypot-def57.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) \]
      9. associate-/l*63.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d + \frac{{c}^{2}}{d}}} \]
    9. Step-by-step derivation
      1. associate-*r/64.6%

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

        \[\leadsto \frac{\color{blue}{-a}}{d + \frac{{c}^{2}}{d}} \]
      3. +-commutative64.6%

        \[\leadsto \frac{-a}{\color{blue}{\frac{{c}^{2}}{d} + d}} \]
      4. unpow264.6%

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

        \[\leadsto \frac{-a}{\color{blue}{c \cdot \frac{c}{d}} + d} \]
      6. fma-udef75.1%

        \[\leadsto \frac{-a}{\color{blue}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}} \]
    10. Simplified75.1%

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

    if -3.29999999999999988e34 < a < 8.50000000000000033e-27

    1. Initial program 70.3%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)} \cdot c} \]
    6. Step-by-step derivation
      1. *-commutative55.4%

        \[\leadsto \color{blue}{c \cdot \frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. associate-*r/57.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 73.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -3.5 \cdot 10^{+31} \lor \neg \left(a \leq 4.7 \cdot 10^{-38}\right):\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\mathsf{hypot}\left(c, d\right)}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= a -3.5e+31) (not (<= a 4.7e-38)))
   (/ (- a) (fma c (/ c d) d))
   (/ (/ c (hypot c d)) (/ (hypot c d) b))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((a <= -3.5e+31) || !(a <= 4.7e-38)) {
		tmp = -a / fma(c, (c / d), d);
	} else {
		tmp = (c / hypot(c, d)) / (hypot(c, d) / b);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((a <= -3.5e+31) || !(a <= 4.7e-38))
		tmp = Float64(Float64(-a) / fma(c, Float64(c / d), d));
	else
		tmp = Float64(Float64(c / hypot(c, d)) / Float64(hypot(c, d) / b));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[a, -3.5e+31], N[Not[LessEqual[a, 4.7e-38]], $MachinePrecision]], N[((-a) / N[(c * N[(c / d), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.5 \cdot 10^{+31} \lor \neg \left(a \leq 4.7 \cdot 10^{-38}\right):\\
\;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -3.5e31 or 4.69999999999999998e-38 < a

    1. Initial program 53.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub50.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. sub-neg50.0%

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

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

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

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

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

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

        \[\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) \]
      9. associate-/l*65.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d + \frac{{c}^{2}}{d}}} \]
    9. Step-by-step derivation
      1. associate-*r/64.2%

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

        \[\leadsto \frac{\color{blue}{-a}}{d + \frac{{c}^{2}}{d}} \]
      3. +-commutative64.2%

        \[\leadsto \frac{-a}{\color{blue}{\frac{{c}^{2}}{d} + d}} \]
      4. unpow264.2%

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

        \[\leadsto \frac{-a}{\color{blue}{c \cdot \frac{c}{d}} + d} \]
      6. fma-udef74.3%

        \[\leadsto \frac{-a}{\color{blue}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}} \]
    10. Simplified74.3%

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

    if -3.5e31 < a < 4.69999999999999998e-38

    1. Initial program 70.2%

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

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

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

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

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

        \[\leadsto \frac{b}{\color{blue}{d \cdot d} + {c}^{2}} \cdot c \]
      5. fma-def56.3%

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

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

        \[\leadsto \color{blue}{c \cdot \frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. associate-*r/58.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 76.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-321} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 5 \cdot 10^{+263}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (or (<= t_0 -5e-321) (and (not (<= t_0 0.0)) (<= t_0 5e+263)))
     t_0
     (/ (- a) (fma c (/ c d) d)))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if ((t_0 <= -5e-321) || (!(t_0 <= 0.0) && (t_0 <= 5e+263))) {
		tmp = t_0;
	} else {
		tmp = -a / fma(c, (c / d), d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if ((t_0 <= -5e-321) || (!(t_0 <= 0.0) && (t_0 <= 5e+263)))
		tmp = t_0;
	else
		tmp = Float64(Float64(-a) / fma(c, Float64(c / d), d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5e-321], And[N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision], LessEqual[t$95$0, 5e+263]]], t$95$0, N[((-a) / N[(c * N[(c / d), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-321} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 5 \cdot 10^{+263}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -4.99994e-321 or -0.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 5.00000000000000022e263

    1. Initial program 92.1%

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

    if -4.99994e-321 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -0.0 or 5.00000000000000022e263 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 34.0%

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

        \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}} \]
      2. sub-neg30.9%

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      9. associate-/l*64.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}{\frac{c \cdot c + d \cdot d}{d}}}\right) \]
      10. add-sqr-sqrt64.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d + \frac{{c}^{2}}{d}}} \]
    9. Step-by-step derivation
      1. associate-*r/58.9%

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

        \[\leadsto \frac{\color{blue}{-a}}{d + \frac{{c}^{2}}{d}} \]
      3. +-commutative58.9%

        \[\leadsto \frac{-a}{\color{blue}{\frac{{c}^{2}}{d} + d}} \]
      4. unpow258.9%

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

        \[\leadsto \frac{-a}{\color{blue}{c \cdot \frac{c}{d}} + d} \]
      6. fma-udef68.2%

        \[\leadsto \frac{-a}{\color{blue}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}} \]
    10. Simplified68.2%

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

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

Alternative 8: 75.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \mathbf{if}\;d \leq -5.7 \cdot 10^{+242}:\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\ \;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\ \mathbf{elif}\;d \leq -1000000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-164}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{a}{c \cdot \frac{c}{d}}, \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{+45}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (- (/ c (/ (pow d 2.0) b)) (/ a d))))
   (if (<= d -5.7e+242)
     (/ (- a) (fma c (/ c d) d))
     (if (<= d -4.8e+192)
       (/ (/ (- c) d) (/ (hypot c d) b))
       (if (<= d -1000000000000.0)
         t_0
         (if (<= d 2.1e-164)
           (fma -1.0 (/ a (* c (/ c d))) (/ b c))
           (if (<= d 5.8e+45)
             (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
             t_0)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c / (pow(d, 2.0) / b)) - (a / d);
	double tmp;
	if (d <= -5.7e+242) {
		tmp = -a / fma(c, (c / d), d);
	} else if (d <= -4.8e+192) {
		tmp = (-c / d) / (hypot(c, d) / b);
	} else if (d <= -1000000000000.0) {
		tmp = t_0;
	} else if (d <= 2.1e-164) {
		tmp = fma(-1.0, (a / (c * (c / d))), (b / c));
	} else if (d <= 5.8e+45) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c / Float64((d ^ 2.0) / b)) - Float64(a / d))
	tmp = 0.0
	if (d <= -5.7e+242)
		tmp = Float64(Float64(-a) / fma(c, Float64(c / d), d));
	elseif (d <= -4.8e+192)
		tmp = Float64(Float64(Float64(-c) / d) / Float64(hypot(c, d) / b));
	elseif (d <= -1000000000000.0)
		tmp = t_0;
	elseif (d <= 2.1e-164)
		tmp = fma(-1.0, Float64(a / Float64(c * Float64(c / d))), Float64(b / c));
	elseif (d <= 5.8e+45)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c / N[(N[Power[d, 2.0], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.7e+242], N[((-a) / N[(c * N[(c / d), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -4.8e+192], N[(N[((-c) / d), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1000000000000.0], t$95$0, If[LessEqual[d, 2.1e-164], N[(-1.0 * N[(a / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.8e+45], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\
\;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\

\mathbf{elif}\;d \leq -1000000000000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 2.1 \cdot 10^{-164}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{a}{c \cdot \frac{c}{d}}, \frac{b}{c}\right)\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


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

    1. Initial program 37.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      6. fma-def37.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)} \]
      7. hypot-def37.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) \]
      8. hypot-def37.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d + \frac{{c}^{2}}{d}}} \]
    9. Step-by-step derivation
      1. associate-*r/83.1%

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

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

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

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

        \[\leadsto \frac{-a}{\color{blue}{c \cdot \frac{c}{d}} + d} \]
      6. fma-udef100.0%

        \[\leadsto \frac{-a}{\color{blue}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}} \]
    10. Simplified100.0%

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

    if -5.7000000000000003e242 < d < -4.7999999999999996e192

    1. Initial program 36.7%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{{c}^{2} + {d}^{2}} \cdot c} \]
      3. +-commutative38.9%

        \[\leadsto \frac{b}{\color{blue}{{d}^{2} + {c}^{2}}} \cdot c \]
      4. unpow238.9%

        \[\leadsto \frac{b}{\color{blue}{d \cdot d} + {c}^{2}} \cdot c \]
      5. fma-def38.9%

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

      \[\leadsto \color{blue}{\frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)} \cdot c} \]
    6. Step-by-step derivation
      1. *-commutative38.9%

        \[\leadsto \color{blue}{c \cdot \frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. associate-*r/36.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.7999999999999996e192 < d < -1e12 or 5.7999999999999994e45 < d

    1. Initial program 45.7%

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

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

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

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

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

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

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

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

    if -1e12 < d < 2.0999999999999999e-164

    1. Initial program 73.2%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{a}{\frac{{c}^{2}}{d}}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. div-inv75.5%

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

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

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

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

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

    if 2.0999999999999999e-164 < d < 5.7999999999999994e45

    1. Initial program 90.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 5 regimes into one program.
  4. Final simplification85.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.7 \cdot 10^{+242}:\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\ \;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\ \mathbf{elif}\;d \leq -1000000000000:\\ \;\;\;\;\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-164}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{a}{c \cdot \frac{c}{d}}, \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{+45}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 73.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.7 \cdot 10^{+242}:\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\ \;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{+63} \lor \neg \left(d \leq 3.8 \cdot 10^{+45}\right):\\ \;\;\;\;\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -5.7e+242)
   (/ (- a) (fma c (/ c d) d))
   (if (<= d -4.8e+192)
     (/ (/ (- c) d) (/ (hypot c d) b))
     (if (or (<= d -1.15e+63) (not (<= d 3.8e+45)))
       (- (/ c (/ (pow d 2.0) b)) (/ a d))
       (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.7e+242) {
		tmp = -a / fma(c, (c / d), d);
	} else if (d <= -4.8e+192) {
		tmp = (-c / d) / (hypot(c, d) / b);
	} else if ((d <= -1.15e+63) || !(d <= 3.8e+45)) {
		tmp = (c / (pow(d, 2.0) / b)) - (a / d);
	} else {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -5.7e+242)
		tmp = Float64(Float64(-a) / fma(c, Float64(c / d), d));
	elseif (d <= -4.8e+192)
		tmp = Float64(Float64(Float64(-c) / d) / Float64(hypot(c, d) / b));
	elseif ((d <= -1.15e+63) || !(d <= 3.8e+45))
		tmp = Float64(Float64(c / Float64((d ^ 2.0) / b)) - Float64(a / d));
	else
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.7e+242], N[((-a) / N[(c * N[(c / d), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -4.8e+192], N[(N[((-c) / d), $MachinePrecision] / N[(N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[d, -1.15e+63], N[Not[LessEqual[d, 3.8e+45]], $MachinePrecision]], N[(N[(c / N[(N[Power[d, 2.0], $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.7 \cdot 10^{+242}:\\
\;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\

\mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\
\;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\

\mathbf{elif}\;d \leq -1.15 \cdot 10^{+63} \lor \neg \left(d \leq 3.8 \cdot 10^{+45}\right):\\
\;\;\;\;\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\

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


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

    1. Initial program 37.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} + \left(-\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      6. fma-def37.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)} \]
      7. hypot-def37.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) \]
      8. hypot-def37.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d + \frac{{c}^{2}}{d}}} \]
    9. Step-by-step derivation
      1. associate-*r/83.1%

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

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

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

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

        \[\leadsto \frac{-a}{\color{blue}{c \cdot \frac{c}{d}} + d} \]
      6. fma-udef100.0%

        \[\leadsto \frac{-a}{\color{blue}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}} \]
    10. Simplified100.0%

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

    if -5.7000000000000003e242 < d < -4.7999999999999996e192

    1. Initial program 36.7%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{{c}^{2} + {d}^{2}} \cdot c} \]
      3. +-commutative38.9%

        \[\leadsto \frac{b}{\color{blue}{{d}^{2} + {c}^{2}}} \cdot c \]
      4. unpow238.9%

        \[\leadsto \frac{b}{\color{blue}{d \cdot d} + {c}^{2}} \cdot c \]
      5. fma-def38.9%

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

      \[\leadsto \color{blue}{\frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)} \cdot c} \]
    6. Step-by-step derivation
      1. *-commutative38.9%

        \[\leadsto \color{blue}{c \cdot \frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. associate-*r/36.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.7999999999999996e192 < d < -1.14999999999999997e63 or 3.8000000000000002e45 < d

    1. Initial program 42.8%

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

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

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

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

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

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

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

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

    if -1.14999999999999997e63 < d < 3.8000000000000002e45

    1. Initial program 78.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 4 regimes into one program.
  4. Final simplification82.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.7 \cdot 10^{+242}:\\ \;\;\;\;\frac{-a}{\mathsf{fma}\left(c, \frac{c}{d}, d\right)}\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{+192}:\\ \;\;\;\;\frac{\frac{-c}{d}}{\frac{\mathsf{hypot}\left(c, d\right)}{b}}\\ \mathbf{elif}\;d \leq -1.15 \cdot 10^{+63} \lor \neg \left(d \leq 3.8 \cdot 10^{+45}\right):\\ \;\;\;\;\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 63.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -190000000:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq -1 \cdot 10^{-68}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -1.95 \cdot 10^{-105}:\\
\;\;\;\;\frac{c \cdot b}{c \cdot c + d \cdot d}\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.9e8 or -1.5000000000000001e-33 < d < -1.00000000000000007e-68 or 5.8e-18 < d

    1. Initial program 48.8%

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

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

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

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

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

    if -1.9e8 < d < -1.5000000000000001e-33 or -1.95e-105 < d < 5.8e-18

    1. Initial program 76.8%

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

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

    if -1.00000000000000007e-68 < d < -1.95e-105

    1. Initial program 80.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -190000000:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -1.5 \cdot 10^{-33}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-68}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -1.95 \cdot 10^{-105}:\\ \;\;\;\;\frac{c \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-18}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 64.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-a}{d}\\ \mathbf{if}\;d \leq -76000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -8.2 \cdot 10^{-34}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{-69}:\\ \;\;\;\;\frac{d \cdot \left(-a\right)}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{-16}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- a) d)))
   (if (<= d -76000000.0)
     t_0
     (if (<= d -8.2e-34)
       (/ b c)
       (if (<= d -3.8e-69)
         (/ (* d (- a)) (+ (* c c) (* d d)))
         (if (<= d 2.7e-16) (/ b c) t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = -a / d;
	double tmp;
	if (d <= -76000000.0) {
		tmp = t_0;
	} else if (d <= -8.2e-34) {
		tmp = b / c;
	} else if (d <= -3.8e-69) {
		tmp = (d * -a) / ((c * c) + (d * d));
	} else if (d <= 2.7e-16) {
		tmp = b / c;
	} else {
		tmp = t_0;
	}
	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 = -a / d
    if (d <= (-76000000.0d0)) then
        tmp = t_0
    else if (d <= (-8.2d-34)) then
        tmp = b / c
    else if (d <= (-3.8d-69)) then
        tmp = (d * -a) / ((c * c) + (d * d))
    else if (d <= 2.7d-16) then
        tmp = b / c
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = -a / d;
	double tmp;
	if (d <= -76000000.0) {
		tmp = t_0;
	} else if (d <= -8.2e-34) {
		tmp = b / c;
	} else if (d <= -3.8e-69) {
		tmp = (d * -a) / ((c * c) + (d * d));
	} else if (d <= 2.7e-16) {
		tmp = b / c;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = -a / d
	tmp = 0
	if d <= -76000000.0:
		tmp = t_0
	elif d <= -8.2e-34:
		tmp = b / c
	elif d <= -3.8e-69:
		tmp = (d * -a) / ((c * c) + (d * d))
	elif d <= 2.7e-16:
		tmp = b / c
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(-a) / d)
	tmp = 0.0
	if (d <= -76000000.0)
		tmp = t_0;
	elseif (d <= -8.2e-34)
		tmp = Float64(b / c);
	elseif (d <= -3.8e-69)
		tmp = Float64(Float64(d * Float64(-a)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 2.7e-16)
		tmp = Float64(b / c);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = -a / d;
	tmp = 0.0;
	if (d <= -76000000.0)
		tmp = t_0;
	elseif (d <= -8.2e-34)
		tmp = b / c;
	elseif (d <= -3.8e-69)
		tmp = (d * -a) / ((c * c) + (d * d));
	elseif (d <= 2.7e-16)
		tmp = b / c;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -76000000.0], t$95$0, If[LessEqual[d, -8.2e-34], N[(b / c), $MachinePrecision], If[LessEqual[d, -3.8e-69], N[(N[(d * (-a)), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.7e-16], N[(b / c), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-a}{d}\\
\mathbf{if}\;d \leq -76000000:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq -3.8 \cdot 10^{-69}:\\
\;\;\;\;\frac{d \cdot \left(-a\right)}{c \cdot c + d \cdot d}\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -7.6e7 or 2.69999999999999999e-16 < d

    1. Initial program 46.8%

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

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

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

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

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

    if -7.6e7 < d < -8.2000000000000007e-34 or -3.7999999999999998e-69 < d < 2.69999999999999999e-16

    1. Initial program 77.0%

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

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

    if -8.2000000000000007e-34 < d < -3.7999999999999998e-69

    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 b around 0 78.7%

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(a \cdot d\right)}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. associate-*r*78.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -76000000:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -8.2 \cdot 10^{-34}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{-69}:\\ \;\;\;\;\frac{d \cdot \left(-a\right)}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{-16}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 74.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.6 \cdot 10^{+121} \lor \neg \left(d \leq 8.2 \cdot 10^{+107}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.5999999999999997e121 or 8.1999999999999998e107 < d

    1. Initial program 33.6%

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

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

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

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

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

    if -4.5999999999999997e121 < d < 8.1999999999999998e107

    1. Initial program 77.2%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification77.8%

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

Alternative 13: 64.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1800000 \lor \neg \left(d \leq 4.1 \cdot 10^{-19}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.8e6 or 4.09999999999999985e-19 < d

    1. Initial program 46.8%

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

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

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

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

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

    if -1.8e6 < d < 4.09999999999999985e-19

    1. Initial program 77.1%

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

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

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

Alternative 14: 43.9% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq 1.4 \cdot 10^{+143}:\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 1.39999999999999999e143

    1. Initial program 69.0%

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

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

    if 1.39999999999999999e143 < d

    1. Initial program 28.5%

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

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

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

        \[\leadsto \color{blue}{\frac{b}{{c}^{2} + {d}^{2}} \cdot c} \]
      3. +-commutative28.5%

        \[\leadsto \frac{b}{\color{blue}{{d}^{2} + {c}^{2}}} \cdot c \]
      4. unpow228.5%

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

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

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

        \[\leadsto \color{blue}{c \cdot \frac{b}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      2. associate-*r/27.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 1.4 \cdot 10^{+143}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 43.3% accurate, 5.0× speedup?

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

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

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

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

    \[\leadsto \frac{b}{c} \]
  5. 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 2024018 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

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

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