Complex division, real part

Percentage Accurate: 61.9% → 82.4%
Time: 10.5s
Alternatives: 8
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 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: 82.4% accurate, 0.1× speedup?

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

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

\mathbf{elif}\;d \leq -8 \cdot 10^{-44}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.06 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.2e23

    1. Initial program 38.8%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    5. Simplified34.6%

      \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. *-un-lft-identity34.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\sqrt{\color{blue}{d \cdot d} + {c}^{2}}} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)} \]
      10. unpow242.1%

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

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

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

        \[\leadsto \frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\sqrt{\color{blue}{{c}^{2}} + d \cdot d}} \]
      14. unpow242.1%

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

        \[\leadsto \frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\sqrt{\color{blue}{{d}^{2} + {c}^{2}}}} \]
      16. unpow242.1%

        \[\leadsto \frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\sqrt{\color{blue}{d \cdot d} + {c}^{2}}} \]
      17. unpow242.1%

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

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

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

    if -1.2e23 < d < -7.99999999999999962e-44 or 6.79999999999999998e-139 < d < 2.06e77

    1. Initial program 80.3%

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

    if -7.99999999999999962e-44 < d < 6.79999999999999998e-139

    1. Initial program 64.5%

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

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

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

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

    if 2.06e77 < d

    1. Initial program 40.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+23}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-44}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-139}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.06 \cdot 10^{+77}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.5% accurate, 0.0× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\

\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+238}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 54.4%

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

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

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

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

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

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

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

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

    1. Initial program 78.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-identity78.7%

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

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

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

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

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

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

    if 4.0000000000000002e238 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 14.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{a + \color{blue}{\frac{b}{\frac{c}{d}}}}{c} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 81.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{b + c \cdot \frac{a}{d}}{d}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{-43}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.3e-43 or 1.84999999999999997e77 < d

    1. Initial program 45.2%

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

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

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

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

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

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

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

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

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

    if -1.3e-43 < d < 2.0500000000000001e-140

    1. Initial program 64.5%

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

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

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

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

    if 2.0500000000000001e-140 < d < 1.84999999999999997e77

    1. Initial program 75.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{-43}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{-140}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{+77}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 77.6% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.1499999999999999e-43 or 5.5000000000000002e56 < d

    1. Initial program 46.5%

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

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

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

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

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

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

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

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

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

    if -1.1499999999999999e-43 < d < 5.5000000000000002e56

    1. Initial program 66.6%

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

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

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

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

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

Alternative 5: 77.7% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.19999999999999984e-44 or 2.0500000000000001e-14 < d

    1. Initial program 48.9%

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

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

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

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

    if -8.19999999999999984e-44 < d < 2.0500000000000001e-14

    1. Initial program 65.2%

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

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

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

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

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

Alternative 6: 72.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+50} \lor \neg \left(d \leq 5.4 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.19999999999999972e50 or 5.3999999999999997e57 < d

    1. Initial program 42.5%

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

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

    if -7.19999999999999972e50 < d < 5.3999999999999997e57

    1. Initial program 67.6%

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 62.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.85 \cdot 10^{+102} \lor \neg \left(c \leq 2.4 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.85000000000000007e102 or 2.40000000000000023e43 < c

    1. Initial program 38.5%

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

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

    if -3.85000000000000007e102 < c < 2.40000000000000023e43

    1. Initial program 67.4%

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

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

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

Alternative 8: 42.6% 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 56.4%

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

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

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

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

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

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024165 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))