Complex division, imag part

Percentage Accurate: 62.1% → 98.2%
Time: 14.6s
Alternatives: 12
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
    8. associate-/l*80.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-sqrt80.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. pow280.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-define80.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-rr80.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. Step-by-step derivation
    1. distribute-rgt-neg-in80.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 \left(-\frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)}\right) \]
    2. distribute-neg-frac80.6%

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \color{blue}{\frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right) \]
  6. Simplified80.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)} \]
  7. Step-by-step derivation
    1. neg-mul-180.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 89.6% 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)}\\ \mathbf{if}\;d \leq -2.4 \cdot 10^{+43}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, t\_1, \frac{a}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{elif}\;d \leq 7 \cdot 10^{+67}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{d}{-{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{-1}{d}\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))))
   (if (<= d -2.4e+43)
     (fma t_0 t_1 (/ a (hypot d c)))
     (if (<= d 7e+67)
       (fma t_0 t_1 (* a (/ d (- (pow (hypot c d) 2.0)))))
       (fma t_0 t_1 (* a (/ -1.0 d)))))))
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 tmp;
	if (d <= -2.4e+43) {
		tmp = fma(t_0, t_1, (a / hypot(d, c)));
	} else if (d <= 7e+67) {
		tmp = fma(t_0, t_1, (a * (d / -pow(hypot(c, d), 2.0))));
	} else {
		tmp = fma(t_0, t_1, (a * (-1.0 / d)));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(c / hypot(c, d))
	t_1 = Float64(b / hypot(c, d))
	tmp = 0.0
	if (d <= -2.4e+43)
		tmp = fma(t_0, t_1, Float64(a / hypot(d, c)));
	elseif (d <= 7e+67)
		tmp = fma(t_0, t_1, Float64(a * Float64(d / Float64(-(hypot(c, d) ^ 2.0)))));
	else
		tmp = fma(t_0, t_1, Float64(a * Float64(-1.0 / d)));
	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]}, If[LessEqual[d, -2.4e+43], N[(t$95$0 * t$95$1 + N[(a / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7e+67], 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], N[(t$95$0 * t$95$1 + N[(a * N[(-1.0 / d), $MachinePrecision]), $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)}\\
\mathbf{if}\;d \leq -2.4 \cdot 10^{+43}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_1, \frac{a}{\mathsf{hypot}\left(d, c\right)}\right)\\

\mathbf{elif}\;d \leq 7 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{d}{-{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\

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


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

    1. Initial program 46.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub46.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. *-commutative46.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-sqrt46.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-frac47.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-neg47.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-define47.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-define61.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.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-sqrt67.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. pow267.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-define67.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-rr67.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. Step-by-step derivation
      1. distribute-rgt-neg-in67.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 \left(-\frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)}\right) \]
      2. distribute-neg-frac67.0%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \color{blue}{\frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right) \]
    6. Simplified67.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)} \]
    7. Step-by-step derivation
      1. neg-mul-167.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.40000000000000023e43 < d < 7e67

    1. Initial program 77.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7e67 < d

    1. Initial program 50.1%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub50.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. *-commutative50.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-sqrt50.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-frac52.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-neg52.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-define52.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-define61.5%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*68.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-sqrt68.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. pow268.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-define68.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-rr68.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. Step-by-step derivation
      1. distribute-rgt-neg-in68.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 \left(-\frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)}\right) \]
      2. distribute-neg-frac68.0%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \color{blue}{\frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right) \]
    6. Simplified68.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)} \]
    7. Taylor expanded in d around inf 99.8%

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

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

Alternative 3: 88.9% accurate, 0.0× speedup?

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

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

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

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

    if 9.9999999999999998e284 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 13.0%

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

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

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

        \[\leadsto \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      4. times-frac16.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-neg16.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-define16.9%

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*61.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-sqrt61.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. pow261.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-define61.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-rr61.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. Step-by-step derivation
      1. distribute-rgt-neg-in61.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 \left(-\frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)}\right) \]
      2. distribute-neg-frac61.4%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \color{blue}{\frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right) \]
    6. Simplified61.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)} \]
    7. Taylor expanded in d around inf 71.5%

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

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

Alternative 4: 80.0% accurate, 0.0× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.4500000000000001e44 or 8.5000000000000004e66 < d

    1. Initial program 48.5%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*68.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-sqrt68.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. pow268.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-define68.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-rr68.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. Step-by-step derivation
      1. distribute-rgt-neg-in68.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 \left(-\frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)}\right) \]
      2. distribute-neg-frac68.0%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \color{blue}{\frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right) \]
    6. Simplified68.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)} \]
    7. Taylor expanded in d around inf 96.4%

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

    if -1.4500000000000001e44 < d < 2.50000000000000007e-140

    1. Initial program 76.1%

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

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

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

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

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

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

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

    if 2.50000000000000007e-140 < d < 8.5000000000000004e66

    1. Initial program 81.1%

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

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

Alternative 5: 77.1% accurate, 0.1× speedup?

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

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

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

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

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


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

    1. Initial program 47.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.4999999999999996e45 < d < 7.99999999999999932e-145

    1. Initial program 76.1%

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

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

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

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

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

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

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

    if 7.99999999999999932e-145 < d < 5.1000000000000002e67

    1. Initial program 81.1%

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

    if 5.1000000000000002e67 < d

    1. Initial program 50.1%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub50.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. *-commutative50.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-sqrt50.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-frac52.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-neg52.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-define52.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-define61.5%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*68.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-sqrt68.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. pow268.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-define68.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-rr68.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. Step-by-step derivation
      1. distribute-rgt-neg-in68.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 \left(-\frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)}\right) \]
      2. distribute-neg-frac68.0%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \color{blue}{\frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}}\right) \]
    6. Simplified68.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)} \]
    7. Taylor expanded in d around inf 99.8%

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

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

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

Alternative 6: 76.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -1.65 \cdot 10^{+44}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 7.4 \cdot 10^{-143}:\\ \;\;\;\;\frac{b}{c} - a \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 7 \cdot 10^{+67}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (- (* (/ c d) (/ b d)) (/ a d))))
   (if (<= d -1.65e+44)
     t_0
     (if (<= d 7.4e-143)
       (- (/ b c) (* a (/ d (pow c 2.0))))
       (if (<= d 7e+67) (/ (- (* c b) (* d a)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -1.65e+44) {
		tmp = t_0;
	} else if (d <= 7.4e-143) {
		tmp = (b / c) - (a * (d / pow(c, 2.0)));
	} else if (d <= 7e+67) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((c / d) * (b / d)) - (a / d)
    if (d <= (-1.65d+44)) then
        tmp = t_0
    else if (d <= 7.4d-143) then
        tmp = (b / c) - (a * (d / (c ** 2.0d0)))
    else if (d <= 7d+67) then
        tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -1.65e+44) {
		tmp = t_0;
	} else if (d <= 7.4e-143) {
		tmp = (b / c) - (a * (d / Math.pow(c, 2.0)));
	} else if (d <= 7e+67) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c / d) * (b / d)) - (a / d)
	tmp = 0
	if d <= -1.65e+44:
		tmp = t_0
	elif d <= 7.4e-143:
		tmp = (b / c) - (a * (d / math.pow(c, 2.0)))
	elif d <= 7e+67:
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d))
	tmp = 0.0
	if (d <= -1.65e+44)
		tmp = t_0;
	elseif (d <= 7.4e-143)
		tmp = Float64(Float64(b / c) - Float64(a * Float64(d / (c ^ 2.0))));
	elseif (d <= 7e+67)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c / d) * (b / d)) - (a / d);
	tmp = 0.0;
	if (d <= -1.65e+44)
		tmp = t_0;
	elseif (d <= 7.4e-143)
		tmp = (b / c) - (a * (d / (c ^ 2.0)));
	elseif (d <= 7e+67)
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.65e+44], t$95$0, If[LessEqual[d, 7.4e-143], N[(N[(b / c), $MachinePrecision] - N[(a * N[(d / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7e+67], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\
\mathbf{if}\;d \leq -1.65 \cdot 10^{+44}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.65000000000000007e44 or 7e67 < d

    1. Initial program 48.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{b \cdot \frac{1}{d}}{\frac{d}{c}}} - \frac{a}{d} \]
      4. un-div-inv88.7%

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

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

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

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

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

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

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

    if -1.65000000000000007e44 < d < 7.4000000000000001e-143

    1. Initial program 76.1%

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

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

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

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

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

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

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

    if 7.4000000000000001e-143 < d < 7e67

    1. Initial program 81.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.65 \cdot 10^{+44}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 7.4 \cdot 10^{-143}:\\ \;\;\;\;\frac{b}{c} - a \cdot \frac{d}{{c}^{2}}\\ \mathbf{elif}\;d \leq 7 \cdot 10^{+67}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.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}\\ t_1 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -2.05 \cdot 10^{+94}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -1.2 \cdot 10^{-193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 8.5 \cdot 10^{-163}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+67}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
        (t_1 (- (* (/ c d) (/ b d)) (/ a d))))
   (if (<= d -2.05e+94)
     t_1
     (if (<= d -1.2e-193)
       t_0
       (if (<= d 8.5e-163) (/ b c) (if (<= d 6.5e+67) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double t_1 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -2.05e+94) {
		tmp = t_1;
	} else if (d <= -1.2e-193) {
		tmp = t_0;
	} else if (d <= 8.5e-163) {
		tmp = b / c;
	} else if (d <= 6.5e+67) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
    t_1 = ((c / d) * (b / d)) - (a / d)
    if (d <= (-2.05d+94)) then
        tmp = t_1
    else if (d <= (-1.2d-193)) then
        tmp = t_0
    else if (d <= 8.5d-163) then
        tmp = b / c
    else if (d <= 6.5d+67) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double t_1 = ((c / d) * (b / d)) - (a / d);
	double tmp;
	if (d <= -2.05e+94) {
		tmp = t_1;
	} else if (d <= -1.2e-193) {
		tmp = t_0;
	} else if (d <= 8.5e-163) {
		tmp = b / c;
	} else if (d <= 6.5e+67) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	t_1 = ((c / d) * (b / d)) - (a / d)
	tmp = 0
	if d <= -2.05e+94:
		tmp = t_1
	elif d <= -1.2e-193:
		tmp = t_0
	elif d <= 8.5e-163:
		tmp = b / c
	elif d <= 6.5e+67:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d))
	tmp = 0.0
	if (d <= -2.05e+94)
		tmp = t_1;
	elseif (d <= -1.2e-193)
		tmp = t_0;
	elseif (d <= 8.5e-163)
		tmp = Float64(b / c);
	elseif (d <= 6.5e+67)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	t_1 = ((c / d) * (b / d)) - (a / d);
	tmp = 0.0;
	if (d <= -2.05e+94)
		tmp = t_1;
	elseif (d <= -1.2e-193)
		tmp = t_0;
	elseif (d <= 8.5e-163)
		tmp = b / c;
	elseif (d <= 6.5e+67)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.05e+94], t$95$1, If[LessEqual[d, -1.2e-193], t$95$0, If[LessEqual[d, 8.5e-163], N[(b / c), $MachinePrecision], If[LessEqual[d, 6.5e+67], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;d \leq 6.5 \cdot 10^{+67}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.05000000000000015e94 or 6.4999999999999995e67 < d

    1. Initial program 46.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(b \cdot \frac{1}{d}\right) \cdot \color{blue}{\frac{1}{\frac{d}{c}}} - \frac{a}{d} \]
      3. un-div-inv89.9%

        \[\leadsto \color{blue}{\frac{b \cdot \frac{1}{d}}{\frac{d}{c}}} - \frac{a}{d} \]
      4. un-div-inv89.9%

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{d}{c}} \cdot \frac{b}{d}} - \frac{a}{d} \]
      4. clear-num90.0%

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

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

    if -2.05000000000000015e94 < d < -1.2e-193 or 8.5e-163 < d < 6.4999999999999995e67

    1. Initial program 81.3%

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

    if -1.2e-193 < d < 8.5e-163

    1. Initial program 72.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.05 \cdot 10^{+94}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.2 \cdot 10^{-193}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 8.5 \cdot 10^{-163}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 71.9% accurate, 0.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.09999999999999988e143 or 4.29999999999999991e58 < c

    1. Initial program 39.3%

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

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

    if -2.09999999999999988e143 < c < -2.29999999999999984e-30

    1. Initial program 78.7%

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

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

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

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

    if -2.29999999999999984e-30 < c < 4.29999999999999991e58

    1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.1 \cdot 10^{+143}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -2.3 \cdot 10^{-30}:\\ \;\;\;\;\frac{c \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{+58}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d}}{d} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 69.2% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.15 \cdot 10^{+26} \lor \neg \left(d \leq 6.5 \cdot 10^{-39}\right):\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.1499999999999999e26 or 6.50000000000000027e-39 < d

    1. Initial program 53.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(b \cdot \frac{1}{d}\right) \cdot \color{blue}{\frac{1}{\frac{d}{c}}} - \frac{a}{d} \]
      3. un-div-inv81.9%

        \[\leadsto \color{blue}{\frac{b \cdot \frac{1}{d}}{\frac{d}{c}}} - \frac{a}{d} \]
      4. un-div-inv81.9%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{c}{d}} \cdot \frac{b}{d} - \frac{a}{d} \]
    11. Applied egg-rr82.3%

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

    if -2.1499999999999999e26 < d < 6.50000000000000027e-39

    1. Initial program 76.0%

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

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

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

Alternative 10: 70.9% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.2 \cdot 10^{-31} \lor \neg \left(c \leq 4.2 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -7.20000000000000007e-31 or 4.19999999999999982e57 < c

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

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

    if -7.20000000000000007e-31 < c < 4.19999999999999982e57

    1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 62.4% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.5000000000000001e101 or 4.60000000000000005e58 < d

    1. Initial program 47.9%

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

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

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

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

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

    if -8.5000000000000001e101 < d < 4.60000000000000005e58

    1. Initial program 76.0%

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

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

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

Alternative 12: 43.2% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  4. Final simplification44.9%

    \[\leadsto \frac{b}{c} \]
  5. Add Preprocessing

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

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

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