Complex division, real part

Percentage Accurate: 61.3% → 82.2%
Time: 4.0s
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.3% 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.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -5.6 \cdot 10^{+132}:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(\frac{d}{c}, b, \left(-b\right) \cdot {\left(\frac{d}{c}\right)}^{3}\right) + a\right) - a \cdot {\left(\frac{d}{c}\right)}^{2}}{c}\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\ \;\;\;\;\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 1.5 \cdot 10^{+99}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\ \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 (<= c -5.6e+132)
   (/
    (-
     (+ (fma (/ d c) b (* (- b) (pow (/ d c) 3.0))) a)
     (* a (pow (/ d c) 2.0)))
    c)
   (if (<= c -1.5e-113)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= c 1.3e-36)
       (/ (fma (/ (fma c a (/ (* (* c c) b) (- d))) d) -1.0 (- b)) (- d))
       (if (<= c 1.5e+99)
         (* (/ (fma b (/ d a) c) (fma d d (* c c))) a)
         (/ (fma b (/ d c) a) c))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -5.6e+132) {
		tmp = ((fma((d / c), b, (-b * pow((d / c), 3.0))) + a) - (a * pow((d / c), 2.0))) / c;
	} else if (c <= -1.5e-113) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (c <= 1.3e-36) {
		tmp = fma((fma(c, a, (((c * c) * b) / -d)) / d), -1.0, -b) / -d;
	} else if (c <= 1.5e+99) {
		tmp = (fma(b, (d / a), c) / fma(d, d, (c * c))) * a;
	} else {
		tmp = fma(b, (d / c), a) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -5.6e+132)
		tmp = Float64(Float64(Float64(fma(Float64(d / c), b, Float64(Float64(-b) * (Float64(d / c) ^ 3.0))) + a) - Float64(a * (Float64(d / c) ^ 2.0))) / c);
	elseif (c <= -1.5e-113)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 1.3e-36)
		tmp = Float64(fma(Float64(fma(c, a, Float64(Float64(Float64(c * c) * b) / Float64(-d))) / d), -1.0, Float64(-b)) / Float64(-d));
	elseif (c <= 1.5e+99)
		tmp = Float64(Float64(fma(b, Float64(d / a), c) / fma(d, d, Float64(c * c))) * a);
	else
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.6e+132], N[(N[(N[(N[(N[(d / c), $MachinePrecision] * b + N[((-b) * N[Power[N[(d / c), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision] - N[(a * N[Power[N[(d / c), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -1.5e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.3e-36], 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, 1.5e+99], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.6 \cdot 10^{+132}:\\
\;\;\;\;\frac{\left(\mathsf{fma}\left(\frac{d}{c}, b, \left(-b\right) \cdot {\left(\frac{d}{c}\right)}^{3}\right) + a\right) - a \cdot {\left(\frac{d}{c}\right)}^{2}}{c}\\

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

\mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\
\;\;\;\;\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 1.5 \cdot 10^{+99}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\

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


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

    1. Initial program 34.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-/.f6489.3

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

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

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

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

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

    if -5.5999999999999998e132 < c < -1.5e-113

    1. Initial program 78.8%

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

    if -1.5e-113 < c < 1.3e-36

    1. Initial program 70.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}{-1 \cdot \frac{-1 \cdot b + -1 \cdot \frac{-1 \cdot \frac{b \cdot {c}^{2}}{d} + a \cdot c}{d}}{d}} \]
    4. 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} \]
    5. Applied rewrites86.9%

      \[\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}} \]

    if 1.3e-36 < c < 1.50000000000000007e99

    1. Initial program 75.2%

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

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

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

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

        \[\leadsto \left(\frac{c}{{c}^{2} + {d}^{2}} + \frac{\frac{b \cdot d}{a}}{{c}^{2} + {d}^{2}}\right) \cdot a \]
      4. div-add-revN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a \]
      14. lift-*.f6481.9

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

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

    if 1.50000000000000007e99 < c

    1. Initial program 33.6%

      \[\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-/.f6489.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.6 \cdot 10^{+132}:\\ \;\;\;\;\frac{\left(\mathsf{fma}\left(\frac{d}{c}, b, \left(-b\right) \cdot {\left(\frac{d}{c}\right)}^{3}\right) + a\right) - a \cdot {\left(\frac{d}{c}\right)}^{2}}{c}\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\ \;\;\;\;\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 1.5 \cdot 10^{+99}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{if}\;c \leq -2.2 \cdot 10^{+132}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\ \;\;\;\;\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 1.5 \cdot 10^{+99}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\ \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 -2.2e+132)
     t_0
     (if (<= c -1.5e-113)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (if (<= c 1.3e-36)
         (/ (fma (/ (fma c a (/ (* (* c c) b) (- d))) d) -1.0 (- b)) (- d))
         (if (<= c 1.5e+99)
           (* (/ (fma b (/ d a) c) (fma d d (* c c))) a)
           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 <= -2.2e+132) {
		tmp = t_0;
	} else if (c <= -1.5e-113) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (c <= 1.3e-36) {
		tmp = fma((fma(c, a, (((c * c) * b) / -d)) / d), -1.0, -b) / -d;
	} else if (c <= 1.5e+99) {
		tmp = (fma(b, (d / a), c) / fma(d, d, (c * c))) * a;
	} 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 <= -2.2e+132)
		tmp = t_0;
	elseif (c <= -1.5e-113)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 1.3e-36)
		tmp = Float64(fma(Float64(fma(c, a, Float64(Float64(Float64(c * c) * b) / Float64(-d))) / d), -1.0, Float64(-b)) / Float64(-d));
	elseif (c <= 1.5e+99)
		tmp = Float64(Float64(fma(b, Float64(d / a), c) / fma(d, d, Float64(c * c))) * a);
	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, -2.2e+132], t$95$0, If[LessEqual[c, -1.5e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.3e-36], 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, 1.5e+99], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $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 -2.2 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\
\;\;\;\;\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 1.5 \cdot 10^{+99}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.19999999999999989e132 or 1.50000000000000007e99 < c

    1. Initial program 33.9%

      \[\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-/.f6489.2

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

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

    if -2.19999999999999989e132 < c < -1.5e-113

    1. Initial program 78.8%

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

    if -1.5e-113 < c < 1.3e-36

    1. Initial program 70.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}{-1 \cdot \frac{-1 \cdot b + -1 \cdot \frac{-1 \cdot \frac{b \cdot {c}^{2}}{d} + a \cdot c}{d}}{d}} \]
    4. 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} \]
    5. Applied rewrites86.9%

      \[\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}} \]

    if 1.3e-36 < c < 1.50000000000000007e99

    1. Initial program 75.2%

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

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

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

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

        \[\leadsto \left(\frac{c}{{c}^{2} + {d}^{2}} + \frac{\frac{b \cdot d}{a}}{{c}^{2} + {d}^{2}}\right) \cdot a \]
      4. div-add-revN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a \]
      14. lift-*.f6481.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.2 \cdot 10^{+132}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\ \;\;\;\;\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 1.5 \cdot 10^{+99}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{if}\;c \leq -2.2 \cdot 10^{+132}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -1.85 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.3 \cdot 10^{-36}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+99}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a\\ \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 -2.2e+132)
     t_0
     (if (<= c -1.85e-113)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (if (<= c 1.3e-36)
         (/ (fma a (/ c d) b) d)
         (if (<= c 1.5e+99)
           (* (/ (fma b (/ d a) c) (fma d d (* c c))) a)
           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 <= -2.2e+132) {
		tmp = t_0;
	} else if (c <= -1.85e-113) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (c <= 1.3e-36) {
		tmp = fma(a, (c / d), b) / d;
	} else if (c <= 1.5e+99) {
		tmp = (fma(b, (d / a), c) / fma(d, d, (c * c))) * a;
	} 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 <= -2.2e+132)
		tmp = t_0;
	elseif (c <= -1.85e-113)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 1.3e-36)
		tmp = Float64(fma(a, Float64(c / d), b) / d);
	elseif (c <= 1.5e+99)
		tmp = Float64(Float64(fma(b, Float64(d / a), c) / fma(d, d, Float64(c * c))) * a);
	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, -2.2e+132], t$95$0, If[LessEqual[c, -1.85e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.3e-36], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.5e+99], N[(N[(N[(b * N[(d / a), $MachinePrecision] + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a), $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 -2.2 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.19999999999999989e132 or 1.50000000000000007e99 < c

    1. Initial program 33.9%

      \[\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-/.f6489.2

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

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

    if -2.19999999999999989e132 < c < -1.8499999999999999e-113

    1. Initial program 78.8%

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

    if -1.8499999999999999e-113 < c < 1.3e-36

    1. Initial program 70.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-/.f6486.9

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

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

    if 1.3e-36 < c < 1.50000000000000007e99

    1. Initial program 75.2%

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

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

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

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

        \[\leadsto \left(\frac{c}{{c}^{2} + {d}^{2}} + \frac{\frac{b \cdot d}{a}}{{c}^{2} + {d}^{2}}\right) \cdot a \]
      4. div-add-revN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{d}{a}, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot a \]
      14. lift-*.f6481.9

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

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

Alternative 4: 73.8% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;c \leq -8.8 \cdot 10^{-73}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.15 \cdot 10^{+143}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.1000000000000001e127 or 1.15e143 < c

    1. Initial program 29.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}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6474.3

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

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

    if -1.1000000000000001e127 < c < -8.8000000000000001e-73 or 8.80000000000000038e-31 < c < 1.15e143

    1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.8000000000000001e-73 < c < 8.80000000000000038e-31

    1. Initial program 71.6%

      \[\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-/.f6487.4

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
    5. Applied rewrites87.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 5: 64.5% accurate, 0.7× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.7499999999999999e-47 or 2.20000000000000007e102 < d

    1. Initial program 44.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-/.f6467.1

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    5. Applied rewrites67.1%

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

    if -1.7499999999999999e-47 < d < -1.17999999999999993e-297

    1. Initial program 71.9%

      \[\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-/.f6475.6

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    5. Applied rewrites75.6%

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

    if -1.17999999999999993e-297 < d < 2.40000000000000007e-53

    1. Initial program 77.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 \frac{a \cdot c + b \cdot d}{\color{blue}{{c}^{2}}} \]
    4. Step-by-step derivation
      1. pow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.40000000000000007e-53 < d < 2.20000000000000007e102

    1. Initial program 77.7%

      \[\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-*.f6462.2

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

      \[\leadsto \color{blue}{b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

        \[\leadsto b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]
      9. lower-*.f6462.3

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

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

Alternative 6: 81.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{if}\;c \leq -2.2 \cdot 10^{+132}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -1.85 \cdot 10^{-113}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 8.8 \cdot 10^{-31}:\\ \;\;\;\;\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 -2.2e+132)
     t_0
     (if (<= c -1.85e-113)
       (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
       (if (<= c 8.8e-31) (/ (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 <= -2.2e+132) {
		tmp = t_0;
	} else if (c <= -1.85e-113) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (c <= 8.8e-31) {
		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 <= -2.2e+132)
		tmp = t_0;
	elseif (c <= -1.85e-113)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 8.8e-31)
		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, -2.2e+132], t$95$0, If[LessEqual[c, -1.85e-113], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 8.8e-31], 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 -2.2 \cdot 10^{+132}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.19999999999999989e132 or 8.80000000000000038e-31 < c

    1. Initial program 45.5%

      \[\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-/.f6481.7

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

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

    if -2.19999999999999989e132 < c < -1.8499999999999999e-113

    1. Initial program 78.8%

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

    if -1.8499999999999999e-113 < c < 8.80000000000000038e-31

    1. Initial program 70.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-/.f6486.9

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

      \[\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 7: 66.0% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.7499999999999999e-47 or 2.20000000000000007e102 < d

    1. Initial program 44.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-/.f6467.1

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    5. Applied rewrites67.1%

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

    if -1.7499999999999999e-47 < d < 2.40000000000000007e-53

    1. Initial program 74.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-/.f6468.8

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

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

    if 2.40000000000000007e-53 < d < 2.20000000000000007e102

    1. Initial program 77.7%

      \[\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-*.f6462.2

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

      \[\leadsto \color{blue}{b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

        \[\leadsto b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]
      9. lower-*.f6462.3

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

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

Alternative 8: 78.2% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -8.8 \cdot 10^{-73} \lor \neg \left(c \leq 8.8 \cdot 10^{-31}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{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 -8.8e-73) (not (<= c 8.8e-31)))
   (/ (fma b (/ d c) a) c)
   (/ (fma a (/ c d) b) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -8.8e-73) || !(c <= 8.8e-31)) {
		tmp = fma(b, (d / c), a) / c;
	} else {
		tmp = fma(a, (c / d), b) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -8.8e-73) || !(c <= 8.8e-31))
		tmp = Float64(fma(b, Float64(d / c), 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, -8.8e-73], N[Not[LessEqual[c, 8.8e-31]], $MachinePrecision]], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.8 \cdot 10^{-73} \lor \neg \left(c \leq 8.8 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{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 < -8.8000000000000001e-73 or 8.80000000000000038e-31 < c

    1. Initial program 53.5%

      \[\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-/.f6476.2

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

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

    if -8.8000000000000001e-73 < c < 8.80000000000000038e-31

    1. Initial program 71.6%

      \[\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-/.f6487.4

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

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

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

Alternative 9: 64.7% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.75 \cdot 10^{-47} \lor \neg \left(d \leq 45000\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.7499999999999999e-47 or 45000 < d

    1. Initial program 49.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-/.f6464.8

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

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

    if -1.7499999999999999e-47 < d < 45000

    1. Initial program 75.0%

      \[\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-/.f6465.6

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    5. Applied rewrites65.6%

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

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

Alternative 10: 43.8% 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.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-/.f6441.8

      \[\leadsto \frac{a}{\color{blue}{c}} \]
  5. Applied rewrites41.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 2025084 
(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))))