Complex division, real part

Percentage Accurate: 61.6% → 84.6%
Time: 10.8s
Alternatives: 10
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 10 alternatives:

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

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 5 \cdot 10^{+257}:\\
\;\;\;\;\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{b + a \cdot \left(c \cdot \frac{1}{d}\right)}{d}\\


\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))) < 5.00000000000000028e257

    1. Initial program 73.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000028e257 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 8.7%

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

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

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

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

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

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

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

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

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

Alternative 2: 80.3% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := a + \frac{b \cdot d}{c}\\
\mathbf{if}\;d \leq -5.5 \cdot 10^{+30}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\

\mathbf{elif}\;d \leq 2.4 \cdot 10^{-228}:\\
\;\;\;\;\frac{t\_0}{c}\\

\mathbf{elif}\;d \leq 1.2 \cdot 10^{+114}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot t\_0}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 33.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.50000000000000025e30 < d < 2.40000000000000002e-228

    1. Initial program 69.1%

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

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

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

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

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

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

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

    if 2.40000000000000002e-228 < d < 1.2e114

    1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      9. hypot-define88.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)}} \]
    6. Applied egg-rr88.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)}} \]
    7. Taylor expanded in c around inf 81.0%

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

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

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

    if 1.2e114 < d

    1. Initial program 23.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.5 \cdot 10^{+30}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{-228}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{+114}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot \left(a + \frac{b \cdot d}{c}\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.6 \cdot 10^{+30}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-153}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+69}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -4.6e+30)
   (/ (+ b (/ c (/ d a))) d)
   (if (<= d 5.8e-153)
     (/ (+ a (/ (* b d) c)) c)
     (if (<= d 5.6e+69)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (/ (+ b (* a (/ c d))) d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.6e+30) {
		tmp = (b + (c / (d / a))) / d;
	} else if (d <= 5.8e-153) {
		tmp = (a + ((b * d) / c)) / c;
	} else if (d <= 5.6e+69) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a * (c / d))) / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= (-4.6d+30)) then
        tmp = (b + (c / (d / a))) / d
    else if (d <= 5.8d-153) then
        tmp = (a + ((b * d) / c)) / c
    else if (d <= 5.6d+69) then
        tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
    else
        tmp = (b + (a * (c / d))) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.6e+30) {
		tmp = (b + (c / (d / a))) / d;
	} else if (d <= 5.8e-153) {
		tmp = (a + ((b * d) / c)) / c;
	} else if (d <= 5.6e+69) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a * (c / d))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -4.6e+30:
		tmp = (b + (c / (d / a))) / d
	elif d <= 5.8e-153:
		tmp = (a + ((b * d) / c)) / c
	elif d <= 5.6e+69:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = (b + (a * (c / d))) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -4.6e+30)
		tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d);
	elseif (d <= 5.8e-153)
		tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c);
	elseif (d <= 5.6e+69)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -4.6e+30)
		tmp = (b + (c / (d / a))) / d;
	elseif (d <= 5.8e-153)
		tmp = (a + ((b * d) / c)) / c;
	elseif (d <= 5.6e+69)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = (b + (a * (c / d))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.6e+30], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 5.8e-153], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.6e+69], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 33.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.6e30 < d < 5.80000000000000004e-153

    1. Initial program 68.7%

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

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

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

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

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

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

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

    if 5.80000000000000004e-153 < d < 5.59999999999999964e69

    1. Initial program 85.6%

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

    if 5.59999999999999964e69 < d

    1. Initial program 32.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.6 \cdot 10^{+30}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-153}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+69}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.6 \cdot 10^{+30} \lor \neg \left(d \leq 1.9 \cdot 10^{-39}\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 -7.6e+30) (not (<= d 1.9e-39)))
   (/ (+ b (* a (/ c d))) d)
   (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -7.6e+30) || !(d <= 1.9e-39)) {
		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 <= (-7.6d+30)) .or. (.not. (d <= 1.9d-39))) 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 <= -7.6e+30) || !(d <= 1.9e-39)) {
		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 <= -7.6e+30) or not (d <= 1.9e-39):
		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 <= -7.6e+30) || !(d <= 1.9e-39))
		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 <= -7.6e+30) || ~((d <= 1.9e-39)))
		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, -7.6e+30], N[Not[LessEqual[d, 1.9e-39]], $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 -7.6 \cdot 10^{+30} \lor \neg \left(d \leq 1.9 \cdot 10^{-39}\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 < -7.6000000000000003e30 or 1.9000000000000001e-39 < d

    1. Initial program 39.5%

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

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

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

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

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

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

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

    if -7.6000000000000003e30 < d < 1.9000000000000001e-39

    1. Initial program 72.5%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.6 \cdot 10^{+30} \lor \neg \left(d \leq 1.9 \cdot 10^{-39}\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 5: 72.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+31} \lor \neg \left(d \leq 9.6 \cdot 10^{-35}\right):\\ \;\;\;\;\frac{b}{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.05e+31) (not (<= d 9.6e-35)))
   (/ b d)
   (/ (+ a (/ (* b d) c)) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.05e+31) || !(d <= 9.6e-35)) {
		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 <= (-1.05d+31)) .or. (.not. (d <= 9.6d-35))) 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 <= -1.05e+31) || !(d <= 9.6e-35)) {
		tmp = b / d;
	} else {
		tmp = (a + ((b * d) / c)) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.05e+31) or not (d <= 9.6e-35):
		tmp = b / d
	else:
		tmp = (a + ((b * d) / c)) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1.05e+31) || !(d <= 9.6e-35))
		tmp = Float64(b / 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.05e+31) || ~((d <= 9.6e-35)))
		tmp = b / d;
	else
		tmp = (a + ((b * d) / c)) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.05e+31], N[Not[LessEqual[d, 9.6e-35]], $MachinePrecision]], N[(b / 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.05 \cdot 10^{+31} \lor \neg \left(d \leq 9.6 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{b}{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.04999999999999989e31 or 9.6000000000000005e-35 < d

    1. Initial program 39.5%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in c around 0 72.7%

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

    if -1.04999999999999989e31 < d < 9.6000000000000005e-35

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

Alternative 6: 72.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{+31} \lor \neg \left(d \leq 9.6 \cdot 10^{-35}\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 -1e+31) (not (<= d 9.6e-35)))
   (/ b d)
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1e+31) || !(d <= 9.6e-35)) {
		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 <= (-1d+31)) .or. (.not. (d <= 9.6d-35))) 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 <= -1e+31) || !(d <= 9.6e-35)) {
		tmp = b / d;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1e+31) or not (d <= 9.6e-35):
		tmp = b / d
	else:
		tmp = (a + (b * (d / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1e+31) || !(d <= 9.6e-35))
		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 <= -1e+31) || ~((d <= 9.6e-35)))
		tmp = b / d;
	else
		tmp = (a + (b * (d / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1e+31], N[Not[LessEqual[d, 9.6e-35]], $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 -1 \cdot 10^{+31} \lor \neg \left(d \leq 9.6 \cdot 10^{-35}\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 < -9.9999999999999996e30 or 9.6000000000000005e-35 < d

    1. Initial program 39.5%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in c around 0 72.7%

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

    if -9.9999999999999996e30 < d < 9.6000000000000005e-35

    1. Initial program 72.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.2% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.7999999999999996e30

    1. Initial program 33.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.7999999999999996e30 < d < 1.9000000000000001e-35

    1. Initial program 72.5%

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

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

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

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

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

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

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

    if 1.9000000000000001e-35 < d

    1. Initial program 45.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{+30}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{-35}:\\ \;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 78.1% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.4e30

    1. Initial program 33.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.4e30 < d < 1.30000000000000002e-35

    1. Initial program 72.5%

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

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

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

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

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

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

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

    if 1.30000000000000002e-35 < d

    1. Initial program 45.8%

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

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

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

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

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

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

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

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

Alternative 9: 64.5% accurate, 1.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.9999999999999998e30 or 3.8000000000000004e-37 < d

    1. Initial program 39.5%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in c around 0 72.7%

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

    if -4.9999999999999998e30 < d < 3.8000000000000004e-37

    1. Initial program 72.5%

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

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

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

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

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

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

Alternative 10: 43.4% 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 54.7%

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

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  6. 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 2024181 
(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))))