Complex division, real part

Percentage Accurate: 61.1% → 83.0%
Time: 3.0s
Alternatives: 8
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 8 alternatives:

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

Initial Program: 61.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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: 83.0% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -1.25 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 5 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 37.6%

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

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

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

    if -3.05e100 < d < -1.24999999999999993e-158 or 4.49999999999999999e-102 < d < 5.0000000000000001e84

    1. Initial program 75.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.24999999999999993e-158 < d < 4.49999999999999999e-102

    1. Initial program 69.5%

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

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

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

    if 5.0000000000000001e84 < d

    1. Initial program 41.3%

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d} \]
      3. lift-fma.f64N/A

        \[\leadsto \frac{a \cdot \frac{c}{d} + b}{d} \]
      4. div-addN/A

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

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

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

        \[\leadsto \frac{\frac{a \cdot c}{d}}{d} + \frac{\color{blue}{b}}{d} \]
      8. associate-*r/N/A

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

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

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

        \[\leadsto \frac{\frac{c}{d} \cdot a}{d} + \frac{b}{d} \]
      12. lift-/.f6481.9

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

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

Alternative 2: 83.0% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d \leq -1.25 \cdot 10^{-158}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 5 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.05e100 or 5.0000000000000001e84 < d

    1. Initial program 39.5%

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

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

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

    if -3.05e100 < d < -1.24999999999999993e-158 or 4.49999999999999999e-102 < d < 5.0000000000000001e84

    1. Initial program 75.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.24999999999999993e-158 < d < 4.49999999999999999e-102

    1. Initial program 69.5%

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

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

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

Alternative 3: 66.6% accurate, 0.7× speedup?

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

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

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

\mathbf{elif}\;c \leq 3.5 \cdot 10^{-18}:\\
\;\;\;\;\frac{b}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.1000000000000001e154 or 1.20000000000000007e154 < c

    1. Initial program 28.3%

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

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

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

    if -1.1000000000000001e154 < c < -7.5e-35

    1. Initial program 72.0%

      \[\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-*.f6460.1

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

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

    if -7.5e-35 < c < 3.4999999999999999e-18

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

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

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

    if 3.4999999999999999e-18 < c < 1.20000000000000007e154

    1. Initial program 68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\color{blue}{{c}^{2}}} \]
    5. Step-by-step derivation
      1. pow2N/A

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

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

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

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

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

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

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

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

Alternative 4: 67.0% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;c \leq -7.5 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 3.1 \cdot 10^{+156}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.1000000000000001e154 or 3.1000000000000002e156 < c

    1. Initial program 28.4%

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

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

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

    if -1.1000000000000001e154 < c < -7.5e-35 or 5e-31 < c < 3.1000000000000002e156

    1. Initial program 70.0%

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

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

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

    if -7.5e-35 < c < 5e-31

    1. Initial program 74.1%

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

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

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

Alternative 5: 73.7% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.59999999999999996e40 or 1.20000000000000007e154 < c

    1. Initial program 38.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-/.f6471.9

        \[\leadsto \frac{a}{\color{blue}{c}} \]
    4. Applied rewrites71.9%

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

    if -3.59999999999999996e40 < c < 3.4999999999999999e-18

    1. Initial program 74.6%

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

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

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

    if 3.4999999999999999e-18 < c < 1.20000000000000007e154

    1. Initial program 68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\color{blue}{{c}^{2}}} \]
    5. Step-by-step derivation
      1. pow2N/A

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

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

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

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

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

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

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

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

Alternative 6: 78.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 -7.4 \cdot 10^{-29}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 3.5 \cdot 10^{-18}:\\ \;\;\;\;\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 -7.4e-29) t_0 (if (<= c 3.5e-18) (/ (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 <= -7.4e-29) {
		tmp = t_0;
	} else if (c <= 3.5e-18) {
		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 <= -7.4e-29)
		tmp = t_0;
	elseif (c <= 3.5e-18)
		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, -7.4e-29], t$95$0, If[LessEqual[c, 3.5e-18], 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 -7.4 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 3.5 \cdot 10^{-18}:\\
\;\;\;\;\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 < -7.3999999999999995e-29 or 3.4999999999999999e-18 < c

    1. Initial program 50.3%

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

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

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

    if -7.3999999999999995e-29 < c < 3.4999999999999999e-18

    1. Initial program 74.2%

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

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

      \[\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.4% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;c \leq 9 \cdot 10^{+17}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.0999999999999999e40 or 9e17 < c

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

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

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

    if -1.0999999999999999e40 < c < 9e17

    1. Initial program 74.9%

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

        \[\leadsto \frac{b}{\color{blue}{d}} \]
    4. Applied rewrites61.8%

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

Alternative 8: 43.1% 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.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}{c}} \]
  3. Step-by-step derivation
    1. lower-/.f6443.1

      \[\leadsto \frac{a}{\color{blue}{c}} \]
  4. Applied rewrites43.1%

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

Developer Target 1: 99.4% 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 2025102 
(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))))