Complex division, real part

Percentage Accurate: 62.4% → 79.9%
Time: 8.4s
Alternatives: 7
Speedup: 1.2×

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 7 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.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: 79.9% accurate, 0.5× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.60000000000000008e97 or 1.6999999999999999e92 < d

    1. Initial program 38.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-*.f6480.7%

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

      \[\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. *-commutativeN/A

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

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

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

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

    if -1.60000000000000008e97 < d < 3.20000000000000013e-165

    1. Initial program 75.6%

      \[\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-*.f6483.3%

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

      \[\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-/.f6484.2%

        \[\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-rr84.2%

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

    if 3.20000000000000013e-165 < d < 1.6999999999999999e92

    1. Initial program 88.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.6 \cdot 10^{+97}:\\ \;\;\;\;\frac{b + \frac{a}{d} \cdot c}{d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-165}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+92}:\\ \;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{d} \cdot c}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 78.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -5.8 \cdot 10^{-19}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \mathbf{elif}\;c \leq 7.2 \cdot 10^{-7}:\\ \;\;\;\;\frac{b + \frac{a \cdot 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 -5.8e-19)
   (/ (+ a (* d (/ b c))) c)
   (if (<= c 7.2e-7) (/ (+ b (/ (* a c) d)) d) (/ (+ a (* b (/ d c))) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -5.8e-19) {
		tmp = (a + (d * (b / c))) / c;
	} else if (c <= 7.2e-7) {
		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 <= (-5.8d-19)) then
        tmp = (a + (d * (b / c))) / c
    else if (c <= 7.2d-7) 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 <= -5.8e-19) {
		tmp = (a + (d * (b / c))) / c;
	} else if (c <= 7.2e-7) {
		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 <= -5.8e-19:
		tmp = (a + (d * (b / c))) / c
	elif c <= 7.2e-7:
		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 <= -5.8e-19)
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	elseif (c <= 7.2e-7)
		tmp = Float64(Float64(b + Float64(Float64(a * 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 <= -5.8e-19)
		tmp = (a + (d * (b / c))) / c;
	elseif (c <= 7.2e-7)
		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, -5.8e-19], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 7.2e-7], N[(N[(b + N[(N[(a * c), $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.8 \cdot 10^{-19}:\\
\;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\

\mathbf{elif}\;c \leq 7.2 \cdot 10^{-7}:\\
\;\;\;\;\frac{b + \frac{a \cdot 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 < -5.8e-19

    1. Initial program 62.0%

      \[\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-*.f6471.4%

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

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

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

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

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

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

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

    if -5.8e-19 < c < 7.19999999999999989e-7

    1. Initial program 75.7%

      \[\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-*.f6485.0%

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

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

    if 7.19999999999999989e-7 < c

    1. Initial program 47.6%

      \[\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-*.f6479.4%

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

      \[\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-/.f6482.6%

        \[\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-rr82.6%

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

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

Alternative 3: 77.5% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.60000000000000008e97 or 3.44999999999999987e-25 < d

    1. Initial program 48.1%

      \[\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-*.f6477.8%

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

      \[\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. *-commutativeN/A

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

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

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

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

    if -1.60000000000000008e97 < d < 3.44999999999999987e-25

    1. Initial program 78.7%

      \[\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-*.f6480.2%

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

      \[\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-/.f6480.8%

        \[\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-rr80.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.6 \cdot 10^{+97}:\\ \;\;\;\;\frac{b + \frac{a}{d} \cdot c}{d}\\ \mathbf{elif}\;d \leq 3.45 \cdot 10^{-25}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + \frac{a}{d} \cdot c}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 72.5% accurate, 0.8× speedup?

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

\mathbf{elif}\;d \leq 9 \cdot 10^{-9}:\\
\;\;\;\;\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.90000000000000018e97 or 8.99999999999999953e-9 < d

    1. Initial program 47.1%

      \[\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-/.f6469.8%

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

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

    if -1.90000000000000018e97 < d < 8.99999999999999953e-9

    1. Initial program 78.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 + \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-*.f6479.3%

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

      \[\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-/.f6480.0%

        \[\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-rr80.0%

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

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

Alternative 5: 71.7% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.60000000000000008e97 or 9.5999999999999999e-9 < d

    1. Initial program 47.1%

      \[\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-/.f6469.8%

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

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

    if -1.60000000000000008e97 < d < 9.5999999999999999e-9

    1. Initial program 78.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 + \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-*.f6479.3%

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

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

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

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

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

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

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

Alternative 6: 64.0% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.55 \cdot 10^{-33}:\\
\;\;\;\;\frac{a}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.54999999999999998e-33 or 1.1000000000000001e-7 < c

    1. Initial program 54.3%

      \[\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-/.f6468.0%

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

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

    if -1.54999999999999998e-33 < c < 1.1000000000000001e-7

    1. Initial program 76.1%

      \[\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.7%

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

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

Alternative 7: 42.3% 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.4%

    \[\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-/.f6442.2%

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

    \[\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 2024163 
(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))))