Complex division, real part

Percentage Accurate: 62.0% → 84.7%
Time: 4.2s
Alternatives: 9
Speedup: 1.6×

Specification

?
\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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 9 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.0% 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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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: 84.7% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;d \leq -5.5 \cdot 10^{-162}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d \leq 5.2 \cdot 10^{+95}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.6999999999999999e98 or 5.19999999999999981e95 < d

    1. Initial program 34.5%

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

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

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

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

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      5. lower-/.f6485.3

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites85.3%

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

    if -3.6999999999999999e98 < d < -5.50000000000000006e-162 or 2.69999999999999984e-162 < d < 5.19999999999999981e95

    1. Initial program 77.8%

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

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

        \[\leadsto \frac{\color{blue}{a \cdot c + b \cdot d}}{c \cdot c + d \cdot d} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{a \cdot c} + b \cdot d}{c \cdot c + d \cdot d} \]
      4. lift-*.f64N/A

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. lift-*.f64N/A

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c} + d \cdot d} \]
      7. lift-*.f64N/A

        \[\leadsto \frac{a \cdot c + b \cdot d}{c \cdot c + \color{blue}{d \cdot d}} \]
      8. pow2N/A

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{{c}^{2}} + d \cdot d} \]
      9. pow2N/A

        \[\leadsto \frac{a \cdot c + b \cdot d}{{c}^{2} + \color{blue}{{d}^{2}}} \]
      10. div-add-revN/A

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

        \[\leadsto \color{blue}{a \cdot \frac{c}{{c}^{2} + {d}^{2}}} + \frac{b \cdot d}{{c}^{2} + {d}^{2}} \]
      12. lower-fma.f64N/A

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

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\color{blue}{{d}^{2} + {c}^{2}}}, \frac{b \cdot d}{{c}^{2} + {d}^{2}}\right) \]
      15. pow2N/A

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\color{blue}{\mathsf{fma}\left(d, d, {c}^{2}\right)}}, \frac{b \cdot d}{{c}^{2} + {d}^{2}}\right) \]
      17. pow2N/A

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)}, \frac{b \cdot d}{{c}^{2} + {d}^{2}}\right) \]
      18. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, \color{blue}{b \cdot \frac{d}{{c}^{2} + {d}^{2}}}\right) \]
      20. lower-*.f64N/A

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

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

    if -5.50000000000000006e-162 < d < 2.69999999999999984e-162

    1. Initial program 58.8%

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

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

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

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

        \[\leadsto \frac{b \cdot \frac{d}{c} + a}{c} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
      5. lower-/.f6491.4

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
    5. Applied rewrites91.4%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 82.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -2.35 \cdot 10^{+81}:\\ \;\;\;\;\mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -3.6 \cdot 10^{-91}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{-91}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 6.5 \cdot 10^{+53}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))))
   (if (<= d -2.35e+81)
     (fma (/ a d) (/ c d) (/ b d))
     (if (<= d -3.6e-91)
       t_0
       (if (<= d 1.25e-91)
         (/ (fma b (/ d c) a) c)
         (if (<= d 6.5e+53) t_0 (/ (fma a (/ c d) b) d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((a * c) + (b * d)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -2.35e+81) {
		tmp = fma((a / d), (c / d), (b / d));
	} else if (d <= -3.6e-91) {
		tmp = t_0;
	} else if (d <= 1.25e-91) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 6.5e+53) {
		tmp = t_0;
	} else {
		tmp = fma(a, (c / d), b) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -2.35e+81)
		tmp = fma(Float64(a / d), Float64(c / d), Float64(b / d));
	elseif (d <= -3.6e-91)
		tmp = t_0;
	elseif (d <= 1.25e-91)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 6.5e+53)
		tmp = t_0;
	else
		tmp = Float64(fma(a, Float64(c / d), b) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.35e+81], N[(N[(a / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.6e-91], t$95$0, If[LessEqual[d, 1.25e-91], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 6.5e+53], t$95$0, N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -3.6 \cdot 10^{-91}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 6.5 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 27.2%

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

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

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

        \[\leadsto \frac{a \cdot c}{d \cdot d} + \frac{b}{d} \]
      3. times-fracN/A

        \[\leadsto \frac{a}{d} \cdot \frac{c}{d} + \frac{\color{blue}{b}}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{a}{d}, \color{blue}{\frac{c}{d}}, \frac{b}{d}\right) \]
      5. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{a}{d}, \frac{\color{blue}{c}}{d}, \frac{b}{d}\right) \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{a}{d}, \frac{c}{\color{blue}{d}}, \frac{b}{d}\right) \]
      7. lower-/.f6488.5

        \[\leadsto \mathsf{fma}\left(\frac{a}{d}, \frac{c}{d}, \frac{b}{d}\right) \]
    5. Applied rewrites88.5%

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

    if -2.3500000000000001e81 < d < -3.6e-91 or 1.24999999999999999e-91 < d < 6.50000000000000017e53

    1. Initial program 86.1%

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

    if -3.6e-91 < d < 1.24999999999999999e-91

    1. Initial program 63.8%

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

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

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

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

        \[\leadsto \frac{b \cdot \frac{d}{c} + a}{c} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
      5. lower-/.f6486.6

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
    5. Applied rewrites86.6%

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

    if 6.50000000000000017e53 < d

    1. Initial program 45.0%

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

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

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

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

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      5. lower-/.f6475.3

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites75.3%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 3: 82.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -3.6 \cdot 10^{-91}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 6.5 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.05000000000000009e84 or 6.50000000000000017e53 < d

    1. Initial program 35.5%

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

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

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

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

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      5. lower-/.f6481.7

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites81.7%

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

    if -1.05000000000000009e84 < d < -3.6e-91 or 1.24999999999999999e-91 < d < 6.50000000000000017e53

    1. Initial program 86.3%

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

    if -3.6e-91 < d < 1.24999999999999999e-91

    1. Initial program 63.8%

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

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

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

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

        \[\leadsto \frac{b \cdot \frac{d}{c} + a}{c} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
      5. lower-/.f6486.6

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
    5. Applied rewrites86.6%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 65.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.32 \cdot 10^{+98}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -9.8 \cdot 10^{-101}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-84}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{+152}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.32e+98)
   (/ b d)
   (if (<= d -9.8e-101)
     (* b (/ d (fma d d (* c c))))
     (if (<= d 1.2e-84)
       (/ a c)
       (if (<= d 4.1e+152) (/ (fma b d (* c a)) (* d d)) (/ b d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.32e+98) {
		tmp = b / d;
	} else if (d <= -9.8e-101) {
		tmp = b * (d / fma(d, d, (c * c)));
	} else if (d <= 1.2e-84) {
		tmp = a / c;
	} else if (d <= 4.1e+152) {
		tmp = fma(b, d, (c * a)) / (d * d);
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.32e+98)
		tmp = Float64(b / d);
	elseif (d <= -9.8e-101)
		tmp = Float64(b * Float64(d / fma(d, d, Float64(c * c))));
	elseif (d <= 1.2e-84)
		tmp = Float64(a / c);
	elseif (d <= 4.1e+152)
		tmp = Float64(fma(b, d, Float64(c * a)) / Float64(d * d));
	else
		tmp = Float64(b / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.32e+98], N[(b / d), $MachinePrecision], If[LessEqual[d, -9.8e-101], N[(b * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.2e-84], N[(a / c), $MachinePrecision], If[LessEqual[d, 4.1e+152], N[(N[(b * d + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq 1.2 \cdot 10^{-84}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;d \leq 4.1 \cdot 10^{+152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.3200000000000001e98 or 4.0999999999999998e152 < d

    1. Initial program 28.3%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    4. Step-by-step derivation
      1. lower-/.f6476.7

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    5. Applied rewrites76.7%

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

    if -1.3200000000000001e98 < d < -9.8000000000000001e-101

    1. Initial program 80.5%

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

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

        \[\leadsto b \cdot \color{blue}{\frac{d}{{c}^{2} + {d}^{2}}} \]
      2. lower-*.f64N/A

        \[\leadsto b \cdot \color{blue}{\frac{d}{{c}^{2} + {d}^{2}}} \]
      3. lower-/.f64N/A

        \[\leadsto b \cdot \frac{d}{\color{blue}{{c}^{2} + {d}^{2}}} \]
      4. +-commutativeN/A

        \[\leadsto b \cdot \frac{d}{{d}^{2} + \color{blue}{{c}^{2}}} \]
      5. pow2N/A

        \[\leadsto b \cdot \frac{d}{d \cdot d + {\color{blue}{c}}^{2}} \]
      6. lower-fma.f64N/A

        \[\leadsto b \cdot \frac{d}{\mathsf{fma}\left(d, \color{blue}{d}, {c}^{2}\right)} \]
      7. pow2N/A

        \[\leadsto b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \]
      8. lift-*.f6460.1

        \[\leadsto b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)} \]
    5. Applied rewrites60.1%

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

    if -9.8000000000000001e-101 < d < 1.20000000000000009e-84

    1. Initial program 63.7%

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6470.7

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    5. Applied rewrites70.7%

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

    if 1.20000000000000009e-84 < d < 4.0999999999999998e152

    1. Initial program 73.8%

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

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

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

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

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      5. lower-/.f6456.7

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites56.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}} \]
    6. Taylor expanded in d around 0

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

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

        \[\leadsto \frac{b \cdot d + a \cdot c}{{d}^{2}} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{{d}^{2}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{{d}^{2}} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{{d}^{2}} \]
      6. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d} \]
      7. lift-*.f6454.2

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d} \]
    8. Applied rewrites54.2%

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

Alternative 5: 64.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -9 \cdot 10^{-12}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-84}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{+152}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -9e-12)
   (/ b d)
   (if (<= d 1.2e-84)
     (/ a c)
     (if (<= d 4.1e+152) (/ (fma b d (* c a)) (* d d)) (/ b d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -9e-12) {
		tmp = b / d;
	} else if (d <= 1.2e-84) {
		tmp = a / c;
	} else if (d <= 4.1e+152) {
		tmp = fma(b, d, (c * a)) / (d * d);
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -9e-12)
		tmp = Float64(b / d);
	elseif (d <= 1.2e-84)
		tmp = Float64(a / c);
	elseif (d <= 4.1e+152)
		tmp = Float64(fma(b, d, Float64(c * a)) / Float64(d * d));
	else
		tmp = Float64(b / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -9e-12], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.2e-84], N[(a / c), $MachinePrecision], If[LessEqual[d, 4.1e+152], N[(N[(b * d + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{-12}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq 1.2 \cdot 10^{-84}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;d \leq 4.1 \cdot 10^{+152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -8.99999999999999962e-12 or 4.0999999999999998e152 < d

    1. Initial program 39.0%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    4. Step-by-step derivation
      1. lower-/.f6472.0

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    5. Applied rewrites72.0%

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

    if -8.99999999999999962e-12 < d < 1.20000000000000009e-84

    1. Initial program 66.2%

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6466.4

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    5. Applied rewrites66.4%

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

    if 1.20000000000000009e-84 < d < 4.0999999999999998e152

    1. Initial program 73.8%

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

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

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

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

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      5. lower-/.f6456.7

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites56.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}} \]
    6. Taylor expanded in d around 0

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

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

        \[\leadsto \frac{b \cdot d + a \cdot c}{{d}^{2}} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{{d}^{2}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{{d}^{2}} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{{d}^{2}} \]
      6. pow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d} \]
      7. lift-*.f6454.2

        \[\leadsto \frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d} \]
    8. Applied rewrites54.2%

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

Alternative 6: 76.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{-12} \lor \neg \left(d \leq 1.55 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.0000000000000001e-12 or 1.55000000000000001e84 < d

    1. Initial program 42.8%

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

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

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

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

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      5. lower-/.f6481.8

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites81.8%

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

    if -7.0000000000000001e-12 < d < 1.55000000000000001e84

    1. Initial program 69.1%

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

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

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

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

        \[\leadsto \frac{b \cdot \frac{d}{c} + a}{c} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
      5. lower-/.f6478.0

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c} \]
    5. Applied rewrites78.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.6%

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

Alternative 7: 72.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.8 \cdot 10^{+114} \lor \neg \left(c \leq 2.5 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.8000000000000001e114 or 2.5e84 < c

    1. Initial program 36.8%

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6470.3

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    5. Applied rewrites70.3%

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

    if -5.8000000000000001e114 < c < 2.5e84

    1. Initial program 68.0%

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

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

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

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

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      5. lower-/.f6472.8

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites72.8%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.0%

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

Alternative 8: 63.2% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -9 \cdot 10^{-12} \lor \neg \left(d \leq 3.1 \cdot 10^{+28}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -9e-12) (not (<= d 3.1e+28))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -9e-12) || !(d <= 3.1e+28)) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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 <= (-9d-12)) .or. (.not. (d <= 3.1d+28))) 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 <= -9e-12) || !(d <= 3.1e+28)) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -9e-12) or not (d <= 3.1e+28):
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -9e-12) || !(d <= 3.1e+28))
		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 <= -9e-12) || ~((d <= 3.1e+28)))
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -9e-12], N[Not[LessEqual[d, 3.1e+28]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -9 \cdot 10^{-12} \lor \neg \left(d \leq 3.1 \cdot 10^{+28}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8.99999999999999962e-12 or 3.1000000000000001e28 < d

    1. Initial program 44.2%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    4. Step-by-step derivation
      1. lower-/.f6466.2

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    5. Applied rewrites66.2%

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

    if -8.99999999999999962e-12 < d < 3.1000000000000001e28

    1. Initial program 69.4%

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6463.4

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    5. Applied rewrites63.4%

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

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

Alternative 9: 42.3% accurate, 3.2× 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;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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 57.8%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Step-by-step derivation
    1. lower-/.f6440.8

      \[\leadsto \frac{a}{\color{blue}{c}} \]
  5. Applied rewrites40.8%

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

Developer Target 1: 99.3% accurate, 0.6× 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;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    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 2025061 
(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))))