Complex division, real part

Percentage Accurate: 62.5% → 84.3%
Time: 8.6s
Alternatives: 8
Speedup: 0.8×

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: 62.5% 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.3% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;d \leq -9 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 5.2 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 26.9%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \frac{a \cdot c}{d}\right), \color{blue}{d}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a \cdot c}{d}\right)\right), d\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot c\right), d\right)\right), d\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(c \cdot a\right), d\right)\right), d\right) \]
      5. *-lowering-*.f6476.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), d\right)\right), d\right) \]
    5. Simplified76.2%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(c \cdot \frac{a}{d}\right)\right), d\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(c \cdot \frac{1}{\frac{d}{a}}\right)\right), d\right) \]
      3. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{c}{\frac{d}{a}}\right)\right), d\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(c, \left(\frac{d}{a}\right)\right)\right), d\right) \]
      5. /-lowering-/.f6489.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(c, \mathsf{/.f64}\left(d, a\right)\right)\right), d\right) \]
    7. Applied egg-rr89.6%

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

    if -3.59999999999999992e113 < d < -8.9999999999999997e-101 or 1.4999999999999999e-129 < d < 5.2000000000000002e63

    1. Initial program 88.8%

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

    if -8.9999999999999997e-101 < d < 1.4999999999999999e-129

    1. Initial program 72.5%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a + \frac{b \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b \cdot d}{c}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\left(b \cdot d\right), c\right)\right), c\right) \]
      4. *-lowering-*.f6489.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), c\right)\right), c\right) \]
    5. Simplified89.9%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{d}{c}\right)\right), c\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{d}{c} \cdot b\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{*.f64}\left(\left(\frac{d}{c}\right), b\right)\right), c\right) \]
      4. /-lowering-/.f6489.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{*.f64}\left(\mathsf{/.f64}\left(d, c\right), b\right)\right), c\right) \]
    7. Applied egg-rr89.9%

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

    if 5.2000000000000002e63 < d

    1. Initial program 27.0%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \frac{a \cdot c}{d}\right), \color{blue}{d}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a \cdot c}{d}\right)\right), d\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot c\right), d\right)\right), d\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(c \cdot a\right), d\right)\right), d\right) \]
      5. *-lowering-*.f6479.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), d\right)\right), d\right) \]
    5. Simplified79.0%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{d}{c \cdot a}}\right)\right), d\right) \]
      2. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{\frac{d}{c}}{a}}\right)\right), d\right) \]
      3. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a}{\frac{d}{c}}\right)\right), d\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \left(\frac{d}{c}\right)\right)\right), d\right) \]
      5. /-lowering-/.f6486.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \mathsf{/.f64}\left(d, c\right)\right)\right), d\right) \]
    7. Applied egg-rr86.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.6 \cdot 10^{+113}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq -9 \cdot 10^{-101}:\\ \;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-129}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{+63}:\\ \;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 77.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{-73}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+48}:\\ \;\;\;\;\frac{d \cdot b}{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.5e-98)
   (/ (+ b (/ c (/ d a))) d)
   (if (<= d 1.18e-73)
     (/ (+ a (/ b (/ c d))) c)
     (if (<= d 3.6e+48)
       (/ (* d b) (+ (* c c) (* d d)))
       (/ (+ b (/ a (/ d c))) d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.5e-98) {
		tmp = (b + (c / (d / a))) / d;
	} else if (d <= 1.18e-73) {
		tmp = (a + (b / (c / d))) / c;
	} else if (d <= 3.6e+48) {
		tmp = (d * b) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a / (d / 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 (d <= (-4.5d-98)) then
        tmp = (b + (c / (d / a))) / d
    else if (d <= 1.18d-73) then
        tmp = (a + (b / (c / d))) / c
    else if (d <= 3.6d+48) then
        tmp = (d * b) / ((c * c) + (d * d))
    else
        tmp = (b + (a / (d / c))) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.5e-98) {
		tmp = (b + (c / (d / a))) / d;
	} else if (d <= 1.18e-73) {
		tmp = (a + (b / (c / d))) / c;
	} else if (d <= 3.6e+48) {
		tmp = (d * b) / ((c * c) + (d * d));
	} else {
		tmp = (b + (a / (d / c))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -4.5e-98:
		tmp = (b + (c / (d / a))) / d
	elif d <= 1.18e-73:
		tmp = (a + (b / (c / d))) / c
	elif d <= 3.6e+48:
		tmp = (d * b) / ((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.5e-98)
		tmp = Float64(Float64(b + Float64(c / Float64(d / a))) / d);
	elseif (d <= 1.18e-73)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) / c);
	elseif (d <= 3.6e+48)
		tmp = Float64(Float64(d * b) / 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.5e-98)
		tmp = (b + (c / (d / a))) / d;
	elseif (d <= 1.18e-73)
		tmp = (a + (b / (c / d))) / c;
	elseif (d <= 3.6e+48)
		tmp = (d * b) / ((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.5e-98], N[(N[(b + N[(c / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.18e-73], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.6e+48], N[(N[(d * b), $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.5 \cdot 10^{-98}:\\
\;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\

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

\mathbf{elif}\;d \leq 3.6 \cdot 10^{+48}:\\
\;\;\;\;\frac{d \cdot b}{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.49999999999999997e-98

    1. Initial program 61.2%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \frac{a \cdot c}{d}\right), \color{blue}{d}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a \cdot c}{d}\right)\right), d\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot c\right), d\right)\right), d\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(c \cdot a\right), d\right)\right), d\right) \]
      5. *-lowering-*.f6471.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), d\right)\right), d\right) \]
    5. Simplified71.2%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(c \cdot \frac{a}{d}\right)\right), d\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(c \cdot \frac{1}{\frac{d}{a}}\right)\right), d\right) \]
      3. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{c}{\frac{d}{a}}\right)\right), d\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(c, \left(\frac{d}{a}\right)\right)\right), d\right) \]
      5. /-lowering-/.f6477.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(c, \mathsf{/.f64}\left(d, a\right)\right)\right), d\right) \]
    7. Applied egg-rr77.4%

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

    if -4.49999999999999997e-98 < d < 1.17999999999999993e-73

    1. Initial program 74.5%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a + \frac{b \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b \cdot d}{c}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\left(b \cdot d\right), c\right)\right), c\right) \]
      4. *-lowering-*.f6488.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), c\right)\right), c\right) \]
    5. Simplified88.1%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{d}{c}\right)\right), c\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{1}{\frac{c}{d}}\right)\right), c\right) \]
      3. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b}{\frac{c}{d}}\right)\right), c\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \left(\frac{c}{d}\right)\right)\right), c\right) \]
      5. /-lowering-/.f6488.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \mathsf{/.f64}\left(c, d\right)\right)\right), c\right) \]
    7. Applied egg-rr88.2%

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

    if 1.17999999999999993e-73 < d < 3.59999999999999983e48

    1. Initial program 83.1%

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

      \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b \cdot d\right), \color{blue}{\left({c}^{2} + {d}^{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), \left(\color{blue}{{c}^{2}} + {d}^{2}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), \mathsf{+.f64}\left(\left({c}^{2}\right), \color{blue}{\left({d}^{2}\right)}\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), \mathsf{+.f64}\left(\left(c \cdot c\right), \left({\color{blue}{d}}^{2}\right)\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \left({\color{blue}{d}}^{2}\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \left(d \cdot \color{blue}{d}\right)\right)\right) \]
      7. *-lowering-*.f6475.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, \color{blue}{d}\right)\right)\right) \]
    5. Simplified75.4%

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

    if 3.59999999999999983e48 < d

    1. Initial program 31.4%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \frac{a \cdot c}{d}\right), \color{blue}{d}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a \cdot c}{d}\right)\right), d\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot c\right), d\right)\right), d\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(c \cdot a\right), d\right)\right), d\right) \]
      5. *-lowering-*.f6478.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), d\right)\right), d\right) \]
    5. Simplified78.3%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{d}{c \cdot a}}\right)\right), d\right) \]
      2. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{\frac{d}{c}}{a}}\right)\right), d\right) \]
      3. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a}{\frac{d}{c}}\right)\right), d\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \left(\frac{d}{c}\right)\right)\right), d\right) \]
      5. /-lowering-/.f6485.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \mathsf{/.f64}\left(d, c\right)\right)\right), d\right) \]
    7. Applied egg-rr85.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{-98}:\\ \;\;\;\;\frac{b + \frac{c}{\frac{d}{a}}}{d}\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{-73}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 3.6 \cdot 10^{+48}:\\ \;\;\;\;\frac{d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{\frac{d}{c}}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 77.5% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 61.2%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \frac{a \cdot c}{d}\right), \color{blue}{d}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a \cdot c}{d}\right)\right), d\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot c\right), d\right)\right), d\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(c \cdot a\right), d\right)\right), d\right) \]
      5. *-lowering-*.f6471.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), d\right)\right), d\right) \]
    5. Simplified71.2%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(c \cdot \frac{a}{d}\right)\right), d\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(c \cdot \frac{1}{\frac{d}{a}}\right)\right), d\right) \]
      3. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{c}{\frac{d}{a}}\right)\right), d\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(c, \left(\frac{d}{a}\right)\right)\right), d\right) \]
      5. /-lowering-/.f6477.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(c, \mathsf{/.f64}\left(d, a\right)\right)\right), d\right) \]
    7. Applied egg-rr77.4%

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

    if -4.49999999999999997e-98 < d < 8.5000000000000001e48

    1. Initial program 76.2%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a + \frac{b \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b \cdot d}{c}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\left(b \cdot d\right), c\right)\right), c\right) \]
      4. *-lowering-*.f6481.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), c\right)\right), c\right) \]
    5. Simplified81.8%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{d}{c}\right)\right), c\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{1}{\frac{c}{d}}\right)\right), c\right) \]
      3. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b}{\frac{c}{d}}\right)\right), c\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \left(\frac{c}{d}\right)\right)\right), c\right) \]
      5. /-lowering-/.f6481.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \mathsf{/.f64}\left(c, d\right)\right)\right), c\right) \]
    7. Applied egg-rr81.9%

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

    if 8.5000000000000001e48 < d

    1. Initial program 31.4%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \frac{a \cdot c}{d}\right), \color{blue}{d}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a \cdot c}{d}\right)\right), d\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot c\right), d\right)\right), d\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(c \cdot a\right), d\right)\right), d\right) \]
      5. *-lowering-*.f6478.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), d\right)\right), d\right) \]
    5. Simplified78.3%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{d}{c \cdot a}}\right)\right), d\right) \]
      2. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{\frac{d}{c}}{a}}\right)\right), d\right) \]
      3. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a}{\frac{d}{c}}\right)\right), d\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \left(\frac{d}{c}\right)\right)\right), d\right) \]
      5. /-lowering-/.f6485.6%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \mathsf{/.f64}\left(d, c\right)\right)\right), d\right) \]
    7. Applied egg-rr85.6%

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

Alternative 4: 77.3% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.39999999999999993e-98 or 1.25e51 < d

    1. Initial program 49.9%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \frac{a \cdot c}{d}\right), \color{blue}{d}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a \cdot c}{d}\right)\right), d\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot c\right), d\right)\right), d\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\left(c \cdot a\right), d\right)\right), d\right) \]
      5. *-lowering-*.f6473.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), d\right)\right), d\right) \]
    5. Simplified73.9%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{d}{c \cdot a}}\right)\right), d\right) \]
      2. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{1}{\frac{\frac{d}{c}}{a}}\right)\right), d\right) \]
      3. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \left(\frac{a}{\frac{d}{c}}\right)\right), d\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \left(\frac{d}{c}\right)\right)\right), d\right) \]
      5. /-lowering-/.f6480.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(b, \mathsf{/.f64}\left(a, \mathsf{/.f64}\left(d, c\right)\right)\right), d\right) \]
    7. Applied egg-rr80.5%

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

    if -4.39999999999999993e-98 < d < 1.25e51

    1. Initial program 76.2%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a + \frac{b \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b \cdot d}{c}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\left(b \cdot d\right), c\right)\right), c\right) \]
      4. *-lowering-*.f6481.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), c\right)\right), c\right) \]
    5. Simplified81.8%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{d}{c}\right)\right), c\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{1}{\frac{c}{d}}\right)\right), c\right) \]
      3. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b}{\frac{c}{d}}\right)\right), c\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \left(\frac{c}{d}\right)\right)\right), c\right) \]
      5. /-lowering-/.f6481.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \mathsf{/.f64}\left(c, d\right)\right)\right), c\right) \]
    7. Applied egg-rr81.9%

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

Alternative 5: 72.9% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.0000000000000002e-6 or 1.25000000000000001e77 < d

    1. Initial program 40.9%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f6471.4%

        \[\leadsto \mathsf{/.f64}\left(b, \color{blue}{d}\right) \]
    5. Simplified71.4%

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

    if -6.0000000000000002e-6 < d < 1.25000000000000001e77

    1. Initial program 78.5%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a + \frac{b \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b \cdot d}{c}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\left(b \cdot d\right), c\right)\right), c\right) \]
      4. *-lowering-*.f6475.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), c\right)\right), c\right) \]
    5. Simplified75.8%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{d}{c}\right)\right), c\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{1}{\frac{c}{d}}\right)\right), c\right) \]
      3. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b}{\frac{c}{d}}\right)\right), c\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \left(\frac{c}{d}\right)\right)\right), c\right) \]
      5. /-lowering-/.f6476.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(b, \mathsf{/.f64}\left(c, d\right)\right)\right), c\right) \]
    7. Applied egg-rr76.5%

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

Alternative 6: 72.7% accurate, 0.8× speedup?

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

\mathbf{elif}\;d \leq 3.7 \cdot 10^{+77}:\\
\;\;\;\;\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 d < -1.71999999999999999e-13 or 3.69999999999999995e77 < d

    1. Initial program 40.9%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f6471.4%

        \[\leadsto \mathsf{/.f64}\left(b, \color{blue}{d}\right) \]
    5. Simplified71.4%

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

    if -1.71999999999999999e-13 < d < 3.69999999999999995e77

    1. Initial program 78.5%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a + \frac{b \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{b \cdot d}{c}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\left(b \cdot d\right), c\right)\right), c\right) \]
      4. *-lowering-*.f6475.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{/.f64}\left(\mathsf{*.f64}\left(b, d\right), c\right)\right), c\right) \]
    5. Simplified75.8%

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(b \cdot \frac{d}{c}\right)\right), c\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \left(\frac{d}{c} \cdot b\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{*.f64}\left(\left(\frac{d}{c}\right), b\right)\right), c\right) \]
      4. /-lowering-/.f6476.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(a, \mathsf{*.f64}\left(\mathsf{/.f64}\left(d, c\right), b\right)\right), c\right) \]
    7. Applied egg-rr76.5%

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

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

Alternative 7: 62.2% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.1 \cdot 10^{-98}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq 3.35 \cdot 10^{-71}:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.0999999999999998e-98 or 3.3499999999999999e-71 < d

    1. Initial program 54.8%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f6462.8%

        \[\leadsto \mathsf{/.f64}\left(b, \color{blue}{d}\right) \]
    5. Simplified62.8%

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

    if -4.0999999999999998e-98 < d < 3.3499999999999999e-71

    1. Initial program 74.8%

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f6465.9%

        \[\leadsto \mathsf{/.f64}\left(a, \color{blue}{c}\right) \]
    5. Simplified65.9%

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

Alternative 8: 42.1% 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 62.9%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f6437.7%

      \[\leadsto \mathsf{/.f64}\left(a, \color{blue}{c}\right) \]
  5. Simplified37.7%

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

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

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

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

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024191 
(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))))