Complex division, imag part

Percentage Accurate: 62.7% → 89.3%
Time: 10.4s
Alternatives: 12
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 12 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.7% 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: 89.3% accurate, 0.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, t\_0, \frac{d \cdot a}{-{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.99999999999999973e65 or 1.49999999999999991e78 < d

    1. Initial program 38.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}\right) \]
    4. Applied egg-rr53.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 \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt53.6%

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

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

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

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

    if -4.99999999999999973e65 < d < 1.49999999999999991e78

    1. Initial program 74.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      10. hypot-define90.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) \]
      11. fma-define90.5%

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

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

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

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

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

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

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

Alternative 2: 88.6% accurate, 0.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{{\left(\sqrt{\mathsf{hypot}\left(c, d\right)}\right)}^{2}}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{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))) < 1.00000000000000006e290

    1. Initial program 80.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000006e290 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 11.1%

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

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

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

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

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

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

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

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

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

        \[\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) \]
      11. fma-define50.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}}\right) \]
    4. Applied egg-rr50.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 \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt50.6%

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

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

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

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

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

Alternative 3: 86.3% accurate, 0.0× speedup?

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

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

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


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

    1. Initial program 81.0%

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

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]
      3. add-sqr-sqrt81.0%

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e300 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 10.0%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 82.5% 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}\;c \leq -4.8 \cdot 10^{+72}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-96}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{-78}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{+147}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (<= c -4.8e+72)
     (* (/ c (hypot d c)) (/ b (hypot d c)))
     (if (<= c -1.05e-96)
       t_0
       (if (<= c 4.3e-78)
         (/ (- (* b (/ c d)) a) d)
         (if (<= c 2.6e+147) t_0 (/ (- b (* d (/ a c))) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -4.8e+72) {
		tmp = (c / hypot(d, c)) * (b / hypot(d, c));
	} else if (c <= -1.05e-96) {
		tmp = t_0;
	} else if (c <= 4.3e-78) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 2.6e+147) {
		tmp = t_0;
	} else {
		tmp = (b - (d * (a / c))) / c;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -4.8e+72) {
		tmp = (c / Math.hypot(d, c)) * (b / Math.hypot(d, c));
	} else if (c <= -1.05e-96) {
		tmp = t_0;
	} else if (c <= 4.3e-78) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 2.6e+147) {
		tmp = t_0;
	} else {
		tmp = (b - (d * (a / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -4.8e+72:
		tmp = (c / math.hypot(d, c)) * (b / math.hypot(d, c))
	elif c <= -1.05e-96:
		tmp = t_0
	elif c <= 4.3e-78:
		tmp = ((b * (c / d)) - a) / d
	elif c <= 2.6e+147:
		tmp = t_0
	else:
		tmp = (b - (d * (a / c))) / c
	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 (c <= -4.8e+72)
		tmp = Float64(Float64(c / hypot(d, c)) * Float64(b / hypot(d, c)));
	elseif (c <= -1.05e-96)
		tmp = t_0;
	elseif (c <= 4.3e-78)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	elseif (c <= 2.6e+147)
		tmp = t_0;
	else
		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -4.8e+72)
		tmp = (c / hypot(d, c)) * (b / hypot(d, c));
	elseif (c <= -1.05e-96)
		tmp = t_0;
	elseif (c <= 4.3e-78)
		tmp = ((b * (c / d)) - a) / d;
	elseif (c <= 2.6e+147)
		tmp = t_0;
	else
		tmp = (b - (d * (a / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.8e+72], N[(N[(c / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.05e-96], t$95$0, If[LessEqual[c, 4.3e-78], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.6e+147], t$95$0, N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -1.05 \cdot 10^{-96}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 2.6 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -4.8000000000000002e72

    1. Initial program 35.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.8000000000000002e72 < c < -1.05000000000000001e-96 or 4.29999999999999994e-78 < c < 2.5999999999999999e147

    1. Initial program 79.7%

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

    if -1.05000000000000001e-96 < c < 4.29999999999999994e-78

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.5999999999999999e147 < c

    1. Initial program 20.3%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.8 \cdot 10^{+72}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-96}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{-78}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{+147}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 82.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;c \leq -5.6 \cdot 10^{+32}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -5.2 \cdot 10^{-95}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{-78}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{+145}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
        (t_1 (/ (- b (* d (/ a c))) c)))
   (if (<= c -5.6e+32)
     t_1
     (if (<= c -5.2e-95)
       t_0
       (if (<= c 8.6e-78)
         (/ (- (* b (/ c d)) a) d)
         (if (<= c 8.6e+145) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double t_1 = (b - (d * (a / c))) / c;
	double tmp;
	if (c <= -5.6e+32) {
		tmp = t_1;
	} else if (c <= -5.2e-95) {
		tmp = t_0;
	} else if (c <= 8.6e-78) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 8.6e+145) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
    t_1 = (b - (d * (a / c))) / c
    if (c <= (-5.6d+32)) then
        tmp = t_1
    else if (c <= (-5.2d-95)) then
        tmp = t_0
    else if (c <= 8.6d-78) then
        tmp = ((b * (c / d)) - a) / d
    else if (c <= 8.6d+145) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double t_1 = (b - (d * (a / c))) / c;
	double tmp;
	if (c <= -5.6e+32) {
		tmp = t_1;
	} else if (c <= -5.2e-95) {
		tmp = t_0;
	} else if (c <= 8.6e-78) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 8.6e+145) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	t_1 = (b - (d * (a / c))) / c
	tmp = 0
	if c <= -5.6e+32:
		tmp = t_1
	elif c <= -5.2e-95:
		tmp = t_0
	elif c <= 8.6e-78:
		tmp = ((b * (c / d)) - a) / d
	elif c <= 8.6e+145:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(b - Float64(d * Float64(a / c))) / c)
	tmp = 0.0
	if (c <= -5.6e+32)
		tmp = t_1;
	elseif (c <= -5.2e-95)
		tmp = t_0;
	elseif (c <= 8.6e-78)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	elseif (c <= 8.6e+145)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	t_1 = (b - (d * (a / c))) / c;
	tmp = 0.0;
	if (c <= -5.6e+32)
		tmp = t_1;
	elseif (c <= -5.2e-95)
		tmp = t_0;
	elseif (c <= 8.6e-78)
		tmp = ((b * (c / d)) - a) / d;
	elseif (c <= 8.6e+145)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -5.6e+32], t$95$1, If[LessEqual[c, -5.2e-95], t$95$0, If[LessEqual[c, 8.6e-78], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8.6e+145], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -5.2 \cdot 10^{-95}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 8.6 \cdot 10^{+145}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.6e32 or 8.59999999999999996e145 < c

    1. Initial program 35.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.8%

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

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

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

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

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

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

    if -5.6e32 < c < -5.20000000000000001e-95 or 8.59999999999999987e-78 < c < 8.59999999999999996e145

    1. Initial program 78.9%

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

    if -5.20000000000000001e-95 < c < 8.59999999999999987e-78

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.6 \cdot 10^{+32}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -5.2 \cdot 10^{-95}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{-78}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{+145}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 77.3% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.10000000000000001e24 or 1.12e11 < d

    1. Initial program 45.2%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      10. hypot-define59.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) \]
      11. fma-define59.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.10000000000000001e24 < d < 1.12e11

    1. Initial program 73.5%

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

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

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

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

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

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

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

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

Alternative 7: 71.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{+24} \lor \neg \left(d \leq 5.4 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.1999999999999997e24 or 5.4e14 < d

    1. Initial program 44.3%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. mul-1-neg70.1%

        \[\leadsto \color{blue}{-\frac{a}{d}} \]
      2. distribute-neg-frac270.1%

        \[\leadsto \color{blue}{\frac{a}{-d}} \]
    5. Simplified70.1%

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

    if -3.1999999999999997e24 < d < 5.4e14

    1. Initial program 73.9%

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

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

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

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

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

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

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

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

Alternative 8: 78.4% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;d \leq 620000000:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.8000000000000002e27

    1. Initial program 40.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      10. hypot-define53.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) \]
      11. fma-define53.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.8000000000000002e27 < d < 6.2e8

    1. Initial program 73.5%

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

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

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

        \[\leadsto \frac{b + \frac{\color{blue}{-a \cdot d}}{c}}{c} \]
      3. distribute-rgt-neg-out85.8%

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

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

    if 6.2e8 < d

    1. Initial program 49.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+27}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;d \leq 620000000:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 77.3% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;d \leq 2350000:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -8.2000000000000007e29

    1. Initial program 40.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      10. hypot-define53.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) \]
      11. fma-define53.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.2000000000000007e29 < d < 2.35e6

    1. Initial program 73.5%

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

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

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

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

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

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

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

    if 2.35e6 < d

    1. Initial program 49.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 63.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1150000000000 \lor \neg \left(c \leq 2.9 \cdot 10^{+41}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.15e12 or 2.89999999999999988e41 < c

    1. Initial program 47.0%

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

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

    if -1.15e12 < c < 2.89999999999999988e41

    1. Initial program 71.0%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. mul-1-neg69.3%

        \[\leadsto \color{blue}{-\frac{a}{d}} \]
      2. distribute-neg-frac269.3%

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

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

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

Alternative 11: 45.0% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 62.4%

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

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

    if 3.2999999999999997e169 < d

    1. Initial program 38.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    7. Simplified75.3%

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
    8. Step-by-step derivation
      1. div-inv75.1%

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

        \[\leadsto \color{blue}{\left(\sqrt{-a} \cdot \sqrt{-a}\right)} \cdot \frac{1}{d} \]
      3. sqrt-unprod53.9%

        \[\leadsto \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}} \cdot \frac{1}{d} \]
      4. sqr-neg53.9%

        \[\leadsto \sqrt{\color{blue}{a \cdot a}} \cdot \frac{1}{d} \]
      5. sqrt-unprod20.0%

        \[\leadsto \color{blue}{\left(\sqrt{a} \cdot \sqrt{a}\right)} \cdot \frac{1}{d} \]
      6. add-sqr-sqrt40.0%

        \[\leadsto \color{blue}{a} \cdot \frac{1}{d} \]
    9. Applied egg-rr40.0%

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

        \[\leadsto \color{blue}{\frac{a \cdot 1}{d}} \]
      2. *-rgt-identity40.0%

        \[\leadsto \frac{\color{blue}{a}}{d} \]
    11. Simplified40.0%

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

Alternative 12: 11.0% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    10. hypot-define75.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) \]
    11. fma-define75.5%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-a}}{d} \]
  7. Simplified43.3%

    \[\leadsto \color{blue}{\frac{-a}{d}} \]
  8. Step-by-step derivation
    1. div-inv43.2%

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

      \[\leadsto \color{blue}{\left(\sqrt{-a} \cdot \sqrt{-a}\right)} \cdot \frac{1}{d} \]
    3. sqrt-unprod23.7%

      \[\leadsto \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}} \cdot \frac{1}{d} \]
    4. sqr-neg23.7%

      \[\leadsto \sqrt{\color{blue}{a \cdot a}} \cdot \frac{1}{d} \]
    5. sqrt-unprod4.8%

      \[\leadsto \color{blue}{\left(\sqrt{a} \cdot \sqrt{a}\right)} \cdot \frac{1}{d} \]
    6. add-sqr-sqrt11.1%

      \[\leadsto \color{blue}{a} \cdot \frac{1}{d} \]
  9. Applied egg-rr11.1%

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

      \[\leadsto \color{blue}{\frac{a \cdot 1}{d}} \]
    2. *-rgt-identity11.1%

      \[\leadsto \frac{\color{blue}{a}}{d} \]
  11. Simplified11.1%

    \[\leadsto \color{blue}{\frac{a}{d}} \]
  12. Add Preprocessing

Developer Target 1: 99.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (< (fabs d) (fabs c))
   (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
   (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (abs(d) < abs(c)) then
        tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (Math.abs(d) < Math.abs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (abs(d) < abs(c))
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (abs(d) < abs(c))
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))

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