Complex division, real part

Percentage Accurate: 62.7% → 90.3%
Time: 10.9s
Alternatives: 13
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

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

Initial Program: 62.7% 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: 90.3% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3.3 \cdot 10^{-158} \lor \neg \left(d \leq 5 \cdot 10^{-101}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -3.3e-158) (not (<= d 5e-101)))
   (* (/ (fma a (/ c d) b) (hypot c d)) (/ d (hypot c d)))
   (/ (+ a (* b (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -3.3e-158) || !(d <= 5e-101)) {
		tmp = (fma(a, (c / d), b) / hypot(c, d)) * (d / hypot(c, d));
	} else {
		tmp = (a + (b * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -3.3e-158) || !(d <= 5e-101))
		tmp = Float64(Float64(fma(a, Float64(c / d), b) / hypot(c, d)) * Float64(d / hypot(c, d)));
	else
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.3e-158], N[Not[LessEqual[d, 5e-101]], $MachinePrecision]], N[(N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.3 \cdot 10^{-158} \lor \neg \left(d \leq 5 \cdot 10^{-101}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.3000000000000002e-158 or 5.0000000000000001e-101 < d

    1. Initial program 64.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(b + a \cdot \frac{c}{d}\right) \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      5. hypot-undefine61.2%

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

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

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

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

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

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

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

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

    if -3.3000000000000002e-158 < d < 5.0000000000000001e-101

    1. Initial program 71.1%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity71.1%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.8% accurate, 0.0× speedup?

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

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

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


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

    1. Initial program 83.1%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified83.2%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity83.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      9. hypot-define96.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)}} \]
    6. Applied egg-rr96.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)}} \]

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

    1. Initial program 13.4%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity13.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -4.7 \cdot 10^{+79}:\\ \;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\ \mathbf{elif}\;d \leq -3.05 \cdot 10^{-158}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-31}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + a \cdot \left(\frac{c}{d} \cdot \frac{1}{d}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -4.7e+79)
   (/ (+ b (- (* a (/ c d)) (* b (pow (/ c d) 2.0)))) d)
   (if (<= d -3.05e-158)
     (/ (fma a c (* d b)) (fma c c (* d d)))
     (if (<= d 1.4e-31)
       (/ (+ a (* b (/ d c))) c)
       (+ (/ b d) (* a (* (/ c d) (/ 1.0 d))))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -4.7e+79) {
		tmp = (b + ((a * (c / d)) - (b * pow((c / d), 2.0)))) / d;
	} else if (d <= -3.05e-158) {
		tmp = fma(a, c, (d * b)) / fma(c, c, (d * d));
	} else if (d <= 1.4e-31) {
		tmp = (a + (b * (d / c))) / c;
	} else {
		tmp = (b / d) + (a * ((c / d) * (1.0 / d)));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -4.7e+79)
		tmp = Float64(Float64(b + Float64(Float64(a * Float64(c / d)) - Float64(b * (Float64(c / d) ^ 2.0)))) / d);
	elseif (d <= -3.05e-158)
		tmp = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d)));
	elseif (d <= 1.4e-31)
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	else
		tmp = Float64(Float64(b / d) + Float64(a * Float64(Float64(c / d) * Float64(1.0 / d))));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.7e+79], N[(N[(b + N[(N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision] - N[(b * N[Power[N[(c / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -3.05e-158], N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.4e-31], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b / d), $MachinePrecision] + N[(a * N[(N[(c / d), $MachinePrecision] * N[(1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.7 \cdot 10^{+79}:\\
\;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -4.70000000000000023e79

    1. Initial program 48.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define48.5%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified48.5%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity48.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.70000000000000023e79 < d < -3.0499999999999999e-158

    1. Initial program 89.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define89.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified89.9%

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

    if -3.0499999999999999e-158 < d < 1.3999999999999999e-31

    1. Initial program 71.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define71.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified71.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity71.9%

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

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

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

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

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

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

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

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

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

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

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

    if 1.3999999999999999e-31 < d

    1. Initial program 55.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define55.7%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified55.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.7 \cdot 10^{+79}:\\ \;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\ \mathbf{elif}\;d \leq -3.05 \cdot 10^{-158}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-31}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + a \cdot \left(\frac{c}{d} \cdot \frac{1}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 79.7% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{+75}:\\
\;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.69999999999999998e75

    1. Initial program 48.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define48.5%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified48.5%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity48.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.69999999999999998e75 < d < -1.44999999999999994e-157

    1. Initial program 89.8%

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

    if -1.44999999999999994e-157 < d < 6.49999999999999988e-32

    1. Initial program 71.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define71.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified71.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity71.9%

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

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

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

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

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

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

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

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

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

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

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

    if 6.49999999999999988e-32 < d

    1. Initial program 55.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define55.7%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified55.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{+75}:\\ \;\;\;\;\frac{b + \left(a \cdot \frac{c}{d} - b \cdot {\left(\frac{c}{d}\right)}^{2}\right)}{d}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-157}:\\ \;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{-32}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + a \cdot \left(\frac{c}{d} \cdot \frac{1}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 79.9% accurate, 0.5× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -4.4999999999999997e76

    1. Initial program 48.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define48.5%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified48.5%

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

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

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

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

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

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

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

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

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

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

    if -4.4999999999999997e76 < d < -4.99999999999999972e-158

    1. Initial program 89.8%

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

    if -4.99999999999999972e-158 < d < 6.79999999999999956e-32

    1. Initial program 71.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define71.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified71.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity71.9%

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

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

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

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

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

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

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

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

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

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

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

    if 6.79999999999999956e-32 < d

    1. Initial program 55.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define55.7%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified55.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.5 \cdot 10^{+76}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-158}:\\ \;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.8 \cdot 10^{-32}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + a \cdot \left(\frac{c}{d} \cdot \frac{1}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 76.2% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.3500000000000001e-68

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.3500000000000001e-68 < d < 1.04999999999999996e-31

    1. Initial program 73.2%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified73.2%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity73.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.04999999999999996e-31 < d

    1. Initial program 55.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define55.7%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified55.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.35 \cdot 10^{-68}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-31}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + a \cdot \left(\frac{c}{d} \cdot \frac{1}{d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 77.2% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.2999999999999999e-68

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.2999999999999999e-68 < d < 1.3999999999999999e-31

    1. Initial program 73.2%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified73.2%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity73.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.3999999999999999e-31 < d

    1. Initial program 55.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define55.7%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified55.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{1 \cdot \frac{c}{d}}{d}} \cdot a \]
      3. *-un-lft-identity86.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{-68}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{a}{d}}{\frac{d}{c}}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{-31}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 77.4% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.3500000000000001e-68

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.3500000000000001e-68 < d < 1e-31

    1. Initial program 73.2%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified73.2%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity73.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1e-31 < d

    1. Initial program 55.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define55.7%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified55.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{1 \cdot \frac{c}{d}}{d}} \cdot a \]
      3. *-un-lft-identity86.3%

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

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

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

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

Alternative 9: 77.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.2 \cdot 10^{-68} \lor \neg \left(d \leq 1.2 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.19999999999999996e-68 or 1.2e-31 < d

    1. Initial program 60.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define60.8%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified60.8%

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

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

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

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

    if -1.19999999999999996e-68 < d < 1.2e-31

    1. Initial program 73.2%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified73.2%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity73.2%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 70.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.3 \cdot 10^{-68} \lor \neg \left(d \leq 7.4 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.2999999999999999e-68 or 7.3999999999999996e-31 < d

    1. Initial program 60.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define60.5%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified60.5%

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

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

    if -1.2999999999999999e-68 < d < 7.3999999999999996e-31

    1. Initial program 73.4%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity73.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 77.4% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.3500000000000001e-68

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.3500000000000001e-68 < d < 1.2599999999999999e-31

    1. Initial program 73.2%

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified73.2%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity73.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.2599999999999999e-31 < d

    1. Initial program 55.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define55.7%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified55.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.35 \cdot 10^{-68}:\\ \;\;\;\;\frac{b + c \cdot \frac{a}{d}}{d}\\ \mathbf{elif}\;d \leq 1.26 \cdot 10^{-31}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 62.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.35 \cdot 10^{-68} \lor \neg \left(d \leq 4.5 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.3500000000000001e-68 or 4.5000000000000004e-31 < d

    1. Initial program 60.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-define60.5%

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    3. Simplified60.5%

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

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

    if -1.3500000000000001e-68 < d < 4.5000000000000004e-31

    1. Initial program 73.4%

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

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

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

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

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

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

Alternative 13: 41.6% 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 66.2%

    \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
  2. Step-by-step derivation
    1. fma-define66.3%

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

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

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

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

Developer Target 1: 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 2024125 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

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

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