Complex division, imag part

Percentage Accurate: 61.4% → 96.0%
Time: 9.4s
Alternatives: 11
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 11 alternatives:

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

Initial Program: 61.4% accurate, 1.0× speedup?

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

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

Alternative 1: 96.0% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{\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(a * Float64(Float64(d / hypot(d, c)) / Float64(-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[(a * N[(N[(d / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision])), $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)}, a \cdot \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{-\mathsf{hypot}\left(d, c\right)}\right)
\end{array}
Derivation
  1. Initial program 65.3%

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

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

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

      \[\leadsto \frac{c \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
    4. times-frac65.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-neg65.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-define65.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-define78.1%

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

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

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

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

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

    \[\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. *-un-lft-identity79.7%

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

      \[\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-frac95.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}{\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)}\right) \]
  6. Applied egg-rr95.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}{\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)}\right) \]
  7. Step-by-step derivation
    1. associate-*l/95.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 \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}\right) \]
    2. *-lft-identity95.5%

      \[\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}{\frac{d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}\right) \]
    3. hypot-undefine79.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\right) \]
  8. Simplified95.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{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}}\right) \]
  9. Final simplification95.5%

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

Alternative 2: 89.4% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;d \leq -2 \cdot 10^{+17}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{--1}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \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 -2e+17)
     (fma t_0 t_1 (* a (/ (- -1.0) (hypot d c))))
     (if (<= d 1.35e+154)
       (fma t_0 t_1 (* a (/ (- d) (pow (hypot c d) 2.0))))
       (/ (- (/ c (/ d b)) a) 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 <= -2e+17) {
		tmp = fma(t_0, t_1, (a * (-(-1.0) / hypot(d, c))));
	} else if (d <= 1.35e+154) {
		tmp = fma(t_0, t_1, (a * (-d / pow(hypot(c, d), 2.0))));
	} else {
		tmp = ((c / (d / b)) - a) / 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 <= -2e+17)
		tmp = fma(t_0, t_1, Float64(a * Float64(Float64(-(-1.0)) / hypot(d, c))));
	elseif (d <= 1.35e+154)
		tmp = fma(t_0, t_1, Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0))));
	else
		tmp = Float64(Float64(Float64(c / Float64(d / b)) - a) / 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, -2e+17], N[(t$95$0 * t$95$1 + N[(a * N[((--1.0) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.35e+154], 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[(N[(N[(c / N[(d / b), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $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 \cdot 10^{+17}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, t\_1, a \cdot \frac{--1}{\mathsf{hypot}\left(d, c\right)}\right)\\

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

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


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

    1. Initial program 44.7%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub44.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. *-commutative44.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-sqrt44.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-frac45.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-neg45.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-define45.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-define59.1%

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

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

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

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

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

      \[\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. *-un-lft-identity61.9%

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

        \[\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-frac91.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}{\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)}\right) \]
    6. Applied egg-rr91.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}{\left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\right)}\right) \]
    7. Step-by-step derivation
      1. associate-*l/91.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 \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}\right) \]
      2. *-lft-identity91.4%

        \[\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}{\frac{d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}\right) \]
      3. hypot-undefine62.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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}}{\mathsf{hypot}\left(d, c\right)}\right) \]

    if -2e17 < d < 1.35000000000000003e154

    1. Initial program 77.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub74.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. *-commutative74.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-sqrt74.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-frac76.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-neg76.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-define76.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-define90.4%

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

    if 1.35000000000000003e154 < d

    1. Initial program 31.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 83.0% accurate, 0.0× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.85000000000000004e-25

    1. Initial program 50.5%

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

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

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

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

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

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

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

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

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

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

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

        \[\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-frac92.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) \]
    6. Applied egg-rr92.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) \]
    7. Step-by-step derivation
      1. associate-*l/92.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 \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}}\right) \]
      2. *-lft-identity92.8%

        \[\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}{\frac{d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}\right) \]
      3. hypot-undefine68.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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}}{\mathsf{hypot}\left(d, c\right)}\right) \]

    if -1.85000000000000004e-25 < d < 1.7500000000000001e-62

    1. Initial program 75.5%

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

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

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

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

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

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

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

    if 1.7500000000000001e-62 < d < 5.4999999999999998e47

    1. Initial program 95.2%

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

    if 5.4999999999999998e47 < d

    1. Initial program 42.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 81.9% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;d \leq -5.1 \cdot 10^{-117}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.45 \cdot 10^{+47}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 38.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.19999999999999973e35 < d < -5.1000000000000002e-117 or 2.20000000000000009e-61 < d < 1.4499999999999999e47

    1. Initial program 90.6%

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

    if -5.1000000000000002e-117 < d < 2.20000000000000009e-61

    1. Initial program 73.9%

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

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

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

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

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

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

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

    if 1.4499999999999999e47 < d

    1. Initial program 42.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.2 \cdot 10^{+35}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -5.1 \cdot 10^{-117}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{-61}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{+47}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{\frac{d}{b}} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.35 \cdot 10^{-14} \lor \neg \left(d \leq 3.1 \cdot 10^{-52}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.3500000000000001e-14 or 3.0999999999999999e-52 < d

    1. Initial program 55.6%

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

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

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

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

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

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

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

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

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

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

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

    if -2.3500000000000001e-14 < d < 3.0999999999999999e-52

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 73.1% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{+32} \lor \neg \left(d \leq 8200000000\right):\\
\;\;\;\;\frac{a}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.09999999999999993e32 or 8.2e9 < d

    1. Initial program 45.5%

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

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

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

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

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

    if -3.09999999999999993e32 < d < 8.2e9

    1. Initial program 78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.3% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.14999999999999999e-14

    1. Initial program 48.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.14999999999999999e-14 < d < 3.1500000000000002e-52

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.1500000000000002e-52 < d

    1. Initial program 60.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 78.3% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.1e-14

    1. Initial program 48.7%

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

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

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

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

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

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

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

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

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

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

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

    if -1.1e-14 < d < 4e-52

    1. Initial program 75.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4e-52 < d

    1. Initial program 60.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 62.4% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.5 \cdot 10^{-107} \lor \neg \left(c \leq 9500000000000\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -9.4999999999999999e-107 or 9.5e12 < c

    1. Initial program 58.4%

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

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

    if -9.4999999999999999e-107 < c < 9.5e12

    1. Initial program 73.3%

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

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

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

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

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

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

Alternative 10: 46.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{+225} \lor \neg \left(d \leq 4.9 \cdot 10^{+154}\right):\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.9e225 or 4.9000000000000002e154 < d

    1. Initial program 33.4%

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

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

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

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

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
    6. Step-by-step derivation
      1. neg-sub084.2%

        \[\leadsto \frac{\color{blue}{0 - a}}{d} \]
      2. sub-neg84.2%

        \[\leadsto \frac{\color{blue}{0 + \left(-a\right)}}{d} \]
      3. add-sqr-sqrt44.0%

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

        \[\leadsto \frac{0 + \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}}{d} \]
      5. sqr-neg43.9%

        \[\leadsto \frac{0 + \sqrt{\color{blue}{a \cdot a}}}{d} \]
      6. sqrt-unprod17.9%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{a} \cdot \sqrt{a}}}{d} \]
      7. add-sqr-sqrt32.3%

        \[\leadsto \frac{0 + \color{blue}{a}}{d} \]
    7. Applied egg-rr32.3%

      \[\leadsto \frac{\color{blue}{0 + a}}{d} \]
    8. Step-by-step derivation
      1. +-lft-identity32.3%

        \[\leadsto \frac{\color{blue}{a}}{d} \]
    9. Simplified32.3%

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

    if -1.9e225 < d < 4.9000000000000002e154

    1. Initial program 71.8%

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

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

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

Alternative 11: 11.1% accurate, 5.0× speedup?

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-a}{d}} \]
  6. Step-by-step derivation
    1. neg-sub039.9%

      \[\leadsto \frac{\color{blue}{0 - a}}{d} \]
    2. sub-neg39.9%

      \[\leadsto \frac{\color{blue}{0 + \left(-a\right)}}{d} \]
    3. add-sqr-sqrt18.7%

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

      \[\leadsto \frac{0 + \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}}{d} \]
    5. sqr-neg18.6%

      \[\leadsto \frac{0 + \sqrt{\color{blue}{a \cdot a}}}{d} \]
    6. sqrt-unprod4.7%

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

      \[\leadsto \frac{0 + \color{blue}{a}}{d} \]
  7. Applied egg-rr9.5%

    \[\leadsto \frac{\color{blue}{0 + a}}{d} \]
  8. Step-by-step derivation
    1. +-lft-identity9.5%

      \[\leadsto \frac{\color{blue}{a}}{d} \]
  9. Simplified9.5%

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

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

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

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

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


\end{array}
\end{array}

Reproduce

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

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

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