Complex division, real part

Percentage Accurate: 62.2% → 80.7%
Time: 12.4s
Alternatives: 12
Speedup: 0.6×

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 12 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.2% 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: 80.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -1.9 \cdot 10^{+27}:\\ \;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -9.5 \cdot 10^{-79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-154}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.85 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2150000000:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -1.9e+27)
     (* (+ a (/ b (/ c d))) (/ -1.0 (hypot c d)))
     (if (<= c -9.5e-79)
       t_0
       (if (<= c 9.2e-154)
         (+ (/ b d) (/ (/ (* a c) d) d))
         (if (<= c 1.85e-56)
           t_0
           (if (<= c 2150000000.0)
             (+ (/ b d) (* (/ c d) (/ a d)))
             (/ (+ a (* b (/ d c))) (hypot c d)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.9e+27) {
		tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d));
	} else if (c <= -9.5e-79) {
		tmp = t_0;
	} else if (c <= 9.2e-154) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else if (c <= 1.85e-56) {
		tmp = t_0;
	} else if (c <= 2150000000.0) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else {
		tmp = (a + (b * (d / c))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -1.9e+27) {
		tmp = (a + (b / (c / d))) * (-1.0 / Math.hypot(c, d));
	} else if (c <= -9.5e-79) {
		tmp = t_0;
	} else if (c <= 9.2e-154) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else if (c <= 1.85e-56) {
		tmp = t_0;
	} else if (c <= 2150000000.0) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else {
		tmp = (a + (b * (d / c))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.9e+27:
		tmp = (a + (b / (c / d))) * (-1.0 / math.hypot(c, d))
	elif c <= -9.5e-79:
		tmp = t_0
	elif c <= 9.2e-154:
		tmp = (b / d) + (((a * c) / d) / d)
	elif c <= 1.85e-56:
		tmp = t_0
	elif c <= 2150000000.0:
		tmp = (b / d) + ((c / d) * (a / d))
	else:
		tmp = (a + (b * (d / c))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -1.9e+27)
		tmp = Float64(Float64(a + Float64(b / Float64(c / d))) * Float64(-1.0 / hypot(c, d)));
	elseif (c <= -9.5e-79)
		tmp = t_0;
	elseif (c <= 9.2e-154)
		tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d));
	elseif (c <= 1.85e-56)
		tmp = t_0;
	elseif (c <= 2150000000.0)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -1.9e+27)
		tmp = (a + (b / (c / d))) * (-1.0 / hypot(c, d));
	elseif (c <= -9.5e-79)
		tmp = t_0;
	elseif (c <= 9.2e-154)
		tmp = (b / d) + (((a * c) / d) / d);
	elseif (c <= 1.85e-56)
		tmp = t_0;
	elseif (c <= 2150000000.0)
		tmp = (b / d) + ((c / d) * (a / d));
	else
		tmp = (a + (b * (d / c))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = 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, -1.9e+27], N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -9.5e-79], t$95$0, If[LessEqual[c, 9.2e-154], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.85e-56], t$95$0, If[LessEqual[c, 2150000000.0], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -9.5 \cdot 10^{-79}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.85 \cdot 10^{-56}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -1.90000000000000011e27

    1. Initial program 39.5%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt39.5%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def39.6%

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(-1 \cdot \frac{b \cdot d}{c} - a\right)} \]
      4. mul-1-neg74.8%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\color{blue}{\left(-\frac{b \cdot d}{c}\right)} - a\right) \]
      5. associate-/l*80.4%

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\left(-\color{blue}{\frac{b}{\frac{c}{d}}}\right) - a\right) \]
      6. distribute-neg-frac80.4%

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

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

    if -1.90000000000000011e27 < c < -9.4999999999999997e-79 or 9.1999999999999999e-154 < c < 1.8500000000000001e-56

    1. Initial program 89.8%

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

    if -9.4999999999999997e-79 < c < 9.1999999999999999e-154

    1. Initial program 73.8%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/80.9%

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

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

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

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

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

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

    if 1.8500000000000001e-56 < c < 2.15e9

    1. Initial program 50.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{d \cdot d} \]
      3. times-frac76.7%

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

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

    if 2.15e9 < c

    1. Initial program 42.3%

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. associate-*l/63.3%

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

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

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

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{1} \cdot \frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)} \]
      3. /-rgt-identity84.0%

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

      \[\leadsto \frac{\color{blue}{a + b \cdot \frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification86.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.9 \cdot 10^{+27}:\\ \;\;\;\;\left(a + \frac{b}{\frac{c}{d}}\right) \cdot \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -9.5 \cdot 10^{-79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-154}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.85 \cdot 10^{-56}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2150000000:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 84.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 5 \cdot 10^{+290}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 5e+290)
   (/ (/ (fma a c (* b d)) (hypot c d)) (hypot c d))
   (+ (/ b d) (* (/ c d) (/ a d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 5e+290) {
		tmp = (fma(a, c, (b * d)) / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (b / d) + ((c / d) * (a / d));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 5e+290)
		tmp = Float64(Float64(fma(a, c, Float64(b * d)) / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+290], N[(N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 78.9%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt78.9%

        \[\leadsto \frac{1 \cdot \left(a \cdot c + b \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac78.9%

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-def78.9%

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

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

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

      \[\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. Step-by-step derivation
      1. associate-*l/95.3%

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

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

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

    if 4.9999999999999998e290 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 6.3%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/50.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{d \cdot d} \]
      3. times-frac55.9%

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

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

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

Alternative 3: 80.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -3.7 \cdot 10^{+78}:\\ \;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \mathbf{elif}\;c \leq -2.65 \cdot 10^{-79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{-153}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.72 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 880000000:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= c -3.7e+78)
     (+ (/ a c) (* d (* (/ 1.0 c) (/ b c))))
     (if (<= c -2.65e-79)
       t_0
       (if (<= c 1.6e-153)
         (+ (/ b d) (/ (/ (* a c) d) d))
         (if (<= c 1.72e-56)
           t_0
           (if (<= c 880000000.0)
             (+ (/ b d) (* (/ c d) (/ a d)))
             (/ (+ a (* b (/ d c))) (hypot c d)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -3.7e+78) {
		tmp = (a / c) + (d * ((1.0 / c) * (b / c)));
	} else if (c <= -2.65e-79) {
		tmp = t_0;
	} else if (c <= 1.6e-153) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else if (c <= 1.72e-56) {
		tmp = t_0;
	} else if (c <= 880000000.0) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else {
		tmp = (a + (b * (d / c))) / hypot(c, d);
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -3.7e+78) {
		tmp = (a / c) + (d * ((1.0 / c) * (b / c)));
	} else if (c <= -2.65e-79) {
		tmp = t_0;
	} else if (c <= 1.6e-153) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else if (c <= 1.72e-56) {
		tmp = t_0;
	} else if (c <= 880000000.0) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else {
		tmp = (a + (b * (d / c))) / Math.hypot(c, d);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -3.7e+78:
		tmp = (a / c) + (d * ((1.0 / c) * (b / c)))
	elif c <= -2.65e-79:
		tmp = t_0
	elif c <= 1.6e-153:
		tmp = (b / d) + (((a * c) / d) / d)
	elif c <= 1.72e-56:
		tmp = t_0
	elif c <= 880000000.0:
		tmp = (b / d) + ((c / d) * (a / d))
	else:
		tmp = (a + (b * (d / c))) / math.hypot(c, d)
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -3.7e+78)
		tmp = Float64(Float64(a / c) + Float64(d * Float64(Float64(1.0 / c) * Float64(b / c))));
	elseif (c <= -2.65e-79)
		tmp = t_0;
	elseif (c <= 1.6e-153)
		tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d));
	elseif (c <= 1.72e-56)
		tmp = t_0;
	elseif (c <= 880000000.0)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / hypot(c, d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -3.7e+78)
		tmp = (a / c) + (d * ((1.0 / c) * (b / c)));
	elseif (c <= -2.65e-79)
		tmp = t_0;
	elseif (c <= 1.6e-153)
		tmp = (b / d) + (((a * c) / d) / d);
	elseif (c <= 1.72e-56)
		tmp = t_0;
	elseif (c <= 880000000.0)
		tmp = (b / d) + ((c / d) * (a / d));
	else
		tmp = (a + (b * (d / c))) / hypot(c, d);
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = 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.7e+78], N[(N[(a / c), $MachinePrecision] + N[(d * N[(N[(1.0 / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -2.65e-79], t$95$0, If[LessEqual[c, 1.6e-153], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.72e-56], t$95$0, If[LessEqual[c, 880000000.0], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -3.7 \cdot 10^{+78}:\\
\;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\

\mathbf{elif}\;c \leq -2.65 \cdot 10^{-79}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.72 \cdot 10^{-56}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -3.69999999999999985e78

    1. Initial program 34.2%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/78.7%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. *-un-lft-identity78.7%

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

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

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

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

    if -3.69999999999999985e78 < c < -2.6499999999999999e-79 or 1.6e-153 < c < 1.72000000000000009e-56

    1. Initial program 83.0%

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

    if -2.6499999999999999e-79 < c < 1.6e-153

    1. Initial program 73.8%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/80.9%

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

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

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

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

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

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

    if 1.72000000000000009e-56 < c < 8.8e8

    1. Initial program 50.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{d \cdot d} \]
      3. times-frac76.7%

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

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

    if 8.8e8 < c

    1. Initial program 42.3%

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. associate-*l/63.3%

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

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

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

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

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

        \[\leadsto \frac{a + \color{blue}{\frac{b}{1} \cdot \frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)} \]
      3. /-rgt-identity84.0%

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

      \[\leadsto \frac{\color{blue}{a + b \cdot \frac{d}{c}}}{\mathsf{hypot}\left(c, d\right)} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification86.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.7 \cdot 10^{+78}:\\ \;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \mathbf{elif}\;c \leq -2.65 \cdot 10^{-79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{-153}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.72 \cdot 10^{-56}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 880000000:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 73.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ t_1 := \frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ t_2 := \frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -6.5 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -2.75 \cdot 10^{-36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 480000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ b d) (* (/ c d) (/ a d))))
        (t_1 (+ (/ a c) (* b (/ (/ d c) c))))
        (t_2 (+ (/ a c) (/ (/ (* b d) c) c))))
   (if (<= c -3.2e+115)
     t_1
     (if (<= c -2.7e+47)
       t_0
       (if (<= c -6.5e-6)
         t_2
         (if (<= c -2.75e-36)
           t_0
           (if (<= c -3.5e-78) t_1 (if (<= c 480000000000.0) t_0 t_2))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c / d) * (a / d));
	double t_1 = (a / c) + (b * ((d / c) / c));
	double t_2 = (a / c) + (((b * d) / c) / c);
	double tmp;
	if (c <= -3.2e+115) {
		tmp = t_1;
	} else if (c <= -2.7e+47) {
		tmp = t_0;
	} else if (c <= -6.5e-6) {
		tmp = t_2;
	} else if (c <= -2.75e-36) {
		tmp = t_0;
	} else if (c <= -3.5e-78) {
		tmp = t_1;
	} else if (c <= 480000000000.0) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = (b / d) + ((c / d) * (a / d))
    t_1 = (a / c) + (b * ((d / c) / c))
    t_2 = (a / c) + (((b * d) / c) / c)
    if (c <= (-3.2d+115)) then
        tmp = t_1
    else if (c <= (-2.7d+47)) then
        tmp = t_0
    else if (c <= (-6.5d-6)) then
        tmp = t_2
    else if (c <= (-2.75d-36)) then
        tmp = t_0
    else if (c <= (-3.5d-78)) then
        tmp = t_1
    else if (c <= 480000000000.0d0) then
        tmp = t_0
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c / d) * (a / d));
	double t_1 = (a / c) + (b * ((d / c) / c));
	double t_2 = (a / c) + (((b * d) / c) / c);
	double tmp;
	if (c <= -3.2e+115) {
		tmp = t_1;
	} else if (c <= -2.7e+47) {
		tmp = t_0;
	} else if (c <= -6.5e-6) {
		tmp = t_2;
	} else if (c <= -2.75e-36) {
		tmp = t_0;
	} else if (c <= -3.5e-78) {
		tmp = t_1;
	} else if (c <= 480000000000.0) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / d) + ((c / d) * (a / d))
	t_1 = (a / c) + (b * ((d / c) / c))
	t_2 = (a / c) + (((b * d) / c) / c)
	tmp = 0
	if c <= -3.2e+115:
		tmp = t_1
	elif c <= -2.7e+47:
		tmp = t_0
	elif c <= -6.5e-6:
		tmp = t_2
	elif c <= -2.75e-36:
		tmp = t_0
	elif c <= -3.5e-78:
		tmp = t_1
	elif c <= 480000000000.0:
		tmp = t_0
	else:
		tmp = t_2
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)))
	t_1 = Float64(Float64(a / c) + Float64(b * Float64(Float64(d / c) / c)))
	t_2 = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c))
	tmp = 0.0
	if (c <= -3.2e+115)
		tmp = t_1;
	elseif (c <= -2.7e+47)
		tmp = t_0;
	elseif (c <= -6.5e-6)
		tmp = t_2;
	elseif (c <= -2.75e-36)
		tmp = t_0;
	elseif (c <= -3.5e-78)
		tmp = t_1;
	elseif (c <= 480000000000.0)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b / d) + ((c / d) * (a / d));
	t_1 = (a / c) + (b * ((d / c) / c));
	t_2 = (a / c) + (((b * d) / c) / c);
	tmp = 0.0;
	if (c <= -3.2e+115)
		tmp = t_1;
	elseif (c <= -2.7e+47)
		tmp = t_0;
	elseif (c <= -6.5e-6)
		tmp = t_2;
	elseif (c <= -2.75e-36)
		tmp = t_0;
	elseif (c <= -3.5e-78)
		tmp = t_1;
	elseif (c <= 480000000000.0)
		tmp = t_0;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(b * N[(N[(d / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.2e+115], t$95$1, If[LessEqual[c, -2.7e+47], t$95$0, If[LessEqual[c, -6.5e-6], t$95$2, If[LessEqual[c, -2.75e-36], t$95$0, If[LessEqual[c, -3.5e-78], t$95$1, If[LessEqual[c, 480000000000.0], t$95$0, t$95$2]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
t_1 := \frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\
t_2 := \frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;c \leq -2.7 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq -6.5 \cdot 10^{-6}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;c \leq -2.75 \cdot 10^{-36}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;c \leq 480000000000:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.2e115 or -2.74999999999999992e-36 < c < -3.4999999999999999e-78

    1. Initial program 45.8%

      \[\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}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*81.1%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/79.6%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. expm1-log1p-u77.9%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)\right)} \]
      2. expm1-udef78.0%

        \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)} - 1\right)} \]
      3. pow278.0%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\frac{b}{\color{blue}{c \cdot c}} \cdot d\right)} - 1\right) \]
      4. div-inv78.0%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(b \cdot \frac{1}{c \cdot c}\right)} \cdot d\right)} - 1\right) \]
      5. associate-*l*79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{b \cdot \left(\frac{1}{c \cdot c} \cdot d\right)}\right)} - 1\right) \]
      6. pow279.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\frac{1}{\color{blue}{{c}^{2}}} \cdot d\right)\right)} - 1\right) \]
      7. pow-flip79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\color{blue}{{c}^{\left(-2\right)}} \cdot d\right)\right)} - 1\right) \]
      8. metadata-eval79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{\color{blue}{-2}} \cdot d\right)\right)} - 1\right) \]
    7. Applied egg-rr79.3%

      \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def79.3%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)\right)} \]
      2. expm1-log1p81.1%

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

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

      \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left(d \cdot {c}^{-2}\right)} \]
    10. Step-by-step derivation
      1. metadata-eval81.1%

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

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

        \[\leadsto \frac{a}{c} + b \cdot \left(d \cdot \frac{1}{\color{blue}{c \cdot c}}\right) \]
      4. div-inv81.1%

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

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

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

    if -3.2e115 < c < -2.69999999999999996e47 or -6.4999999999999996e-6 < c < -2.74999999999999992e-36 or -3.4999999999999999e-78 < c < 4.8e11

    1. Initial program 70.9%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/77.8%

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

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

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

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

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

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

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

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

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

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

    if -2.69999999999999996e47 < c < -6.4999999999999996e-6 or 4.8e11 < c

    1. Initial program 50.7%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/78.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{+47}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -6.5 \cdot 10^{-6}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -2.75 \cdot 10^{-36}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 480000000000:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\ t_1 := \frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ t_2 := \frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{+47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1.25 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-36}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 7000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ b d) (/ (* c (/ a d)) d)))
        (t_1 (+ (/ a c) (* b (/ (/ d c) c))))
        (t_2 (+ (/ a c) (/ (/ (* b d) c) c))))
   (if (<= c -3.2e+115)
     t_1
     (if (<= c -2.5e+47)
       t_0
       (if (<= c -1.25e-7)
         t_2
         (if (<= c -2.4e-36)
           (+ (/ b d) (* (/ c d) (/ a d)))
           (if (<= c -3.5e-78) t_1 (if (<= c 7000000000.0) t_0 t_2))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c * (a / d)) / d);
	double t_1 = (a / c) + (b * ((d / c) / c));
	double t_2 = (a / c) + (((b * d) / c) / c);
	double tmp;
	if (c <= -3.2e+115) {
		tmp = t_1;
	} else if (c <= -2.5e+47) {
		tmp = t_0;
	} else if (c <= -1.25e-7) {
		tmp = t_2;
	} else if (c <= -2.4e-36) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= -3.5e-78) {
		tmp = t_1;
	} else if (c <= 7000000000.0) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = (b / d) + ((c * (a / d)) / d)
    t_1 = (a / c) + (b * ((d / c) / c))
    t_2 = (a / c) + (((b * d) / c) / c)
    if (c <= (-3.2d+115)) then
        tmp = t_1
    else if (c <= (-2.5d+47)) then
        tmp = t_0
    else if (c <= (-1.25d-7)) then
        tmp = t_2
    else if (c <= (-2.4d-36)) then
        tmp = (b / d) + ((c / d) * (a / d))
    else if (c <= (-3.5d-78)) then
        tmp = t_1
    else if (c <= 7000000000.0d0) then
        tmp = t_0
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b / d) + ((c * (a / d)) / d);
	double t_1 = (a / c) + (b * ((d / c) / c));
	double t_2 = (a / c) + (((b * d) / c) / c);
	double tmp;
	if (c <= -3.2e+115) {
		tmp = t_1;
	} else if (c <= -2.5e+47) {
		tmp = t_0;
	} else if (c <= -1.25e-7) {
		tmp = t_2;
	} else if (c <= -2.4e-36) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= -3.5e-78) {
		tmp = t_1;
	} else if (c <= 7000000000.0) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / d) + ((c * (a / d)) / d)
	t_1 = (a / c) + (b * ((d / c) / c))
	t_2 = (a / c) + (((b * d) / c) / c)
	tmp = 0
	if c <= -3.2e+115:
		tmp = t_1
	elif c <= -2.5e+47:
		tmp = t_0
	elif c <= -1.25e-7:
		tmp = t_2
	elif c <= -2.4e-36:
		tmp = (b / d) + ((c / d) * (a / d))
	elif c <= -3.5e-78:
		tmp = t_1
	elif c <= 7000000000.0:
		tmp = t_0
	else:
		tmp = t_2
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b / d) + Float64(Float64(c * Float64(a / d)) / d))
	t_1 = Float64(Float64(a / c) + Float64(b * Float64(Float64(d / c) / c)))
	t_2 = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c))
	tmp = 0.0
	if (c <= -3.2e+115)
		tmp = t_1;
	elseif (c <= -2.5e+47)
		tmp = t_0;
	elseif (c <= -1.25e-7)
		tmp = t_2;
	elseif (c <= -2.4e-36)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	elseif (c <= -3.5e-78)
		tmp = t_1;
	elseif (c <= 7000000000.0)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b / d) + ((c * (a / d)) / d);
	t_1 = (a / c) + (b * ((d / c) / c));
	t_2 = (a / c) + (((b * d) / c) / c);
	tmp = 0.0;
	if (c <= -3.2e+115)
		tmp = t_1;
	elseif (c <= -2.5e+47)
		tmp = t_0;
	elseif (c <= -1.25e-7)
		tmp = t_2;
	elseif (c <= -2.4e-36)
		tmp = (b / d) + ((c / d) * (a / d));
	elseif (c <= -3.5e-78)
		tmp = t_1;
	elseif (c <= 7000000000.0)
		tmp = t_0;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(b * N[(N[(d / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.2e+115], t$95$1, If[LessEqual[c, -2.5e+47], t$95$0, If[LessEqual[c, -1.25e-7], t$95$2, If[LessEqual[c, -2.4e-36], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -3.5e-78], t$95$1, If[LessEqual[c, 7000000000.0], t$95$0, t$95$2]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\
t_1 := \frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\
t_2 := \frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\
\mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;c \leq -2.5 \cdot 10^{+47}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq -1.25 \cdot 10^{-7}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;c \leq 7000000000:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -3.2e115 or -2.4e-36 < c < -3.4999999999999999e-78

    1. Initial program 45.8%

      \[\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}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*81.1%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/79.6%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. expm1-log1p-u77.9%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)\right)} \]
      2. expm1-udef78.0%

        \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)} - 1\right)} \]
      3. pow278.0%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\frac{b}{\color{blue}{c \cdot c}} \cdot d\right)} - 1\right) \]
      4. div-inv78.0%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(b \cdot \frac{1}{c \cdot c}\right)} \cdot d\right)} - 1\right) \]
      5. associate-*l*79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{b \cdot \left(\frac{1}{c \cdot c} \cdot d\right)}\right)} - 1\right) \]
      6. pow279.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\frac{1}{\color{blue}{{c}^{2}}} \cdot d\right)\right)} - 1\right) \]
      7. pow-flip79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\color{blue}{{c}^{\left(-2\right)}} \cdot d\right)\right)} - 1\right) \]
      8. metadata-eval79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{\color{blue}{-2}} \cdot d\right)\right)} - 1\right) \]
    7. Applied egg-rr79.3%

      \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def79.3%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)\right)} \]
      2. expm1-log1p81.1%

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

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

      \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left(d \cdot {c}^{-2}\right)} \]
    10. Step-by-step derivation
      1. metadata-eval81.1%

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

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

        \[\leadsto \frac{a}{c} + b \cdot \left(d \cdot \frac{1}{\color{blue}{c \cdot c}}\right) \]
      4. div-inv81.1%

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

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

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

    if -3.2e115 < c < -2.50000000000000011e47 or -3.4999999999999999e-78 < c < 7e9

    1. Initial program 72.1%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.9%

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

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

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

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

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

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

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

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

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

    if -2.50000000000000011e47 < c < -1.24999999999999994e-7 or 7e9 < c

    1. Initial program 50.7%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/78.3%

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

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

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

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

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

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

    if -1.24999999999999994e-7 < c < -2.4e-36

    1. Initial program 41.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/100.0%

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      2. *-commutative100.0%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{d \cdot d} \]
      3. times-frac100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{+47}:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq -1.25 \cdot 10^{-7}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-36}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 7000000000:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 74.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ t_1 := \frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -3 \cdot 10^{+47}:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq -8.4 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -9.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 14500000000:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ a c) (* b (/ (/ d c) c))))
        (t_1 (+ (/ a c) (/ (/ (* b d) c) c))))
   (if (<= c -3.2e+115)
     t_0
     (if (<= c -3e+47)
       (+ (/ b d) (/ (* c (/ a d)) d))
       (if (<= c -8.4e-7)
         t_1
         (if (<= c -9.2e-36)
           (+ (/ b d) (* (/ c d) (/ a d)))
           (if (<= c -3e-78)
             t_0
             (if (<= c 14500000000.0)
               (+ (/ b d) (/ (/ (* a c) d) d))
               t_1))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + (b * ((d / c) / c));
	double t_1 = (a / c) + (((b * d) / c) / c);
	double tmp;
	if (c <= -3.2e+115) {
		tmp = t_0;
	} else if (c <= -3e+47) {
		tmp = (b / d) + ((c * (a / d)) / d);
	} else if (c <= -8.4e-7) {
		tmp = t_1;
	} else if (c <= -9.2e-36) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= -3e-78) {
		tmp = t_0;
	} else if (c <= 14500000000.0) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = (a / c) + (b * ((d / c) / c))
    t_1 = (a / c) + (((b * d) / c) / c)
    if (c <= (-3.2d+115)) then
        tmp = t_0
    else if (c <= (-3d+47)) then
        tmp = (b / d) + ((c * (a / d)) / d)
    else if (c <= (-8.4d-7)) then
        tmp = t_1
    else if (c <= (-9.2d-36)) then
        tmp = (b / d) + ((c / d) * (a / d))
    else if (c <= (-3d-78)) then
        tmp = t_0
    else if (c <= 14500000000.0d0) then
        tmp = (b / d) + (((a * c) / d) / d)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + (b * ((d / c) / c));
	double t_1 = (a / c) + (((b * d) / c) / c);
	double tmp;
	if (c <= -3.2e+115) {
		tmp = t_0;
	} else if (c <= -3e+47) {
		tmp = (b / d) + ((c * (a / d)) / d);
	} else if (c <= -8.4e-7) {
		tmp = t_1;
	} else if (c <= -9.2e-36) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= -3e-78) {
		tmp = t_0;
	} else if (c <= 14500000000.0) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a / c) + (b * ((d / c) / c))
	t_1 = (a / c) + (((b * d) / c) / c)
	tmp = 0
	if c <= -3.2e+115:
		tmp = t_0
	elif c <= -3e+47:
		tmp = (b / d) + ((c * (a / d)) / d)
	elif c <= -8.4e-7:
		tmp = t_1
	elif c <= -9.2e-36:
		tmp = (b / d) + ((c / d) * (a / d))
	elif c <= -3e-78:
		tmp = t_0
	elif c <= 14500000000.0:
		tmp = (b / d) + (((a * c) / d) / d)
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a / c) + Float64(b * Float64(Float64(d / c) / c)))
	t_1 = Float64(Float64(a / c) + Float64(Float64(Float64(b * d) / c) / c))
	tmp = 0.0
	if (c <= -3.2e+115)
		tmp = t_0;
	elseif (c <= -3e+47)
		tmp = Float64(Float64(b / d) + Float64(Float64(c * Float64(a / d)) / d));
	elseif (c <= -8.4e-7)
		tmp = t_1;
	elseif (c <= -9.2e-36)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	elseif (c <= -3e-78)
		tmp = t_0;
	elseif (c <= 14500000000.0)
		tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a / c) + (b * ((d / c) / c));
	t_1 = (a / c) + (((b * d) / c) / c);
	tmp = 0.0;
	if (c <= -3.2e+115)
		tmp = t_0;
	elseif (c <= -3e+47)
		tmp = (b / d) + ((c * (a / d)) / d);
	elseif (c <= -8.4e-7)
		tmp = t_1;
	elseif (c <= -9.2e-36)
		tmp = (b / d) + ((c / d) * (a / d));
	elseif (c <= -3e-78)
		tmp = t_0;
	elseif (c <= 14500000000.0)
		tmp = (b / d) + (((a * c) / d) / d);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(b * N[(N[(d / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.2e+115], t$95$0, If[LessEqual[c, -3e+47], N[(N[(b / d), $MachinePrecision] + N[(N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8.4e-7], t$95$1, If[LessEqual[c, -9.2e-36], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -3e-78], t$95$0, If[LessEqual[c, 14500000000.0], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;c \leq -8.4 \cdot 10^{-7}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;c \leq -3 \cdot 10^{-78}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -3.2e115 or -9.19999999999999986e-36 < c < -2.99999999999999988e-78

    1. Initial program 45.8%

      \[\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}{c} + \frac{b \cdot d}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*81.1%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/79.6%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. expm1-log1p-u77.9%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)\right)} \]
      2. expm1-udef78.0%

        \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)} - 1\right)} \]
      3. pow278.0%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\frac{b}{\color{blue}{c \cdot c}} \cdot d\right)} - 1\right) \]
      4. div-inv78.0%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(b \cdot \frac{1}{c \cdot c}\right)} \cdot d\right)} - 1\right) \]
      5. associate-*l*79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{b \cdot \left(\frac{1}{c \cdot c} \cdot d\right)}\right)} - 1\right) \]
      6. pow279.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\frac{1}{\color{blue}{{c}^{2}}} \cdot d\right)\right)} - 1\right) \]
      7. pow-flip79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\color{blue}{{c}^{\left(-2\right)}} \cdot d\right)\right)} - 1\right) \]
      8. metadata-eval79.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{\color{blue}{-2}} \cdot d\right)\right)} - 1\right) \]
    7. Applied egg-rr79.3%

      \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def79.3%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)\right)} \]
      2. expm1-log1p81.1%

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

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

      \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left(d \cdot {c}^{-2}\right)} \]
    10. Step-by-step derivation
      1. metadata-eval81.1%

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

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

        \[\leadsto \frac{a}{c} + b \cdot \left(d \cdot \frac{1}{\color{blue}{c \cdot c}}\right) \]
      4. div-inv81.1%

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

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

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

    if -3.2e115 < c < -3.0000000000000001e47

    1. Initial program 43.0%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/68.0%

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

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

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

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

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

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

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

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

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

    if -3.0000000000000001e47 < c < -8.4e-7 or 1.45e10 < c

    1. Initial program 50.7%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/78.3%

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

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

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

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

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

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

    if -8.4e-7 < c < -9.19999999999999986e-36

    1. Initial program 41.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/100.0%

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      2. *-commutative100.0%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{d \cdot d} \]
      3. times-frac100.0%

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

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

    if -2.99999999999999988e-78 < c < 1.45e10

    1. Initial program 75.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/77.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{+115}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -3 \cdot 10^{+47}:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq -8.4 \cdot 10^{-7}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -9.2 \cdot 10^{-36}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3 \cdot 10^{-78}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 14500000000:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 80.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \mathbf{if}\;c \leq -3.65 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -2.6 \cdot 10^{-79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-154}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.8 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 950000000000:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
        (t_1 (+ (/ a c) (* d (* (/ 1.0 c) (/ b c))))))
   (if (<= c -3.65e+78)
     t_1
     (if (<= c -2.6e-79)
       t_0
       (if (<= c 2.6e-154)
         (+ (/ b d) (/ (/ (* a c) d) d))
         (if (<= c 2.8e-56)
           t_0
           (if (<= c 950000000000.0) (+ (/ b d) (* (/ c d) (/ a d))) t_1)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a / c) + (d * ((1.0 / c) * (b / c)));
	double tmp;
	if (c <= -3.65e+78) {
		tmp = t_1;
	} else if (c <= -2.6e-79) {
		tmp = t_0;
	} else if (c <= 2.6e-154) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else if (c <= 2.8e-56) {
		tmp = t_0;
	} else if (c <= 950000000000.0) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
    t_1 = (a / c) + (d * ((1.0d0 / c) * (b / c)))
    if (c <= (-3.65d+78)) then
        tmp = t_1
    else if (c <= (-2.6d-79)) then
        tmp = t_0
    else if (c <= 2.6d-154) then
        tmp = (b / d) + (((a * c) / d) / d)
    else if (c <= 2.8d-56) then
        tmp = t_0
    else if (c <= 950000000000.0d0) then
        tmp = (b / d) + ((c / d) * (a / d))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double t_1 = (a / c) + (d * ((1.0 / c) * (b / c)));
	double tmp;
	if (c <= -3.65e+78) {
		tmp = t_1;
	} else if (c <= -2.6e-79) {
		tmp = t_0;
	} else if (c <= 2.6e-154) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else if (c <= 2.8e-56) {
		tmp = t_0;
	} else if (c <= 950000000000.0) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d))
	t_1 = (a / c) + (d * ((1.0 / c) * (b / c)))
	tmp = 0
	if c <= -3.65e+78:
		tmp = t_1
	elif c <= -2.6e-79:
		tmp = t_0
	elif c <= 2.6e-154:
		tmp = (b / d) + (((a * c) / d) / d)
	elif c <= 2.8e-56:
		tmp = t_0
	elif c <= 950000000000.0:
		tmp = (b / d) + ((c / d) * (a / d))
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(a / c) + Float64(d * Float64(Float64(1.0 / c) * Float64(b / c))))
	tmp = 0.0
	if (c <= -3.65e+78)
		tmp = t_1;
	elseif (c <= -2.6e-79)
		tmp = t_0;
	elseif (c <= 2.6e-154)
		tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d));
	elseif (c <= 2.8e-56)
		tmp = t_0;
	elseif (c <= 950000000000.0)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	t_1 = (a / c) + (d * ((1.0 / c) * (b / c)));
	tmp = 0.0;
	if (c <= -3.65e+78)
		tmp = t_1;
	elseif (c <= -2.6e-79)
		tmp = t_0;
	elseif (c <= 2.6e-154)
		tmp = (b / d) + (((a * c) / d) / d);
	elseif (c <= 2.8e-56)
		tmp = t_0;
	elseif (c <= 950000000000.0)
		tmp = (b / d) + ((c / d) * (a / d));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(d * N[(N[(1.0 / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.65e+78], t$95$1, If[LessEqual[c, -2.6e-79], t$95$0, If[LessEqual[c, 2.6e-154], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.8e-56], t$95$0, If[LessEqual[c, 950000000000.0], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
t_1 := \frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\
\mathbf{if}\;c \leq -3.65 \cdot 10^{+78}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;c \leq -2.6 \cdot 10^{-79}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 2.8 \cdot 10^{-56}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -3.65e78 or 9.5e11 < c

    1. Initial program 38.1%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/78.6%

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{1 \cdot b}}{{c}^{2}} \cdot d \]
      2. pow278.6%

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

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

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

    if -3.65e78 < c < -2.59999999999999994e-79 or 2.6e-154 < c < 2.79999999999999993e-56

    1. Initial program 83.0%

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

    if -2.59999999999999994e-79 < c < 2.6e-154

    1. Initial program 73.8%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/80.9%

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

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

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

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

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

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

    if 2.79999999999999993e-56 < c < 9.5e11

    1. Initial program 50.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{d \cdot d} \]
      3. times-frac76.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.65 \cdot 10^{+78}:\\ \;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \mathbf{elif}\;c \leq -2.6 \cdot 10^{-79}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.6 \cdot 10^{-154}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.8 \cdot 10^{-56}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 950000000000:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 77.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \mathbf{if}\;c \leq -0.00033:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-36}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 8200000000:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ a c) (* d (* (/ 1.0 c) (/ b c))))))
   (if (<= c -0.00033)
     t_0
     (if (<= c -2.7e-36)
       (+ (/ b d) (* (/ c d) (/ a d)))
       (if (<= c -3.5e-78)
         (+ (/ a c) (* b (/ (/ d c) c)))
         (if (<= c 8200000000.0) (+ (/ b d) (/ (/ (* a c) d) d)) t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + (d * ((1.0 / c) * (b / c)));
	double tmp;
	if (c <= -0.00033) {
		tmp = t_0;
	} else if (c <= -2.7e-36) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= -3.5e-78) {
		tmp = (a / c) + (b * ((d / c) / c));
	} else if (c <= 8200000000.0) {
		tmp = (b / d) + (((a * 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 = (a / c) + (d * ((1.0d0 / c) * (b / c)))
    if (c <= (-0.00033d0)) then
        tmp = t_0
    else if (c <= (-2.7d-36)) then
        tmp = (b / d) + ((c / d) * (a / d))
    else if (c <= (-3.5d-78)) then
        tmp = (a / c) + (b * ((d / c) / c))
    else if (c <= 8200000000.0d0) then
        tmp = (b / d) + (((a * 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 = (a / c) + (d * ((1.0 / c) * (b / c)));
	double tmp;
	if (c <= -0.00033) {
		tmp = t_0;
	} else if (c <= -2.7e-36) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else if (c <= -3.5e-78) {
		tmp = (a / c) + (b * ((d / c) / c));
	} else if (c <= 8200000000.0) {
		tmp = (b / d) + (((a * c) / d) / d);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a / c) + (d * ((1.0 / c) * (b / c)))
	tmp = 0
	if c <= -0.00033:
		tmp = t_0
	elif c <= -2.7e-36:
		tmp = (b / d) + ((c / d) * (a / d))
	elif c <= -3.5e-78:
		tmp = (a / c) + (b * ((d / c) / c))
	elif c <= 8200000000.0:
		tmp = (b / d) + (((a * c) / d) / d)
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a / c) + Float64(d * Float64(Float64(1.0 / c) * Float64(b / c))))
	tmp = 0.0
	if (c <= -0.00033)
		tmp = t_0;
	elseif (c <= -2.7e-36)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	elseif (c <= -3.5e-78)
		tmp = Float64(Float64(a / c) + Float64(b * Float64(Float64(d / c) / c)));
	elseif (c <= 8200000000.0)
		tmp = Float64(Float64(b / d) + Float64(Float64(Float64(a * c) / d) / d));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a / c) + (d * ((1.0 / c) * (b / c)));
	tmp = 0.0;
	if (c <= -0.00033)
		tmp = t_0;
	elseif (c <= -2.7e-36)
		tmp = (b / d) + ((c / d) * (a / d));
	elseif (c <= -3.5e-78)
		tmp = (a / c) + (b * ((d / c) / c));
	elseif (c <= 8200000000.0)
		tmp = (b / d) + (((a * c) / d) / d);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(d * N[(N[(1.0 / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -0.00033], t$95$0, If[LessEqual[c, -2.7e-36], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -3.5e-78], N[(N[(a / c), $MachinePrecision] + N[(b * N[(N[(d / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8200000000.0], N[(N[(b / d), $MachinePrecision] + N[(N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\
\mathbf{if}\;c \leq -0.00033:\\
\;\;\;\;t_0\\

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

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

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -3.3e-4 or 8.2e9 < c

    1. Initial program 43.5%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/76.5%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. *-un-lft-identity76.5%

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

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

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

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

    if -3.3e-4 < c < -2.70000000000000007e-36

    1. Initial program 41.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/100.0%

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      2. *-commutative100.0%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{c \cdot a}}{d \cdot d} \]
      3. times-frac100.0%

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

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

    if -2.70000000000000007e-36 < c < -3.4999999999999999e-78

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/68.7%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. expm1-log1p-u68.3%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)\right)} \]
      2. expm1-udef68.3%

        \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)} - 1\right)} \]
      3. pow268.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\frac{b}{\color{blue}{c \cdot c}} \cdot d\right)} - 1\right) \]
      4. div-inv68.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(b \cdot \frac{1}{c \cdot c}\right)} \cdot d\right)} - 1\right) \]
      5. associate-*l*75.9%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{b \cdot \left(\frac{1}{c \cdot c} \cdot d\right)}\right)} - 1\right) \]
      6. pow275.9%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\frac{1}{\color{blue}{{c}^{2}}} \cdot d\right)\right)} - 1\right) \]
      7. pow-flip75.9%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\color{blue}{{c}^{\left(-2\right)}} \cdot d\right)\right)} - 1\right) \]
      8. metadata-eval75.9%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{\color{blue}{-2}} \cdot d\right)\right)} - 1\right) \]
    7. Applied egg-rr75.9%

      \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def75.9%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)\right)} \]
      2. expm1-log1p77.1%

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

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

      \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left(d \cdot {c}^{-2}\right)} \]
    10. Step-by-step derivation
      1. metadata-eval77.1%

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

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

        \[\leadsto \frac{a}{c} + b \cdot \left(d \cdot \frac{1}{\color{blue}{c \cdot c}}\right) \]
      4. div-inv77.1%

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

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

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

    if -3.4999999999999999e-78 < c < 8.2e9

    1. Initial program 75.2%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/77.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -0.00033:\\ \;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \mathbf{elif}\;c \leq -2.7 \cdot 10^{-36}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-78}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 8200000000:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a \cdot c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + d \cdot \left(\frac{1}{c} \cdot \frac{b}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 65.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.35 \cdot 10^{+86} \lor \neg \left(c \leq -3.2 \cdot 10^{+47} \lor \neg \left(c \leq -3 \cdot 10^{-78}\right) \land c \leq 3 \cdot 10^{-153}\right):\\
\;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.3500000000000001e86 or -3.2e47 < c < -2.99999999999999988e-78 or 3e-153 < c

    1. Initial program 53.1%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/69.5%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{b}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. expm1-log1p-u66.4%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)\right)} \]
      2. expm1-udef65.2%

        \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)} - 1\right)} \]
      3. pow265.2%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\frac{b}{\color{blue}{c \cdot c}} \cdot d\right)} - 1\right) \]
      4. div-inv65.2%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(b \cdot \frac{1}{c \cdot c}\right)} \cdot d\right)} - 1\right) \]
      5. associate-*l*66.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{b \cdot \left(\frac{1}{c \cdot c} \cdot d\right)}\right)} - 1\right) \]
      6. pow266.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\frac{1}{\color{blue}{{c}^{2}}} \cdot d\right)\right)} - 1\right) \]
      7. pow-flip66.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\color{blue}{{c}^{\left(-2\right)}} \cdot d\right)\right)} - 1\right) \]
      8. metadata-eval66.3%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{\color{blue}{-2}} \cdot d\right)\right)} - 1\right) \]
    7. Applied egg-rr66.3%

      \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def67.0%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)\right)} \]
      2. expm1-log1p70.7%

        \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left({c}^{-2} \cdot d\right)} \]
      3. *-commutative70.7%

        \[\leadsto \frac{a}{c} + b \cdot \color{blue}{\left(d \cdot {c}^{-2}\right)} \]
    9. Simplified70.7%

      \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left(d \cdot {c}^{-2}\right)} \]
    10. Step-by-step derivation
      1. metadata-eval70.7%

        \[\leadsto \frac{a}{c} + b \cdot \left(d \cdot {c}^{\color{blue}{\left(-2\right)}}\right) \]
      2. pow-flip70.7%

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

        \[\leadsto \frac{a}{c} + b \cdot \left(d \cdot \frac{1}{\color{blue}{c \cdot c}}\right) \]
      4. div-inv70.7%

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

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

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

    if -2.3500000000000001e86 < c < -3.2e47 or -2.99999999999999988e-78 < c < 3e-153

    1. Initial program 70.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.35 \cdot 10^{+86} \lor \neg \left(c \leq -3.2 \cdot 10^{+47} \lor \neg \left(c \leq -3 \cdot 10^{-78}\right) \land c \leq 3 \cdot 10^{-153}\right):\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 65.9% accurate, 0.5× speedup?

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

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

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

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

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.3500000000000001e86 or 3e-153 < c

    1. Initial program 46.5%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/71.3%

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

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

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

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

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

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

    if -2.3500000000000001e86 < c < -3.2e47 or -5.99999999999999999e-79 < c < 3e-153

    1. Initial program 70.5%

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

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

    if -3.2e47 < c < -5.99999999999999999e-79

    1. Initial program 83.0%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{\frac{{c}^{2}}{d}}} \]
      2. associate-/r/61.5%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)\right)} \]
      2. expm1-udef53.9%

        \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{b}{{c}^{2}} \cdot d\right)} - 1\right)} \]
      3. pow253.9%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\frac{b}{\color{blue}{c \cdot c}} \cdot d\right)} - 1\right) \]
      4. div-inv53.9%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{\left(b \cdot \frac{1}{c \cdot c}\right)} \cdot d\right)} - 1\right) \]
      5. associate-*l*56.8%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(\color{blue}{b \cdot \left(\frac{1}{c \cdot c} \cdot d\right)}\right)} - 1\right) \]
      6. pow256.8%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\frac{1}{\color{blue}{{c}^{2}}} \cdot d\right)\right)} - 1\right) \]
      7. pow-flip56.8%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left(\color{blue}{{c}^{\left(-2\right)}} \cdot d\right)\right)} - 1\right) \]
      8. metadata-eval56.8%

        \[\leadsto \frac{a}{c} + \left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{\color{blue}{-2}} \cdot d\right)\right)} - 1\right) \]
    7. Applied egg-rr56.8%

      \[\leadsto \frac{a}{c} + \color{blue}{\left(e^{\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def60.0%

        \[\leadsto \frac{a}{c} + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(b \cdot \left({c}^{-2} \cdot d\right)\right)\right)} \]
      2. expm1-log1p64.6%

        \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left({c}^{-2} \cdot d\right)} \]
      3. *-commutative64.6%

        \[\leadsto \frac{a}{c} + b \cdot \color{blue}{\left(d \cdot {c}^{-2}\right)} \]
    9. Simplified64.6%

      \[\leadsto \frac{a}{c} + \color{blue}{b \cdot \left(d \cdot {c}^{-2}\right)} \]
    10. Step-by-step derivation
      1. metadata-eval64.6%

        \[\leadsto \frac{a}{c} + b \cdot \left(d \cdot {c}^{\color{blue}{\left(-2\right)}}\right) \]
      2. pow-flip64.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.35 \cdot 10^{+86}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -3.2 \cdot 10^{+47}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-79}:\\ \;\;\;\;\frac{a}{c} + b \cdot \frac{\frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{-153}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b \cdot d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 62.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6 \cdot 10^{+99} \lor \neg \left(c \leq -5.8 \cdot 10^{-36}\right) \land \left(c \leq -3.5 \cdot 10^{-78} \lor \neg \left(c \leq 3.5 \cdot 10^{+53}\right)\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -6.00000000000000029e99 or -5.80000000000000026e-36 < c < -3.4999999999999999e-78 or 3.50000000000000019e53 < c

    1. Initial program 41.9%

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

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

    if -6.00000000000000029e99 < c < -5.80000000000000026e-36 or -3.4999999999999999e-78 < c < 3.50000000000000019e53

    1. Initial program 72.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6 \cdot 10^{+99} \lor \neg \left(c \leq -5.8 \cdot 10^{-36}\right) \land \left(c \leq -3.5 \cdot 10^{-78} \lor \neg \left(c \leq 3.5 \cdot 10^{+53}\right)\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 42.5% 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 59.6%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification46.0%

    \[\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 2024021 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :herbie-target
  (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))))