Complex division, real part

Percentage Accurate: 61.8% → 85.6%
Time: 10.9s
Alternatives: 15
Speedup: 2.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 61.8% accurate, 1.0× speedup?

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

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

Alternative 1: 85.6% accurate, 0.0× speedup?

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

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

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

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


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

    1. Initial program 44.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{c \cdot \left(a + b \cdot \frac{d}{c}\right)}{c \cdot c}\right)\right)} \]
      2. expm1-udef0.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{c \cdot \left(a + b \cdot \frac{d}{c}\right)}{c \cdot c}\right)} - 1} \]
      3. times-frac0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{c}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      4. pow10.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{c}^{1}}}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      5. pow10.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{{c}^{1}}{\color{blue}{{c}^{1}}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      6. pow-div0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{{c}^{\left(1 - 1\right)}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      7. metadata-eval0.0%

        \[\leadsto e^{\mathsf{log1p}\left({c}^{\color{blue}{0}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      8. metadata-eval0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      9. *-un-lft-identity0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      10. +-commutative0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{b \cdot \frac{d}{c} + a}}{c}\right)} - 1 \]
      11. fma-def0.0%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    10. Applied egg-rr0.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def0.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p83.2%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    12. Simplified83.2%

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

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

    1. Initial program 81.6%

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999988e237 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 15.2%

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

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

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

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

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

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

Alternative 2: 84.2% accurate, 0.1× speedup?

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

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

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

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

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

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


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

    1. Initial program 27.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.64999999999999987e89 < d < -7e-105

    1. Initial program 77.1%

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

    if -7e-105 < d < 3.1999999999999998e-97

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{c \cdot \left(a + b \cdot \frac{d}{c}\right)}{c \cdot c}\right)} - 1} \]
      3. times-frac32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{c}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      4. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{c}^{1}}}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      5. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{{c}^{1}}{\color{blue}{{c}^{1}}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      6. pow-div32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{{c}^{\left(1 - 1\right)}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      7. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left({c}^{\color{blue}{0}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      8. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      9. *-un-lft-identity32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      10. +-commutative32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{b \cdot \frac{d}{c} + a}}{c}\right)} - 1 \]
      11. fma-def32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    10. Applied egg-rr32.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def63.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p91.9%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    12. Simplified91.9%

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

    if 3.1999999999999998e-97 < d < 2.9000000000000002e112

    1. Initial program 80.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-def80.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified80.9%

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

    if 2.9000000000000002e112 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.65 \cdot 10^{+89}:\\ \;\;\;\;\left(b + {\left(\frac{\frac{d}{a}}{c}\right)}^{-1}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -7 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-97}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+112}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \mathsf{fma}\left(-0.5, \frac{b}{d} \cdot \left(c \cdot \frac{c}{d}\right), \frac{c}{\frac{d}{a}}\right)}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 84.4% accurate, 0.1× speedup?

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

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

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

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

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

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


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

    1. Initial program 30.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.1999999999999997e82 < d < -3.5e-105

    1. Initial program 76.0%

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

    if -3.5e-105 < d < 5.5000000000000004e-87

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{c \cdot \left(a + b \cdot \frac{d}{c}\right)}{c \cdot c}\right)} - 1} \]
      3. times-frac32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{c}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      4. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{c}^{1}}}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      5. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{{c}^{1}}{\color{blue}{{c}^{1}}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      6. pow-div32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{{c}^{\left(1 - 1\right)}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      7. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left({c}^{\color{blue}{0}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      8. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      9. *-un-lft-identity32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      10. +-commutative32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{b \cdot \frac{d}{c} + a}}{c}\right)} - 1 \]
      11. fma-def32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    10. Applied egg-rr32.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def63.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p91.9%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    12. Simplified91.9%

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

    if 5.5000000000000004e-87 < d < 1.99999999999999991e111

    1. Initial program 80.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-def80.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified80.9%

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

    if 1.99999999999999991e111 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{+82}:\\ \;\;\;\;\left(b + \frac{c}{\frac{d}{a}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.5 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-87}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2 \cdot 10^{+111}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-c}{\frac{d}{a}} - b\right)\\ \end{array} \]

Alternative 4: 84.3% accurate, 0.1× speedup?

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

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

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

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

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

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


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

    1. Initial program 27.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.84999999999999975e89 < d < -3.3e-102

    1. Initial program 77.1%

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

    if -3.3e-102 < d < 1.2499999999999999e-95

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{c \cdot \left(a + b \cdot \frac{d}{c}\right)}{c \cdot c}\right)} - 1} \]
      3. times-frac32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{c}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      4. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{c}^{1}}}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      5. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{{c}^{1}}{\color{blue}{{c}^{1}}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      6. pow-div32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{{c}^{\left(1 - 1\right)}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      7. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left({c}^{\color{blue}{0}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      8. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      9. *-un-lft-identity32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      10. +-commutative32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{b \cdot \frac{d}{c} + a}}{c}\right)} - 1 \]
      11. fma-def32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    10. Applied egg-rr32.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def63.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p91.9%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    12. Simplified91.9%

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

    if 1.2499999999999999e-95 < d < 1.99999999999999991e111

    1. Initial program 80.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-def80.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified80.9%

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

    if 1.99999999999999991e111 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.85 \cdot 10^{+89}:\\ \;\;\;\;\left(b + {\left(\frac{\frac{d}{a}}{c}\right)}^{-1}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -3.3 \cdot 10^{-102}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{-95}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2 \cdot 10^{+111}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-c}{\frac{d}{a}} - b\right)\\ \end{array} \]

Alternative 5: 84.3% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -6.4 \cdot 10^{-105}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 4 \cdot 10^{+111}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 30.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.4999999999999997e82 < d < -6.39999999999999962e-105 or 5.49999999999999948e-97 < d < 3.99999999999999983e111

    1. Initial program 78.4%

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

    if -6.39999999999999962e-105 < d < 5.49999999999999948e-97

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{c \cdot \left(a + b \cdot \frac{d}{c}\right)}{c \cdot c}\right)} - 1} \]
      3. times-frac32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{c}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      4. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{c}^{1}}}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      5. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{{c}^{1}}{\color{blue}{{c}^{1}}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      6. pow-div32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{{c}^{\left(1 - 1\right)}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      7. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left({c}^{\color{blue}{0}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      8. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      9. *-un-lft-identity32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      10. +-commutative32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{b \cdot \frac{d}{c} + a}}{c}\right)} - 1 \]
      11. fma-def32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    10. Applied egg-rr32.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def63.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p91.9%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    12. Simplified91.9%

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

    if 3.99999999999999983e111 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{+82}:\\ \;\;\;\;\left(b + \frac{c}{\frac{d}{a}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq -6.4 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-97}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 4 \cdot 10^{+111}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-c}{\frac{d}{a}} - b\right)\\ \end{array} \]

Alternative 6: 84.2% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -4.2 \cdot 10^{-103}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 8.2 \cdot 10^{+111}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 30.9%

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

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

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

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

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

    if -7.4000000000000005e83 < d < -4.20000000000000009e-103 or 3.8999999999999998e-97 < d < 8.19999999999999973e111

    1. Initial program 78.4%

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

    if -4.20000000000000009e-103 < d < 3.8999999999999998e-97

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{c \cdot \left(a + b \cdot \frac{d}{c}\right)}{c \cdot c}\right)} - 1} \]
      3. times-frac32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{c}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      4. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{{c}^{1}}}{c} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      5. pow132.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{{c}^{1}}{\color{blue}{{c}^{1}}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      6. pow-div32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{{c}^{\left(1 - 1\right)}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      7. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left({c}^{\color{blue}{0}} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      8. metadata-eval32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{a + b \cdot \frac{d}{c}}{c}\right)} - 1 \]
      9. *-un-lft-identity32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}}\right)} - 1 \]
      10. +-commutative32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{b \cdot \frac{d}{c} + a}}{c}\right)} - 1 \]
      11. fma-def32.7%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}}{c}\right)} - 1 \]
    10. Applied egg-rr32.7%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)} - 1} \]
    11. Step-by-step derivation
      1. expm1-def63.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\right)\right)} \]
      2. expm1-log1p91.9%

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
    12. Simplified91.9%

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

    if 8.19999999999999973e111 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.4 \cdot 10^{+83}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -4.2 \cdot 10^{-103}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.9 \cdot 10^{-97}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 8.2 \cdot 10^{+111}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-c}{\frac{d}{a}} - b\right)\\ \end{array} \]

Alternative 7: 83.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -2.1 \cdot 10^{+83}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{-104}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{-86}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 2 \cdot 10^{+111}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-c}{\frac{d}{a}} - b\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -2.1e+83)
     (+ (/ b d) (* (/ c d) (/ a d)))
     (if (<= d -1.8e-104)
       t_0
       (if (<= d 3.5e-86)
         (+ (/ a c) (/ (/ b (/ c d)) c))
         (if (<= d 2e+111) t_0 (* (/ -1.0 d) (- (/ (- c) (/ d a)) b))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -2.1e+83) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (d <= -1.8e-104) {
		tmp = t_0;
	} else if (d <= 3.5e-86) {
		tmp = (a / c) + ((b / (c / d)) / c);
	} else if (d <= 2e+111) {
		tmp = t_0;
	} else {
		tmp = (-1.0 / d) * ((-c / (d / a)) - b);
	}
	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 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (d <= (-2.1d+83)) then
        tmp = (b / d) + ((c / d) * (a / d))
    else if (d <= (-1.8d-104)) then
        tmp = t_0
    else if (d <= 3.5d-86) then
        tmp = (a / c) + ((b / (c / d)) / c)
    else if (d <= 2d+111) then
        tmp = t_0
    else
        tmp = ((-1.0d0) / d) * ((-c / (d / a)) - b)
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -2.1e+83) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (d <= -1.8e-104) {
		tmp = t_0;
	} else if (d <= 3.5e-86) {
		tmp = (a / c) + ((b / (c / d)) / c);
	} else if (d <= 2e+111) {
		tmp = t_0;
	} else {
		tmp = (-1.0 / d) * ((-c / (d / a)) - b);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if d <= -2.1e+83:
		tmp = (b / d) + ((c / d) * (a / d))
	elif d <= -1.8e-104:
		tmp = t_0
	elif d <= 3.5e-86:
		tmp = (a / c) + ((b / (c / d)) / c)
	elif d <= 2e+111:
		tmp = t_0
	else:
		tmp = (-1.0 / d) * ((-c / (d / a)) - b)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -2.1e+83)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	elseif (d <= -1.8e-104)
		tmp = t_0;
	elseif (d <= 3.5e-86)
		tmp = Float64(Float64(a / c) + Float64(Float64(b / Float64(c / d)) / c));
	elseif (d <= 2e+111)
		tmp = t_0;
	else
		tmp = Float64(Float64(-1.0 / d) * Float64(Float64(Float64(-c) / Float64(d / a)) - b));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (d <= -2.1e+83)
		tmp = (b / d) + ((c / d) * (a / d));
	elseif (d <= -1.8e-104)
		tmp = t_0;
	elseif (d <= 3.5e-86)
		tmp = (a / c) + ((b / (c / d)) / c);
	elseif (d <= 2e+111)
		tmp = t_0;
	else
		tmp = (-1.0 / d) * ((-c / (d / a)) - b);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.1e+83], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.8e-104], t$95$0, If[LessEqual[d, 3.5e-86], N[(N[(a / c), $MachinePrecision] + N[(N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2e+111], t$95$0, N[(N[(-1.0 / d), $MachinePrecision] * N[(N[((-c) / N[(d / a), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -1.8 \cdot 10^{-104}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 2 \cdot 10^{+111}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 30.9%

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

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

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

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

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

    if -2.10000000000000002e83 < d < -1.7999999999999999e-104 or 3.50000000000000021e-86 < d < 1.99999999999999991e111

    1. Initial program 78.4%

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

    if -1.7999999999999999e-104 < d < 3.50000000000000021e-86

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c \cdot \frac{c}{d}}{b}}} \]
    8. Simplified89.6%

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{c \cdot \frac{c}{d}}} \]
      2. add-cube-cbrt89.5%

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{{\left(\sqrt[3]{b}\right)}^{2}}}{c} \cdot \frac{\sqrt[3]{b}}{\frac{c}{d}} \]
    10. Applied egg-rr90.6%

      \[\leadsto \frac{a}{c} + \color{blue}{\frac{{\left(\sqrt[3]{b}\right)}^{2}}{c} \cdot \frac{\sqrt[3]{b}}{\frac{c}{d}}} \]
    11. Step-by-step derivation
      1. associate-*l/90.6%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{\frac{\color{blue}{b}}{\frac{c}{d}}}{c} \]
    12. Simplified90.7%

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

    if 1.99999999999999991e111 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.1 \cdot 10^{+83}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{-104}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{-86}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 2 \cdot 10^{+111}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{d} \cdot \left(\frac{-c}{\frac{d}{a}} - b\right)\\ \end{array} \]

Alternative 8: 77.9% accurate, 0.9× speedup?

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

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

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

\mathbf{elif}\;d \leq 8 \cdot 10^{+84}:\\
\;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.39999999999999999e41 or 8.00000000000000046e84 < d

    1. Initial program 43.2%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{c}{d} \cdot \frac{a}{d}} \]
    4. Simplified84.1%

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

    if -5.39999999999999999e41 < d < 1.12e-60

    1. Initial program 72.6%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
    4. Simplified73.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c \cdot \frac{c}{d}}{b}}} \]
    8. Simplified78.9%

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{{\left(\sqrt[3]{b}\right)}^{2}}}{c} \cdot \frac{\sqrt[3]{b}}{\frac{c}{d}} \]
    10. Applied egg-rr79.5%

      \[\leadsto \frac{a}{c} + \color{blue}{\frac{{\left(\sqrt[3]{b}\right)}^{2}}{c} \cdot \frac{\sqrt[3]{b}}{\frac{c}{d}}} \]
    11. Step-by-step derivation
      1. associate-*l/79.5%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{\frac{\color{blue}{b}}{\frac{c}{d}}}{c} \]
    12. Simplified79.6%

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

    if 1.12e-60 < d < 8.00000000000000046e84

    1. Initial program 74.5%

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

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

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

        \[\leadsto \color{blue}{\frac{a}{\frac{{d}^{2} + {c}^{2}}{c}}} \]
      3. unpow246.7%

        \[\leadsto \frac{a}{\frac{\color{blue}{d \cdot d} + {c}^{2}}{c}} \]
      4. unpow246.7%

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

        \[\leadsto \frac{a}{\frac{\color{blue}{c \cdot c + d \cdot d}}{c}} \]
      6. fma-udef46.8%

        \[\leadsto \frac{a}{\frac{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} \]
    4. Simplified46.8%

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

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

        \[\leadsto \frac{a}{c + \frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-lft-identity64.4%

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

        \[\leadsto \frac{a}{c + \color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
      4. /-rgt-identity64.4%

        \[\leadsto \frac{a}{c + \color{blue}{d} \cdot \frac{d}{c}} \]
    7. Simplified64.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.4 \cdot 10^{+41}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.12 \cdot 10^{-60}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+84}:\\ \;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 9: 77.7% accurate, 0.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.0000000000000001e-13 or 8.5 < c

    1. Initial program 52.6%

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

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

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

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

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

    if -4.0000000000000001e-13 < c < 8.5

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 69.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{+43}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 1.18 \cdot 10^{+85}:\\
\;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.2500000000000001e43 or 1.17999999999999997e85 < d

    1. Initial program 43.2%

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

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

    if -1.2500000000000001e43 < d < 4.8000000000000002e-61

    1. Initial program 72.6%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
    4. Simplified73.1%

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{c \cdot c}} \]
    5. Taylor expanded in d around 0 73.1%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{d \cdot \frac{b}{c \cdot c}} \]
    7. Simplified69.8%

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

    if 4.8000000000000002e-61 < d < 1.17999999999999997e85

    1. Initial program 74.5%

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

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

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

        \[\leadsto \color{blue}{\frac{a}{\frac{{d}^{2} + {c}^{2}}{c}}} \]
      3. unpow246.7%

        \[\leadsto \frac{a}{\frac{\color{blue}{d \cdot d} + {c}^{2}}{c}} \]
      4. unpow246.7%

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

        \[\leadsto \frac{a}{\frac{\color{blue}{c \cdot c + d \cdot d}}{c}} \]
      6. fma-udef46.8%

        \[\leadsto \frac{a}{\frac{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} \]
    4. Simplified46.8%

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

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

        \[\leadsto \frac{a}{c + \frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-lft-identity64.4%

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

        \[\leadsto \frac{a}{c + \color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
      4. /-rgt-identity64.4%

        \[\leadsto \frac{a}{c + \color{blue}{d} \cdot \frac{d}{c}} \]
    7. Simplified64.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.25 \cdot 10^{+43}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 4.8 \cdot 10^{-61}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{c \cdot c}\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{+85}:\\ \;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 11: 72.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.8 \cdot 10^{+43}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{+85}:\\
\;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.80000000000000008e43 or 4.50000000000000007e85 < d

    1. Initial program 43.2%

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

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

    if -3.80000000000000008e43 < d < 2.35e-60

    1. Initial program 72.6%

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{d}{c} \cdot \frac{b}{c}} \]
    4. Simplified78.2%

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

    if 2.35e-60 < d < 4.50000000000000007e85

    1. Initial program 74.5%

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

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

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

        \[\leadsto \color{blue}{\frac{a}{\frac{{d}^{2} + {c}^{2}}{c}}} \]
      3. unpow246.7%

        \[\leadsto \frac{a}{\frac{\color{blue}{d \cdot d} + {c}^{2}}{c}} \]
      4. unpow246.7%

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

        \[\leadsto \frac{a}{\frac{\color{blue}{c \cdot c + d \cdot d}}{c}} \]
      6. fma-udef46.8%

        \[\leadsto \frac{a}{\frac{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} \]
    4. Simplified46.8%

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

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

        \[\leadsto \frac{a}{c + \frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-lft-identity64.4%

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

        \[\leadsto \frac{a}{c + \color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
      4. /-rgt-identity64.4%

        \[\leadsto \frac{a}{c + \color{blue}{d} \cdot \frac{d}{c}} \]
    7. Simplified64.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.8 \cdot 10^{+43}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.35 \cdot 10^{-60}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+85}:\\ \;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 12: 73.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{+42}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 5.2 \cdot 10^{+86}:\\
\;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -7.00000000000000047e42 or 5.1999999999999995e86 < d

    1. Initial program 43.2%

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

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

    if -7.00000000000000047e42 < d < 5.0000000000000001e-60

    1. Initial program 72.6%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
    4. Simplified73.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c \cdot \frac{c}{d}}{b}}} \]
    8. Simplified78.9%

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{{\left(\sqrt[3]{b}\right)}^{2}}}{c} \cdot \frac{\sqrt[3]{b}}{\frac{c}{d}} \]
    10. Applied egg-rr79.5%

      \[\leadsto \frac{a}{c} + \color{blue}{\frac{{\left(\sqrt[3]{b}\right)}^{2}}{c} \cdot \frac{\sqrt[3]{b}}{\frac{c}{d}}} \]
    11. Step-by-step derivation
      1. associate-*l/79.5%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{\frac{\color{blue}{b}}{\frac{c}{d}}}{c} \]
    12. Simplified79.6%

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

    if 5.0000000000000001e-60 < d < 5.1999999999999995e86

    1. Initial program 74.5%

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

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

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

        \[\leadsto \color{blue}{\frac{a}{\frac{{d}^{2} + {c}^{2}}{c}}} \]
      3. unpow246.7%

        \[\leadsto \frac{a}{\frac{\color{blue}{d \cdot d} + {c}^{2}}{c}} \]
      4. unpow246.7%

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

        \[\leadsto \frac{a}{\frac{\color{blue}{c \cdot c + d \cdot d}}{c}} \]
      6. fma-udef46.8%

        \[\leadsto \frac{a}{\frac{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} \]
    4. Simplified46.8%

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

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

        \[\leadsto \frac{a}{c + \frac{\color{blue}{d \cdot d}}{c}} \]
      2. *-lft-identity64.4%

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

        \[\leadsto \frac{a}{c + \color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
      4. /-rgt-identity64.4%

        \[\leadsto \frac{a}{c + \color{blue}{d} \cdot \frac{d}{c}} \]
    7. Simplified64.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{+42}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 5 \cdot 10^{-60}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{+86}:\\ \;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 13: 68.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9.6 \cdot 10^{+42}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq 6.7 \cdot 10^{+84}:\\
\;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -9.5999999999999994e42 or 6.70000000000000041e84 < d

    1. Initial program 43.2%

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

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

    if -9.5999999999999994e42 < d < 6.70000000000000041e84

    1. Initial program 73.0%

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

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

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

        \[\leadsto \color{blue}{\frac{a}{\frac{{d}^{2} + {c}^{2}}{c}}} \]
      3. unpow249.6%

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

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

        \[\leadsto \frac{a}{\frac{\color{blue}{c \cdot c + d \cdot d}}{c}} \]
      6. fma-udef49.6%

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

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

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

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

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

        \[\leadsto \frac{a}{c + \color{blue}{\frac{d}{1} \cdot \frac{d}{c}}} \]
      4. /-rgt-identity65.9%

        \[\leadsto \frac{a}{c + \color{blue}{d} \cdot \frac{d}{c}} \]
    7. Simplified65.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.6 \cdot 10^{+42}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 6.7 \cdot 10^{+84}:\\ \;\;\;\;\frac{a}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 14: 63.1% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{+104}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 8:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.20000000000000001e104 or 8 < c

    1. Initial program 46.7%

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

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

    if -5.20000000000000001e104 < c < 8

    1. Initial program 71.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.2 \cdot 10^{+104}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 8:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 15: 41.8% accurate, 5.0× speedup?

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

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 61.2%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification40.2%

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

Developer target: 99.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \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))
   (/ (+ a (* b (/ d c))) (+ c (* d (/ d c))))
   (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

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

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

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