Complex division, real part

Percentage Accurate: 61.4% → 82.0%
Time: 8.4s
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.4% 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.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -2.06 \cdot 10^{+152}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;c \leq -3.4 \cdot 10^{-116}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-28}:\\ \;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\ \mathbf{elif}\;c \leq 3.2 \cdot 10^{+105}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* d b) (* c a)) (+ (* c c) (* d d)))))
   (if (<= c -2.06e+152)
     (/ (+ a (/ b (/ c d))) c)
     (if (<= c -3.4e-116)
       t_0
       (if (<= c 1.25e-28)
         (/ (+ b (/ (* c a) d)) d)
         (if (<= c 3.2e+105) t_0 (/ (+ a (* b (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -2.06e+152) {
		tmp = (a + (b / (c / d))) / c;
	} else if (c <= -3.4e-116) {
		tmp = t_0;
	} else if (c <= 1.25e-28) {
		tmp = (b + ((c * a) / d)) / d;
	} else if (c <= 3.2e+105) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d))
    if (c <= (-2.06d+152)) then
        tmp = (a + (b / (c / d))) / c
    else if (c <= (-3.4d-116)) then
        tmp = t_0
    else if (c <= 1.25d-28) then
        tmp = (b + ((c * a) / d)) / d
    else if (c <= 3.2d+105) then
        tmp = t_0
    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 t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -2.06e+152) {
		tmp = (a + (b / (c / d))) / c;
	} else if (c <= -3.4e-116) {
		tmp = t_0;
	} else if (c <= 1.25e-28) {
		tmp = (b + ((c * a) / d)) / d;
	} else if (c <= 3.2e+105) {
		tmp = t_0;
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -2.06e+152:
		tmp = (a + (b / (c / d))) / c
	elif c <= -3.4e-116:
		tmp = t_0
	elif c <= 1.25e-28:
		tmp = (b + ((c * a) / d)) / d
	elif c <= 3.2e+105:
		tmp = t_0
	else:
		tmp = (a + (b * (d / c))) / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -2.06e+152)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c);
	elseif (c <= -3.4e-116)
		tmp = t_0;
	elseif (c <= 1.25e-28)
		tmp = Float64(Float64(b + Float64(Float64(c * a) / d)) / d);
	elseif (c <= 3.2e+105)
		tmp = t_0;
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((d * b) + (c * a)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -2.06e+152)
		tmp = (a + (b / (c / d))) / c;
	elseif (c <= -3.4e-116)
		tmp = t_0;
	elseif (c <= 1.25e-28)
		tmp = (b + ((c * a) / d)) / d;
	elseif (c <= 3.2e+105)
		tmp = t_0;
	else
		tmp = (a + (b * (d / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.06e+152], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -3.4e-116], t$95$0, If[LessEqual[c, 1.25e-28], N[(N[(b + N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.2e+105], t$95$0, N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -3.4 \cdot 10^{-116}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 3.2 \cdot 10^{+105}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 27.5%

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

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

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

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

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

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

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

    if -2.06e152 < c < -3.39999999999999992e-116 or 1.25e-28 < c < 3.2e105

    1. Initial program 85.0%

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

    if -3.39999999999999992e-116 < c < 1.25e-28

    1. Initial program 71.6%

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

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

    if 3.2e105 < c

    1. Initial program 39.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.06 \cdot 10^{+152}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;c \leq -3.4 \cdot 10^{-116}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-28}:\\ \;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\ \mathbf{elif}\;c \leq 3.2 \cdot 10^{+105}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;d \leq 2 \cdot 10^{-148}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 6 \cdot 10^{+147}:\\ \;\;\;\;\frac{d \cdot b + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -4.2e-36)
   (* (/ d (hypot d c)) (/ b (hypot d c)))
   (if (<= d 2e-148)
     (/ (+ a (/ (* d b) c)) c)
     (if (<= d 6e+147)
       (/ (+ (* d b) (* c a)) (+ (* c c) (* d d)))
       (/ (+ b (/ a (/ d c))) d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.2e-36) {
		tmp = (d / hypot(d, c)) * (b / hypot(d, c));
	} else if (d <= 2e-148) {
		tmp = (a + ((d * b) / c)) / c;
	} else if (d <= 6e+147) {
		tmp = ((d * b) + (c * a)) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a / (d / c))) / d;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.2e-36) {
		tmp = (d / Math.hypot(d, c)) * (b / Math.hypot(d, c));
	} else if (d <= 2e-148) {
		tmp = (a + ((d * b) / c)) / c;
	} else if (d <= 6e+147) {
		tmp = ((d * b) + (c * a)) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a / (d / c))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -4.2e-36:
		tmp = (d / math.hypot(d, c)) * (b / math.hypot(d, c))
	elif d <= 2e-148:
		tmp = (a + ((d * b) / c)) / c
	elif d <= 6e+147:
		tmp = ((d * b) + (c * a)) / ((c * c) + (d * d))
	else:
		tmp = (b + (a / (d / c))) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -4.2e-36)
		tmp = Float64(Float64(d / hypot(d, c)) * Float64(b / hypot(d, c)));
	elseif (d <= 2e-148)
		tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c);
	elseif (d <= 6e+147)
		tmp = Float64(Float64(Float64(d * b) + Float64(c * a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(Float64(b + Float64(a / Float64(d / c))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -4.2e-36)
		tmp = (d / hypot(d, c)) * (b / hypot(d, c));
	elseif (d <= 2e-148)
		tmp = (a + ((d * b) / c)) / c;
	elseif (d <= 6e+147)
		tmp = ((d * b) + (c * a)) / ((c * c) + (d * d));
	else
		tmp = (b + (a / (d / c))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.2e-36], 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, 2e-148], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6e+147], N[(N[(N[(d * b), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a / N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.2 \cdot 10^{-36}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{b}{\mathsf{hypot}\left(d, c\right)}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -4.19999999999999982e-36

    1. Initial program 56.3%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt47.4%

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

        \[\leadsto \color{blue}{\frac{d}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. +-commutative53.4%

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

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

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

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

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

    if -4.19999999999999982e-36 < d < 1.99999999999999987e-148

    1. Initial program 69.6%

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

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

    if 1.99999999999999987e-148 < d < 5.99999999999999987e147

    1. Initial program 83.9%

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

    if 5.99999999999999987e147 < d

    1. Initial program 39.0%

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

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

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

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

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

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

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

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

Alternative 3: 72.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -8.1 \cdot 10^{+132} \lor \neg \left(d \leq -1.5 \cdot 10^{+109}\right) \land \left(d \leq -8.2 \cdot 10^{+18} \lor \neg \left(d \leq 9.8 \cdot 10^{-17}\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -8.1e+132)
         (and (not (<= d -1.5e+109))
              (or (<= d -8.2e+18) (not (<= d 9.8e-17)))))
   (/ b d)
   (/ (+ a (/ (* d b) c)) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -8.1e+132) || (!(d <= -1.5e+109) && ((d <= -8.2e+18) || !(d <= 9.8e-17)))) {
		tmp = b / d;
	} else {
		tmp = (a + ((d * b) / 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.1d+132)) .or. (.not. (d <= (-1.5d+109))) .and. (d <= (-8.2d+18)) .or. (.not. (d <= 9.8d-17))) then
        tmp = b / d
    else
        tmp = (a + ((d * b) / 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.1e+132) || (!(d <= -1.5e+109) && ((d <= -8.2e+18) || !(d <= 9.8e-17)))) {
		tmp = b / d;
	} else {
		tmp = (a + ((d * b) / c)) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -8.1e+132) or (not (d <= -1.5e+109) and ((d <= -8.2e+18) or not (d <= 9.8e-17))):
		tmp = b / d
	else:
		tmp = (a + ((d * b) / c)) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -8.1e+132) || (!(d <= -1.5e+109) && ((d <= -8.2e+18) || !(d <= 9.8e-17))))
		tmp = Float64(b / d);
	else
		tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -8.1e+132) || (~((d <= -1.5e+109)) && ((d <= -8.2e+18) || ~((d <= 9.8e-17)))))
		tmp = b / d;
	else
		tmp = (a + ((d * b) / c)) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -8.1e+132], And[N[Not[LessEqual[d, -1.5e+109]], $MachinePrecision], Or[LessEqual[d, -8.2e+18], N[Not[LessEqual[d, 9.8e-17]], $MachinePrecision]]]], N[(b / d), $MachinePrecision], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -8.1 \cdot 10^{+132} \lor \neg \left(d \leq -1.5 \cdot 10^{+109}\right) \land \left(d \leq -8.2 \cdot 10^{+18} \lor \neg \left(d \leq 9.8 \cdot 10^{-17}\right)\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.09999999999999988e132 or -1.50000000000000008e109 < d < -8.2e18 or 9.80000000000000024e-17 < d

    1. Initial program 55.4%

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

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

    if -8.09999999999999988e132 < d < -1.50000000000000008e109 or -8.2e18 < d < 9.80000000000000024e-17

    1. Initial program 73.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8.1 \cdot 10^{+132} \lor \neg \left(d \leq -1.5 \cdot 10^{+109}\right) \land \left(d \leq -8.2 \cdot 10^{+18} \lor \neg \left(d \leq 9.8 \cdot 10^{-17}\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 69.6% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.2 \cdot 10^{-84} \lor \neg \left(c \leq 31000000\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.2e-84 or 3.1e7 < c

    1. Initial program 59.3%

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

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

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

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

    if -5.2e-84 < c < 3.1e7

    1. Initial program 73.4%

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

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

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

Alternative 5: 77.9% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.90000000000000026e-6

    1. Initial program 54.0%

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

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

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

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

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

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

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

    if -5.90000000000000026e-6 < c < 7.5e14

    1. Initial program 76.0%

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

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

    if 7.5e14 < c

    1. Initial program 56.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.9 \cdot 10^{-6}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;c \leq 7.5 \cdot 10^{+14}:\\ \;\;\;\;\frac{b + \frac{c \cdot a}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 77.8% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;c \leq 85000000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.79999999999999987e-6

    1. Initial program 54.0%

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

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

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

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

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

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

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

    if -2.79999999999999987e-6 < c < 8.5e7

    1. Initial program 76.0%

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

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

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

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

    if 8.5e7 < c

    1. Initial program 56.2%

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

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

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

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

Alternative 7: 64.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.3 \cdot 10^{-36} \lor \neg \left(d \leq 8 \cdot 10^{-17}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.29999999999999991e-36 or 8.00000000000000057e-17 < d

    1. Initial program 58.6%

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

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

    if -3.29999999999999991e-36 < d < 8.00000000000000057e-17

    1. Initial program 73.2%

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

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

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

Alternative 8: 42.8% accurate, 5.0× speedup?

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

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 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 42.3%

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

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (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))))