Complex division, real part

Percentage Accurate: 61.8% → 82.7%
Time: 12.4s
Alternatives: 11
Speedup: 1.2×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 61.8% accurate, 1.0× speedup?

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

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

Alternative 1: 82.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \mathsf{fma}\left(\frac{1}{c} \cdot d, \frac{b}{c}, \frac{a}{c}\right)\\ t_2 := c \cdot a + d \cdot b\\ \mathbf{if}\;c \leq -1.4 \cdot 10^{+89}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-29}:\\ \;\;\;\;\frac{1}{t\_0} \cdot t\_2\\ \mathbf{elif}\;c \leq 6 \cdot 10^{-145}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{+53}:\\ \;\;\;\;\frac{1}{\frac{t\_0}{t\_2}}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d)))
        (t_1 (fma (* (/ 1.0 c) d) (/ b c) (/ a c)))
        (t_2 (+ (* c a) (* d b))))
   (if (<= c -1.4e+89)
     t_1
     (if (<= c -2.5e-29)
       (* (/ 1.0 t_0) t_2)
       (if (<= c 6e-145)
         (/ (+ b (/ 1.0 (/ d (* c a)))) d)
         (if (<= c 4e+53) (/ 1.0 (/ t_0 t_2)) t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = fma(((1.0 / c) * d), (b / c), (a / c));
	double t_2 = (c * a) + (d * b);
	double tmp;
	if (c <= -1.4e+89) {
		tmp = t_1;
	} else if (c <= -2.5e-29) {
		tmp = (1.0 / t_0) * t_2;
	} else if (c <= 6e-145) {
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	} else if (c <= 4e+53) {
		tmp = 1.0 / (t_0 / t_2);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	t_1 = fma(Float64(Float64(1.0 / c) * d), Float64(b / c), Float64(a / c))
	t_2 = Float64(Float64(c * a) + Float64(d * b))
	tmp = 0.0
	if (c <= -1.4e+89)
		tmp = t_1;
	elseif (c <= -2.5e-29)
		tmp = Float64(Float64(1.0 / t_0) * t_2);
	elseif (c <= 6e-145)
		tmp = Float64(Float64(b + Float64(1.0 / Float64(d / Float64(c * a)))) / d);
	elseif (c <= 4e+53)
		tmp = Float64(1.0 / Float64(t_0 / t_2));
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 / c), $MachinePrecision] * d), $MachinePrecision] * N[(b / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.4e+89], t$95$1, If[LessEqual[c, -2.5e-29], N[(N[(1.0 / t$95$0), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[c, 6e-145], N[(N[(b + N[(1.0 / N[(d / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4e+53], N[(1.0 / N[(t$95$0 / t$95$2), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := c \cdot c + d \cdot d\\
t_1 := \mathsf{fma}\left(\frac{1}{c} \cdot d, \frac{b}{c}, \frac{a}{c}\right)\\
t_2 := c \cdot a + d \cdot b\\
\mathbf{if}\;c \leq -1.4 \cdot 10^{+89}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -2.5 \cdot 10^{-29}:\\
\;\;\;\;\frac{1}{t\_0} \cdot t\_2\\

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

\mathbf{elif}\;c \leq 4 \cdot 10^{+53}:\\
\;\;\;\;\frac{1}{\frac{t\_0}{t\_2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.3999999999999999e89 or 4e53 < c

    1. Initial program 39.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{c} \cdot \color{blue}{\left(a + \frac{b \cdot d}{c}\right)} \]
      3. +-commutativeN/A

        \[\leadsto \frac{1}{c} \cdot \left(\frac{b \cdot d}{c} + \color{blue}{a}\right) \]
      4. distribute-lft-inN/A

        \[\leadsto \frac{1}{c} \cdot \frac{b \cdot d}{c} + \color{blue}{\frac{1}{c} \cdot a} \]
      5. *-commutativeN/A

        \[\leadsto \frac{1}{c} \cdot \frac{d \cdot b}{c} + \frac{1}{c} \cdot a \]
      6. associate-/l*N/A

        \[\leadsto \frac{1}{c} \cdot \left(d \cdot \frac{b}{c}\right) + \frac{1}{\color{blue}{c}} \cdot a \]
      7. associate-*r*N/A

        \[\leadsto \left(\frac{1}{c} \cdot d\right) \cdot \frac{b}{c} + \color{blue}{\frac{1}{c}} \cdot a \]
      8. associate-/r/N/A

        \[\leadsto \left(\frac{1}{c} \cdot d\right) \cdot \frac{b}{c} + \frac{1}{\color{blue}{\frac{c}{a}}} \]
      9. clear-numN/A

        \[\leadsto \left(\frac{1}{c} \cdot d\right) \cdot \frac{b}{c} + \frac{a}{\color{blue}{c}} \]
      10. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{c}\right), d\right), \left(\frac{\color{blue}{b}}{c}\right), \left(\frac{a}{c}\right)\right) \]
      12. /-lowering-/.f64N/A

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

        \[\leadsto \mathsf{fma.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, c\right), d\right), \mathsf{/.f64}\left(b, \color{blue}{c}\right), \left(\frac{a}{c}\right)\right) \]
      14. /-lowering-/.f6484.9%

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

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

    if -1.3999999999999999e89 < c < -2.49999999999999993e-29

    1. Initial program 89.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-invN/A

        \[\leadsto \left(a \cdot c + b \cdot d\right) \cdot \color{blue}{\frac{1}{c \cdot c + d \cdot d}} \]
      2. flip-+N/A

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

        \[\leadsto \left(a \cdot c + b \cdot d\right) \cdot \frac{c \cdot c - d \cdot d}{\color{blue}{\left(c \cdot c\right) \cdot \left(c \cdot c\right) - \left(d \cdot d\right) \cdot \left(d \cdot d\right)}} \]
      4. *-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{\left(c \cdot c\right) \cdot \left(c \cdot c\right) - \left(d \cdot d\right) \cdot \left(d \cdot d\right)}{c \cdot c - d \cdot d}}\right), \left(\color{blue}{a \cdot c} + b \cdot d\right)\right) \]
      7. flip-+N/A

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

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

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

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

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

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

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

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

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

    if -2.49999999999999993e-29 < c < 5.99999999999999985e-145

    1. Initial program 66.1%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

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

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

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

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

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

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

    if 5.99999999999999985e-145 < c < 4e53

    1. Initial program 88.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}} \]
      2. /-lowering-/.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a, c\right), \mathsf{*.f64}\left(b, \color{blue}{d}\right)\right)\right)\right) \]
    4. Applied egg-rr88.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.4 \cdot 10^{+89}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{c} \cdot d, \frac{b}{c}, \frac{a}{c}\right)\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-29}:\\ \;\;\;\;\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot a + d \cdot b\right)\\ \mathbf{elif}\;c \leq 6 \cdot 10^{-145}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{+53}:\\ \;\;\;\;\frac{1}{\frac{c \cdot c + d \cdot d}{c \cdot a + d \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{c} \cdot d, \frac{b}{c}, \frac{a}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{a + \frac{b}{\frac{c}{d}}}{c}\\ t_2 := c \cdot a + d \cdot b\\ \mathbf{if}\;c \leq -3.5 \cdot 10^{+88}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -2.35 \cdot 10^{-26}:\\ \;\;\;\;\frac{1}{t\_0} \cdot t\_2\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-143}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 2.5 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\frac{t\_0}{t\_2}}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d)))
        (t_1 (/ (+ a (/ b (/ c d))) c))
        (t_2 (+ (* c a) (* d b))))
   (if (<= c -3.5e+88)
     t_1
     (if (<= c -2.35e-26)
       (* (/ 1.0 t_0) t_2)
       (if (<= c 4e-143)
         (/ (+ b (/ 1.0 (/ d (* c a)))) d)
         (if (<= c 2.5e+108) (/ 1.0 (/ t_0 t_2)) t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = (a + (b / (c / d))) / c;
	double t_2 = (c * a) + (d * b);
	double tmp;
	if (c <= -3.5e+88) {
		tmp = t_1;
	} else if (c <= -2.35e-26) {
		tmp = (1.0 / t_0) * t_2;
	} else if (c <= 4e-143) {
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	} else if (c <= 2.5e+108) {
		tmp = 1.0 / (t_0 / t_2);
	} 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) :: t_2
    real(8) :: tmp
    t_0 = (c * c) + (d * d)
    t_1 = (a + (b / (c / d))) / c
    t_2 = (c * a) + (d * b)
    if (c <= (-3.5d+88)) then
        tmp = t_1
    else if (c <= (-2.35d-26)) then
        tmp = (1.0d0 / t_0) * t_2
    else if (c <= 4d-143) then
        tmp = (b + (1.0d0 / (d / (c * a)))) / d
    else if (c <= 2.5d+108) then
        tmp = 1.0d0 / (t_0 / t_2)
    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 = (c * c) + (d * d);
	double t_1 = (a + (b / (c / d))) / c;
	double t_2 = (c * a) + (d * b);
	double tmp;
	if (c <= -3.5e+88) {
		tmp = t_1;
	} else if (c <= -2.35e-26) {
		tmp = (1.0 / t_0) * t_2;
	} else if (c <= 4e-143) {
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	} else if (c <= 2.5e+108) {
		tmp = 1.0 / (t_0 / t_2);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (c * c) + (d * d)
	t_1 = (a + (b / (c / d))) / c
	t_2 = (c * a) + (d * b)
	tmp = 0
	if c <= -3.5e+88:
		tmp = t_1
	elif c <= -2.35e-26:
		tmp = (1.0 / t_0) * t_2
	elif c <= 4e-143:
		tmp = (b + (1.0 / (d / (c * a)))) / d
	elif c <= 2.5e+108:
		tmp = 1.0 / (t_0 / t_2)
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	t_1 = Float64(Float64(a + Float64(b / Float64(c / d))) / c)
	t_2 = Float64(Float64(c * a) + Float64(d * b))
	tmp = 0.0
	if (c <= -3.5e+88)
		tmp = t_1;
	elseif (c <= -2.35e-26)
		tmp = Float64(Float64(1.0 / t_0) * t_2);
	elseif (c <= 4e-143)
		tmp = Float64(Float64(b + Float64(1.0 / Float64(d / Float64(c * a)))) / d);
	elseif (c <= 2.5e+108)
		tmp = Float64(1.0 / Float64(t_0 / t_2));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (c * c) + (d * d);
	t_1 = (a + (b / (c / d))) / c;
	t_2 = (c * a) + (d * b);
	tmp = 0.0;
	if (c <= -3.5e+88)
		tmp = t_1;
	elseif (c <= -2.35e-26)
		tmp = (1.0 / t_0) * t_2;
	elseif (c <= 4e-143)
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	elseif (c <= 2.5e+108)
		tmp = 1.0 / (t_0 / t_2);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.5e+88], t$95$1, If[LessEqual[c, -2.35e-26], N[(N[(1.0 / t$95$0), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[c, 4e-143], N[(N[(b + N[(1.0 / N[(d / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.5e+108], N[(1.0 / N[(t$95$0 / t$95$2), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -2.35 \cdot 10^{-26}:\\
\;\;\;\;\frac{1}{t\_0} \cdot t\_2\\

\mathbf{elif}\;c \leq 4 \cdot 10^{-143}:\\
\;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\

\mathbf{elif}\;c \leq 2.5 \cdot 10^{+108}:\\
\;\;\;\;\frac{1}{\frac{t\_0}{t\_2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -3.4999999999999998e88 or 2.49999999999999995e108 < c

    1. Initial program 35.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.4999999999999998e88 < c < -2.34999999999999995e-26

    1. Initial program 89.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-invN/A

        \[\leadsto \left(a \cdot c + b \cdot d\right) \cdot \color{blue}{\frac{1}{c \cdot c + d \cdot d}} \]
      2. flip-+N/A

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

        \[\leadsto \left(a \cdot c + b \cdot d\right) \cdot \frac{c \cdot c - d \cdot d}{\color{blue}{\left(c \cdot c\right) \cdot \left(c \cdot c\right) - \left(d \cdot d\right) \cdot \left(d \cdot d\right)}} \]
      4. *-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{\left(c \cdot c\right) \cdot \left(c \cdot c\right) - \left(d \cdot d\right) \cdot \left(d \cdot d\right)}{c \cdot c - d \cdot d}}\right), \left(\color{blue}{a \cdot c} + b \cdot d\right)\right) \]
      7. flip-+N/A

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

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

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

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

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

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

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

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

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

    if -2.34999999999999995e-26 < c < 3.9999999999999998e-143

    1. Initial program 66.1%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

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

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

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

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

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

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

    if 3.9999999999999998e-143 < c < 2.49999999999999995e108

    1. Initial program 82.2%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}} \]
      2. /-lowering-/.f64N/A

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a, c\right), \left(\color{blue}{b} \cdot d\right)\right)\right)\right) \]
      9. *-lowering-*.f6482.2%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a, c\right), \mathsf{*.f64}\left(b, \color{blue}{d}\right)\right)\right)\right) \]
    4. Applied egg-rr82.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.5 \cdot 10^{+88}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;c \leq -2.35 \cdot 10^{-26}:\\ \;\;\;\;\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot a + d \cdot b\right)\\ \mathbf{elif}\;c \leq 4 \cdot 10^{-143}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 2.5 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\frac{c \cdot c + d \cdot d}{c \cdot a + d \cdot b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{a + \frac{b}{\frac{c}{d}}}{c}\\ t_2 := c \cdot a + d \cdot b\\ \mathbf{if}\;c \leq -9 \cdot 10^{+88}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-32}:\\ \;\;\;\;\frac{1}{t\_0} \cdot t\_2\\ \mathbf{elif}\;c \leq 3.8 \cdot 10^{-146}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 6 \cdot 10^{+111}:\\ \;\;\;\;\frac{t\_2}{t\_0}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d)))
        (t_1 (/ (+ a (/ b (/ c d))) c))
        (t_2 (+ (* c a) (* d b))))
   (if (<= c -9e+88)
     t_1
     (if (<= c -6e-32)
       (* (/ 1.0 t_0) t_2)
       (if (<= c 3.8e-146)
         (/ (+ b (/ 1.0 (/ d (* c a)))) d)
         (if (<= c 6e+111) (/ t_2 t_0) t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = (a + (b / (c / d))) / c;
	double t_2 = (c * a) + (d * b);
	double tmp;
	if (c <= -9e+88) {
		tmp = t_1;
	} else if (c <= -6e-32) {
		tmp = (1.0 / t_0) * t_2;
	} else if (c <= 3.8e-146) {
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	} else if (c <= 6e+111) {
		tmp = t_2 / t_0;
	} 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) :: t_2
    real(8) :: tmp
    t_0 = (c * c) + (d * d)
    t_1 = (a + (b / (c / d))) / c
    t_2 = (c * a) + (d * b)
    if (c <= (-9d+88)) then
        tmp = t_1
    else if (c <= (-6d-32)) then
        tmp = (1.0d0 / t_0) * t_2
    else if (c <= 3.8d-146) then
        tmp = (b + (1.0d0 / (d / (c * a)))) / d
    else if (c <= 6d+111) then
        tmp = t_2 / t_0
    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 = (c * c) + (d * d);
	double t_1 = (a + (b / (c / d))) / c;
	double t_2 = (c * a) + (d * b);
	double tmp;
	if (c <= -9e+88) {
		tmp = t_1;
	} else if (c <= -6e-32) {
		tmp = (1.0 / t_0) * t_2;
	} else if (c <= 3.8e-146) {
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	} else if (c <= 6e+111) {
		tmp = t_2 / t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (c * c) + (d * d)
	t_1 = (a + (b / (c / d))) / c
	t_2 = (c * a) + (d * b)
	tmp = 0
	if c <= -9e+88:
		tmp = t_1
	elif c <= -6e-32:
		tmp = (1.0 / t_0) * t_2
	elif c <= 3.8e-146:
		tmp = (b + (1.0 / (d / (c * a)))) / d
	elif c <= 6e+111:
		tmp = t_2 / t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	t_1 = Float64(Float64(a + Float64(b / Float64(c / d))) / c)
	t_2 = Float64(Float64(c * a) + Float64(d * b))
	tmp = 0.0
	if (c <= -9e+88)
		tmp = t_1;
	elseif (c <= -6e-32)
		tmp = Float64(Float64(1.0 / t_0) * t_2);
	elseif (c <= 3.8e-146)
		tmp = Float64(Float64(b + Float64(1.0 / Float64(d / Float64(c * a)))) / d);
	elseif (c <= 6e+111)
		tmp = Float64(t_2 / t_0);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (c * c) + (d * d);
	t_1 = (a + (b / (c / d))) / c;
	t_2 = (c * a) + (d * b);
	tmp = 0.0;
	if (c <= -9e+88)
		tmp = t_1;
	elseif (c <= -6e-32)
		tmp = (1.0 / t_0) * t_2;
	elseif (c <= 3.8e-146)
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	elseif (c <= 6e+111)
		tmp = t_2 / t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -9e+88], t$95$1, If[LessEqual[c, -6e-32], N[(N[(1.0 / t$95$0), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[c, 3.8e-146], N[(N[(b + N[(1.0 / N[(d / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6e+111], N[(t$95$2 / t$95$0), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -6 \cdot 10^{-32}:\\
\;\;\;\;\frac{1}{t\_0} \cdot t\_2\\

\mathbf{elif}\;c \leq 3.8 \cdot 10^{-146}:\\
\;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\

\mathbf{elif}\;c \leq 6 \cdot 10^{+111}:\\
\;\;\;\;\frac{t\_2}{t\_0}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -9e88 or 6e111 < c

    1. Initial program 35.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9e88 < c < -6.0000000000000001e-32

    1. Initial program 89.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-invN/A

        \[\leadsto \left(a \cdot c + b \cdot d\right) \cdot \color{blue}{\frac{1}{c \cdot c + d \cdot d}} \]
      2. flip-+N/A

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

        \[\leadsto \left(a \cdot c + b \cdot d\right) \cdot \frac{c \cdot c - d \cdot d}{\color{blue}{\left(c \cdot c\right) \cdot \left(c \cdot c\right) - \left(d \cdot d\right) \cdot \left(d \cdot d\right)}} \]
      4. *-commutativeN/A

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

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

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{\left(c \cdot c\right) \cdot \left(c \cdot c\right) - \left(d \cdot d\right) \cdot \left(d \cdot d\right)}{c \cdot c - d \cdot d}}\right), \left(\color{blue}{a \cdot c} + b \cdot d\right)\right) \]
      7. flip-+N/A

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

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

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

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

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

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

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

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

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

    if -6.0000000000000001e-32 < c < 3.79999999999999994e-146

    1. Initial program 66.1%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

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

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

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

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

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

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

    if 3.79999999999999994e-146 < c < 6e111

    1. Initial program 82.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{+88}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-32}:\\ \;\;\;\;\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot a + d \cdot b\right)\\ \mathbf{elif}\;c \leq 3.8 \cdot 10^{-146}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 6 \cdot 10^{+111}:\\ \;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ t_1 := \frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{if}\;c \leq -1.6 \cdot 10^{+85}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -8.6 \cdot 10^{-30}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.12 \cdot 10^{-141}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{+109}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* c a) (* d b)) (+ (* c c) (* d d))))
        (t_1 (/ (+ a (/ b (/ c d))) c)))
   (if (<= c -1.6e+85)
     t_1
     (if (<= c -8.6e-30)
       t_0
       (if (<= c 1.12e-141)
         (/ (+ b (/ 1.0 (/ d (* c a)))) d)
         (if (<= c 1.65e+109) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
	double t_1 = (a + (b / (c / d))) / c;
	double tmp;
	if (c <= -1.6e+85) {
		tmp = t_1;
	} else if (c <= -8.6e-30) {
		tmp = t_0;
	} else if (c <= 1.12e-141) {
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	} else if (c <= 1.65e+109) {
		tmp = t_0;
	} 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 = ((c * a) + (d * b)) / ((c * c) + (d * d))
    t_1 = (a + (b / (c / d))) / c
    if (c <= (-1.6d+85)) then
        tmp = t_1
    else if (c <= (-8.6d-30)) then
        tmp = t_0
    else if (c <= 1.12d-141) then
        tmp = (b + (1.0d0 / (d / (c * a)))) / d
    else if (c <= 1.65d+109) then
        tmp = t_0
    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 = ((c * a) + (d * b)) / ((c * c) + (d * d));
	double t_1 = (a + (b / (c / d))) / c;
	double tmp;
	if (c <= -1.6e+85) {
		tmp = t_1;
	} else if (c <= -8.6e-30) {
		tmp = t_0;
	} else if (c <= 1.12e-141) {
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	} else if (c <= 1.65e+109) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d))
	t_1 = (a + (b / (c / d))) / c
	tmp = 0
	if c <= -1.6e+85:
		tmp = t_1
	elif c <= -8.6e-30:
		tmp = t_0
	elif c <= 1.12e-141:
		tmp = (b + (1.0 / (d / (c * a)))) / d
	elif c <= 1.65e+109:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * a) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(a + Float64(b / Float64(c / d))) / c)
	tmp = 0.0
	if (c <= -1.6e+85)
		tmp = t_1;
	elseif (c <= -8.6e-30)
		tmp = t_0;
	elseif (c <= 1.12e-141)
		tmp = Float64(Float64(b + Float64(1.0 / Float64(d / Float64(c * a)))) / d);
	elseif (c <= 1.65e+109)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * a) + (d * b)) / ((c * c) + (d * d));
	t_1 = (a + (b / (c / d))) / c;
	tmp = 0.0;
	if (c <= -1.6e+85)
		tmp = t_1;
	elseif (c <= -8.6e-30)
		tmp = t_0;
	elseif (c <= 1.12e-141)
		tmp = (b + (1.0 / (d / (c * a)))) / d;
	elseif (c <= 1.65e+109)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * a), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.6e+85], t$95$1, If[LessEqual[c, -8.6e-30], t$95$0, If[LessEqual[c, 1.12e-141], N[(N[(b + N[(1.0 / N[(d / N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.65e+109], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -8.6 \cdot 10^{-30}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.12 \cdot 10^{-141}:\\
\;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\

\mathbf{elif}\;c \leq 1.65 \cdot 10^{+109}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.60000000000000009e85 or 1.6499999999999999e109 < c

    1. Initial program 35.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.60000000000000009e85 < c < -8.59999999999999932e-30 or 1.12000000000000002e-141 < c < 1.6499999999999999e109

    1. Initial program 84.4%

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

    if -8.59999999999999932e-30 < c < 1.12000000000000002e-141

    1. Initial program 66.1%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.6 \cdot 10^{+85}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;c \leq -8.6 \cdot 10^{-30}:\\ \;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.12 \cdot 10^{-141}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{+109}:\\ \;\;\;\;\frac{c \cdot a + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.5% accurate, 0.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.7e24 or 9.4999999999999997e48 < c

    1. Initial program 45.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.7e24 < c < 3.59999999999999978e-56

    1. Initial program 73.6%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

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

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

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

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

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

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

    if 3.59999999999999978e-56 < c < 9.4999999999999997e48

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \left(d \cdot \color{blue}{d}\right)\right)\right) \]
      8. *-lowering-*.f6480.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.7 \cdot 10^{+24}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-56}:\\ \;\;\;\;\frac{b + \frac{1}{\frac{d}{c \cdot a}}}{d}\\ \mathbf{elif}\;c \leq 9.5 \cdot 10^{+48}:\\ \;\;\;\;\frac{c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 78.5% accurate, 0.6× speedup?

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

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

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

\mathbf{elif}\;c \leq 1.8 \cdot 10^{+53}:\\
\;\;\;\;\frac{c \cdot a}{c \cdot c + d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.5000000000000003e25 or 1.8e53 < c

    1. Initial program 45.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.5000000000000003e25 < c < 3.59999999999999978e-56

    1. Initial program 73.6%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

    if 3.59999999999999978e-56 < c < 1.8e53

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, a\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \left(d \cdot \color{blue}{d}\right)\right)\right) \]
      8. *-lowering-*.f6480.3%

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

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

Alternative 7: 78.4% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.4199999999999999e25 or 1.8999999999999999e-57 < c

    1. Initial program 51.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.4199999999999999e25 < c < 1.8999999999999999e-57

    1. Initial program 73.6%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

Alternative 8: 77.9% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.2000000000000002e24 or 3.4999999999999998e-56 < c

    1. Initial program 51.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.2000000000000002e24 < c < 3.4999999999999998e-56

    1. Initial program 73.6%

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(b\right)\right)\right)}{d} + \frac{\color{blue}{a} \cdot c}{{d}^{2}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{\mathsf{neg}\left(-1 \cdot b\right)}{d} + \frac{a \cdot c}{{d}^{2}} \]
      3. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{-1 \cdot b}{d}\right)\right) + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      4. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{\mathsf{neg}\left(d\right)} + \frac{\color{blue}{a \cdot c}}{{d}^{2}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \color{blue}{c}}{{d}^{2}} \]
      6. unpow2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot c}{d \cdot \color{blue}{d}} \]
      7. associate-/r*N/A

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

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{a \cdot \frac{c}{d}}{d} \]
      9. associate-/l*N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\frac{a \cdot c}{d}}{d} \]
      10. remove-double-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot c}{d}\right)\right)\right)}{d} \]
      11. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \frac{\mathsf{neg}\left(-1 \cdot \frac{a \cdot c}{d}\right)}{d} \]
      12. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{-1 \cdot \frac{a \cdot c}{d}}{d}\right)\right) \]
      13. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\mathsf{neg}\left(\frac{a \cdot c}{d}\right)}{d}\right)\right) \]
      14. distribute-frac-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{d}\right)\right)\right)\right) \]
      15. distribute-frac-neg2N/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{\mathsf{neg}\left(d\right)}\right)\right) \]
      16. mul-1-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} + \left(\mathsf{neg}\left(\frac{\frac{a \cdot c}{d}}{-1 \cdot d}\right)\right) \]
      17. sub-negN/A

        \[\leadsto \frac{-1 \cdot b}{-1 \cdot d} - \color{blue}{\frac{\frac{a \cdot c}{d}}{-1 \cdot d}} \]
      18. div-subN/A

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

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

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

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

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

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

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

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

Alternative 9: 73.4% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.5e74 or 5.7999999999999997e70 < d

    1. Initial program 45.7%

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

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

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

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

    if -7.5e74 < d < 5.7999999999999997e70

    1. Initial program 70.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 64.3% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;d \leq 225000000:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.64999999999999991e58 or 2.25e8 < d

    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

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

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

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

    if -1.64999999999999991e58 < d < 2.25e8

    1. Initial program 69.2%

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

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

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

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

Alternative 11: 43.1% accurate, 5.0× speedup?

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

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 60.6%

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

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

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

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

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

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

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

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))

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