Complex division, real part

Percentage Accurate: 61.9% → 89.4%
Time: 7.4s
Alternatives: 8
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 8 alternatives:

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

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

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


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

    1. Initial program 81.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt81.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-frac81.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-def81.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-def81.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-def97.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-rr97.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/97.8%

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

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

      \[\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 2.0000000000000001e270 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 14.9%

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

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

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

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

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

        \[\leadsto \frac{d}{d \cdot d + \color{blue}{c \cdot c}} \cdot b + \frac{c \cdot a}{{d}^{2} + {c}^{2}} \]
      5. fma-udef17.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 82.7% accurate, 0.1× speedup?

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

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

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

\mathbf{elif}\;d \leq 1.4 \cdot 10^{+123}:\\
\;\;\;\;b \cdot \frac{d}{t_0} + a \cdot \frac{c}{t_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.10000000000000004e26 or 1.40000000000000006e123 < d

    1. Initial program 41.7%

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

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

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

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

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

    if -1.10000000000000004e26 < d < 1.7e-158

    1. Initial program 77.3%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b + \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a} \]
    5. Step-by-step derivation
      1. *-un-lft-identity73.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.7e-158 < d < 1.40000000000000006e123

    1. Initial program 79.5%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b + \color{blue}{\frac{c}{{d}^{2} + {c}^{2}} \cdot a} \]
      8. unpow284.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.1 \cdot 10^{+26}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-158}:\\ \;\;\;\;\frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{b}} + a \cdot \frac{1}{c}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{+123}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} + a \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 3: 80.8% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq 1.5 \cdot 10^{-93}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 2.6 \cdot 10^{+100}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -6.4999999999999996e23 or 2.6000000000000002e100 < d

    1. Initial program 43.1%

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

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

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

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

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

    if -6.4999999999999996e23 < d < 1.5000000000000001e-93 or 3.30000000000000023e65 < d < 2.6000000000000002e100

    1. Initial program 76.3%

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

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

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

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

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

        \[\leadsto \frac{d}{d \cdot d + \color{blue}{c \cdot c}} \cdot b + \frac{c \cdot a}{{d}^{2} + {c}^{2}} \]
      5. fma-udef72.6%

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

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

        \[\leadsto \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b + \color{blue}{\frac{c}{{d}^{2} + {c}^{2}} \cdot a} \]
      8. unpow274.5%

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

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

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

      \[\leadsto \color{blue}{\frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b + \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a} \]
    5. Step-by-step derivation
      1. *-un-lft-identity74.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5000000000000001e-93 < d < 3.30000000000000023e65

    1. Initial program 83.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.5 \cdot 10^{+23}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-93}:\\ \;\;\;\;\frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{b}} + a \cdot \frac{1}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+65}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{+100}:\\ \;\;\;\;\frac{\frac{d}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{b}} + a \cdot \frac{1}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 4: 82.7% 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{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{if}\;d \leq -1.9 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -2.15 \cdot 10^{-150}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 10^{-154}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+82}:\\ \;\;\;\;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 (+ (/ b d) (* (/ c d) (/ a d)))))
   (if (<= d -1.9e+94)
     t_1
     (if (<= d -2.15e-150)
       t_0
       (if (<= d 1e-154)
         (+ (/ a c) (/ b (* c (/ c d))))
         (if (<= d 1.7e+82) 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 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -1.9e+94) {
		tmp = t_1;
	} else if (d <= -2.15e-150) {
		tmp = t_0;
	} else if (d <= 1e-154) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 1.7e+82) {
		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 = (b / d) + ((c / d) * (a / d))
    if (d <= (-1.9d+94)) then
        tmp = t_1
    else if (d <= (-2.15d-150)) then
        tmp = t_0
    else if (d <= 1d-154) then
        tmp = (a / c) + (b / (c * (c / d)))
    else if (d <= 1.7d+82) 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 = (b / d) + ((c / d) * (a / d));
	double tmp;
	if (d <= -1.9e+94) {
		tmp = t_1;
	} else if (d <= -2.15e-150) {
		tmp = t_0;
	} else if (d <= 1e-154) {
		tmp = (a / c) + (b / (c * (c / d)));
	} else if (d <= 1.7e+82) {
		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 = (b / d) + ((c / d) * (a / d))
	tmp = 0
	if d <= -1.9e+94:
		tmp = t_1
	elif d <= -2.15e-150:
		tmp = t_0
	elif d <= 1e-154:
		tmp = (a / c) + (b / (c * (c / d)))
	elif d <= 1.7e+82:
		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(b / d) + Float64(Float64(c / d) * Float64(a / d)))
	tmp = 0.0
	if (d <= -1.9e+94)
		tmp = t_1;
	elseif (d <= -2.15e-150)
		tmp = t_0;
	elseif (d <= 1e-154)
		tmp = Float64(Float64(a / c) + Float64(b / Float64(c * Float64(c / d))));
	elseif (d <= 1.7e+82)
		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 = (b / d) + ((c / d) * (a / d));
	tmp = 0.0;
	if (d <= -1.9e+94)
		tmp = t_1;
	elseif (d <= -2.15e-150)
		tmp = t_0;
	elseif (d <= 1e-154)
		tmp = (a / c) + (b / (c * (c / d)));
	elseif (d <= 1.7e+82)
		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[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.9e+94], t$95$1, If[LessEqual[d, -2.15e-150], t$95$0, If[LessEqual[d, 1e-154], N[(N[(a / c), $MachinePrecision] + N[(b / N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.7e+82], 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{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -1.9 \cdot 10^{+94}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq -2.15 \cdot 10^{-150}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.7 \cdot 10^{+82}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.8999999999999998e94 or 1.69999999999999997e82 < d

    1. Initial program 40.0%

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

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

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

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

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

    if -1.8999999999999998e94 < d < -2.15000000000000002e-150 or 9.9999999999999997e-155 < d < 1.69999999999999997e82

    1. Initial program 84.0%

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

    if -2.15000000000000002e-150 < d < 9.9999999999999997e-155

    1. Initial program 73.4%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.9 \cdot 10^{+94}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;d \leq -2.15 \cdot 10^{-150}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 10^{-154}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+82}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \]

Alternative 5: 76.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.8 \cdot 10^{+22} \lor \neg \left(d \leq -1.05 \cdot 10^{-37}\right) \land \left(d \leq -2 \cdot 10^{-67} \lor \neg \left(d \leq 800000000\right)\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.8e22 or -1.05e-37 < d < -1.99999999999999989e-67 or 8e8 < d

    1. Initial program 50.4%

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

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

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

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

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

    if -4.8e22 < d < -1.05e-37 or -1.99999999999999989e-67 < d < 8e8

    1. Initial program 78.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{+22} \lor \neg \left(d \leq -1.05 \cdot 10^{-37}\right) \land \left(d \leq -2 \cdot 10^{-67} \lor \neg \left(d \leq 800000000\right)\right):\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]

Alternative 6: 71.8% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.0000000000000001e30 or 4.1e13 < d

    1. Initial program 47.6%

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

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

    if -4.0000000000000001e30 < d < 4.1e13

    1. Initial program 79.8%

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

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

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

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

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

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

Alternative 7: 64.3% accurate, 2.1× speedup?

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

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

\mathbf{elif}\;d \leq 3100:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.7999999999999999e23 or 3100 < d

    1. Initial program 48.4%

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

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

    if -1.7999999999999999e23 < d < 3100

    1. Initial program 79.5%

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

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

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

Alternative 8: 42.7% accurate, 5.0× speedup?

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

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

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

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

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

Developer target: 99.4% 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 2023208 
(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))))