Complex division, imag part

Percentage Accurate: 60.8% → 90.3%
Time: 10.9s
Alternatives: 15
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 15 alternatives:

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

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

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

\\
\begin{array}{l}
t_0 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;d \leq -8 \cdot 10^{+120} \lor \neg \left(d \leq 7.5 \cdot 10^{+86}\right):\\
\;\;\;\;\mathsf{fma}\left(t\_1, t\_0, \frac{a}{-d}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.9999999999999998e120 or 7.4999999999999997e86 < d

    1. Initial program 44.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.9999999999999998e120 < d < 7.4999999999999997e86

    1. Initial program 74.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8 \cdot 10^{+120} \lor \neg \left(d \leq 7.5 \cdot 10^{+86}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \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}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}} \cdot \left(-a\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 89.8% accurate, 0.0× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := c \cdot b - d \cdot a\\
t_2 := \frac{t\_1}{c \cdot c + d \cdot d}\\
t_3 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\
t_4 := \frac{a}{-d}\\
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_3 \cdot b, t\_4\right)\\

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{+193}:\\
\;\;\;\;t\_0 \cdot \frac{t\_1}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 45.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 4.99999999999999972e193

    1. Initial program 84.8%

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

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

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

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

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

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

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

    if 4.99999999999999972e193 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 22.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 88.5% accurate, 0.0× speedup?

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

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

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

    1. Initial program 80.8%

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

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

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

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

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

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

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

    if 4.99999999999999972e193 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 22.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 85.6% accurate, 0.1× speedup?

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

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

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


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

    1. Initial program 81.1%

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

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

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

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

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

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

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

    if 5e287 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 16.5%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 83.4% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -1.45 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.1 \cdot 10^{+64}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 52.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.4499999999999999e121 < d < -1.4499999999999999e-158 or 6.19999999999999951e-104 < d < 4.09999999999999978e64

    1. Initial program 78.2%

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

    if -1.4499999999999999e-158 < d < 6.19999999999999951e-104

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.09999999999999978e64 < d

    1. Initial program 40.6%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.45 \cdot 10^{+121}:\\ \;\;\;\;\frac{a - b \cdot \frac{c}{d}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-158}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.2 \cdot 10^{-104}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{+64}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 81.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}\;d \leq -1.4 \cdot 10^{+121}:\\ \;\;\;\;b \cdot \frac{c}{{d}^{2}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.5 \cdot 10^{-158}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-106}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 1.52 \cdot 10^{+59}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (<= d -1.4e+121)
     (- (* b (/ c (pow d 2.0))) (/ a d))
     (if (<= d -1.5e-158)
       t_0
       (if (<= d 5.5e-106)
         (/ (- b (/ (* d a) c)) c)
         (if (<= d 1.52e+59) t_0 (/ (- (* c (/ b d)) a) d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.4e+121) {
		tmp = (b * (c / pow(d, 2.0))) - (a / d);
	} else if (d <= -1.5e-158) {
		tmp = t_0;
	} else if (d <= 5.5e-106) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 1.52e+59) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
    if (d <= (-1.4d+121)) then
        tmp = (b * (c / (d ** 2.0d0))) - (a / d)
    else if (d <= (-1.5d-158)) then
        tmp = t_0
    else if (d <= 5.5d-106) then
        tmp = (b - ((d * a) / c)) / c
    else if (d <= 1.52d+59) then
        tmp = t_0
    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 t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.4e+121) {
		tmp = (b * (c / Math.pow(d, 2.0))) - (a / d);
	} else if (d <= -1.5e-158) {
		tmp = t_0;
	} else if (d <= 5.5e-106) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 1.52e+59) {
		tmp = t_0;
	} else {
		tmp = ((c * (b / d)) - a) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -1.4e+121:
		tmp = (b * (c / math.pow(d, 2.0))) - (a / d)
	elif d <= -1.5e-158:
		tmp = t_0
	elif d <= 5.5e-106:
		tmp = (b - ((d * a) / c)) / c
	elif d <= 1.52e+59:
		tmp = t_0
	else:
		tmp = ((c * (b / d)) - a) / d
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -1.4e+121)
		tmp = Float64(Float64(b * Float64(c / (d ^ 2.0))) - Float64(a / d));
	elseif (d <= -1.5e-158)
		tmp = t_0;
	elseif (d <= 5.5e-106)
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c);
	elseif (d <= 1.52e+59)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d);
	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 (d <= -1.4e+121)
		tmp = (b * (c / (d ^ 2.0))) - (a / d);
	elseif (d <= -1.5e-158)
		tmp = t_0;
	elseif (d <= 5.5e-106)
		tmp = (b - ((d * a) / c)) / c;
	elseif (d <= 1.52e+59)
		tmp = t_0;
	else
		tmp = ((c * (b / d)) - a) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.4e+121], N[(N[(b * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.5e-158], t$95$0, If[LessEqual[d, 5.5e-106], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.52e+59], t$95$0, N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -1.4 \cdot 10^{+121}:\\
\;\;\;\;b \cdot \frac{c}{{d}^{2}} - \frac{a}{d}\\

\mathbf{elif}\;d \leq -1.5 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.52 \cdot 10^{+59}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 52.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.40000000000000003e121 < d < -1.5e-158 or 5.5000000000000001e-106 < d < 1.5199999999999999e59

    1. Initial program 78.2%

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

    if -1.5e-158 < d < 5.5000000000000001e-106

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5199999999999999e59 < d

    1. Initial program 40.6%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.4 \cdot 10^{+121}:\\ \;\;\;\;b \cdot \frac{c}{{d}^{2}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.5 \cdot 10^{-158}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-106}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 1.52 \cdot 10^{+59}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 83.4% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;d \leq -1.5 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.95 \cdot 10^{+64}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.5999999999999999e121 or 1.9499999999999999e64 < d

    1. Initial program 44.6%

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

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

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

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

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

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

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

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

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

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

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

    if -2.5999999999999999e121 < d < -1.5e-158 or 4.19999999999999997e-104 < d < 1.9499999999999999e64

    1. Initial program 78.2%

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

    if -1.5e-158 < d < 4.19999999999999997e-104

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.6 \cdot 10^{+121}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;d \leq -1.5 \cdot 10^{-158}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{-104}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{+64}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 77.2% accurate, 0.7× speedup?

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

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

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

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


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

    1. Initial program 60.1%

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

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

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

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

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

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

    if -1.56e-9 < c < 2.0500000000000002e38

    1. Initial program 74.9%

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

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

    if 2.0500000000000002e38 < c

    1. Initial program 45.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    8. Taylor expanded in b around inf 71.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.56 \cdot 10^{-9}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 2.05 \cdot 10^{+38}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \left(1 - a \cdot \frac{d}{c \cdot b}\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 77.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-7} \lor \neg \left(c \leq 9 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -6.1999999999999999e-7 or 9.00000000000000023e-6 < c

    1. Initial program 54.5%

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

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

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

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

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

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

    if -6.1999999999999999e-7 < c < 9.00000000000000023e-6

    1. Initial program 75.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 77.7% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.75 \cdot 10^{-9} \lor \neg \left(c \leq 3.2 \cdot 10^{+35}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.7499999999999998e-9 or 3.19999999999999983e35 < c

    1. Initial program 53.2%

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

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

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

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

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

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

    if -2.7499999999999998e-9 < c < 3.19999999999999983e35

    1. Initial program 74.9%

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

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

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

Alternative 11: 77.8% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 53.2%

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

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

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

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

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

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

    if -1.55000000000000014e-11 < c < 1.40000000000000004e34

    1. Initial program 74.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 72.9% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+66} \lor \neg \left(d \leq 1.25 \cdot 10^{+73}\right):\\
\;\;\;\;\frac{a}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.05000000000000003e66 or 1.24999999999999994e73 < d

    1. Initial program 50.3%

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

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

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

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

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

    if -1.05000000000000003e66 < d < 1.24999999999999994e73

    1. Initial program 74.5%

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

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

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

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

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

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

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

Alternative 13: 62.8% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{+66} \lor \neg \left(d \leq 2.15 \cdot 10^{-92}\right):\\
\;\;\;\;\frac{a}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.8e66 or 2.15000000000000007e-92 < d

    1. Initial program 56.8%

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

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

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

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

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

    if -1.8e66 < d < 2.15000000000000007e-92

    1. Initial program 73.4%

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

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

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

Alternative 14: 45.7% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.84999999999999998e123 or 6.5000000000000006e107 < d

    1. Initial program 44.9%

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

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

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

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

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt32.0%

        \[\leadsto \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{d} \]
      2. sqrt-unprod47.2%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}}{d} \]
      3. sqr-neg47.2%

        \[\leadsto \frac{\sqrt{\color{blue}{a \cdot a}}}{d} \]
      4. sqrt-unprod22.9%

        \[\leadsto \frac{\color{blue}{\sqrt{a} \cdot \sqrt{a}}}{d} \]
      5. add-sqr-sqrt35.6%

        \[\leadsto \frac{\color{blue}{a}}{d} \]
      6. *-un-lft-identity35.6%

        \[\leadsto \frac{\color{blue}{1 \cdot a}}{d} \]
    7. Applied egg-rr35.6%

      \[\leadsto \frac{\color{blue}{1 \cdot a}}{d} \]
    8. Step-by-step derivation
      1. *-lft-identity35.6%

        \[\leadsto \frac{\color{blue}{a}}{d} \]
    9. Simplified35.6%

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

    if -1.84999999999999998e123 < d < 6.5000000000000006e107

    1. Initial program 73.3%

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

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

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

Alternative 15: 10.9% accurate, 5.0× speedup?

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-a}{d}} \]
  6. Step-by-step derivation
    1. add-sqr-sqrt22.3%

      \[\leadsto \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{d} \]
    2. sqrt-unprod27.7%

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

      \[\leadsto \frac{\sqrt{\color{blue}{a \cdot a}}}{d} \]
    4. sqrt-unprod7.6%

      \[\leadsto \frac{\color{blue}{\sqrt{a} \cdot \sqrt{a}}}{d} \]
    5. add-sqr-sqrt12.7%

      \[\leadsto \frac{\color{blue}{a}}{d} \]
    6. *-un-lft-identity12.7%

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

    \[\leadsto \frac{\color{blue}{1 \cdot a}}{d} \]
  8. Step-by-step derivation
    1. *-lft-identity12.7%

      \[\leadsto \frac{\color{blue}{a}}{d} \]
  9. Simplified12.7%

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

Developer Target 1: 99.3% 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 2024130 
(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))))