Complex division, real part

Percentage Accurate: 62.4% → 87.2%
Time: 3.9s
Alternatives: 11
Speedup: 1.1×

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: 62.4% 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: 87.2% accurate, 0.4× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_1}{\mathsf{fma}\left(t\_0, c, 1\right)}}{d}\\


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

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.72e50 < d < -4.30000000000000037e-149

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.30000000000000037e-149 < d < 1.3499999999999999e-35

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.3499999999999999e-35 < d

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.0% accurate, 0.6× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{\mathsf{fma}\left(\frac{c}{d \cdot d}, c, 1\right)}}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.69999999999999987e-30

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.69999999999999987e-30 < d < -2.70000000000000014e-149

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.70000000000000014e-149 < d < 1.3499999999999999e-35

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.3499999999999999e-35 < d

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 85.8% accurate, 0.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.69999999999999987e-30 or 1.3499999999999999e-35 < d

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.69999999999999987e-30 < d < -2.70000000000000014e-149

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.70000000000000014e-149 < d < 1.3499999999999999e-35

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 85.0% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;c \leq -8 \cdot 10^{-39}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 2.55 \cdot 10^{+87}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.99999999999999982e95 < c < -7.99999999999999943e-39 or 1.69999999999999997e-107 < c < 2.54999999999999994e87

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.99999999999999943e-39 < c < 1.69999999999999997e-107

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.54999999999999994e87 < c

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 82.6% accurate, 0.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4e-30 or 1.3499999999999999e-35 < d

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4e-30 < d < -2.70000000000000014e-149

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.70000000000000014e-149 < d < 1.3499999999999999e-35

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 78.0% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.54999999999999991e-38 < c < 4.7e21

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.7e21 < c

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.8% accurate, 1.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.54999999999999991e-38 or 4.7e21 < c

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.54999999999999991e-38 < c < 4.7e21

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 70.8% accurate, 1.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.54999999999999991e-38 or 1.70000000000000009e113 < c

    1. Initial program 62.4%

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

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

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

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

    if -1.54999999999999991e-38 < c < 1.70000000000000009e113

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 70.0% accurate, 1.1× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.54999999999999991e-38 or 1.70000000000000009e113 < c

    1. Initial program 62.4%

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

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

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

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

    if -1.54999999999999991e-38 < c < 1.70000000000000009e113

    1. Initial program 62.4%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 62.0% accurate, 1.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.50000000000000018e44 or 2.2000000000000001e101 < d

    1. Initial program 62.4%

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

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

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

    if -6.50000000000000018e44 < d < 2.2000000000000001e101

    1. Initial program 62.4%

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

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

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

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

Alternative 11: 42.2% 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 62.4%

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

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

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

    \[\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 2025149 
(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))))