Complex division, imag part

Percentage Accurate: 61.3% → 92.4%
Time: 10.2s
Alternatives: 13
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 13 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: 61.3% 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: 92.4% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ t_2 := \mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\ \mathbf{if}\;d \leq -1.55 \cdot 10^{+140}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, t\_1, \frac{a}{-d}\right)\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{-124}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-168}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+155}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ c (hypot c d)))
        (t_1 (/ b (hypot c d)))
        (t_2 (fma t_0 t_1 (* a (/ (- d) (pow (hypot c d) 2.0))))))
   (if (<= d -1.55e+140)
     (fma t_0 t_1 (/ a (- d)))
     (if (<= d -7.5e-124)
       t_2
       (if (<= d 9.5e-168)
         (/ (- b (/ (* d a) c)) c)
         (if (<= d 1.02e+155)
           t_2
           (* (/ 1.0 (+ d (* 0.5 (* c (/ c d))))) (- (* b (/ c d)) a))))))))
double code(double a, double b, double c, double d) {
	double t_0 = c / hypot(c, d);
	double t_1 = b / hypot(c, d);
	double t_2 = fma(t_0, t_1, (a * (-d / pow(hypot(c, d), 2.0))));
	double tmp;
	if (d <= -1.55e+140) {
		tmp = fma(t_0, t_1, (a / -d));
	} else if (d <= -7.5e-124) {
		tmp = t_2;
	} else if (d <= 9.5e-168) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 1.02e+155) {
		tmp = t_2;
	} else {
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(c / hypot(c, d))
	t_1 = Float64(b / hypot(c, d))
	t_2 = fma(t_0, t_1, Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0))))
	tmp = 0.0
	if (d <= -1.55e+140)
		tmp = fma(t_0, t_1, Float64(a / Float64(-d)));
	elseif (d <= -7.5e-124)
		tmp = t_2;
	elseif (d <= 9.5e-168)
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c);
	elseif (d <= 1.02e+155)
		tmp = t_2;
	else
		tmp = Float64(Float64(1.0 / Float64(d + Float64(0.5 * Float64(c * Float64(c / d))))) * Float64(Float64(b * Float64(c / d)) - a));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * t$95$1 + N[(a * N[((-d) / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.55e+140], N[(t$95$0 * t$95$1 + N[(a / (-d)), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -7.5e-124], t$95$2, If[LessEqual[d, 9.5e-168], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 1.02e+155], t$95$2, N[(N[(1.0 / N[(d + N[(0.5 * N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -7.5 \cdot 10^{-124}:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;d \leq 1.02 \cdot 10^{+155}:\\
\;\;\;\;t\_2\\

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


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

    1. Initial program 28.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub28.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. *-commutative28.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-sqrt28.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-frac28.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-neg28.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-define28.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-define41.4%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
    5. Taylor expanded in d around inf 100.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 -1.55e140 < d < -7.4999999999999996e-124 or 9.49999999999999918e-168 < d < 1.02e155

    1. Initial program 75.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub75.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. *-commutative75.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-sqrt75.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-frac79.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-neg79.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-define79.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-define92.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*95.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-sqrt95.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. pow295.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-define95.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-rr95.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)} \]

    if -7.4999999999999996e-124 < d < 9.49999999999999918e-168

    1. Initial program 61.4%

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

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

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

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

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

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

    if 1.02e155 < d

    1. Initial program 19.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-identity19.6%

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

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

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

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

      \[\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 c around 0 78.0%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{d + 0.5 \cdot \frac{{c}^{2}}{d}}} \cdot \left(b \cdot \frac{c}{d} - a\right) \]
    9. Step-by-step derivation
      1. unpow276.8%

        \[\leadsto \frac{1}{d + 0.5 \cdot \frac{\color{blue}{c \cdot c}}{d}} \cdot \left(b \cdot \frac{c}{d} - a\right) \]
      2. *-un-lft-identity76.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+140}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{a}{-d}\right)\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{-124}:\\ \;\;\;\;\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)\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-168}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 1.02 \cdot 10^{+155}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 88.0% 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 10^{+206}:\\ \;\;\;\;\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))) 1e+206)
     (* (/ 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))) <= 1e+206) {
		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))) <= 1e+206)
		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], 1e+206], 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 10^{+206}:\\
\;\;\;\;\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))) < 1e206

    1. Initial program 75.5%

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. 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 1e206 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 15.4%

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

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

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

        \[\leadsto \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      4. times-frac18.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-neg18.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-define18.6%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d} \leq 10^{+206}:\\ \;\;\;\;\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: 86.7% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -4.5 \cdot 10^{-163}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.7 \cdot 10^{+55}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot t\_1\\


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

    1. Initial program 30.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub30.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. *-commutative30.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-sqrt30.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-frac32.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-neg32.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-define32.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-define44.4%

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

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

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

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

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

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

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

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

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

    if -2.7999999999999998e100 < d < -4.4999999999999997e-163 or 7.99999999999999987e-170 < d < 4.7000000000000001e55

    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. *-un-lft-identity74.9%

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

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac75.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-define75.0%

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

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

      \[\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.4999999999999997e-163 < d < 7.99999999999999987e-170

    1. Initial program 62.3%

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

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

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

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

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

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

    if 4.7000000000000001e55 < d

    1. Initial program 40.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-identity40.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt40.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-frac40.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-define40.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-define57.6%

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

      \[\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 c around 0 77.9%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d + 0.5 \cdot \frac{\color{blue}{c \cdot c}}{d}} \cdot \left(b \cdot \frac{c}{d} - a\right) \]
      2. *-un-lft-identity78.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.8 \cdot 10^{+100}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;d \leq -4.5 \cdot 10^{-163}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{-170}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 4.7 \cdot 10^{+55}:\\ \;\;\;\;\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{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 83.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot b - d \cdot a\\ \mathbf{if}\;d \leq -6.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;d \leq -1.1 \cdot 10^{-115}:\\ \;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{-148}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 7.7 \cdot 10^{+105}:\\ \;\;\;\;t\_0 \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (- (* c b) (* d a))))
   (if (<= d -6.2e+86)
     (/ (- (/ c (/ d b)) a) d)
     (if (<= d -1.1e-115)
       (/ t_0 (+ (* c c) (* d d)))
       (if (<= d 8.4e-148)
         (/ (- b (/ (* d a) c)) c)
         (if (<= d 7.7e+105)
           (* t_0 (/ 1.0 (pow (hypot c d) 2.0)))
           (* (/ 1.0 (+ d (* 0.5 (* c (/ c d))))) (- (* b (/ c d)) a))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * b) - (d * a);
	double tmp;
	if (d <= -6.2e+86) {
		tmp = ((c / (d / b)) - a) / d;
	} else if (d <= -1.1e-115) {
		tmp = t_0 / ((c * c) + (d * d));
	} else if (d <= 8.4e-148) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 7.7e+105) {
		tmp = t_0 * (1.0 / pow(hypot(c, d), 2.0));
	} else {
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (c * b) - (d * a);
	double tmp;
	if (d <= -6.2e+86) {
		tmp = ((c / (d / b)) - a) / d;
	} else if (d <= -1.1e-115) {
		tmp = t_0 / ((c * c) + (d * d));
	} else if (d <= 8.4e-148) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 7.7e+105) {
		tmp = t_0 * (1.0 / Math.pow(Math.hypot(c, d), 2.0));
	} else {
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (c * b) - (d * a)
	tmp = 0
	if d <= -6.2e+86:
		tmp = ((c / (d / b)) - a) / d
	elif d <= -1.1e-115:
		tmp = t_0 / ((c * c) + (d * d))
	elif d <= 8.4e-148:
		tmp = (b - ((d * a) / c)) / c
	elif d <= 7.7e+105:
		tmp = t_0 * (1.0 / math.pow(math.hypot(c, d), 2.0))
	else:
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(c * b) - Float64(d * a))
	tmp = 0.0
	if (d <= -6.2e+86)
		tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d);
	elseif (d <= -1.1e-115)
		tmp = Float64(t_0 / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 8.4e-148)
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c);
	elseif (d <= 7.7e+105)
		tmp = Float64(t_0 * Float64(1.0 / (hypot(c, d) ^ 2.0)));
	else
		tmp = Float64(Float64(1.0 / Float64(d + Float64(0.5 * Float64(c * Float64(c / d))))) * Float64(Float64(b * Float64(c / d)) - a));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (c * b) - (d * a);
	tmp = 0.0;
	if (d <= -6.2e+86)
		tmp = ((c / (d / b)) - a) / d;
	elseif (d <= -1.1e-115)
		tmp = t_0 / ((c * c) + (d * d));
	elseif (d <= 8.4e-148)
		tmp = (b - ((d * a) / c)) / c;
	elseif (d <= 7.7e+105)
		tmp = t_0 * (1.0 / (hypot(c, d) ^ 2.0));
	else
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a);
	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[d, -6.2e+86], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -1.1e-115], N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 8.4e-148], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.7e+105], N[(t$95$0 * N[(1.0 / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(d + N[(0.5 * N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1.1 \cdot 10^{-115}:\\
\;\;\;\;\frac{t\_0}{c \cdot c + d \cdot d}\\

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

\mathbf{elif}\;d \leq 7.7 \cdot 10^{+105}:\\
\;\;\;\;t\_0 \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\

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


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

    1. Initial program 32.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.2000000000000004e86 < d < -1.1e-115

    1. Initial program 82.1%

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

    if -1.1e-115 < d < 8.4000000000000001e-148

    1. Initial program 61.5%

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

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

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

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

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

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

    if 8.4000000000000001e-148 < d < 7.70000000000000011e105

    1. Initial program 79.1%

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

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

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

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

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

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

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

    if 7.70000000000000011e105 < d

    1. Initial program 31.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-identity31.6%

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

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

        \[\leadsto \frac{1}{\color{blue}{\mathsf{hypot}\left(c, d\right)}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \]
      5. hypot-define51.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-rr51.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)}} \]
    5. Taylor expanded in c around 0 76.6%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{d + 0.5 \cdot \frac{{c}^{2}}{d}}} \cdot \left(b \cdot \frac{c}{d} - a\right) \]
    9. Step-by-step derivation
      1. unpow275.8%

        \[\leadsto \frac{1}{d + 0.5 \cdot \frac{\color{blue}{c \cdot c}}{d}} \cdot \left(b \cdot \frac{c}{d} - a\right) \]
      2. *-un-lft-identity75.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;d \leq -1.1 \cdot 10^{-115}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 8.4 \cdot 10^{-148}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 7.7 \cdot 10^{+105}:\\ \;\;\;\;\left(c \cdot b - d \cdot a\right) \cdot \frac{1}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 83.7% 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}\\ \mathbf{if}\;d \leq -7.5 \cdot 10^{+80}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;d \leq -4.5 \cdot 10^{-120}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 9.2 \cdot 10^{-142}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+55}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (<= d -7.5e+80)
     (/ (- (/ c (/ d b)) a) d)
     (if (<= d -4.5e-120)
       t_0
       (if (<= d 9.2e-142)
         (/ (- b (/ (* d a) c)) c)
         (if (<= d 4.5e+55)
           t_0
           (* (/ 1.0 (+ d (* 0.5 (* c (/ c d))))) (- (* b (/ c d)) a))))))))
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 <= -7.5e+80) {
		tmp = ((c / (d / b)) - a) / d;
	} else if (d <= -4.5e-120) {
		tmp = t_0;
	} else if (d <= 9.2e-142) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 4.5e+55) {
		tmp = t_0;
	} else {
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a);
	}
	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 <= (-7.5d+80)) then
        tmp = ((c / (d / b)) - a) / d
    else if (d <= (-4.5d-120)) then
        tmp = t_0
    else if (d <= 9.2d-142) then
        tmp = (b - ((d * a) / c)) / c
    else if (d <= 4.5d+55) then
        tmp = t_0
    else
        tmp = (1.0d0 / (d + (0.5d0 * (c * (c / d))))) * ((b * (c / d)) - a)
    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 <= -7.5e+80) {
		tmp = ((c / (d / b)) - a) / d;
	} else if (d <= -4.5e-120) {
		tmp = t_0;
	} else if (d <= 9.2e-142) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 4.5e+55) {
		tmp = t_0;
	} else {
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -7.5e+80:
		tmp = ((c / (d / b)) - a) / d
	elif d <= -4.5e-120:
		tmp = t_0
	elif d <= 9.2e-142:
		tmp = (b - ((d * a) / c)) / c
	elif d <= 4.5e+55:
		tmp = t_0
	else:
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a)
	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 <= -7.5e+80)
		tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d);
	elseif (d <= -4.5e-120)
		tmp = t_0;
	elseif (d <= 9.2e-142)
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c);
	elseif (d <= 4.5e+55)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / Float64(d + Float64(0.5 * Float64(c * Float64(c / d))))) * Float64(Float64(b * Float64(c / d)) - a));
	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 <= -7.5e+80)
		tmp = ((c / (d / b)) - a) / d;
	elseif (d <= -4.5e-120)
		tmp = t_0;
	elseif (d <= 9.2e-142)
		tmp = (b - ((d * a) / c)) / c;
	elseif (d <= 4.5e+55)
		tmp = t_0;
	else
		tmp = (1.0 / (d + (0.5 * (c * (c / d))))) * ((b * (c / d)) - a);
	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, -7.5e+80], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -4.5e-120], t$95$0, If[LessEqual[d, 9.2e-142], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 4.5e+55], t$95$0, N[(N[(1.0 / N[(d + N[(0.5 * N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -4.5 \cdot 10^{-120}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{+55}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 32.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.49999999999999994e80 < d < -4.5e-120 or 9.20000000000000009e-142 < d < 4.49999999999999998e55

    1. Initial program 78.8%

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

    if -4.5e-120 < d < 9.20000000000000009e-142

    1. Initial program 61.5%

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

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

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

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

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

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

    if 4.49999999999999998e55 < d

    1. Initial program 40.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-identity40.6%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt40.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-frac40.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-define40.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-define57.6%

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

      \[\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 c around 0 77.9%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{d + 0.5 \cdot \frac{\color{blue}{c \cdot c}}{d}} \cdot \left(b \cdot \frac{c}{d} - a\right) \]
      2. *-un-lft-identity78.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{+80}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;d \leq -4.5 \cdot 10^{-120}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 9.2 \cdot 10^{-142}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+55}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d + 0.5 \cdot \left(c \cdot \frac{c}{d}\right)} \cdot \left(b \cdot \frac{c}{d} - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 83.0% 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}\\ \mathbf{if}\;d \leq -1.22 \cdot 10^{+82}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;d \leq -4.5 \cdot 10^{-122}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{-145}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+143}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{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.22e+82)
     (/ (- (/ c (/ d b)) a) d)
     (if (<= d -4.5e-122)
       t_0
       (if (<= d 2.5e-145)
         (/ (- b (/ (* d a) c)) c)
         (if (<= d 2.1e+143) t_0 (/ (- (* b (/ c 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.22e+82) {
		tmp = ((c / (d / b)) - a) / d;
	} else if (d <= -4.5e-122) {
		tmp = t_0;
	} else if (d <= 2.5e-145) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 2.1e+143) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
    if (d <= (-1.22d+82)) then
        tmp = ((c / (d / b)) - a) / d
    else if (d <= (-4.5d-122)) then
        tmp = t_0
    else if (d <= 2.5d-145) then
        tmp = (b - ((d * a) / c)) / c
    else if (d <= 2.1d+143) then
        tmp = t_0
    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 t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -1.22e+82) {
		tmp = ((c / (d / b)) - a) / d;
	} else if (d <= -4.5e-122) {
		tmp = t_0;
	} else if (d <= 2.5e-145) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (d <= 2.1e+143) {
		tmp = t_0;
	} else {
		tmp = ((b * (c / 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.22e+82:
		tmp = ((c / (d / b)) - a) / d
	elif d <= -4.5e-122:
		tmp = t_0
	elif d <= 2.5e-145:
		tmp = (b - ((d * a) / c)) / c
	elif d <= 2.1e+143:
		tmp = t_0
	else:
		tmp = ((b * (c / 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.22e+82)
		tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / d);
	elseif (d <= -4.5e-122)
		tmp = t_0;
	elseif (d <= 2.5e-145)
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c);
	elseif (d <= 2.1e+143)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(b * Float64(c / 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.22e+82)
		tmp = ((c / (d / b)) - a) / d;
	elseif (d <= -4.5e-122)
		tmp = t_0;
	elseif (d <= 2.5e-145)
		tmp = (b - ((d * a) / c)) / c;
	elseif (d <= 2.1e+143)
		tmp = t_0;
	else
		tmp = ((b * (c / 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.22e+82], N[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -4.5e-122], t$95$0, If[LessEqual[d, 2.5e-145], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.1e+143], t$95$0, N[(N[(N[(b * N[(c / 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.22 \cdot 10^{+82}:\\
\;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\

\mathbf{elif}\;d \leq -4.5 \cdot 10^{-122}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.1 \cdot 10^{+143}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 32.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.22000000000000008e82 < d < -4.4999999999999998e-122 or 2.4999999999999999e-145 < d < 2.09999999999999988e143

    1. Initial program 79.7%

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

    if -4.4999999999999998e-122 < d < 2.4999999999999999e-145

    1. Initial program 61.5%

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

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

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

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

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

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

    if 2.09999999999999988e143 < d

    1. Initial program 24.5%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.22 \cdot 10^{+82}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \mathbf{elif}\;d \leq -4.5 \cdot 10^{-122}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.5 \cdot 10^{-145}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+143}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 77.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+89} \lor \neg \left(c \leq 2400000000000\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 -7.5e+89) (not (<= c 2400000000000.0)))
   (/ (- b (* a (/ d c))) c)
   (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -7.5e+89) || !(c <= 2400000000000.0)) {
		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 <= (-7.5d+89)) .or. (.not. (c <= 2400000000000.0d0))) 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 <= -7.5e+89) || !(c <= 2400000000000.0)) {
		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 <= -7.5e+89) or not (c <= 2400000000000.0):
		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 <= -7.5e+89) || !(c <= 2400000000000.0))
		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 <= -7.5e+89) || ~((c <= 2400000000000.0)))
		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, -7.5e+89], N[Not[LessEqual[c, 2400000000000.0]], $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 -7.5 \cdot 10^{+89} \lor \neg \left(c \leq 2400000000000\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 < -7.49999999999999947e89 or 2.4e12 < c

    1. Initial program 47.1%

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

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

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

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

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

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

    if -7.49999999999999947e89 < c < 2.4e12

    1. Initial program 63.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+89} \lor \neg \left(c \leq 2400000000000\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 8: 73.3% accurate, 0.8× speedup?

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

    1. Initial program 43.8%

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

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

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

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

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

    if -5.20000000000000013e35 < d < 4.2e21

    1. Initial program 68.2%

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

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

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

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

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

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

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

Alternative 9: 76.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+89}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{elif}\;c \leq 440000000000:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -7.5e+89)
   (/ (- b (/ (* d a) c)) c)
   (if (<= c 440000000000.0)
     (/ (- (* b (/ c d)) a) d)
     (/ (- b (* a (/ d c))) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -7.5e+89) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (c <= 440000000000.0) {
		tmp = ((b * (c / d)) - 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 (c <= (-7.5d+89)) then
        tmp = (b - ((d * a) / c)) / c
    else if (c <= 440000000000.0d0) then
        tmp = ((b * (c / d)) - 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 (c <= -7.5e+89) {
		tmp = (b - ((d * a) / c)) / c;
	} else if (c <= 440000000000.0) {
		tmp = ((b * (c / d)) - a) / d;
	} else {
		tmp = (b - (a * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -7.5e+89:
		tmp = (b - ((d * a) / c)) / c
	elif c <= 440000000000.0:
		tmp = ((b * (c / d)) - a) / d
	else:
		tmp = (b - (a * (d / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -7.5e+89)
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c);
	elseif (c <= 440000000000.0)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / 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 (c <= -7.5e+89)
		tmp = (b - ((d * a) / c)) / c;
	elseif (c <= 440000000000.0)
		tmp = ((b * (c / d)) - a) / d;
	else
		tmp = (b - (a * (d / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -7.5e+89], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 440000000000.0], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -7.49999999999999947e89

    1. Initial program 34.9%

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

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

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

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

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

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

    if -7.49999999999999947e89 < c < 4.4e11

    1. Initial program 63.7%

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

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

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

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

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

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

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

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

    if 4.4e11 < c

    1. Initial program 55.3%

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

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

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

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

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

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

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

Alternative 10: 63.4% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.5000000000000002e111 or 3.1e5 < c

    1. Initial program 46.5%

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

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

    if -3.5000000000000002e111 < c < 3.1e5

    1. Initial program 63.7%

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

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

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

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

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

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

Alternative 11: 44.4% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.5 \cdot 10^{+152}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d) :precision binary64 (if (<= d -5.5e+152) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -5.5e+152) {
		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 <= (-5.5d+152)) 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 <= -5.5e+152) {
		tmp = a / d;
	} else {
		tmp = b / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -5.5e+152:
		tmp = a / d
	else:
		tmp = b / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -5.5e+152)
		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 <= -5.5e+152)
		tmp = a / d;
	else
		tmp = b / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -5.5e+152], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.5 \cdot 10^{+152}:\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5.4999999999999999e152

    1. Initial program 28.7%

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

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

        \[\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-frac28.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-define28.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-define53.7%

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

      \[\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 c around 0 29.3%

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

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

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

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

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

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

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

    if -5.4999999999999999e152 < d

    1. Initial program 61.6%

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

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

Alternative 12: 12.1% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq 1.45 \cdot 10^{+89}:\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < 1.45000000000000013e89

    1. Initial program 59.3%

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

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

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

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

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

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

      \[\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 c around 0 37.3%

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

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

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

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

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

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

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

    if 1.45000000000000013e89 < c

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

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

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

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

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

      \[\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 c around -inf 23.1%

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

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

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

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

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

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

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

Alternative 13: 9.9% accurate, 5.0× speedup?

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

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 56.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-identity56.8%

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

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

      \[\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-define72.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-rr72.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)}} \]
  5. Taylor expanded in c around -inf 27.7%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  9. Add Preprocessing

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

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

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

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024146 
(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))))