Complex division, real part

Percentage Accurate: 60.6% → 84.4%
Time: 11.8s
Alternatives: 11
Speedup: 1.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 11 alternatives:

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

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

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\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)}\\

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


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

    1. Initial program 79.1%

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

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

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

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

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

        \[\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-define94.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)}} \]
    4. Applied egg-rr94.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)}} \]

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 79.6% accurate, 0.1× speedup?

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

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

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

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

\mathbf{elif}\;c \leq 2.8 \cdot 10^{+116}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d \cdot \left(b + a \cdot \frac{c}{d}\right)}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 40.8%

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

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

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

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

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

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

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

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

    if -2.9500000000000001e91 < c < -1850

    1. Initial program 75.2%

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

    if -1850 < c < 2.4e-133

    1. Initial program 73.5%

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

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

    if 2.4e-133 < c < 2.80000000000000004e116

    1. Initial program 75.0%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt75.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-frac75.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-define75.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-define75.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-define88.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)}} \]
    4. Applied egg-rr88.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)}} \]
    5. Taylor expanded in d around inf 80.7%

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

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

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

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

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

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

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

    if 2.80000000000000004e116 < c

    1. Initial program 32.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-a \cdot \left(-1 \cdot \frac{b \cdot d}{a \cdot c} - 1\right)}}{c} \]
      2. distribute-rgt-neg-in74.4%

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

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

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

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

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

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

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

Alternative 3: 80.0% 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}\;c \leq -4.2 \cdot 10^{+91}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -1800:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{-130}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.95 \cdot 10^{+83}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-1, \frac{b}{c} \cdot \frac{d}{a}, -1\right) \cdot \left(-a\right)}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -4.2e+91)
     (/ (+ a (* b (/ d c))) c)
     (if (<= c -1800.0)
       t_0
       (if (<= c 4.2e-130)
         (/ (+ b (/ (* a c) d)) d)
         (if (<= c 1.95e+83)
           t_0
           (/ (* (fma -1.0 (* (/ b c) (/ d a)) -1.0) (- a)) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -4.2e+91) {
		tmp = (a + (b * (d / c))) / c;
	} else if (c <= -1800.0) {
		tmp = t_0;
	} else if (c <= 4.2e-130) {
		tmp = (b + ((a * c) / d)) / d;
	} else if (c <= 1.95e+83) {
		tmp = t_0;
	} else {
		tmp = (fma(-1.0, ((b / c) * (d / a)), -1.0) * -a) / c;
	}
	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 (c <= -4.2e+91)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	elseif (c <= -1800.0)
		tmp = t_0;
	elseif (c <= 4.2e-130)
		tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d);
	elseif (c <= 1.95e+83)
		tmp = t_0;
	else
		tmp = Float64(Float64(fma(-1.0, Float64(Float64(b / c) * Float64(d / a)), -1.0) * Float64(-a)) / c);
	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[c, -4.2e+91], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1800.0], t$95$0, If[LessEqual[c, 4.2e-130], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.95e+83], t$95$0, N[(N[(N[(-1.0 * N[(N[(b / c), $MachinePrecision] * N[(d / a), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * (-a)), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -1800:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.95 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 40.8%

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

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

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

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

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

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

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

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

    if -4.20000000000000015e91 < c < -1800 or 4.20000000000000004e-130 < c < 1.9500000000000001e83

    1. Initial program 80.1%

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

    if -1800 < c < 4.20000000000000004e-130

    1. Initial program 73.5%

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

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

    if 1.9500000000000001e83 < c

    1. Initial program 34.9%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-a \cdot \left(-1 \cdot \frac{b \cdot d}{a \cdot c} - 1\right)}}{c} \]
      2. distribute-rgt-neg-in71.0%

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

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

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

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

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

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

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

Alternative 4: 81.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}\\ t_1 := a + b \cdot \frac{d}{c}\\ \mathbf{if}\;c \leq -2.45 \cdot 10^{+91}:\\ \;\;\;\;\frac{t\_1}{c}\\ \mathbf{elif}\;c \leq -2500:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 4.8 \cdot 10^{-133}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+61}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (+ a (* b (/ d c)))))
   (if (<= c -2.45e+91)
     (/ t_1 c)
     (if (<= c -2500.0)
       t_0
       (if (<= c 4.8e-133)
         (/ (+ b (/ (* a c) d)) d)
         (if (<= c 2.2e+61) t_0 (* (/ 1.0 (hypot c d)) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = a + (b * (d / c));
	double tmp;
	if (c <= -2.45e+91) {
		tmp = t_1 / c;
	} else if (c <= -2500.0) {
		tmp = t_0;
	} else if (c <= 4.8e-133) {
		tmp = (b + ((a * c) / d)) / d;
	} else if (c <= 2.2e+61) {
		tmp = t_0;
	} else {
		tmp = (1.0 / hypot(c, d)) * t_1;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = a + (b * (d / c));
	double tmp;
	if (c <= -2.45e+91) {
		tmp = t_1 / c;
	} else if (c <= -2500.0) {
		tmp = t_0;
	} else if (c <= 4.8e-133) {
		tmp = (b + ((a * c) / d)) / d;
	} else if (c <= 2.2e+61) {
		tmp = t_0;
	} else {
		tmp = (1.0 / Math.hypot(c, d)) * t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = a + (b * (d / c))
	tmp = 0
	if c <= -2.45e+91:
		tmp = t_1 / c
	elif c <= -2500.0:
		tmp = t_0
	elif c <= 4.8e-133:
		tmp = (b + ((a * c) / d)) / d
	elif c <= 2.2e+61:
		tmp = t_0
	else:
		tmp = (1.0 / math.hypot(c, d)) * t_1
	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)))
	t_1 = Float64(a + Float64(b * Float64(d / c)))
	tmp = 0.0
	if (c <= -2.45e+91)
		tmp = Float64(t_1 / c);
	elseif (c <= -2500.0)
		tmp = t_0;
	elseif (c <= 4.8e-133)
		tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d);
	elseif (c <= 2.2e+61)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / hypot(c, d)) * t_1);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = a + (b * (d / c));
	tmp = 0.0;
	if (c <= -2.45e+91)
		tmp = t_1 / c;
	elseif (c <= -2500.0)
		tmp = t_0;
	elseif (c <= 4.8e-133)
		tmp = (b + ((a * c) / d)) / d;
	elseif (c <= 2.2e+61)
		tmp = t_0;
	else
		tmp = (1.0 / hypot(c, d)) * t_1;
	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]}, Block[{t$95$1 = N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.45e+91], N[(t$95$1 / c), $MachinePrecision], If[LessEqual[c, -2500.0], t$95$0, If[LessEqual[c, 4.8e-133], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.2e+61], t$95$0, N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -2500:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 2.2 \cdot 10^{+61}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 40.8%

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

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

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

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

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

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

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

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

    if -2.45000000000000015e91 < c < -2500 or 4.8e-133 < c < 2.2e61

    1. Initial program 81.7%

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

    if -2500 < c < 4.8e-133

    1. Initial program 73.5%

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

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

    if 2.2e61 < c

    1. Initial program 37.4%

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

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

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

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

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

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

        \[\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)}} \]
    4. Applied egg-rr57.7%

      \[\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)}} \]
    5. Taylor expanded in d around inf 55.9%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.45 \cdot 10^{+91}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -2500:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.8 \cdot 10^{-133}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+61}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + b \cdot \frac{d}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 81.1% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{if}\;c \leq -2 \cdot 10^{+91}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -7500:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-131}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.08 \cdot 10^{+83}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (/ (+ a (* b (/ d c))) c)))
   (if (<= c -2e+91)
     t_1
     (if (<= c -7500.0)
       t_0
       (if (<= c 4e-131)
         (/ (+ b (/ (* a c) d)) d)
         (if (<= c 1.08e+83) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a + (b * (d / c))) / c;
	double tmp;
	if (c <= -2e+91) {
		tmp = t_1;
	} else if (c <= -7500.0) {
		tmp = t_0;
	} else if (c <= 4e-131) {
		tmp = (b + ((a * c) / d)) / d;
	} else if (c <= 1.08e+83) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (a + (b * (d / c))) / c
    if (c <= (-2d+91)) then
        tmp = t_1
    else if (c <= (-7500.0d0)) then
        tmp = t_0
    else if (c <= 4d-131) then
        tmp = (b + ((a * c) / d)) / d
    else if (c <= 1.08d+83) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a + (b * (d / c))) / c;
	double tmp;
	if (c <= -2e+91) {
		tmp = t_1;
	} else if (c <= -7500.0) {
		tmp = t_0;
	} else if (c <= 4e-131) {
		tmp = (b + ((a * c) / d)) / d;
	} else if (c <= 1.08e+83) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (a + (b * (d / c))) / c
	tmp = 0
	if c <= -2e+91:
		tmp = t_1
	elif c <= -7500.0:
		tmp = t_0
	elif c <= 4e-131:
		tmp = (b + ((a * c) / d)) / d
	elif c <= 1.08e+83:
		tmp = t_0
	else:
		tmp = t_1
	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)))
	t_1 = Float64(Float64(a + Float64(b * Float64(d / c))) / c)
	tmp = 0.0
	if (c <= -2e+91)
		tmp = t_1;
	elseif (c <= -7500.0)
		tmp = t_0;
	elseif (c <= 4e-131)
		tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d);
	elseif (c <= 1.08e+83)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (a + (b * (d / c))) / c;
	tmp = 0.0;
	if (c <= -2e+91)
		tmp = t_1;
	elseif (c <= -7500.0)
		tmp = t_0;
	elseif (c <= 4e-131)
		tmp = (b + ((a * c) / d)) / d;
	elseif (c <= 1.08e+83)
		tmp = t_0;
	else
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2e+91], t$95$1, If[LessEqual[c, -7500.0], t$95$0, If[LessEqual[c, 4e-131], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.08e+83], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -7500:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.08 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.00000000000000016e91 or 1.08e83 < c

    1. Initial program 37.5%

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

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

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

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

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

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

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

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

    if -2.00000000000000016e91 < c < -7500 or 3.9999999999999999e-131 < c < 1.08e83

    1. Initial program 80.1%

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

    if -7500 < c < 3.9999999999999999e-131

    1. Initial program 73.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2 \cdot 10^{+91}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -7500:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-131}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.08 \cdot 10^{+83}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 78.6% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.99999999999999996e34 or 3.9e11 < d

    1. Initial program 51.0%

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

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

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

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

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

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

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

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

    if -6.99999999999999996e34 < d < 3.9e11

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

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

Alternative 7: 78.6% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.50000000000000011e35 or 1e13 < d

    1. Initial program 51.0%

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

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

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

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

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

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

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

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

    if -2.50000000000000011e35 < d < 1e13

    1. Initial program 74.8%

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

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

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

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

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

Alternative 8: 78.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+35} \lor \neg \left(d \leq 1.18 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.02000000000000007e35 or 1.18e14 < d

    1. Initial program 51.0%

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

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

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

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

    if -1.02000000000000007e35 < d < 1.18e14

    1. Initial program 74.8%

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

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

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

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

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

Alternative 9: 72.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2 \cdot 10^{+34} \lor \neg \left(d \leq 1.5 \cdot 10^{+15}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.99999999999999989e34 or 1.5e15 < d

    1. Initial program 51.0%

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

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

    if -1.99999999999999989e34 < d < 1.5e15

    1. Initial program 74.8%

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

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

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

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

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

Alternative 10: 63.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{+34} \lor \neg \left(d \leq 13500000000000\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.25e34 or 1.35e13 < d

    1. Initial program 51.0%

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

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

    if -1.25e34 < d < 1.35e13

    1. Initial program 74.8%

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

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

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

Alternative 11: 41.5% 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 63.1%

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

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

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

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{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 2024157 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (! :herbie-platform default (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))))