Complex division, real part

Percentage Accurate: 62.2% → 83.6%
Time: 12.0s
Alternatives: 10
Speedup: 2.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 62.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.6% 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 -5.8 \cdot 10^{+89}:\\ \;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-141}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{+108}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{\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 -5.8e+89)
     (/ (- (- a) (/ b (/ c d))) (hypot c d))
     (if (<= c -2.4e-43)
       t_0
       (if (<= c 8e-141)
         (* (/ 1.0 d) (+ b (/ a (/ d c))))
         (if (<= c 1.75e+108) t_0 (/ (+ a (* d (/ b c))) (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 <= -5.8e+89) {
		tmp = (-a - (b / (c / d))) / hypot(c, d);
	} else if (c <= -2.4e-43) {
		tmp = t_0;
	} else if (c <= 8e-141) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 1.75e+108) {
		tmp = t_0;
	} else {
		tmp = (a + (d * (b / c))) / 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 <= -5.8e+89) {
		tmp = (-a - (b / (c / d))) / Math.hypot(c, d);
	} else if (c <= -2.4e-43) {
		tmp = t_0;
	} else if (c <= 8e-141) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 1.75e+108) {
		tmp = t_0;
	} else {
		tmp = (a + (d * (b / c))) / 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 <= -5.8e+89:
		tmp = (-a - (b / (c / d))) / math.hypot(c, d)
	elif c <= -2.4e-43:
		tmp = t_0
	elif c <= 8e-141:
		tmp = (1.0 / d) * (b + (a / (d / c)))
	elif c <= 1.75e+108:
		tmp = t_0
	else:
		tmp = (a + (d * (b / c))) / 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 <= -5.8e+89)
		tmp = Float64(Float64(Float64(-a) - Float64(b / Float64(c / d))) / hypot(c, d));
	elseif (c <= -2.4e-43)
		tmp = t_0;
	elseif (c <= 8e-141)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c))));
	elseif (c <= 1.75e+108)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / 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 <= -5.8e+89)
		tmp = (-a - (b / (c / d))) / hypot(c, d);
	elseif (c <= -2.4e-43)
		tmp = t_0;
	elseif (c <= 8e-141)
		tmp = (1.0 / d) * (b + (a / (d / c)));
	elseif (c <= 1.75e+108)
		tmp = t_0;
	else
		tmp = (a + (d * (b / c))) / 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, -5.8e+89], N[(N[((-a) - N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.4e-43], t$95$0, If[LessEqual[c, 8e-141], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.75e+108], t$95$0, N[(N[(a + N[(d * N[(b / c), $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 -5.8 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -2.4 \cdot 10^{-43}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.75 \cdot 10^{+108}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 39.3%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Step-by-step derivation
      1. associate-*l/58.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-identity58.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-rr58.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)}} \]
    6. Taylor expanded in c around -inf 94.0%

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

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

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

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

    if -5.80000000000000051e89 < c < -2.4000000000000002e-43 or 8.0000000000000003e-141 < c < 1.7500000000000001e108

    1. Initial program 87.1%

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

    if -2.4000000000000002e-43 < c < 8.0000000000000003e-141

    1. Initial program 66.5%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def77.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-rr77.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. Taylor expanded in c around 0 55.2%

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

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

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

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

    if 1.7500000000000001e108 < c

    1. Initial program 41.5%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-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. Step-by-step derivation
      1. div-inv60.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.8 \cdot 10^{+89}:\\ \;\;\;\;\frac{\left(-a\right) - \frac{b}{\frac{c}{d}}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-141}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{+108}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 2: 86.0% 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(b, d, a \cdot c\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 b d (* a c)) (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(b, d, (a * c)) / 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(b, d, Float64(a * c)) / 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[(b * d + N[(a * c), $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(b, d, a \cdot c\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 79.0%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def93.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-rr93.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/93.7%

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

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

      \[\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. Step-by-step derivation
      1. div-inv93.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(b, d, c \cdot a\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.3%

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

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

      \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.3%

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

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

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

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

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

    \[\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(b, d, a \cdot c\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: 86.0% 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 79.0%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def93.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-rr93.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/93.7%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{c \cdot a}}{c \cdot c + d \cdot d} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt1.3%

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

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

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

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

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

    \[\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 4: 82.5% 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 -7.5 \cdot 10^{+99}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;c \leq -1.12 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3.3 \cdot 10^{-145}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{+108}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{\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 -7.5e+99)
     (* (/ 1.0 c) (+ a (/ (* b d) c)))
     (if (<= c -1.12e-43)
       t_0
       (if (<= c 3.3e-145)
         (* (/ 1.0 d) (+ b (/ a (/ d c))))
         (if (<= c 3.6e+108) t_0 (/ (+ a (* d (/ b c))) (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 <= -7.5e+99) {
		tmp = (1.0 / c) * (a + ((b * d) / c));
	} else if (c <= -1.12e-43) {
		tmp = t_0;
	} else if (c <= 3.3e-145) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 3.6e+108) {
		tmp = t_0;
	} else {
		tmp = (a + (d * (b / c))) / 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 <= -7.5e+99) {
		tmp = (1.0 / c) * (a + ((b * d) / c));
	} else if (c <= -1.12e-43) {
		tmp = t_0;
	} else if (c <= 3.3e-145) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 3.6e+108) {
		tmp = t_0;
	} else {
		tmp = (a + (d * (b / c))) / 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 <= -7.5e+99:
		tmp = (1.0 / c) * (a + ((b * d) / c))
	elif c <= -1.12e-43:
		tmp = t_0
	elif c <= 3.3e-145:
		tmp = (1.0 / d) * (b + (a / (d / c)))
	elif c <= 3.6e+108:
		tmp = t_0
	else:
		tmp = (a + (d * (b / c))) / 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 <= -7.5e+99)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c)));
	elseif (c <= -1.12e-43)
		tmp = t_0;
	elseif (c <= 3.3e-145)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c))));
	elseif (c <= 3.6e+108)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / 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 <= -7.5e+99)
		tmp = (1.0 / c) * (a + ((b * d) / c));
	elseif (c <= -1.12e-43)
		tmp = t_0;
	elseif (c <= 3.3e-145)
		tmp = (1.0 / d) * (b + (a / (d / c)));
	elseif (c <= 3.6e+108)
		tmp = t_0;
	else
		tmp = (a + (d * (b / c))) / 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, -7.5e+99], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.12e-43], t$95$0, If[LessEqual[c, 3.3e-145], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.6e+108], t$95$0, N[(N[(a + N[(d * N[(b / c), $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 -7.5 \cdot 10^{+99}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\

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

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

\mathbf{elif}\;c \leq 3.6 \cdot 10^{+108}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 37.7%

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

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

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

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

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

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

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

    if -7.49999999999999963e99 < c < -1.12e-43 or 3.29999999999999981e-145 < c < 3.6e108

    1. Initial program 87.2%

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

    if -1.12e-43 < c < 3.29999999999999981e-145

    1. Initial program 66.5%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def77.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-rr77.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. Taylor expanded in c around 0 55.2%

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

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

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

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

    if 3.6e108 < c

    1. Initial program 41.5%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-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. Step-by-step derivation
      1. div-inv60.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+99}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;c \leq -1.12 \cdot 10^{-43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 3.3 \cdot 10^{-145}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{+108}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 5: 83.8% 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 := d \cdot \frac{b}{c}\\ \mathbf{if}\;c \leq -1.45 \cdot 10^{+89}:\\ \;\;\;\;\frac{\left(-a\right) - t_1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.2 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.95 \cdot 10^{-142}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 3.8 \cdot 10^{+106}:\\ \;\;\;\;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 (* d (/ b c))))
   (if (<= c -1.45e+89)
     (/ (- (- a) t_1) (hypot c d))
     (if (<= c -1.2e-43)
       t_0
       (if (<= c 2.95e-142)
         (* (/ 1.0 d) (+ b (/ a (/ d c))))
         (if (<= c 3.8e+106) 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 = d * (b / c);
	double tmp;
	if (c <= -1.45e+89) {
		tmp = (-a - t_1) / hypot(c, d);
	} else if (c <= -1.2e-43) {
		tmp = t_0;
	} else if (c <= 2.95e-142) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 3.8e+106) {
		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 = d * (b / c);
	double tmp;
	if (c <= -1.45e+89) {
		tmp = (-a - t_1) / Math.hypot(c, d);
	} else if (c <= -1.2e-43) {
		tmp = t_0;
	} else if (c <= 2.95e-142) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 3.8e+106) {
		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 = d * (b / c)
	tmp = 0
	if c <= -1.45e+89:
		tmp = (-a - t_1) / math.hypot(c, d)
	elif c <= -1.2e-43:
		tmp = t_0
	elif c <= 2.95e-142:
		tmp = (1.0 / d) * (b + (a / (d / c)))
	elif c <= 3.8e+106:
		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(d * Float64(b / c))
	tmp = 0.0
	if (c <= -1.45e+89)
		tmp = Float64(Float64(Float64(-a) - t_1) / hypot(c, d));
	elseif (c <= -1.2e-43)
		tmp = t_0;
	elseif (c <= 2.95e-142)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c))));
	elseif (c <= 3.8e+106)
		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 = d * (b / c);
	tmp = 0.0;
	if (c <= -1.45e+89)
		tmp = (-a - t_1) / hypot(c, d);
	elseif (c <= -1.2e-43)
		tmp = t_0;
	elseif (c <= 2.95e-142)
		tmp = (1.0 / d) * (b + (a / (d / c)));
	elseif (c <= 3.8e+106)
		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[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.45e+89], N[(N[((-a) - t$95$1), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.2e-43], t$95$0, If[LessEqual[c, 2.95e-142], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.8e+106], 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 := d \cdot \frac{b}{c}\\
\mathbf{if}\;c \leq -1.45 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-a\right) - t_1}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -1.2 \cdot 10^{-43}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 3.8 \cdot 10^{+106}:\\
\;\;\;\;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 < -1.45000000000000013e89

    1. Initial program 39.3%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}} \]
    4. Step-by-step derivation
      1. associate-*l/58.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-identity58.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-rr58.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)}} \]
    6. Step-by-step derivation
      1. div-inv58.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{0 - \left(a + \frac{b}{\frac{c}{d}}\right)}}{\mathsf{hypot}\left(c, d\right)} \]
      5. associate--r+96.7%

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

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

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

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

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

    if -1.45000000000000013e89 < c < -1.2000000000000001e-43 or 2.94999999999999983e-142 < c < 3.7999999999999998e106

    1. Initial program 87.1%

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

    if -1.2000000000000001e-43 < c < 2.94999999999999983e-142

    1. Initial program 66.5%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def77.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-rr77.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. Taylor expanded in c around 0 55.2%

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

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

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

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

    if 3.7999999999999998e106 < c

    1. Initial program 41.5%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-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. Step-by-step derivation
      1. div-inv60.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.45 \cdot 10^{+89}:\\ \;\;\;\;\frac{\left(-a\right) - d \cdot \frac{b}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -1.2 \cdot 10^{-43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.95 \cdot 10^{-142}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 3.8 \cdot 10^{+106}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternative 6: 81.2% 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}\\ t_1 := \frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{if}\;c \leq -1.15 \cdot 10^{+101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -5 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 5 \cdot 10^{-141}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 3.2 \cdot 10^{+118}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (* (/ 1.0 c) (+ a (/ (* b d) c)))))
   (if (<= c -1.15e+101)
     t_1
     (if (<= c -5e-43)
       t_0
       (if (<= c 5e-141)
         (* (/ 1.0 d) (+ b (/ a (/ d c))))
         (if (<= c 3.2e+118) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (1.0 / c) * (a + ((b * d) / c));
	double tmp;
	if (c <= -1.15e+101) {
		tmp = t_1;
	} else if (c <= -5e-43) {
		tmp = t_0;
	} else if (c <= 5e-141) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 3.2e+118) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (1.0d0 / c) * (a + ((b * d) / c))
    if (c <= (-1.15d+101)) then
        tmp = t_1
    else if (c <= (-5d-43)) then
        tmp = t_0
    else if (c <= 5d-141) then
        tmp = (1.0d0 / d) * (b + (a / (d / c)))
    else if (c <= 3.2d+118) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (1.0 / c) * (a + ((b * d) / c));
	double tmp;
	if (c <= -1.15e+101) {
		tmp = t_1;
	} else if (c <= -5e-43) {
		tmp = t_0;
	} else if (c <= 5e-141) {
		tmp = (1.0 / d) * (b + (a / (d / c)));
	} else if (c <= 3.2e+118) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (1.0 / c) * (a + ((b * d) / c))
	tmp = 0
	if c <= -1.15e+101:
		tmp = t_1
	elif c <= -5e-43:
		tmp = t_0
	elif c <= 5e-141:
		tmp = (1.0 / d) * (b + (a / (d / c)))
	elif c <= 3.2e+118:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(1.0 / c) * Float64(a + Float64(Float64(b * d) / c)))
	tmp = 0.0
	if (c <= -1.15e+101)
		tmp = t_1;
	elseif (c <= -5e-43)
		tmp = t_0;
	elseif (c <= 5e-141)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a / Float64(d / c))));
	elseif (c <= 3.2e+118)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (1.0 / c) * (a + ((b * d) / c));
	tmp = 0.0;
	if (c <= -1.15e+101)
		tmp = t_1;
	elseif (c <= -5e-43)
		tmp = t_0;
	elseif (c <= 5e-141)
		tmp = (1.0 / d) * (b + (a / (d / c)));
	elseif (c <= 3.2e+118)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.15e+101], t$95$1, If[LessEqual[c, -5e-43], t$95$0, If[LessEqual[c, 5e-141], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.2e+118], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -5 \cdot 10^{-43}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 3.2 \cdot 10^{+118}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.1500000000000001e101 or 3.20000000000000016e118 < c

    1. Initial program 38.8%

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

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

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

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

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

    if -1.1500000000000001e101 < c < -5.00000000000000019e-43 or 4.9999999999999999e-141 < c < 3.20000000000000016e118

    1. Initial program 86.6%

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

    if -5.00000000000000019e-43 < c < 4.9999999999999999e-141

    1. Initial program 66.5%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d}} \]
      6. hypot-def77.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-rr77.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. Taylor expanded in c around 0 55.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.15 \cdot 10^{+101}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \mathbf{elif}\;c \leq -5 \cdot 10^{-43}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 5 \cdot 10^{-141}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + \frac{a}{\frac{d}{c}}\right)\\ \mathbf{elif}\;c \leq 3.2 \cdot 10^{+118}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\ \end{array} \]

Alternative 7: 71.7% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.42 \cdot 10^{+88} \lor \neg \left(d \leq 9 \cdot 10^{+17}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.41999999999999996e88 or 9e17 < d

    1. Initial program 45.6%

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

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

    if -1.41999999999999996e88 < d < 9e17

    1. Initial program 75.6%

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 76.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{-43} \lor \neg \left(c \leq 1.36 \cdot 10^{+37}\right):\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b \cdot d}{c}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.44999999999999994e-43 or 1.3599999999999999e37 < c

    1. Initial program 55.1%

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

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

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

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

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

    if -2.44999999999999994e-43 < c < 1.3599999999999999e37

    1. Initial program 73.5%

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 63.7% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -600 \lor \neg \left(c \leq 6.5 \cdot 10^{+36}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -600 or 6.4999999999999998e36 < c

    1. Initial program 52.5%

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

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

    if -600 < c < 6.4999999999999998e36

    1. Initial program 74.5%

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

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

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

Alternative 10: 43.0% 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 64.5%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification45.5%

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

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023305 
(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))))