Complex division, real part

Percentage Accurate: 61.2% → 85.2%
Time: 9.5s
Alternatives: 9
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 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.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: 85.2% 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{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \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))
   (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (fma(b, d, (a * c)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (a / c) + ((d / c) * (b / c));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(fma(b, d, Float64(a * c)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(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[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / 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 \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{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\


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

    1. Initial program 73.7%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt73.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-frac73.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-define73.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-define73.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-define93.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)}} \]
    4. 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)}} \]
    5. Step-by-step derivation
      1. frac-times73.7%

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

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

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

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

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

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

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

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

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

        \[\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)} \]
    6. Applied egg-rr93.8%

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\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. Add Preprocessing
    3. Taylor expanded in c around inf 51.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{if}\;c \leq -2.05 \cdot 10^{+71}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-107}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{-151}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{+112}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (+ (/ a c) (* (/ d c) (/ b c)))))
   (if (<= c -2.05e+71)
     t_1
     (if (<= c -1.5e-107)
       t_0
       (if (<= c 1.75e-151)
         (+ (/ b d) (* a (/ c (pow d 2.0))))
         (if (<= c 1.8e+112) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a / c) + ((d / c) * (b / c));
	double tmp;
	if (c <= -2.05e+71) {
		tmp = t_1;
	} else if (c <= -1.5e-107) {
		tmp = t_0;
	} else if (c <= 1.75e-151) {
		tmp = (b / d) + (a * (c / pow(d, 2.0)));
	} else if (c <= 1.8e+112) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (a / c) + ((d / c) * (b / c))
    if (c <= (-2.05d+71)) then
        tmp = t_1
    else if (c <= (-1.5d-107)) then
        tmp = t_0
    else if (c <= 1.75d-151) then
        tmp = (b / d) + (a * (c / (d ** 2.0d0)))
    else if (c <= 1.8d+112) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a / c) + ((d / c) * (b / c));
	double tmp;
	if (c <= -2.05e+71) {
		tmp = t_1;
	} else if (c <= -1.5e-107) {
		tmp = t_0;
	} else if (c <= 1.75e-151) {
		tmp = (b / d) + (a * (c / Math.pow(d, 2.0)));
	} else if (c <= 1.8e+112) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (a / c) + ((d / c) * (b / c))
	tmp = 0
	if c <= -2.05e+71:
		tmp = t_1
	elif c <= -1.5e-107:
		tmp = t_0
	elif c <= 1.75e-151:
		tmp = (b / d) + (a * (c / math.pow(d, 2.0)))
	elif c <= 1.8e+112:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)))
	tmp = 0.0
	if (c <= -2.05e+71)
		tmp = t_1;
	elseif (c <= -1.5e-107)
		tmp = t_0;
	elseif (c <= 1.75e-151)
		tmp = Float64(Float64(b / d) + Float64(a * Float64(c / (d ^ 2.0))));
	elseif (c <= 1.8e+112)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (a / c) + ((d / c) * (b / c));
	tmp = 0.0;
	if (c <= -2.05e+71)
		tmp = t_1;
	elseif (c <= -1.5e-107)
		tmp = t_0;
	elseif (c <= 1.75e-151)
		tmp = (b / d) + (a * (c / (d ^ 2.0)));
	elseif (c <= 1.8e+112)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.05e+71], t$95$1, If[LessEqual[c, -1.5e-107], t$95$0, If[LessEqual[c, 1.75e-151], N[(N[(b / d), $MachinePrecision] + N[(a * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.8e+112], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -1.5 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.8 \cdot 10^{+112}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.0500000000000001e71 or 1.8e112 < c

    1. Initial program 34.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.0500000000000001e71 < c < -1.4999999999999999e-107 or 1.74999999999999998e-151 < c < 1.8e112

    1. Initial program 78.0%

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

    if -1.4999999999999999e-107 < c < 1.74999999999999998e-151

    1. Initial program 68.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.05 \cdot 10^{+71}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-107}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{-151}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{elif}\;c \leq 1.8 \cdot 10^{+112}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.25 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+67}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.25e-21)
   (+ (/ b d) (* a (/ c (pow d 2.0))))
   (if (<= d 1.9e+67)
     (+ (/ a c) (/ (/ (* b d) c) c))
     (/ (+ b (* a (/ c d))) (hypot c d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.25e-21) {
		tmp = (b / d) + (a * (c / pow(d, 2.0)));
	} else if (d <= 1.9e+67) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else {
		tmp = (b + (a * (c / d))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.25e-21) {
		tmp = (b / d) + (a * (c / Math.pow(d, 2.0)));
	} else if (d <= 1.9e+67) {
		tmp = (a / c) + (((b * d) / c) / c);
	} else {
		tmp = (b + (a * (c / d))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -1.25e-21:
		tmp = (b / d) + (a * (c / math.pow(d, 2.0)))
	elif d <= 1.9e+67:
		tmp = (a / c) + (((b * d) / c) / c)
	else:
		tmp = (b + (a * (c / d))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.25e-21)
		tmp = Float64(Float64(b / d) + Float64(a * Float64(c / (d ^ 2.0))));
	elseif (d <= 1.9e+67)
		tmp = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -1.25e-21)
		tmp = (b / d) + (a * (c / (d ^ 2.0)));
	elseif (d <= 1.9e+67)
		tmp = (a / c) + (((b * d) / c) / c);
	else
		tmp = (b + (a * (c / d))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.25e-21], N[(N[(b / d), $MachinePrecision] + N[(a * N[(c / N[Power[d, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.9e+67], N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.24999999999999993e-21

    1. Initial program 50.3%

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

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

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

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

    if -1.24999999999999993e-21 < d < 1.9000000000000001e67

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

    if 1.9000000000000001e67 < d

    1. Initial program 39.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt39.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-frac39.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-define39.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-define39.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-define63.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.25 \cdot 10^{-21}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+67}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.8% accurate, 0.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.99999999999999982e-21

    1. Initial program 50.3%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt50.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-frac50.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-define50.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-define50.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-define70.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\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)} \]
    6. Applied egg-rr70.8%

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

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

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

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

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

    if -1.99999999999999982e-21 < d < 1.9000000000000001e67

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

    if 1.9000000000000001e67 < d

    1. Initial program 39.1%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt39.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-frac39.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-define39.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-define39.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-define63.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{-21}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+67}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.5% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;c \leq -3.1 \cdot 10^{-107}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.76 \cdot 10^{+112}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -8.80000000000000003e70 or 1.75999999999999999e112 < c

    1. Initial program 34.0%

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.80000000000000003e70 < c < -3.10000000000000022e-107 or 4.00000000000000026e-152 < c < 1.75999999999999999e112

    1. Initial program 78.0%

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

    if -3.10000000000000022e-107 < c < 4.00000000000000026e-152

    1. Initial program 68.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{+70}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -3.1 \cdot 10^{-107}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-152}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 1.76 \cdot 10^{+112}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 69.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.3 \cdot 10^{-21} \lor \neg \left(d \leq 3.4 \cdot 10^{+67}\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 -2.3e-21) (not (<= d 3.4e+67)))
   (/ b d)
   (+ (/ a c) (* (/ d c) (/ b c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -2.3e-21) || !(d <= 3.4e+67)) {
		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 <= (-2.3d-21)) .or. (.not. (d <= 3.4d+67))) 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 <= -2.3e-21) || !(d <= 3.4e+67)) {
		tmp = b / d;
	} else {
		tmp = (a / c) + ((d / c) * (b / c));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -2.3e-21) or not (d <= 3.4e+67):
		tmp = b / d
	else:
		tmp = (a / c) + ((d / c) * (b / c))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -2.3e-21) || !(d <= 3.4e+67))
		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 <= -2.3e-21) || ~((d <= 3.4e+67)))
		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, -2.3e-21], N[Not[LessEqual[d, 3.4e+67]], $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 -2.3 \cdot 10^{-21} \lor \neg \left(d \leq 3.4 \cdot 10^{+67}\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 < -2.29999999999999999e-21 or 3.4000000000000002e67 < d

    1. Initial program 45.8%

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

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

    if -2.29999999999999999e-21 < d < 3.4000000000000002e67

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 70.7% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{-21} \lor \neg \left(d \leq 1.8 \cdot 10^{+67}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.8999999999999999e-21 or 1.7999999999999999e67 < d

    1. Initial program 45.8%

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

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

    if -1.8999999999999999e-21 < d < 1.7999999999999999e67

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

Alternative 8: 62.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{-22} \lor \neg \left(d \leq 3.4 \cdot 10^{+68}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.19999999999999987e-22 or 3.40000000000000015e68 < d

    1. Initial program 45.8%

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

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

    if -3.19999999999999987e-22 < d < 3.40000000000000015e68

    1. Initial program 71.4%

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

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

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

Alternative 9: 42.8% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification45.0%

    \[\leadsto \frac{a}{c} \]
  5. Add Preprocessing

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 2024039 
(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))))