Complex division, real part

Percentage Accurate: 61.8% → 85.4%
Time: 3.9s
Alternatives: 11
Speedup: 1.8×

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 11 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.8% 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: 85.4% accurate, 0.4× speedup?

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

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

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

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

\mathbf{elif}\;c \leq 1.75 \cdot 10^{+73}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{d}{t\_1}, d, \frac{c}{t\_1} \cdot c\right)}\\

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


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

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

    if -2.2e149 < c < -2.49999999999999985e-99

    1. Initial program 61.8%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(-1 \cdot \left(a \cdot c + b \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]
      4. mul-1-negN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c + b \cdot d\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      6. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      7. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - a \cdot c\right)}\right)}{c \cdot c + d \cdot d} \]
      8. *-rgt-identityN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(a \cdot c\right) \cdot 1}\right)\right)}{c \cdot c + d \cdot d} \]
      9. lft-mult-inverseN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \left(a \cdot c\right) \cdot \color{blue}{\left(\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      10. associate-*l*N/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(\left(a \cdot c\right) \cdot \frac{1}{c \cdot c + d \cdot d}\right) \cdot \left(c \cdot c + d \cdot d\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      11. mult-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\frac{a \cdot c}{c \cdot c + d \cdot d}} \cdot \left(c \cdot c + d \cdot d\right)\right)\right)}{c \cdot c + d \cdot d} \]
      12. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right) - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)\right)\right)}\right)}{c \cdot c + d \cdot d} \]
      13. add-flipN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(b \cdot d + \frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      15. distribute-neg-inN/A

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, a, d \cdot b\right)\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)}} \]
      4. remove-double-negN/A

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

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

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

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

        \[\leadsto \frac{d \cdot b + \color{blue}{c \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      9. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{\color{blue}{d \cdot b - \left(\mathsf{neg}\left(c\right)\right) \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      10. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{d \cdot b + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      11. remove-double-negN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b} + \frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]
      17. remove-double-negN/A

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

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

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

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

    if -2.49999999999999985e-99 < c < 2.4000000000000001e-148

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
      4. lower-*.f6452.7

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
    4. Applied rewrites52.7%

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

    if 2.4000000000000001e-148 < c < 1.75000000000000001e73

    1. Initial program 61.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied rewrites61.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{neg}\left(\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)}{\mathsf{neg}\left(\mathsf{fma}\left(d, b, c \cdot a\right)\right)}} \]
      10. frac-2negN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(d, b, c \cdot a\right)\right)\right)\right)}}} \]
      11. remove-double-negN/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{d \cdot d + \color{blue}{c \cdot c}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(d, b, c \cdot a\right)\right)\right)\right)}} \]
      20. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{1}{\frac{\color{blue}{d \cdot d - \left(\mathsf{neg}\left(c\right)\right) \cdot c}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(d, b, c \cdot a\right)\right)\right)\right)}} \]
      21. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{1}{\frac{\color{blue}{d \cdot d + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot c}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(d, b, c \cdot a\right)\right)\right)\right)}} \]
      22. remove-double-negN/A

        \[\leadsto \frac{1}{\frac{d \cdot d + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot c}{\color{blue}{\mathsf{fma}\left(d, b, c \cdot a\right)}}} \]
    4. Applied rewrites75.0%

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

    if 1.75000000000000001e73 < c

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 2: 85.2% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;c \leq -2.5 \cdot 10^{-99}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;c \leq 3.05 \cdot 10^{+136}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.2e149

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

    if -2.2e149 < c < -2.49999999999999985e-99 or 1.75000000000000008e-155 < c < 3.0499999999999998e136

    1. Initial program 61.8%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(-1 \cdot \left(a \cdot c + b \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]
      4. mul-1-negN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c + b \cdot d\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      6. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      7. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - a \cdot c\right)}\right)}{c \cdot c + d \cdot d} \]
      8. *-rgt-identityN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(a \cdot c\right) \cdot 1}\right)\right)}{c \cdot c + d \cdot d} \]
      9. lft-mult-inverseN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \left(a \cdot c\right) \cdot \color{blue}{\left(\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      10. associate-*l*N/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(\left(a \cdot c\right) \cdot \frac{1}{c \cdot c + d \cdot d}\right) \cdot \left(c \cdot c + d \cdot d\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      11. mult-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\frac{a \cdot c}{c \cdot c + d \cdot d}} \cdot \left(c \cdot c + d \cdot d\right)\right)\right)}{c \cdot c + d \cdot d} \]
      12. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right) - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)\right)\right)}\right)}{c \cdot c + d \cdot d} \]
      13. add-flipN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(b \cdot d + \frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      15. distribute-neg-inN/A

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, a, d \cdot b\right)\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)}} \]
      4. remove-double-negN/A

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

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

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

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

        \[\leadsto \frac{d \cdot b + \color{blue}{c \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      9. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{\color{blue}{d \cdot b - \left(\mathsf{neg}\left(c\right)\right) \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      10. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{d \cdot b + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      11. remove-double-negN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b} + \frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]
      17. remove-double-negN/A

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

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

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

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

    if -2.49999999999999985e-99 < c < 1.75000000000000008e-155

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
      4. lower-*.f6452.7

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
    4. Applied rewrites52.7%

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

    if 3.0499999999999998e136 < c

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 3: 84.1% accurate, 0.5× speedup?

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

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

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

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

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

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


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

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

    if -3.09999999999999987e149 < c < -1.15e-98

    1. Initial program 61.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied rewrites61.7%

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

    if -1.15e-98 < c < 1.85e-155

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
      4. lower-*.f6452.7

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
    4. Applied rewrites52.7%

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

    if 1.85e-155 < c < 1.59999999999999999e133

    1. Initial program 61.8%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(-1 \cdot \left(a \cdot c + b \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]
      4. mul-1-negN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c + b \cdot d\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      6. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      7. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - a \cdot c\right)}\right)}{c \cdot c + d \cdot d} \]
      8. *-rgt-identityN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(a \cdot c\right) \cdot 1}\right)\right)}{c \cdot c + d \cdot d} \]
      9. lft-mult-inverseN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \left(a \cdot c\right) \cdot \color{blue}{\left(\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      10. associate-*l*N/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(\left(a \cdot c\right) \cdot \frac{1}{c \cdot c + d \cdot d}\right) \cdot \left(c \cdot c + d \cdot d\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      11. mult-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\frac{a \cdot c}{c \cdot c + d \cdot d}} \cdot \left(c \cdot c + d \cdot d\right)\right)\right)}{c \cdot c + d \cdot d} \]
      12. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right) - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)\right)\right)}\right)}{c \cdot c + d \cdot d} \]
      13. add-flipN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(b \cdot d + \frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      15. distribute-neg-inN/A

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, a, d \cdot b\right)\right)\right)\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)}} \]
      4. remove-double-negN/A

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

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

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

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

        \[\leadsto \frac{d \cdot b + \color{blue}{c \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      9. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{\color{blue}{d \cdot b - \left(\mathsf{neg}\left(c\right)\right) \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      10. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{d \cdot b + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot a}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\mathsf{fma}\left(c, c, d \cdot d\right)\right)\right)\right)} \]
      11. remove-double-negN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot b} + \frac{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(c\right)\right)\right)\right) \cdot a}{\mathsf{fma}\left(c, c, d \cdot d\right)} \]
      17. remove-double-negN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, b, \color{blue}{\left(a \cdot \frac{1}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)} \cdot c\right) \]
      8. mult-flipN/A

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

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

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

    if 1.59999999999999999e133 < c

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 4: 83.7% accurate, 0.6× speedup?

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

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

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

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

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

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


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

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

    if -3.09999999999999987e149 < c < -1.15e-98

    1. Initial program 61.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied rewrites61.7%

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

    if -1.15e-98 < c < 1.85e-155

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
      4. lower-*.f6452.7

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
    4. Applied rewrites52.7%

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

    if 1.85e-155 < c < 1.25999999999999993e73

    1. Initial program 61.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied rewrites61.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.25999999999999993e73 < c

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 5: 82.8% accurate, 0.6× speedup?

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

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

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

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

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

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


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

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

    if -4.60000000000000042e130 < c < -2.49999999999999985e-99

    1. Initial program 61.8%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(-1 \cdot \left(a \cdot c + b \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]
      4. mul-1-negN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c + b \cdot d\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      6. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      7. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - a \cdot c\right)}\right)}{c \cdot c + d \cdot d} \]
      8. *-rgt-identityN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(a \cdot c\right) \cdot 1}\right)\right)}{c \cdot c + d \cdot d} \]
      9. lft-mult-inverseN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \left(a \cdot c\right) \cdot \color{blue}{\left(\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      10. associate-*l*N/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(\left(a \cdot c\right) \cdot \frac{1}{c \cdot c + d \cdot d}\right) \cdot \left(c \cdot c + d \cdot d\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      11. mult-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\frac{a \cdot c}{c \cdot c + d \cdot d}} \cdot \left(c \cdot c + d \cdot d\right)\right)\right)}{c \cdot c + d \cdot d} \]
      12. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right) - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)\right)\right)}\right)}{c \cdot c + d \cdot d} \]
      13. add-flipN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(b \cdot d + \frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      15. distribute-neg-inN/A

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

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

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

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

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

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

    if -2.49999999999999985e-99 < c < 1.85e-155

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
      4. lower-*.f6452.7

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
    4. Applied rewrites52.7%

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

    if 1.85e-155 < c < 1.25999999999999993e73

    1. Initial program 61.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied rewrites61.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.25999999999999993e73 < c

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 6: 82.8% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;c \leq -2.5 \cdot 10^{-99}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.26 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -4.60000000000000042e130

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

    if -4.60000000000000042e130 < c < -2.49999999999999985e-99 or 1.85e-155 < c < 1.25999999999999993e73

    1. Initial program 61.8%

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

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)} \cdot \left(a \cdot c + b \cdot d\right)}{c \cdot c + d \cdot d} \]
      3. distribute-lft-neg-outN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(-1 \cdot \left(a \cdot c + b \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]
      4. mul-1-negN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c + b \cdot d\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      6. add-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(a \cdot c - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      7. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - a \cdot c\right)}\right)}{c \cdot c + d \cdot d} \]
      8. *-rgt-identityN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(a \cdot c\right) \cdot 1}\right)\right)}{c \cdot c + d \cdot d} \]
      9. lft-mult-inverseN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \left(a \cdot c\right) \cdot \color{blue}{\left(\frac{1}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      10. associate-*l*N/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\left(\left(a \cdot c\right) \cdot \frac{1}{c \cdot c + d \cdot d}\right) \cdot \left(c \cdot c + d \cdot d\right)}\right)\right)}{c \cdot c + d \cdot d} \]
      11. mult-flipN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(\left(\mathsf{neg}\left(b \cdot d\right)\right) - \color{blue}{\frac{a \cdot c}{c \cdot c + d \cdot d}} \cdot \left(c \cdot c + d \cdot d\right)\right)\right)}{c \cdot c + d \cdot d} \]
      12. sub-negateN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right) - \left(\mathsf{neg}\left(b \cdot d\right)\right)\right)\right)\right)}\right)}{c \cdot c + d \cdot d} \]
      13. add-flipN/A

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

        \[\leadsto \frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left(b \cdot d + \frac{a \cdot c}{c \cdot c + d \cdot d} \cdot \left(c \cdot c + d \cdot d\right)\right)}\right)\right)\right)}{c \cdot c + d \cdot d} \]
      15. distribute-neg-inN/A

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

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

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

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

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

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

    if -2.49999999999999985e-99 < c < 1.85e-155

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
      4. lower-*.f6452.7

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
    4. Applied rewrites52.7%

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

    if 1.25999999999999993e73 < c

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 7: 78.0% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

    if -1.25 < c < 1e20

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
      4. lower-*.f6452.7

        \[\leadsto \frac{b + \frac{a \cdot c}{d}}{d} \]
    4. Applied rewrites52.7%

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

    if 1e20 < c

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 8: 72.8% accurate, 1.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.30000000000000013e44 or 2.35000000000000011e89 < d

    1. Initial program 61.8%

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

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

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

    if -3.30000000000000013e44 < d < 2.35000000000000011e89

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{d}{c} \cdot b + \frac{a}{c} \cdot c}{c} \]
      14. mult-flipN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      15. associate-*l*N/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      16. inv-powN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      17. pow-plusN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      18. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot {c}^{0}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{d}{c} \cdot b + a \cdot 1}{c} \]
      20. *-rgt-identityN/A

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

        \[\leadsto \frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c} \]
      22. lower-/.f6453.9

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

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

Alternative 9: 72.1% accurate, 1.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.30000000000000013e44 or 2.35000000000000011e89 < d

    1. Initial program 61.8%

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

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

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

    if -3.30000000000000013e44 < d < 2.35000000000000011e89

    1. Initial program 61.8%

      \[\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. lower-+.f64N/A

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      4. lower-*.f6452.1

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
    4. Applied rewrites52.1%

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

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

        \[\leadsto \frac{a + \frac{b \cdot d}{c}}{c} \]
      3. add-to-fractionN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{b}{c} \cdot d + \frac{a}{c} \cdot c}{c} \]
      15. mult-flipN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + \left(a \cdot \frac{1}{c}\right) \cdot c}{c} \]
      16. associate-*l*N/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left(\frac{1}{c} \cdot c\right)}{c} \]
      17. inv-powN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot \left({c}^{-1} \cdot c\right)}{c} \]
      18. pow-plusN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{\left(-1 + 1\right)}}{c} \]
      19. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot {c}^{0}}{c} \]
      20. metadata-evalN/A

        \[\leadsto \frac{\frac{b}{c} \cdot d + a \cdot 1}{c} \]
      21. *-rgt-identityN/A

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

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

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

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

Alternative 10: 63.7% accurate, 1.8× speedup?

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

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

\mathbf{elif}\;d \leq 2.2 \cdot 10^{+48}:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.94999999999999982e44 or 2.1999999999999999e48 < d

    1. Initial program 61.8%

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

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

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

    if -2.94999999999999982e44 < d < 2.1999999999999999e48

    1. Initial program 61.8%

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

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

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

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

Alternative 11: 42.7% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{a}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
	return a / c;
}
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.8%

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

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

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

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

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

  :alt
  (! :herbie-platform c (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))))