Complex division, real part

Percentage Accurate: 61.6% → 80.0%
Time: 9.2s
Alternatives: 8
Speedup: 2.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 61.6% accurate, 1.0× speedup?

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

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

Alternative 1: 80.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\ \mathbf{if}\;c \leq -2.35 \cdot 10^{+98}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq -1.6 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{-123}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 9.4 \cdot 10^{-54}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;c \leq 1.85 \cdot 10^{+56}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (/ a c) (/ 1.0 (* c (/ (/ c b) d))))))
   (if (<= c -2.35e+98)
     t_0
     (if (<= c -1.6e-9)
       (* (fma a c (* b d)) (/ 1.0 (fma c c (* d d))))
       (if (<= c 5.2e-123)
         (* (/ 1.0 d) (+ b (* a (/ c d))))
         (if (<= c 9.4e-54)
           (/ (+ (* b d) (* c a)) (+ (* d d) (* c c)))
           (if (<= c 1.85e+56) (+ (/ b d) (* (/ c d) (/ a d))) t_0)))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a / c) + (1.0 / (c * ((c / b) / d)));
	double tmp;
	if (c <= -2.35e+98) {
		tmp = t_0;
	} else if (c <= -1.6e-9) {
		tmp = fma(a, c, (b * d)) * (1.0 / fma(c, c, (d * d)));
	} else if (c <= 5.2e-123) {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	} else if (c <= 9.4e-54) {
		tmp = ((b * d) + (c * a)) / ((d * d) + (c * c));
	} else if (c <= 1.85e+56) {
		tmp = (b / d) + ((c / d) * (a / d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(a / c) + Float64(1.0 / Float64(c * Float64(Float64(c / b) / d))))
	tmp = 0.0
	if (c <= -2.35e+98)
		tmp = t_0;
	elseif (c <= -1.6e-9)
		tmp = Float64(fma(a, c, Float64(b * d)) * Float64(1.0 / fma(c, c, Float64(d * d))));
	elseif (c <= 5.2e-123)
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	elseif (c <= 9.4e-54)
		tmp = Float64(Float64(Float64(b * d) + Float64(c * a)) / Float64(Float64(d * d) + Float64(c * c)));
	elseif (c <= 1.85e+56)
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) * Float64(a / d)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(c * N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.35e+98], t$95$0, If[LessEqual[c, -1.6e-9], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.2e-123], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 9.4e-54], N[(N[(N[(b * d), $MachinePrecision] + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.85e+56], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -1.6 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

\mathbf{elif}\;c \leq 5.2 \cdot 10^{-123}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -2.34999999999999985e98 or 1.84999999999999998e56 < c

    1. Initial program 35.1%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{{\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)}} \]
      5. associate-/l/72.7%

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

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

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

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

        \[\leadsto \frac{a}{c} + {\left(\frac{c}{d} \cdot \frac{c}{b}\right)}^{\color{blue}{-0.5}} \cdot {\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)} \]
      10. associate-/l/73.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c \cdot \frac{c}{b}}{d}}} \]
      5. *-lft-identity85.8%

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c}{1} \cdot \frac{\frac{c}{b}}{d}}} \]
      7. /-rgt-identity88.7%

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{c} \cdot \frac{\frac{c}{b}}{d}} \]
    8. Simplified88.7%

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

    if -2.34999999999999985e98 < c < -1.60000000000000006e-9

    1. Initial program 72.3%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. div-inv72.4%

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

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

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

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

    if -1.60000000000000006e-9 < c < 5.1999999999999999e-123

    1. Initial program 69.3%

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{\frac{c}{d}}}} \]
      2. *-rgt-identity94.1%

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

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

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

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

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

        \[\leadsto \frac{a}{\frac{d}{c}} \cdot \frac{1}{d} + \color{blue}{b \cdot \frac{1}{d}} \]
      3. distribute-rgt-out96.4%

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

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

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

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

    if 5.1999999999999999e-123 < c < 9.4e-54

    1. Initial program 80.6%

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

    if 9.4e-54 < c < 1.84999999999999998e56

    1. Initial program 53.6%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.35 \cdot 10^{+98}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\ \mathbf{elif}\;c \leq -1.6 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{-123}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 9.4 \cdot 10^{-54}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;c \leq 1.85 \cdot 10^{+56}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\ \end{array} \]

Alternative 2: 80.1% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;c \leq -1.6 \cdot 10^{-9}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;c \leq 1.5 \cdot 10^{-122}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\

\mathbf{elif}\;c \leq 4.3 \cdot 10^{-44}:\\
\;\;\;\;t_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -3.20000000000000016e97 or 1.5e59 < c

    1. Initial program 35.1%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{{\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)}} \]
      5. associate-/l/72.7%

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

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

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

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

        \[\leadsto \frac{a}{c} + {\left(\frac{c}{d} \cdot \frac{c}{b}\right)}^{\color{blue}{-0.5}} \cdot {\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)} \]
      10. associate-/l/73.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c \cdot \frac{c}{b}}{d}}} \]
      5. *-lft-identity85.8%

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c}{1} \cdot \frac{\frac{c}{b}}{d}}} \]
      7. /-rgt-identity88.7%

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{c} \cdot \frac{\frac{c}{b}}{d}} \]
    8. Simplified88.7%

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

    if -3.20000000000000016e97 < c < -1.60000000000000006e-9 or 1.50000000000000002e-122 < c < 4.30000000000000013e-44

    1. Initial program 75.3%

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

    if -1.60000000000000006e-9 < c < 1.50000000000000002e-122

    1. Initial program 69.3%

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{a}{\color{blue}{\frac{d}{\frac{c}{d}}}} \]
      2. *-rgt-identity94.1%

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

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

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

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

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

        \[\leadsto \frac{a}{\frac{d}{c}} \cdot \frac{1}{d} + \color{blue}{b \cdot \frac{1}{d}} \]
      3. distribute-rgt-out96.4%

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

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

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

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

    if 4.30000000000000013e-44 < c < 1.5e59

    1. Initial program 53.6%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{+97}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\ \mathbf{elif}\;c \leq -1.6 \cdot 10^{-9}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{-122}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{-44}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+59}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\ \end{array} \]

Alternative 3: 76.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.05 \cdot 10^{+88} \lor \neg \left(c \leq 10^{+57}\right):\\ \;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -2.05e+88) (not (<= c 1e+57)))
   (+ (/ a c) (/ 1.0 (* c (/ (/ c b) d))))
   (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.05e+88) || !(c <= 1e+57)) {
		tmp = (a / c) + (1.0 / (c * ((c / b) / d)));
	} else {
		tmp = (1.0 / d) * (b + (a * (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 ((c <= (-2.05d+88)) .or. (.not. (c <= 1d+57))) then
        tmp = (a / c) + (1.0d0 / (c * ((c / b) / d)))
    else
        tmp = (1.0d0 / d) * (b + (a * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.05e+88) || !(c <= 1e+57)) {
		tmp = (a / c) + (1.0 / (c * ((c / b) / d)));
	} else {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -2.05e+88) or not (c <= 1e+57):
		tmp = (a / c) + (1.0 / (c * ((c / b) / d)))
	else:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -2.05e+88) || !(c <= 1e+57))
		tmp = Float64(Float64(a / c) + Float64(1.0 / Float64(c * Float64(Float64(c / b) / d))));
	else
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -2.05e+88) || ~((c <= 1e+57)))
		tmp = (a / c) + (1.0 / (c * ((c / b) / d)));
	else
		tmp = (1.0 / d) * (b + (a * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.05e+88], N[Not[LessEqual[c, 1e+57]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(1.0 / N[(c * N[(N[(c / b), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.05 \cdot 10^{+88} \lor \neg \left(c \leq 10^{+57}\right):\\
\;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.05000000000000014e88 or 1.00000000000000005e57 < c

    1. Initial program 38.1%

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{1}{\frac{\frac{c \cdot c}{d}}{b}}} \]
      2. inv-pow78.1%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{{\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)}} \]
      5. associate-/l/69.3%

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

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

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

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

        \[\leadsto \frac{a}{c} + {\left(\frac{c}{d} \cdot \frac{c}{b}\right)}^{\color{blue}{-0.5}} \cdot {\left(\frac{\frac{c \cdot c}{d}}{b}\right)}^{\left(\frac{-1}{2}\right)} \]
      10. associate-/l/70.1%

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

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

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

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

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

      \[\leadsto \frac{a}{c} + \color{blue}{{\left(\frac{c}{d} \cdot \frac{c}{b}\right)}^{-0.5} \cdot {\left(\frac{c}{d} \cdot \frac{c}{b}\right)}^{-0.5}} \]
    7. Step-by-step derivation
      1. pow-sqr85.6%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c \cdot \frac{c}{b}}{d}}} \]
      5. *-lft-identity84.7%

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

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{\frac{c}{1} \cdot \frac{\frac{c}{b}}{d}}} \]
      7. /-rgt-identity87.4%

        \[\leadsto \frac{a}{c} + \frac{1}{\color{blue}{c} \cdot \frac{\frac{c}{b}}{d}} \]
    8. Simplified87.4%

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

    if -2.05000000000000014e88 < c < 1.00000000000000005e57

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.05 \cdot 10^{+88} \lor \neg \left(c \leq 10^{+57}\right):\\ \;\;\;\;\frac{a}{c} + \frac{1}{c \cdot \frac{\frac{c}{b}}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \]

Alternative 4: 72.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.6 \cdot 10^{+90} \lor \neg \left(c \leq 3.3 \cdot 10^{+56}\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -2.6e+90) (not (<= c 3.3e+56)))
   (/ a c)
   (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.6e+90) || !(c <= 3.3e+56)) {
		tmp = a / c;
	} else {
		tmp = (1.0 / d) * (b + (a * (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 ((c <= (-2.6d+90)) .or. (.not. (c <= 3.3d+56))) then
        tmp = a / c
    else
        tmp = (1.0d0 / d) * (b + (a * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.6e+90) || !(c <= 3.3e+56)) {
		tmp = a / c;
	} else {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -2.6e+90) or not (c <= 3.3e+56):
		tmp = a / c
	else:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -2.6e+90) || !(c <= 3.3e+56))
		tmp = Float64(a / c);
	else
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -2.6e+90) || ~((c <= 3.3e+56)))
		tmp = a / c;
	else
		tmp = (1.0 / d) * (b + (a * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.6e+90], N[Not[LessEqual[c, 3.3e+56]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.6 \cdot 10^{+90} \lor \neg \left(c \leq 3.3 \cdot 10^{+56}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.5999999999999998e90 or 3.30000000000000002e56 < c

    1. Initial program 38.1%

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

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

    if -2.5999999999999998e90 < c < 3.30000000000000002e56

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.6 \cdot 10^{+90} \lor \neg \left(c \leq 3.3 \cdot 10^{+56}\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \]

Alternative 5: 76.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -6.5 \cdot 10^{+88} \lor \neg \left(c \leq 2.5 \cdot 10^{+57}\right):\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -6.5e+88) (not (<= c 2.5e+57)))
   (+ (/ a c) (* (/ d c) (/ b c)))
   (* (/ 1.0 d) (+ b (* a (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -6.5e+88) || !(c <= 2.5e+57)) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else {
		tmp = (1.0 / d) * (b + (a * (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 ((c <= (-6.5d+88)) .or. (.not. (c <= 2.5d+57))) then
        tmp = (a / c) + ((d / c) * (b / c))
    else
        tmp = (1.0d0 / d) * (b + (a * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -6.5e+88) || !(c <= 2.5e+57)) {
		tmp = (a / c) + ((d / c) * (b / c));
	} else {
		tmp = (1.0 / d) * (b + (a * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -6.5e+88) or not (c <= 2.5e+57):
		tmp = (a / c) + ((d / c) * (b / c))
	else:
		tmp = (1.0 / d) * (b + (a * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -6.5e+88) || !(c <= 2.5e+57))
		tmp = Float64(Float64(a / c) + Float64(Float64(d / c) * Float64(b / c)));
	else
		tmp = Float64(Float64(1.0 / d) * Float64(b + Float64(a * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -6.5e+88) || ~((c <= 2.5e+57)))
		tmp = (a / c) + ((d / c) * (b / c));
	else
		tmp = (1.0 / d) * (b + (a * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6.5e+88], N[Not[LessEqual[c, 2.5e+57]], $MachinePrecision]], N[(N[(a / c), $MachinePrecision] + N[(N[(d / c), $MachinePrecision] * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / d), $MachinePrecision] * N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.5 \cdot 10^{+88} \lor \neg \left(c \leq 2.5 \cdot 10^{+57}\right):\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -6.5000000000000002e88 or 2.49999999999999986e57 < c

    1. Initial program 38.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c} + \frac{\color{blue}{d \cdot b}}{c \cdot c} \]
      4. times-frac85.4%

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

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

    if -6.5000000000000002e88 < c < 2.49999999999999986e57

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.5 \cdot 10^{+88} \lor \neg \left(c \leq 2.5 \cdot 10^{+57}\right):\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \end{array} \]

Alternative 6: 73.1% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;c \leq 3 \cdot 10^{+56}:\\
\;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.79999999999999997e87

    1. Initial program 39.4%

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

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

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

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

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

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

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

    if -1.79999999999999997e87 < c < 3.00000000000000006e56

    1. Initial program 68.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.00000000000000006e56 < c

    1. Initial program 36.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.8 \cdot 10^{+87}:\\ \;\;\;\;\frac{a}{c} + d \cdot \frac{b}{c \cdot c}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{+56}:\\ \;\;\;\;\frac{1}{d} \cdot \left(b + a \cdot \frac{c}{d}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 7: 63.3% accurate, 2.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.6999999999999999e-9 or 4.4e19 < c

    1. Initial program 44.7%

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

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

    if -1.6999999999999999e-9 < c < 4.4e19

    1. Initial program 69.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.7 \cdot 10^{-9}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 4.4 \cdot 10^{+19}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 8: 42.7% 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 56.9%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification43.4%

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

Developer target: 99.3% accurate, 0.1× speedup?

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

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

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


\end{array}
\end{array}

Reproduce

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

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

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