Complex division, real part

Percentage Accurate: 61.7% → 82.7%
Time: 3.6s
Alternatives: 10
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}

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 10 alternatives:

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

Initial Program: 61.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));
}
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: 82.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ t_1 := \mathsf{fma}\left(\frac{b}{c}, \frac{d}{c}, \frac{a}{c}\right)\\ \mathbf{if}\;c \leq -4.5 \cdot 10^{+128}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -7.4 \cdot 10^{-119}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{-150}:\\ \;\;\;\;-\frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(c, a, -\frac{\left(c \cdot c\right) \cdot b}{d}\right)}{d}, -1, -b\right)}{d}\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{+89}:\\ \;\;\;\;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 (/ b c) (/ d c) (/ a c))))
   (if (<= c -4.5e+128)
     t_1
     (if (<= c -7.4e-119)
       t_0
       (if (<= c 1.02e-150)
         (- (/ (fma (/ (fma c a (- (/ (* (* c c) b) d))) d) -1.0 (- b)) d))
         (if (<= c 4.2e+89) 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((b / c), (d / c), (a / c));
	double tmp;
	if (c <= -4.5e+128) {
		tmp = t_1;
	} else if (c <= -7.4e-119) {
		tmp = t_0;
	} else if (c <= 1.02e-150) {
		tmp = -(fma((fma(c, a, -(((c * c) * b) / d)) / d), -1.0, -b) / d);
	} else if (c <= 4.2e+89) {
		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 = fma(Float64(b / c), Float64(d / c), Float64(a / c))
	tmp = 0.0
	if (c <= -4.5e+128)
		tmp = t_1;
	elseif (c <= -7.4e-119)
		tmp = t_0;
	elseif (c <= 1.02e-150)
		tmp = Float64(-Float64(fma(Float64(fma(c, a, Float64(-Float64(Float64(Float64(c * c) * b) / d))) / d), -1.0, Float64(-b)) / d));
	elseif (c <= 4.2e+89)
		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[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.5e+128], t$95$1, If[LessEqual[c, -7.4e-119], t$95$0, If[LessEqual[c, 1.02e-150], (-N[(N[(N[(N[(c * a + (-N[(N[(N[(c * c), $MachinePrecision] * b), $MachinePrecision] / d), $MachinePrecision])), $MachinePrecision] / d), $MachinePrecision] * -1.0 + (-b)), $MachinePrecision] / d), $MachinePrecision]), If[LessEqual[c, 4.2e+89], 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 := \mathsf{fma}\left(\frac{b}{c}, \frac{d}{c}, \frac{a}{c}\right)\\
\mathbf{if}\;c \leq -4.5 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -7.4 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 4.2 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.5000000000000001e128 or 4.19999999999999972e89 < c

    1. Initial program 38.1%

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

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

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

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

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

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

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

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

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

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

    if -4.5000000000000001e128 < c < -7.4000000000000003e-119 or 1.0199999999999999e-150 < c < 4.19999999999999972e89

    1. Initial program 76.1%

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

    if -7.4000000000000003e-119 < c < 1.0199999999999999e-150

    1. Initial program 69.7%

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

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

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

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

        \[\leadsto -\frac{-1 \cdot b + -1 \cdot \frac{-1 \cdot \frac{b \cdot {c}^{2}}{d} + a \cdot c}{d}}{d} \]
    4. Applied rewrites91.0%

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

Alternative 2: 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 := \mathsf{fma}\left(\frac{b}{c}, \frac{d}{c}, \frac{a}{c}\right)\\ \mathbf{if}\;c \leq -4.5 \cdot 10^{+128}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -7.4 \cdot 10^{-119}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{-150}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{+89}:\\ \;\;\;\;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 (/ b c) (/ d c) (/ a c))))
   (if (<= c -4.5e+128)
     t_1
     (if (<= c -7.4e-119)
       t_0
       (if (<= c 1.02e-150)
         (/ (fma a (/ c d) b) d)
         (if (<= c 4.2e+89) 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((b / c), (d / c), (a / c));
	double tmp;
	if (c <= -4.5e+128) {
		tmp = t_1;
	} else if (c <= -7.4e-119) {
		tmp = t_0;
	} else if (c <= 1.02e-150) {
		tmp = fma(a, (c / d), b) / d;
	} else if (c <= 4.2e+89) {
		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 = fma(Float64(b / c), Float64(d / c), Float64(a / c))
	tmp = 0.0
	if (c <= -4.5e+128)
		tmp = t_1;
	elseif (c <= -7.4e-119)
		tmp = t_0;
	elseif (c <= 1.02e-150)
		tmp = Float64(fma(a, Float64(c / d), b) / d);
	elseif (c <= 4.2e+89)
		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[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision] + N[(a / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.5e+128], t$95$1, If[LessEqual[c, -7.4e-119], t$95$0, If[LessEqual[c, 1.02e-150], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.2e+89], 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 := \mathsf{fma}\left(\frac{b}{c}, \frac{d}{c}, \frac{a}{c}\right)\\
\mathbf{if}\;c \leq -4.5 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -7.4 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 4.2 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.5000000000000001e128 or 4.19999999999999972e89 < c

    1. Initial program 38.1%

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

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

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

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

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

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

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

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

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

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

    if -4.5000000000000001e128 < c < -7.4000000000000003e-119 or 1.0199999999999999e-150 < c < 4.19999999999999972e89

    1. Initial program 76.1%

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

    if -7.4000000000000003e-119 < c < 1.0199999999999999e-150

    1. Initial program 69.7%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    3. 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-/.f6491.4

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

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

Alternative 3: 82.6% 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(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{if}\;c \leq -4.5 \cdot 10^{+128}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -7.4 \cdot 10^{-119}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{-150}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{+89}:\\ \;\;\;\;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 b (/ d c) a) c)))
   (if (<= c -4.5e+128)
     t_1
     (if (<= c -7.4e-119)
       t_0
       (if (<= c 1.02e-150)
         (/ (fma a (/ c d) b) d)
         (if (<= c 4.2e+89) 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(b, (d / c), a) / c;
	double tmp;
	if (c <= -4.5e+128) {
		tmp = t_1;
	} else if (c <= -7.4e-119) {
		tmp = t_0;
	} else if (c <= 1.02e-150) {
		tmp = fma(a, (c / d), b) / d;
	} else if (c <= 4.2e+89) {
		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(b, Float64(d / c), a) / c)
	tmp = 0.0
	if (c <= -4.5e+128)
		tmp = t_1;
	elseif (c <= -7.4e-119)
		tmp = t_0;
	elseif (c <= 1.02e-150)
		tmp = Float64(fma(a, Float64(c / d), b) / d);
	elseif (c <= 4.2e+89)
		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[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.5e+128], t$95$1, If[LessEqual[c, -7.4e-119], t$95$0, If[LessEqual[c, 1.02e-150], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.2e+89], 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(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -4.5 \cdot 10^{+128}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -7.4 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 4.2 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.5000000000000001e128 or 4.19999999999999972e89 < c

    1. Initial program 38.1%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    3. 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-/.f6483.1

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

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

    if -4.5000000000000001e128 < c < -7.4000000000000003e-119 or 1.0199999999999999e-150 < c < 4.19999999999999972e89

    1. Initial program 76.1%

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

    if -7.4000000000000003e-119 < c < 1.0199999999999999e-150

    1. Initial program 69.7%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    3. 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-/.f6491.4

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

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

Alternative 4: 62.9% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;d \leq 8.5 \cdot 10^{-44}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\

\mathbf{elif}\;d \leq 1.9 \cdot 10^{+81}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.4e15 or 1.9e81 < d

    1. Initial program 46.2%

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

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

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    4. Applied rewrites69.3%

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

    if -4.4e15 < d < 8.5000000000000002e-44

    1. Initial program 73.2%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    3. 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-/.f6481.6

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.5000000000000002e-44 < d < 1.9e81

    1. Initial program 74.3%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{d \cdot \color{blue}{d}} \]
      2. lift-*.f6450.5

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(d, b, \color{blue}{c \cdot a}\right)}{d \cdot d} \]
      8. lower-*.f6450.5

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

        \[\leadsto \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{d \cdot d} \]
      10. pow250.5

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

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

        \[\leadsto \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{d \cdot d} \]
      13. pow250.5

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

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

Alternative 5: 77.1% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
\mathbf{if}\;c \leq -2800000000:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.8e9 or 2.9e11 < c

    1. Initial program 48.7%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    3. 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-/.f6474.8

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

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

    if -2.8e9 < c < 2.9e11

    1. Initial program 74.1%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    3. 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-/.f6479.2

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

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

Alternative 6: 72.0% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -12500000000:\\
\;\;\;\;\frac{a}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.25e10 or 2.10000000000000009 < c

    1. Initial program 49.2%

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

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

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    4. Applied rewrites64.2%

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

    if -1.25e10 < c < 2.10000000000000009

    1. Initial program 74.1%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    3. 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-/.f6479.6

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

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

Alternative 7: 64.9% accurate, 0.9× speedup?

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

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

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

\mathbf{elif}\;c \leq 0.11:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.90000000000000003e129 or 0.110000000000000001 < c

    1. Initial program 44.7%

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

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

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

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

    if -2.90000000000000003e129 < c < -1.59999999999999995e-27

    1. Initial program 71.6%

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

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

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

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

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

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

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

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

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

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

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

    if -1.59999999999999995e-27 < c < 0.110000000000000001

    1. Initial program 73.7%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    3. Step-by-step derivation
      1. lower-/.f6464.5

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    4. Applied rewrites64.5%

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

Alternative 8: 63.5% accurate, 0.9× speedup?

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

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

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

\mathbf{elif}\;c \leq 0.11:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -7.99999999999999987e157 or 0.110000000000000001 < c

    1. Initial program 43.6%

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

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

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    4. Applied rewrites67.8%

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

    if -7.99999999999999987e157 < c < -1.25000000000000006e-102

    1. Initial program 72.7%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    3. 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-/.f6455.5

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.25000000000000006e-102 < c < 0.110000000000000001

    1. Initial program 72.7%

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

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

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    4. Applied rewrites66.9%

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

Alternative 9: 63.4% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;c \leq 0.11:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.44999999999999988e-27 or 0.110000000000000001 < c

    1. Initial program 51.0%

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

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

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

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

    if -2.44999999999999988e-27 < c < 0.110000000000000001

    1. Initial program 73.7%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    3. Step-by-step derivation
      1. lower-/.f6464.5

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    4. Applied rewrites64.5%

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

Alternative 10: 42.7% 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 61.7%

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

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

      \[\leadsto \frac{a}{\color{blue}{c}} \]
  4. Applied rewrites42.7%

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

Developer Target 1: 99.2% 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 2025095 
(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))))