Complex division, real part

Percentage Accurate: 62.0% → 85.8%
Time: 10.3s
Alternatives: 11
Speedup: 1.1×

Specification

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

\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 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.0% 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: 85.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+299}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 2e+299)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 2e+299) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 2e+299)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+299], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+299}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\

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


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

    1. Initial program 77.6%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}} \]
      2. associate-*r/77.6%

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

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e299 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 13.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+299}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -3.6 \cdot 10^{+65}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-108}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{-18}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -3.6e+65)
   (/ (+ a (* b (/ d c))) (- (hypot c d)))
   (if (<= c -2.5e-108)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= c 8.5e-18) (/ (+ b (/ (* a c) d)) d) (/ (+ a (* d (/ b c))) c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -3.6e+65) {
		tmp = (a + (b * (d / c))) / -hypot(c, d);
	} else if (c <= -2.5e-108) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (c <= 8.5e-18) {
		tmp = (b + ((a * c) / d)) / d;
	} else {
		tmp = (a + (d * (b / c))) / c;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -3.6e+65) {
		tmp = (a + (b * (d / c))) / -Math.hypot(c, d);
	} else if (c <= -2.5e-108) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (c <= 8.5e-18) {
		tmp = (b + ((a * c) / d)) / d;
	} else {
		tmp = (a + (d * (b / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -3.6e+65:
		tmp = (a + (b * (d / c))) / -math.hypot(c, d)
	elif c <= -2.5e-108:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif c <= 8.5e-18:
		tmp = (b + ((a * c) / d)) / d
	else:
		tmp = (a + (d * (b / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -3.6e+65)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(-hypot(c, d)));
	elseif (c <= -2.5e-108)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 8.5e-18)
		tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d);
	else
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -3.6e+65)
		tmp = (a + (b * (d / c))) / -hypot(c, d);
	elseif (c <= -2.5e-108)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (c <= 8.5e-18)
		tmp = (b + ((a * c) / d)) / d;
	else
		tmp = (a + (d * (b / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -3.6e+65], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision])), $MachinePrecision], If[LessEqual[c, -2.5e-108], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.5e-18], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 32.2%

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

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}} \]
      2. associate-*r/32.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(-1 \cdot a + -1 \cdot \frac{b \cdot d}{c}\right)}{\mathsf{hypot}\left(c, d\right)}} \]
      2. *-un-lft-identity77.9%

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

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

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

    if -3.59999999999999978e65 < c < -2.5e-108

    1. Initial program 94.4%

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

    if -2.5e-108 < c < 8.4999999999999995e-18

    1. Initial program 73.4%

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

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

    if 8.4999999999999995e-18 < c

    1. Initial program 50.6%

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

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*81.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.6 \cdot 10^{+65}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{-\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-108}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8.5 \cdot 10^{-18}:\\ \;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.0% accurate, 0.6× speedup?

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

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

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

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

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


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

    1. Initial program 32.2%

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

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

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

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

    if -3.4000000000000001e70 < c < -3.00000000000000019e-106

    1. Initial program 94.4%

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

    if -3.00000000000000019e-106 < c < 3.5999999999999998e-13

    1. Initial program 73.4%

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

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

    if 3.5999999999999998e-13 < c

    1. Initial program 50.6%

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

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*81.3%

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

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

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

Alternative 4: 70.0% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.3999999999999999e-43 or 8.8000000000000002e-22 < c

    1. Initial program 52.5%

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

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

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

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

    if -1.3999999999999999e-43 < c < 8.8000000000000002e-22

    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 67.1%

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

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

Alternative 5: 70.2% accurate, 0.8× speedup?

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

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

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

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


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

    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 inf 73.8%

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

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

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

    if -7.50000000000000027e-46 < c < 6.5000000000000001e-19

    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 67.1%

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

    if 6.5000000000000001e-19 < c

    1. Initial program 50.6%

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

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*81.3%

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

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

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

Alternative 6: 70.1% accurate, 0.8× speedup?

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

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

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

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


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

    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 inf 73.8%

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*75.5%

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{d \cdot b}{c}}}{c} \]
      2. associate-*l/75.5%

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

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

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

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

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

    if -3.49999999999999997e-43 < c < 2.44999999999999997e-14

    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 67.1%

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

    if 2.44999999999999997e-14 < c

    1. Initial program 50.6%

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

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*81.3%

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

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

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

Alternative 7: 78.1% accurate, 0.8× speedup?

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

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

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

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


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

    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 inf 73.8%

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*75.5%

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{d \cdot b}{c}}}{c} \]
      2. associate-*l/75.5%

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

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

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

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

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

    if -4.20000000000000013e-42 < c < 1.65e-13

    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 d around inf 86.0%

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

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

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

    if 1.65e-13 < c

    1. Initial program 50.6%

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

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*81.3%

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

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

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

Alternative 8: 78.2% accurate, 0.8× speedup?

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

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

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

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


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

    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 inf 73.8%

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*75.5%

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{d \cdot b}{c}}}{c} \]
      2. associate-*l/75.5%

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

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

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

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

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

    if -4.8000000000000004e-43 < c < 8.39999999999999955e-13

    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 d around inf 86.0%

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

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

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

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

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

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

    if 8.39999999999999955e-13 < c

    1. Initial program 50.6%

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

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*81.3%

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

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

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

Alternative 9: 78.2% accurate, 0.8× speedup?

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

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

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

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


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

    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 inf 73.8%

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*75.5%

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{d \cdot b}{c}}}{c} \]
      2. associate-*l/75.5%

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

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

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

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

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

    if -5.8000000000000006e-42 < c < 2.2e-17

    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 d around inf 86.0%

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

    if 2.2e-17 < c

    1. Initial program 50.6%

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

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

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
      2. associate-/l*81.3%

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

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

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

Alternative 10: 64.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.3 \cdot 10^{-42} \lor \neg \left(c \leq 2 \cdot 10^{-18}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.30000000000000004e-42 or 2.0000000000000001e-18 < c

    1. Initial program 52.5%

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

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

    if -2.30000000000000004e-42 < c < 2.0000000000000001e-18

    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 67.1%

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

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

Alternative 11: 43.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 63.2%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification42.6%

    \[\leadsto \frac{a}{c} \]
  5. Add Preprocessing

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

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