Complex division, real part

Percentage Accurate: 62.2% → 83.2%
Time: 12.0s
Alternatives: 13
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 13 alternatives:

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

Initial Program: 62.2% 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: 83.2% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;c \leq -1.1 \cdot 10^{-112}:\\
\;\;\;\;\frac{t_0}{c \cdot c + d \cdot d}\\

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

\mathbf{elif}\;c \leq 3.1 \cdot 10^{+93}:\\
\;\;\;\;\frac{t_0}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{a + t_1}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 33.9%

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

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

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

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

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

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

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

      \[\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/53.6%

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

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

      \[\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 -inf 81.7%

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

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

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

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

    if -3.59999999999999978e133 < c < -1.10000000000000011e-112

    1. Initial program 91.2%

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

    if -1.10000000000000011e-112 < c < 2.9499999999999999e-139

    1. Initial program 63.9%

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

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

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

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

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

        \[\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-def81.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-rr81.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. Taylor expanded in c around 0 57.9%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/38.2%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d}\right)} - 1 \]
      6. div-inv38.2%

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

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

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

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

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

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

    if 2.9499999999999999e-139 < c < 3.10000000000000019e93

    1. Initial program 78.3%

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

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

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

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

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

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

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

    if 3.10000000000000019e93 < c

    1. Initial program 32.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt32.0%

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

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

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

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

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

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

      \[\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/60.6%

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

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

      \[\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 inf 76.3%

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Simplified83.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.6 \cdot 10^{+133}:\\ \;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.1 \cdot 10^{-112}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.95 \cdot 10^{-139}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 3.1 \cdot 10^{+93}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 2: 85.1% 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{\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{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
   (* (/ c (hypot c d)) (/ a (hypot c d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (c / hypot(c, d)) * (a / hypot(c, d));
	}
	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(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(a / hypot(c, d)));
	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[(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[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(a / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $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{\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{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\


\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 74.9%

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

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

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

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

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

        \[\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-def92.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)}} \]
    3. Applied egg-rr92.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)}} \]
    4. Step-by-step derivation
      1. associate-*l/92.9%

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

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

      \[\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 +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. Taylor expanded in a around inf 1.6%

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

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

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

        \[\leadsto \frac{c \cdot a}{\color{blue}{{c}^{2}} + d \cdot d} \]
      2. add-sqr-sqrt1.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{a}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 3: 80.4% 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 -1.35 \cdot 10^{+141}:\\ \;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-112}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-138}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{+92}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -1.35e+141)
     (/ (- a) (hypot c d))
     (if (<= c -1.05e-112)
       t_0
       (if (<= c 1.15e-138)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 1.8e+92) t_0 (+ (/ a c) (* d (/ b (pow c 2.0))))))))))
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 <= -1.35e+141) {
		tmp = -a / hypot(c, d);
	} else if (c <= -1.05e-112) {
		tmp = t_0;
	} else if (c <= 1.15e-138) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.8e+92) {
		tmp = t_0;
	} else {
		tmp = (a / c) + (d * (b / pow(c, 2.0)));
	}
	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 tmp;
	if (c <= -1.35e+141) {
		tmp = -a / Math.hypot(c, d);
	} else if (c <= -1.05e-112) {
		tmp = t_0;
	} else if (c <= 1.15e-138) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.8e+92) {
		tmp = t_0;
	} else {
		tmp = (a / c) + (d * (b / Math.pow(c, 2.0)));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.35e+141:
		tmp = -a / math.hypot(c, d)
	elif c <= -1.05e-112:
		tmp = t_0
	elif c <= 1.15e-138:
		tmp = (b + (a * (c / d))) / d
	elif c <= 1.8e+92:
		tmp = t_0
	else:
		tmp = (a / c) + (d * (b / math.pow(c, 2.0)))
	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 <= -1.35e+141)
		tmp = Float64(Float64(-a) / hypot(c, d));
	elseif (c <= -1.05e-112)
		tmp = t_0;
	elseif (c <= 1.15e-138)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 1.8e+92)
		tmp = t_0;
	else
		tmp = Float64(Float64(a / c) + Float64(d * Float64(b / (c ^ 2.0))));
	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 (c <= -1.35e+141)
		tmp = -a / hypot(c, d);
	elseif (c <= -1.05e-112)
		tmp = t_0;
	elseif (c <= 1.15e-138)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 1.8e+92)
		tmp = t_0;
	else
		tmp = (a / c) + (d * (b / (c ^ 2.0)));
	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[c, -1.35e+141], N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.05e-112], t$95$0, If[LessEqual[c, 1.15e-138], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.8e+92], t$95$0, N[(N[(a / c), $MachinePrecision] + N[(d * N[(b / N[Power[c, 2.0], $MachinePrecision]), $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}\;c \leq -1.35 \cdot 10^{+141}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -1.05 \cdot 10^{-112}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.8 \cdot 10^{+92}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 33.9%

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

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

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

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

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

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

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

      \[\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/53.6%

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

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

      \[\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 -inf 78.6%

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

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

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

    if -1.35e141 < c < -1.05e-112 or 1.14999999999999995e-138 < c < 1.8e92

    1. Initial program 84.2%

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

    if -1.05e-112 < c < 1.14999999999999995e-138

    1. Initial program 63.9%

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

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

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

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

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

        \[\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-def81.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-rr81.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. Taylor expanded in c around 0 57.9%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/38.2%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d}\right)} - 1 \]
      6. div-inv38.2%

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

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

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

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

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

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

    if 1.8e92 < c

    1. Initial program 32.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.35 \cdot 10^{+141}:\\ \;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-112}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.15 \cdot 10^{-138}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \end{array} \]

Alternative 4: 75.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -6.4 \cdot 10^{+125}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \mathbf{elif}\;d \leq -8.6 \cdot 10^{+75}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{elif}\;d \leq -1.1 \cdot 10^{-131}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+65}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -6.4e+125)
   (* (/ 1.0 d) (+ b (* c (/ a d))))
   (if (<= d -8.6e+75)
     (+ (/ a c) (* d (/ b (pow c 2.0))))
     (if (<= d -1.1e-131)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (if (<= d 6.5e+65)
         (+ (/ a c) (/ b (/ (pow c 2.0) d)))
         (/ (+ b (* a (/ c d))) d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -6.4e+125) {
		tmp = (1.0 / d) * (b + (c * (a / d)));
	} else if (d <= -8.6e+75) {
		tmp = (a / c) + (d * (b / pow(c, 2.0)));
	} else if (d <= -1.1e-131) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 6.5e+65) {
		tmp = (a / c) + (b / (pow(c, 2.0) / d));
	} else {
		tmp = (b + (a * (c / d))) / 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 <= (-6.4d+125)) then
        tmp = (1.0d0 / d) * (b + (c * (a / d)))
    else if (d <= (-8.6d+75)) then
        tmp = (a / c) + (d * (b / (c ** 2.0d0)))
    else if (d <= (-1.1d-131)) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
    else if (d <= 6.5d+65) then
        tmp = (a / c) + (b / ((c ** 2.0d0) / d))
    else
        tmp = (b + (a * (c / d))) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -6.4e+125) {
		tmp = (1.0 / d) * (b + (c * (a / d)));
	} else if (d <= -8.6e+75) {
		tmp = (a / c) + (d * (b / Math.pow(c, 2.0)));
	} else if (d <= -1.1e-131) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 6.5e+65) {
		tmp = (a / c) + (b / (Math.pow(c, 2.0) / d));
	} else {
		tmp = (b + (a * (c / d))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -6.4e+125:
		tmp = (1.0 / d) * (b + (c * (a / d)))
	elif d <= -8.6e+75:
		tmp = (a / c) + (d * (b / math.pow(c, 2.0)))
	elif d <= -1.1e-131:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif d <= 6.5e+65:
		tmp = (a / c) + (b / (math.pow(c, 2.0) / d))
	else:
		tmp = (b + (a * (c / d))) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -6.4e+125)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(c * Float64(a / d))));
	elseif (d <= -8.6e+75)
		tmp = Float64(Float64(a / c) + Float64(d * Float64(b / (c ^ 2.0))));
	elseif (d <= -1.1e-131)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 6.5e+65)
		tmp = Float64(Float64(a / c) + Float64(b / Float64((c ^ 2.0) / d)));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -6.4e+125)
		tmp = (1.0 / d) * (b + (c * (a / d)));
	elseif (d <= -8.6e+75)
		tmp = (a / c) + (d * (b / (c ^ 2.0)));
	elseif (d <= -1.1e-131)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (d <= 6.5e+65)
		tmp = (a / c) + (b / ((c ^ 2.0) / d));
	else
		tmp = (b + (a * (c / d))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -6.4e+125], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8.6e+75], N[(N[(a / c), $MachinePrecision] + N[(d * N[(b / N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.1e-131], 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, 6.5e+65], N[(N[(a / c), $MachinePrecision] + N[(b / N[(N[Power[c, 2.0], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.4 \cdot 10^{+125}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\

\mathbf{elif}\;d \leq -8.6 \cdot 10^{+75}:\\
\;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\

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

\mathbf{elif}\;d \leq 6.5 \cdot 10^{+65}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}\\

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


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

    1. Initial program 45.1%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt45.1%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity45.1%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}} \]
      3. times-frac45.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-def45.1%

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

        \[\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-def73.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-rr73.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 c around 0 37.2%

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

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

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

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

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

    if -6.39999999999999967e125 < d < -8.6000000000000002e75

    1. Initial program 34.6%

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

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

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

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

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

    if -8.6000000000000002e75 < d < -1.1e-131

    1. Initial program 92.5%

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

    if -1.1e-131 < d < 6.5000000000000003e65

    1. Initial program 68.1%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
    4. Simplified84.8%

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

    if 6.5000000000000003e65 < d

    1. Initial program 41.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt41.8%

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

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

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

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

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

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

      \[\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 c around 0 68.7%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/28.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.4 \cdot 10^{+125}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + c \cdot \frac{a}{d}\right)\\ \mathbf{elif}\;d \leq -8.6 \cdot 10^{+75}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\ \mathbf{elif}\;d \leq -1.1 \cdot 10^{-131}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+65}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]

Alternative 5: 81.7% 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 -3 \cdot 10^{+138}:\\ \;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-112}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.42 \cdot 10^{-139}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.4 \cdot 10^{+91}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -3e+138)
     (/ (- a) (hypot c d))
     (if (<= c -2.7e-112)
       t_0
       (if (<= c 1.42e-139)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 1.4e+91) t_0 (/ (+ a (/ b (/ c d))) (hypot c 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 (c <= -3e+138) {
		tmp = -a / hypot(c, d);
	} else if (c <= -2.7e-112) {
		tmp = t_0;
	} else if (c <= 1.42e-139) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.4e+91) {
		tmp = t_0;
	} else {
		tmp = (a + (b / (c / d))) / hypot(c, d);
	}
	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 tmp;
	if (c <= -3e+138) {
		tmp = -a / Math.hypot(c, d);
	} else if (c <= -2.7e-112) {
		tmp = t_0;
	} else if (c <= 1.42e-139) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.4e+91) {
		tmp = t_0;
	} else {
		tmp = (a + (b / (c / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -3e+138:
		tmp = -a / math.hypot(c, d)
	elif c <= -2.7e-112:
		tmp = t_0
	elif c <= 1.42e-139:
		tmp = (b + (a * (c / d))) / d
	elif c <= 1.4e+91:
		tmp = t_0
	else:
		tmp = (a + (b / (c / d))) / math.hypot(c, 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 (c <= -3e+138)
		tmp = Float64(Float64(-a) / hypot(c, d));
	elseif (c <= -2.7e-112)
		tmp = t_0;
	elseif (c <= 1.42e-139)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 1.4e+91)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / hypot(c, d));
	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 (c <= -3e+138)
		tmp = -a / hypot(c, d);
	elseif (c <= -2.7e-112)
		tmp = t_0;
	elseif (c <= 1.42e-139)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 1.4e+91)
		tmp = t_0;
	else
		tmp = (a + (b / (c / d))) / hypot(c, d);
	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[c, -3e+138], N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.7e-112], t$95$0, If[LessEqual[c, 1.42e-139], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.4e+91], t$95$0, N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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}\;c \leq -3 \cdot 10^{+138}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -2.7 \cdot 10^{-112}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.4 \cdot 10^{+91}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 33.9%

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

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

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

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

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

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

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

      \[\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/53.6%

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

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

      \[\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 -inf 78.6%

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

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

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

    if -3.0000000000000001e138 < c < -2.7000000000000001e-112 or 1.41999999999999997e-139 < c < 1.3999999999999999e91

    1. Initial program 84.2%

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

    if -2.7000000000000001e-112 < c < 1.41999999999999997e-139

    1. Initial program 63.9%

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

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

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

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

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

        \[\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-def81.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-rr81.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. Taylor expanded in c around 0 57.9%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/38.2%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d}\right)} - 1 \]
      6. div-inv38.2%

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

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

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

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

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

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

    if 1.3999999999999999e91 < c

    1. Initial program 32.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt32.0%

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

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

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

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

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

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

      \[\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/60.6%

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

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

      \[\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 inf 76.3%

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Simplified83.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3 \cdot 10^{+138}:\\ \;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-112}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.42 \cdot 10^{-139}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.4 \cdot 10^{+91}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 6: 83.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}\;c \leq -3.7 \cdot 10^{+137}:\\ \;\;\;\;\frac{d \cdot \frac{-b}{c} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.9 \cdot 10^{-112}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 6.9 \cdot 10^{-140}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{+94}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -3.7e+137)
     (/ (- (* d (/ (- b) c)) a) (hypot c d))
     (if (<= c -1.9e-112)
       t_0
       (if (<= c 6.9e-140)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 2.1e+94) t_0 (/ (+ a (/ b (/ c d))) (hypot c 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 (c <= -3.7e+137) {
		tmp = ((d * (-b / c)) - a) / hypot(c, d);
	} else if (c <= -1.9e-112) {
		tmp = t_0;
	} else if (c <= 6.9e-140) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 2.1e+94) {
		tmp = t_0;
	} else {
		tmp = (a + (b / (c / d))) / hypot(c, d);
	}
	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 tmp;
	if (c <= -3.7e+137) {
		tmp = ((d * (-b / c)) - a) / Math.hypot(c, d);
	} else if (c <= -1.9e-112) {
		tmp = t_0;
	} else if (c <= 6.9e-140) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 2.1e+94) {
		tmp = t_0;
	} else {
		tmp = (a + (b / (c / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -3.7e+137:
		tmp = ((d * (-b / c)) - a) / math.hypot(c, d)
	elif c <= -1.9e-112:
		tmp = t_0
	elif c <= 6.9e-140:
		tmp = (b + (a * (c / d))) / d
	elif c <= 2.1e+94:
		tmp = t_0
	else:
		tmp = (a + (b / (c / d))) / math.hypot(c, 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 (c <= -3.7e+137)
		tmp = Float64(Float64(Float64(d * Float64(Float64(-b) / c)) - a) / hypot(c, d));
	elseif (c <= -1.9e-112)
		tmp = t_0;
	elseif (c <= 6.9e-140)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 2.1e+94)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / hypot(c, d));
	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 (c <= -3.7e+137)
		tmp = ((d * (-b / c)) - a) / hypot(c, d);
	elseif (c <= -1.9e-112)
		tmp = t_0;
	elseif (c <= 6.9e-140)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 2.1e+94)
		tmp = t_0;
	else
		tmp = (a + (b / (c / d))) / hypot(c, d);
	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[c, -3.7e+137], N[(N[(N[(d * N[((-b) / c), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.9e-112], t$95$0, If[LessEqual[c, 6.9e-140], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.1e+94], t$95$0, N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $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}\;c \leq -3.7 \cdot 10^{+137}:\\
\;\;\;\;\frac{d \cdot \frac{-b}{c} - a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -1.9 \cdot 10^{-112}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 2.1 \cdot 10^{+94}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 33.9%

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

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

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

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

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

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

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

      \[\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/53.6%

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

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

      \[\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 -inf 81.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(-\color{blue}{d \cdot \frac{b}{c}}\right) - a}{\mathsf{hypot}\left(c, d\right)} \]
      4. distribute-rgt-neg-in84.4%

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

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

    if -3.7000000000000002e137 < c < -1.89999999999999997e-112 or 6.9000000000000004e-140 < c < 2.09999999999999989e94

    1. Initial program 84.2%

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

    if -1.89999999999999997e-112 < c < 6.9000000000000004e-140

    1. Initial program 63.9%

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

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

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

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

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

        \[\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-def81.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-rr81.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. Taylor expanded in c around 0 57.9%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/38.2%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d}\right)} - 1 \]
      6. div-inv38.2%

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

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

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

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

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

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

    if 2.09999999999999989e94 < c

    1. Initial program 32.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt32.0%

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

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

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

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

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

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

      \[\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/60.6%

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

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

      \[\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 inf 76.3%

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Simplified83.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.7 \cdot 10^{+137}:\\ \;\;\;\;\frac{d \cdot \frac{-b}{c} - a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.9 \cdot 10^{-112}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 6.9 \cdot 10^{-140}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{+94}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 7: 83.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 := \frac{b}{\frac{c}{d}}\\ \mathbf{if}\;c \leq -5.7 \cdot 10^{+135}:\\ \;\;\;\;\frac{\left(-a\right) - t_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -7.5 \cdot 10^{-113}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{-140}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{+92}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + t_1}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))) (t_1 (/ b (/ c d))))
   (if (<= c -5.7e+135)
     (/ (- (- a) t_1) (hypot c d))
     (if (<= c -7.5e-113)
       t_0
       (if (<= c 1.5e-140)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 8e+92) t_0 (/ (+ a t_1) (hypot c d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = b / (c / d);
	double tmp;
	if (c <= -5.7e+135) {
		tmp = (-a - t_1) / hypot(c, d);
	} else if (c <= -7.5e-113) {
		tmp = t_0;
	} else if (c <= 1.5e-140) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 8e+92) {
		tmp = t_0;
	} else {
		tmp = (a + t_1) / hypot(c, d);
	}
	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 = b / (c / d);
	double tmp;
	if (c <= -5.7e+135) {
		tmp = (-a - t_1) / Math.hypot(c, d);
	} else if (c <= -7.5e-113) {
		tmp = t_0;
	} else if (c <= 1.5e-140) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 8e+92) {
		tmp = t_0;
	} else {
		tmp = (a + t_1) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = b / (c / d)
	tmp = 0
	if c <= -5.7e+135:
		tmp = (-a - t_1) / math.hypot(c, d)
	elif c <= -7.5e-113:
		tmp = t_0
	elif c <= 1.5e-140:
		tmp = (b + (a * (c / d))) / d
	elif c <= 8e+92:
		tmp = t_0
	else:
		tmp = (a + t_1) / math.hypot(c, 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)))
	t_1 = Float64(b / Float64(c / d))
	tmp = 0.0
	if (c <= -5.7e+135)
		tmp = Float64(Float64(Float64(-a) - t_1) / hypot(c, d));
	elseif (c <= -7.5e-113)
		tmp = t_0;
	elseif (c <= 1.5e-140)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 8e+92)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + t_1) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = b / (c / d);
	tmp = 0.0;
	if (c <= -5.7e+135)
		tmp = (-a - t_1) / hypot(c, d);
	elseif (c <= -7.5e-113)
		tmp = t_0;
	elseif (c <= 1.5e-140)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 8e+92)
		tmp = t_0;
	else
		tmp = (a + t_1) / hypot(c, d);
	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[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.7e+135], N[(N[((-a) - t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -7.5e-113], t$95$0, If[LessEqual[c, 1.5e-140], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+92], t$95$0, N[(N[(a + t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -7.5 \cdot 10^{-113}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 8 \cdot 10^{+92}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{a + t_1}{\mathsf{hypot}\left(c, d\right)}\\


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

    1. Initial program 33.9%

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

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

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

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

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

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

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

      \[\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/53.6%

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

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

      \[\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 -inf 81.7%

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

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

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

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

    if -5.7000000000000002e135 < c < -7.5000000000000002e-113 or 1.50000000000000009e-140 < c < 8.0000000000000003e92

    1. Initial program 84.2%

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

    if -7.5000000000000002e-113 < c < 1.50000000000000009e-140

    1. Initial program 63.9%

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

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

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

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

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

        \[\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-def81.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-rr81.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. Taylor expanded in c around 0 57.9%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/38.2%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d}\right)} - 1 \]
      6. div-inv38.2%

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

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

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

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

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

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

    if 8.0000000000000003e92 < c

    1. Initial program 32.0%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt32.0%

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

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

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

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

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

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

      \[\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/60.6%

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

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

      \[\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 inf 76.3%

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Simplified83.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.7 \cdot 10^{+135}:\\ \;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -7.5 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{-140}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 8: 79.9% 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^{+140}:\\ \;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-113}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-140}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{+141}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{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+140)
     (/ (- a) (hypot c d))
     (if (<= c -9e-113)
       t_0
       (if (<= c 2.15e-140)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 1.25e+141) t_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+140) {
		tmp = -a / hypot(c, d);
	} else if (c <= -9e-113) {
		tmp = t_0;
	} else if (c <= 2.15e-140) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.25e+141) {
		tmp = t_0;
	} else {
		tmp = a / c;
	}
	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 tmp;
	if (c <= -4.2e+140) {
		tmp = -a / Math.hypot(c, d);
	} else if (c <= -9e-113) {
		tmp = t_0;
	} else if (c <= 2.15e-140) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.25e+141) {
		tmp = t_0;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -4.2e+140:
		tmp = -a / math.hypot(c, d)
	elif c <= -9e-113:
		tmp = t_0
	elif c <= 2.15e-140:
		tmp = (b + (a * (c / d))) / d
	elif c <= 1.25e+141:
		tmp = t_0
	else:
		tmp = 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+140)
		tmp = Float64(Float64(-a) / hypot(c, d));
	elseif (c <= -9e-113)
		tmp = t_0;
	elseif (c <= 2.15e-140)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 1.25e+141)
		tmp = t_0;
	else
		tmp = Float64(a / c);
	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 (c <= -4.2e+140)
		tmp = -a / hypot(c, d);
	elseif (c <= -9e-113)
		tmp = t_0;
	elseif (c <= 2.15e-140)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 1.25e+141)
		tmp = t_0;
	else
		tmp = a / c;
	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[c, -4.2e+140], N[((-a) / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -9e-113], t$95$0, If[LessEqual[c, 2.15e-140], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.25e+141], t$95$0, N[(a / 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^{+140}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -9 \cdot 10^{-113}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.25 \cdot 10^{+141}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 33.9%

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

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

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

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

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

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

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

      \[\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/53.6%

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

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

      \[\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 -inf 78.6%

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

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

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

    if -4.2000000000000004e140 < c < -9.0000000000000002e-113 or 2.14999999999999981e-140 < c < 1.25000000000000006e141

    1. Initial program 82.3%

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

    if -9.0000000000000002e-113 < c < 2.14999999999999981e-140

    1. Initial program 63.9%

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

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

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

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

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

        \[\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-def81.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-rr81.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. Taylor expanded in c around 0 57.9%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/38.2%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d}\right)} - 1 \]
      6. div-inv38.2%

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

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

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

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

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

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

    if 1.25000000000000006e141 < c

    1. Initial program 21.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.2 \cdot 10^{+140}:\\ \;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{-140}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{+141}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 9: 79.9% 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}\;c \leq -4.8 \cdot 10^{+140}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -1.12 \cdot 10^{-112}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-139}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.06 \cdot 10^{+141}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{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.8e+140)
     (/ a c)
     (if (<= c -1.12e-112)
       t_0
       (if (<= c 2.6e-139)
         (/ (+ b (* a (/ c d))) d)
         (if (<= c 1.06e+141) t_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.8e+140) {
		tmp = a / c;
	} else if (c <= -1.12e-112) {
		tmp = t_0;
	} else if (c <= 2.6e-139) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.06e+141) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    if (c <= (-4.8d+140)) then
        tmp = a / c
    else if (c <= (-1.12d-112)) then
        tmp = t_0
    else if (c <= 2.6d-139) then
        tmp = (b + (a * (c / d))) / d
    else if (c <= 1.06d+141) then
        tmp = t_0
    else
        tmp = a / c
    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 (c <= -4.8e+140) {
		tmp = a / c;
	} else if (c <= -1.12e-112) {
		tmp = t_0;
	} else if (c <= 2.6e-139) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.06e+141) {
		tmp = t_0;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -4.8e+140:
		tmp = a / c
	elif c <= -1.12e-112:
		tmp = t_0
	elif c <= 2.6e-139:
		tmp = (b + (a * (c / d))) / d
	elif c <= 1.06e+141:
		tmp = t_0
	else:
		tmp = 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.8e+140)
		tmp = Float64(a / c);
	elseif (c <= -1.12e-112)
		tmp = t_0;
	elseif (c <= 2.6e-139)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 1.06e+141)
		tmp = t_0;
	else
		tmp = Float64(a / c);
	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 (c <= -4.8e+140)
		tmp = a / c;
	elseif (c <= -1.12e-112)
		tmp = t_0;
	elseif (c <= 2.6e-139)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 1.06e+141)
		tmp = t_0;
	else
		tmp = a / c;
	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[c, -4.8e+140], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.12e-112], t$95$0, If[LessEqual[c, 2.6e-139], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.06e+141], t$95$0, N[(a / 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.8 \cdot 10^{+140}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq -1.12 \cdot 10^{-112}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.06 \cdot 10^{+141}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.7999999999999999e140 or 1.05999999999999997e141 < c

    1. Initial program 27.7%

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

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

    if -4.7999999999999999e140 < c < -1.12e-112 or 2.5999999999999998e-139 < c < 1.05999999999999997e141

    1. Initial program 82.3%

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

    if -1.12e-112 < c < 2.5999999999999998e-139

    1. Initial program 63.9%

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

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

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

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

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

        \[\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-def81.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-rr81.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. Taylor expanded in c around 0 57.9%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/38.2%

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{b + \color{blue}{\frac{a}{\frac{d}{c}}}}{d}\right)} - 1 \]
      6. div-inv38.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.8 \cdot 10^{+140}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -1.12 \cdot 10^{-112}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-139}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.06 \cdot 10^{+141}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 10: 72.2% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{+45} \lor \neg \left(c \leq 5.5 \cdot 10^{+109}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.4500000000000001e45 or 5.4999999999999998e109 < c

    1. Initial program 41.0%

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

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

    if -2.4500000000000001e45 < c < 5.4999999999999998e109

    1. Initial program 73.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt73.8%

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

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

        \[\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-def73.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-def73.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-def84.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-rr84.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 c around 0 42.8%

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{d} \cdot \left(b + \frac{a \cdot c}{d}\right)\right)} - 1} \]
      3. associate-*l/30.1%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 62.0% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.4 \cdot 10^{+125} \lor \neg \left(d \leq -9.8 \cdot 10^{+72} \lor \neg \left(d \leq -6 \cdot 10^{-23}\right) \land d \leq 3.45 \cdot 10^{+65}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.39999999999999967e125 or -9.80000000000000012e72 < d < -6.00000000000000006e-23 or 3.45e65 < d

    1. Initial program 51.1%

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

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

    if -6.39999999999999967e125 < d < -9.80000000000000012e72 or -6.00000000000000006e-23 < d < 3.45e65

    1. Initial program 69.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.4 \cdot 10^{+125} \lor \neg \left(d \leq -9.8 \cdot 10^{+72} \lor \neg \left(d \leq -6 \cdot 10^{-23}\right) \land d \leq 3.45 \cdot 10^{+65}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 12: 43.0% accurate, 3.0× speedup?

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

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

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


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

    1. Initial program 45.1%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt45.1%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      2. *-un-lft-identity45.1%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}} \]
      3. times-frac45.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-def45.1%

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

        \[\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-def73.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-rr73.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 c around 0 37.2%

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

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

    if -2.60000000000000022e139 < d

    1. Initial program 63.4%

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

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

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

Alternative 13: 42.7% 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 60.6%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification43.1%

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

Developer target: 99.2% 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 2023314 
(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))))