Complex division, real part

Percentage Accurate: 61.1% → 83.7%
Time: 8.6s
Alternatives: 12
Speedup: 1.3×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 alternatives:

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

Initial Program: 61.1% 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: 83.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ \mathbf{if}\;c \leq -3.2 \cdot 10^{+101}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(d \cdot \left(-\frac{b}{c}\right) - a\right)\\ \mathbf{elif}\;c \leq -1.75 \cdot 10^{-143}:\\ \;\;\;\;\frac{b}{\frac{t_0}{d}} + \frac{a}{\frac{t_0}{c}}\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{-161}:\\ \;\;\;\;\frac{d}{d} \cdot \frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{+138}:\\ \;\;\;\;\frac{b}{\frac{t_1}{d}} + c \cdot \frac{a}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d))) (t_1 (fma d d (* c c))))
   (if (<= c -3.2e+101)
     (* (/ -1.0 c) (- (* d (- (/ b c))) a))
     (if (<= c -1.75e-143)
       (+ (/ b (/ t_0 d)) (/ a (/ t_0 c)))
       (if (<= c 5.8e-161)
         (* (/ d d) (/ (+ b (* c (/ a d))) d))
         (if (<= c 3.9e+138)
           (+ (/ b (/ t_1 d)) (* c (/ a t_1)))
           (+ (/ a c) (* (/ b c) (/ d c)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = fma(d, d, (c * c));
	double tmp;
	if (c <= -3.2e+101) {
		tmp = (-1.0 / c) * ((d * -(b / c)) - a);
	} else if (c <= -1.75e-143) {
		tmp = (b / (t_0 / d)) + (a / (t_0 / c));
	} else if (c <= 5.8e-161) {
		tmp = (d / d) * ((b + (c * (a / d))) / d);
	} else if (c <= 3.9e+138) {
		tmp = (b / (t_1 / d)) + (c * (a / t_1));
	} else {
		tmp = (a / c) + ((b / c) * (d / c));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	t_1 = fma(d, d, Float64(c * c))
	tmp = 0.0
	if (c <= -3.2e+101)
		tmp = Float64(Float64(-1.0 / c) * Float64(Float64(d * Float64(-Float64(b / c))) - a));
	elseif (c <= -1.75e-143)
		tmp = Float64(Float64(b / Float64(t_0 / d)) + Float64(a / Float64(t_0 / c)));
	elseif (c <= 5.8e-161)
		tmp = Float64(Float64(d / d) * Float64(Float64(b + Float64(c * Float64(a / d))) / d));
	elseif (c <= 3.9e+138)
		tmp = Float64(Float64(b / Float64(t_1 / d)) + Float64(c * Float64(a / t_1)));
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(b / c) * Float64(d / c)));
	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[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.2e+101], N[(N[(-1.0 / c), $MachinePrecision] * N[(N[(d * (-N[(b / c), $MachinePrecision])), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.75e-143], N[(N[(b / N[(t$95$0 / d), $MachinePrecision]), $MachinePrecision] + N[(a / N[(t$95$0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5.8e-161], N[(N[(d / d), $MachinePrecision] * N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.9e+138], N[(N[(b / N[(t$95$1 / d), $MachinePrecision]), $MachinePrecision] + N[(c * N[(a / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;c \leq 3.9 \cdot 10^{+138}:\\
\;\;\;\;\frac{b}{\frac{t_1}{d}} + c \cdot \frac{a}{t_1}\\

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


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

    1. Initial program 25.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(-1 \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\right) \]
    8. Step-by-step derivation
      1. associate-/r/86.2%

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

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

    if -3.20000000000000005e101 < c < -1.75000000000000003e-143

    1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{\frac{c \cdot c + d \cdot d}{d}} + \frac{a}{\frac{c \cdot c + \color{blue}{d \cdot d}}{c}} \]
    6. Simplified88.0%

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

    if -1.75000000000000003e-143 < c < 5.8e-161

    1. Initial program 68.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.8e-161 < c < 3.8999999999999998e138

    1. Initial program 72.0%

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

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

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

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

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

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

        \[\leadsto \frac{b}{\frac{\color{blue}{\mathsf{fma}\left(d, d, {c}^{2}\right)}}{d}} + \frac{a \cdot c}{{c}^{2} + {d}^{2}} \]
      6. unpow277.4%

        \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)}{d}} + \frac{a \cdot c}{{c}^{2} + {d}^{2}} \]
      7. associate-/l*81.1%

        \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{d}} + \color{blue}{\frac{a}{\frac{{c}^{2} + {d}^{2}}{c}}} \]
      8. associate-/r/81.1%

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

        \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{d}} + \frac{a}{\color{blue}{{d}^{2} + {c}^{2}}} \cdot c \]
      10. unpow281.1%

        \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{d}} + \frac{a}{\color{blue}{d \cdot d} + {c}^{2}} \cdot c \]
      11. fma-def81.1%

        \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{d}} + \frac{a}{\color{blue}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \cdot c \]
      12. unpow281.1%

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

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

    if 3.8999999999999998e138 < c

    1. Initial program 23.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{+101}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(d \cdot \left(-\frac{b}{c}\right) - a\right)\\ \mathbf{elif}\;c \leq -1.75 \cdot 10^{-143}:\\ \;\;\;\;\frac{b}{\frac{c \cdot c + d \cdot d}{d}} + \frac{a}{\frac{c \cdot c + d \cdot d}{c}}\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{-161}:\\ \;\;\;\;\frac{d}{d} \cdot \frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{+138}:\\ \;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{d}} + c \cdot \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \end{array} \]

Alternative 2: 84.5% accurate, 0.0× speedup?

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

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

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


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

    1. Initial program 77.2%

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

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

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

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

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

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

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

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

    if 2.50000000000000017e245 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 18.3%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(-1 \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\right) \]
    8. Step-by-step derivation
      1. associate-/r/73.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2.5 \cdot 10^{+245}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(d \cdot \left(-\frac{b}{c}\right) - a\right)\\ \end{array} \]

Alternative 3: 84.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{b}{\frac{t_0}{d}} + \frac{a}{\frac{t_0}{c}}\\ \mathbf{if}\;c \leq -7.5 \cdot 10^{+103}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(d \cdot \left(-\frac{b}{c}\right) - a\right)\\ \mathbf{elif}\;c \leq -3.8 \cdot 10^{-143}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{-161}:\\ \;\;\;\;\frac{d}{d} \cdot \frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* c c) (* d d))) (t_1 (+ (/ b (/ t_0 d)) (/ a (/ t_0 c)))))
   (if (<= c -7.5e+103)
     (* (/ -1.0 c) (- (* d (- (/ b c))) a))
     (if (<= c -3.8e-143)
       t_1
       (if (<= c 5.5e-161)
         (* (/ d d) (/ (+ b (* c (/ a d))) d))
         (if (<= c 3.6e+138) t_1 (+ (/ a c) (* (/ b c) (/ d c)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = (b / (t_0 / d)) + (a / (t_0 / c));
	double tmp;
	if (c <= -7.5e+103) {
		tmp = (-1.0 / c) * ((d * -(b / c)) - a);
	} else if (c <= -3.8e-143) {
		tmp = t_1;
	} else if (c <= 5.5e-161) {
		tmp = (d / d) * ((b + (c * (a / d))) / d);
	} else if (c <= 3.6e+138) {
		tmp = t_1;
	} else {
		tmp = (a / c) + ((b / c) * (d / 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (c * c) + (d * d)
    t_1 = (b / (t_0 / d)) + (a / (t_0 / c))
    if (c <= (-7.5d+103)) then
        tmp = ((-1.0d0) / c) * ((d * -(b / c)) - a)
    else if (c <= (-3.8d-143)) then
        tmp = t_1
    else if (c <= 5.5d-161) then
        tmp = (d / d) * ((b + (c * (a / d))) / d)
    else if (c <= 3.6d+138) then
        tmp = t_1
    else
        tmp = (a / c) + ((b / c) * (d / c))
    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 = (b / (t_0 / d)) + (a / (t_0 / c));
	double tmp;
	if (c <= -7.5e+103) {
		tmp = (-1.0 / c) * ((d * -(b / c)) - a);
	} else if (c <= -3.8e-143) {
		tmp = t_1;
	} else if (c <= 5.5e-161) {
		tmp = (d / d) * ((b + (c * (a / d))) / d);
	} else if (c <= 3.6e+138) {
		tmp = t_1;
	} else {
		tmp = (a / c) + ((b / c) * (d / c));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (c * c) + (d * d)
	t_1 = (b / (t_0 / d)) + (a / (t_0 / c))
	tmp = 0
	if c <= -7.5e+103:
		tmp = (-1.0 / c) * ((d * -(b / c)) - a)
	elif c <= -3.8e-143:
		tmp = t_1
	elif c <= 5.5e-161:
		tmp = (d / d) * ((b + (c * (a / d))) / d)
	elif c <= 3.6e+138:
		tmp = t_1
	else:
		tmp = (a / c) + ((b / c) * (d / c))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(c * c) + Float64(d * d))
	t_1 = Float64(Float64(b / Float64(t_0 / d)) + Float64(a / Float64(t_0 / c)))
	tmp = 0.0
	if (c <= -7.5e+103)
		tmp = Float64(Float64(-1.0 / c) * Float64(Float64(d * Float64(-Float64(b / c))) - a));
	elseif (c <= -3.8e-143)
		tmp = t_1;
	elseif (c <= 5.5e-161)
		tmp = Float64(Float64(d / d) * Float64(Float64(b + Float64(c * Float64(a / d))) / d));
	elseif (c <= 3.6e+138)
		tmp = t_1;
	else
		tmp = Float64(Float64(a / c) + Float64(Float64(b / c) * Float64(d / c)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (c * c) + (d * d);
	t_1 = (b / (t_0 / d)) + (a / (t_0 / c));
	tmp = 0.0;
	if (c <= -7.5e+103)
		tmp = (-1.0 / c) * ((d * -(b / c)) - a);
	elseif (c <= -3.8e-143)
		tmp = t_1;
	elseif (c <= 5.5e-161)
		tmp = (d / d) * ((b + (c * (a / d))) / d);
	elseif (c <= 3.6e+138)
		tmp = t_1;
	else
		tmp = (a / c) + ((b / c) * (d / c));
	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[(b / N[(t$95$0 / d), $MachinePrecision]), $MachinePrecision] + N[(a / N[(t$95$0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -7.5e+103], N[(N[(-1.0 / c), $MachinePrecision] * N[(N[(d * (-N[(b / c), $MachinePrecision])), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -3.8e-143], t$95$1, If[LessEqual[c, 5.5e-161], N[(N[(d / d), $MachinePrecision] * N[(N[(b + N[(c * N[(a / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.6e+138], t$95$1, N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -3.8 \cdot 10^{-143}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;c \leq 3.6 \cdot 10^{+138}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 25.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(-1 \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\right) \]
    8. Step-by-step derivation
      1. associate-/r/86.2%

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

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

    if -7.49999999999999922e103 < c < -3.79999999999999981e-143 or 5.5e-161 < c < 3.6000000000000001e138

    1. Initial program 77.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.79999999999999981e-143 < c < 5.5e-161

    1. Initial program 68.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6000000000000001e138 < c

    1. Initial program 23.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+103}:\\ \;\;\;\;\frac{-1}{c} \cdot \left(d \cdot \left(-\frac{b}{c}\right) - a\right)\\ \mathbf{elif}\;c \leq -3.8 \cdot 10^{-143}:\\ \;\;\;\;\frac{b}{\frac{c \cdot c + d \cdot d}{d}} + \frac{a}{\frac{c \cdot c + d \cdot d}{c}}\\ \mathbf{elif}\;c \leq 5.5 \cdot 10^{-161}:\\ \;\;\;\;\frac{d}{d} \cdot \frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{+138}:\\ \;\;\;\;\frac{b}{\frac{c \cdot c + d \cdot d}{d}} + \frac{a}{\frac{c \cdot c + d \cdot d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \end{array} \]

Alternative 4: 75.9% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.00000000000000011e32

    1. Initial program 53.9%

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000011e32 < d < 4.79999999999999958e80

    1. Initial program 67.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{c}} \cdot \left(-1 \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\right) \]
    8. Step-by-step derivation
      1. associate-/r/80.6%

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

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

    if 4.79999999999999958e80 < d

    1. Initial program 33.4%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. unpow242.1%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c} + {d}^{2}}{d}} \]
      3. unpow242.1%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{d}}} \]
    5. Taylor expanded in c around 0 74.9%

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      2. *-lft-identity74.9%

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

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

        \[\leadsto \frac{b}{d + \color{blue}{c} \cdot \frac{c}{d}} \]
    7. Simplified85.0%

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

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

Alternative 5: 76.7% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.9999999999999999e31

    1. Initial program 53.9%

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

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

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

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

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

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

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

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

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

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

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

    if -1.9999999999999999e31 < d < 3.29999999999999991e80

    1. Initial program 67.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.29999999999999991e80 < d

    1. Initial program 33.4%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. unpow242.1%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c} + {d}^{2}}{d}} \]
      3. unpow242.1%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{d}}} \]
    5. Taylor expanded in c around 0 74.9%

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      2. *-lft-identity74.9%

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

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

        \[\leadsto \frac{b}{d + \color{blue}{c} \cdot \frac{c}{d}} \]
    7. Simplified85.0%

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

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

Alternative 6: 74.4% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -12000000000000 \lor \neg \left(d \leq 3.9 \cdot 10^{+80}\right):\\
\;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.2e13 or 3.89999999999999999e80 < d

    1. Initial program 48.2%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. unpow244.9%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c} + {d}^{2}}{d}} \]
      3. unpow244.9%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{d}}} \]
    5. Taylor expanded in c around 0 67.5%

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

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

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

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

        \[\leadsto \frac{b}{d + \color{blue}{c} \cdot \frac{c}{d}} \]
    7. Simplified74.0%

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

    if -1.2e13 < d < 3.89999999999999999e80

    1. Initial program 67.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 74.3% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.9999999999999997e32

    1. Initial program 53.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.9999999999999997e32 < d < 3.39999999999999992e80

    1. Initial program 67.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.39999999999999992e80 < d

    1. Initial program 33.4%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. unpow242.1%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c} + {d}^{2}}{d}} \]
      3. unpow242.1%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{d}}} \]
    5. Taylor expanded in c around 0 74.9%

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      2. *-lft-identity74.9%

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

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

        \[\leadsto \frac{b}{d + \color{blue}{c} \cdot \frac{c}{d}} \]
    7. Simplified85.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{+32}:\\ \;\;\;\;\frac{b}{d} + a \cdot \frac{\frac{c}{d}}{d}\\ \mathbf{elif}\;d \leq 3.4 \cdot 10^{+80}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Alternative 8: 75.3% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.49999999999999995e31

    1. Initial program 53.9%

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

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

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

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

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

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

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

    if -1.49999999999999995e31 < d < 7.79999999999999998e80

    1. Initial program 67.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.79999999999999998e80 < d

    1. Initial program 33.4%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. unpow242.1%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c} + {d}^{2}}{d}} \]
      3. unpow242.1%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{d}}} \]
    5. Taylor expanded in c around 0 74.9%

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      2. *-lft-identity74.9%

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

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

        \[\leadsto \frac{b}{d + \color{blue}{c} \cdot \frac{c}{d}} \]
    7. Simplified85.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{+31}:\\ \;\;\;\;\frac{b}{d} + \frac{a}{d} \cdot \frac{c}{d}\\ \mathbf{elif}\;d \leq 7.8 \cdot 10^{+80}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Alternative 9: 75.3% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.6e31

    1. Initial program 53.9%

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

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

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

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

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

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

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

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

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

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

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

    if -2.6e31 < d < 3.29999999999999991e80

    1. Initial program 67.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.29999999999999991e80 < d

    1. Initial program 33.4%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. unpow242.1%

        \[\leadsto \frac{b}{\frac{\color{blue}{c \cdot c} + {d}^{2}}{d}} \]
      3. unpow242.1%

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{d}}} \]
    5. Taylor expanded in c around 0 74.9%

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      2. *-lft-identity74.9%

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

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

        \[\leadsto \frac{b}{d + \color{blue}{c} \cdot \frac{c}{d}} \]
    7. Simplified85.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.6 \cdot 10^{+31}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+80}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\ \end{array} \]

Alternative 10: 64.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -8.6 \cdot 10^{+63}:\\
\;\;\;\;\frac{a}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -8.6000000000000001e63 or 7.99999999999999965e111 < a

    1. Initial program 47.7%

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

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

    if -8.6000000000000001e63 < a < 7.99999999999999965e111

    1. Initial program 66.7%

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

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

        \[\leadsto \color{blue}{\frac{b}{\frac{{c}^{2} + {d}^{2}}{d}}} \]
      2. unpow255.3%

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

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{d}}} \]
    5. Taylor expanded in c around 0 70.9%

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      2. *-lft-identity70.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -8.6 \cdot 10^{+63}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;a \leq 8 \cdot 10^{+111}:\\ \;\;\;\;\frac{b}{d + c \cdot \frac{c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 11: 63.1% accurate, 1.3× speedup?

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

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

\mathbf{elif}\;c \leq -1.75 \cdot 10^{-32} \lor \neg \left(c \leq -3.05 \cdot 10^{-64}\right) \land c \leq 900000000:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.9999999999999994e28 or -1.7499999999999999e-32 < c < -3.0499999999999998e-64 or 9e8 < c

    1. Initial program 45.8%

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

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

    if -8.9999999999999994e28 < c < -1.7499999999999999e-32 or -3.0499999999999998e-64 < c < 9e8

    1. Initial program 71.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -9 \cdot 10^{+28}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -1.75 \cdot 10^{-32} \lor \neg \left(c \leq -3.05 \cdot 10^{-64}\right) \land c \leq 900000000:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 12: 42.9% accurate, 5.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification45.9%

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