Complex division, imag part

Percentage Accurate: 62.1% → 89.3%
Time: 8.5s
Alternatives: 10
Speedup: 1.8×

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 10 alternatives:

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

Initial Program: 62.1% accurate, 1.0× speedup?

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

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

Alternative 1: 89.3% accurate, 0.0× speedup?

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

\\
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+281}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{-a}{d}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{t_0}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 17.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. div-sub7.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. *-commutative7.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-sqrt7.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-frac15.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-neg15.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-def15.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-def45.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*56.7%

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

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

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

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

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

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

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

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

Alternative 2: 84.8% accurate, 0.1× speedup?

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

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

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


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

    1. Initial program 80.0%

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

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

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

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

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

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

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

    if 1e281 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 16.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{d \cdot d}{c \cdot b - d \cdot a}\right)}^{-1}} \]
    7. Step-by-step derivation
      1. unpow-117.4%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 82.5% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -6.5 \cdot 10^{-97}:\\
\;\;\;\;\frac{b \cdot c - a \cdot d}{t_0}\\

\mathbf{elif}\;c \leq 8.5 \cdot 10^{-137}:\\
\;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\

\mathbf{elif}\;c \leq 1.5 \cdot 10^{+66}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-d, a, b \cdot c\right)}{t_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -5.50000000000000001e42

    1. Initial program 59.6%

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

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

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

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

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

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

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

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

    if -5.50000000000000001e42 < c < -6.5000000000000004e-97

    1. Initial program 79.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]

    if -6.5000000000000004e-97 < c < 8.5000000000000001e-137

    1. Initial program 67.9%

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{d \cdot d}{b \cdot c - a \cdot d}}} \]
      2. inv-pow65.8%

        \[\leadsto \color{blue}{{\left(\frac{d \cdot d}{b \cdot c - a \cdot d}\right)}^{-1}} \]
      3. *-commutative65.8%

        \[\leadsto {\left(\frac{d \cdot d}{\color{blue}{c \cdot b} - a \cdot d}\right)}^{-1} \]
      4. *-commutative65.8%

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

      \[\leadsto \color{blue}{{\left(\frac{d \cdot d}{c \cdot b - d \cdot a}\right)}^{-1}} \]
    7. Step-by-step derivation
      1. unpow-165.8%

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

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

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

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

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

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

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

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

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

    if 8.5000000000000001e-137 < c < 1.50000000000000001e66

    1. Initial program 89.6%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. sub-neg89.6%

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

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

        \[\leadsto \frac{\left(-\color{blue}{d \cdot a}\right) + b \cdot c}{c \cdot c + d \cdot d} \]
      4. distribute-lft-neg-in89.6%

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

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

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

    if 1.50000000000000001e66 < c

    1. Initial program 52.1%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{+42}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -6.5 \cdot 10^{-97}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{-137}:\\ \;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+66}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-d, a, b \cdot c\right)}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]

Alternative 4: 82.6% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;c \leq -2.8 \cdot 10^{-98}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 1.05 \cdot 10^{-136}:\\
\;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\

\mathbf{elif}\;c \leq 5.8 \cdot 10^{+69}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 59.6%

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

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

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

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

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

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

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

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

    if -4.7999999999999997e42 < c < -2.7999999999999999e-98 or 1.0499999999999999e-136 < c < 5.7999999999999997e69

    1. Initial program 85.7%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]

    if -2.7999999999999999e-98 < c < 1.0499999999999999e-136

    1. Initial program 67.9%

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{d \cdot d}{b \cdot c - a \cdot d}}} \]
      2. inv-pow65.8%

        \[\leadsto \color{blue}{{\left(\frac{d \cdot d}{b \cdot c - a \cdot d}\right)}^{-1}} \]
      3. *-commutative65.8%

        \[\leadsto {\left(\frac{d \cdot d}{\color{blue}{c \cdot b} - a \cdot d}\right)}^{-1} \]
      4. *-commutative65.8%

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

      \[\leadsto \color{blue}{{\left(\frac{d \cdot d}{c \cdot b - d \cdot a}\right)}^{-1}} \]
    7. Step-by-step derivation
      1. unpow-165.8%

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

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

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

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

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

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

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

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

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

    if 5.7999999999999997e69 < c

    1. Initial program 52.1%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.8 \cdot 10^{+42}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\ \mathbf{elif}\;c \leq -2.8 \cdot 10^{-98}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{-136}:\\ \;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{+69}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]

Alternative 5: 76.4% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -10500 or 9.7000000000000001e-26 < c

    1. Initial program 61.0%

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

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

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

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

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

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

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

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

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

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

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

    if -10500 < c < 9.7000000000000001e-26

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -10500 \lor \neg \left(c \leq 9.7 \cdot 10^{-26}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]

Alternative 6: 77.1% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -6.2e9 or 2.74999999999999989e-21 < c

    1. Initial program 61.0%

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

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

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

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

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

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

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

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

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

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

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

    if -6.2e9 < c < 2.74999999999999989e-21

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{d \cdot d}{c \cdot b - d \cdot a}\right)}^{-1}} \]
    7. Step-by-step derivation
      1. unpow-159.7%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6200000000 \lor \neg \left(c \leq 2.75 \cdot 10^{-21}\right):\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(\frac{c}{\frac{d}{b}} - a\right)\\ \end{array} \]

Alternative 7: 69.8% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.50000000000000038e-14 or 3.0999999999999999e-68 < c

    1. Initial program 63.7%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\frac{a}{c} \cdot d}{c}} \]
      2. sub-div78.3%

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

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

    if -8.50000000000000038e-14 < c < 3.0999999999999999e-68

    1. Initial program 71.7%

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

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

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

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

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

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

Alternative 8: 62.6% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3 \cdot 10^{-15}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{elif}\;c \leq 5.4 \cdot 10^{-68}:\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3e-15 or 5.4000000000000003e-68 < c

    1. Initial program 63.7%

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

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

    if -3e-15 < c < 5.4000000000000003e-68

    1. Initial program 71.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3 \cdot 10^{-15}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 5.4 \cdot 10^{-68}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]

Alternative 9: 46.0% accurate, 2.1× speedup?

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

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

\mathbf{elif}\;d \leq 2.6 \cdot 10^{+191}:\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.6e90 or 2.6e191 < d

    1. Initial program 46.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.6e90 < d < 2.6e191

    1. Initial program 73.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+90}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+191}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]

Alternative 10: 11.2% 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 67.4%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{a}{d}} \]
  8. Final simplification12.0%

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

Developer target: 99.4% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

  :herbie-target
  (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))))