Complex division, real part

Percentage Accurate: 61.6% → 83.3%
Time: 5.4s
Alternatives: 10
Speedup: 1.6×

Specification

?
\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

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

Initial Program: 61.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}

Alternative 1: 83.3% accurate, 0.6× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.6000000000000001e165 or 5.50000000000000036e77 < d

    1. Initial program 38.9%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites38.9%

      \[\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 0

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

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

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

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

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

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

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

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

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

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

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

    if -2.6000000000000001e165 < d < -2.3000000000000001e-60

    1. Initial program 68.8%

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

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

    if -2.3000000000000001e-60 < d < 2.89999999999999988e-126

    1. Initial program 65.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites65.8%

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

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

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

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

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

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

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

    if 2.89999999999999988e-126 < d < 5.50000000000000036e77

    1. Initial program 87.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites87.7%

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

Alternative 2: 64.3% accurate, 0.7× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.55e81 or 1.1e-5 < d

    1. Initial program 51.2%

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

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

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites78.7%

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

    if -1.55e81 < d < -2.35e-63

    1. Initial program 72.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)} \cdot d \]
      10. lower-*.f6458.0

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

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

    if -2.35e-63 < d < 7.5000000000000003e-204

    1. Initial program 62.8%

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

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

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

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

    if 7.5000000000000003e-204 < d < 1.1e-5

    1. Initial program 87.0%

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{a \cdot c} + b \cdot d}{c \cdot c} \]
      3. lower-fma.f6470.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+81}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-63}:\\ \;\;\;\;\frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot d\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-204}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.1 \cdot 10^{-5}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.4% accurate, 0.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -7.49999999999999959e68 or 5.50000000000000036e77 < d

    1. Initial program 45.5%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites45.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.49999999999999959e68 < d < 2.89999999999999988e-126

    1. Initial program 66.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites66.7%

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

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

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

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

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

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

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

    if 2.89999999999999988e-126 < d < 5.50000000000000036e77

    1. Initial program 87.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites87.7%

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

Alternative 4: 70.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{if}\;d \leq -9 \cdot 10^{-54}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-204}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-11}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma (/ a d) c b) d)))
   (if (<= d -9e-54)
     t_0
     (if (<= d 7.5e-204)
       (/ a c)
       (if (<= d 9.5e-11) (/ (fma a c (* b d)) (* c c)) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = fma((a / d), c, b) / d;
	double tmp;
	if (d <= -9e-54) {
		tmp = t_0;
	} else if (d <= 7.5e-204) {
		tmp = a / c;
	} else if (d <= 9.5e-11) {
		tmp = fma(a, c, (b * d)) / (c * c);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(Float64(a / d), c, b) / d)
	tmp = 0.0
	if (d <= -9e-54)
		tmp = t_0;
	elseif (d <= 7.5e-204)
		tmp = Float64(a / c);
	elseif (d <= 9.5e-11)
		tmp = Float64(fma(a, c, Float64(b * d)) / Float64(c * 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] / d), $MachinePrecision]}, If[LessEqual[d, -9e-54], t$95$0, If[LessEqual[d, 7.5e-204], N[(a / c), $MachinePrecision], If[LessEqual[d, 9.5e-11], N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -8.9999999999999997e-54 or 9.49999999999999951e-11 < d

    1. Initial program 55.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.9999999999999997e-54 < d < 7.5000000000000003e-204

    1. Initial program 63.2%

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

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

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Applied rewrites73.7%

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

    if 7.5000000000000003e-204 < d < 9.49999999999999951e-11

    1. Initial program 87.0%

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{a \cdot c} + b \cdot d}{c \cdot c} \]
      3. lower-fma.f6470.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9 \cdot 10^{-54}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-204}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 9.5 \cdot 10^{-11}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{+68} \lor \neg \left(d \leq 3000\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -7.5e+68) (not (<= d 3000.0)))
   (/ (fma (/ c d) a b) d)
   (/ (fma (/ d c) b a) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -7.5e+68) || !(d <= 3000.0)) {
		tmp = fma((c / d), a, b) / d;
	} else {
		tmp = fma((d / c), b, a) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -7.5e+68) || !(d <= 3000.0))
		tmp = Float64(fma(Float64(c / d), a, b) / d);
	else
		tmp = Float64(fma(Float64(d / c), b, a) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.5e+68], N[Not[LessEqual[d, 3000.0]], $MachinePrecision]], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(d / c), $MachinePrecision] * b + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.49999999999999959e68 or 3e3 < d

    1. Initial program 51.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites51.7%

      \[\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 0

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

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

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

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

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

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

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

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

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

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

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

    if -7.49999999999999959e68 < d < 3e3

    1. Initial program 71.8%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites71.8%

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

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

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

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

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

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

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

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

Alternative 6: 77.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{+68} \lor \neg \left(d \leq 3000\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -7.5e+68) (not (<= d 3000.0)))
   (/ (fma (/ c d) a b) d)
   (/ (fma (/ b c) d a) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -7.5e+68) || !(d <= 3000.0)) {
		tmp = fma((c / d), a, b) / d;
	} else {
		tmp = fma((b / c), d, a) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -7.5e+68) || !(d <= 3000.0))
		tmp = Float64(fma(Float64(c / d), a, b) / d);
	else
		tmp = Float64(fma(Float64(b / c), d, a) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.5e+68], N[Not[LessEqual[d, 3000.0]], $MachinePrecision]], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.49999999999999959e68 or 3e3 < d

    1. Initial program 51.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites51.7%

      \[\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 0

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

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

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

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

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

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

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

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

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

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

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

    if -7.49999999999999959e68 < d < 3e3

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{+68} \lor \neg \left(d \leq 3000\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -7.5e+68) (not (<= d 3000.0)))
   (/ (fma (/ a d) c b) d)
   (/ (fma (/ b c) d a) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -7.5e+68) || !(d <= 3000.0)) {
		tmp = fma((a / d), c, b) / d;
	} else {
		tmp = fma((b / c), d, a) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -7.5e+68) || !(d <= 3000.0))
		tmp = Float64(fma(Float64(a / d), c, b) / d);
	else
		tmp = Float64(fma(Float64(b / c), d, a) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -7.5e+68], N[Not[LessEqual[d, 3000.0]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.49999999999999959e68 or 3e3 < d

    1. Initial program 51.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.49999999999999959e68 < d < 3e3

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 64.7% accurate, 0.9× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.55e81 or 1.1e-5 < d

    1. Initial program 51.2%

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

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

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites78.7%

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

    if -1.55e81 < d < -2.35e-63

    1. Initial program 72.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)} \cdot d \]
      10. lower-*.f6458.0

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

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

    if -2.35e-63 < d < 1.1e-5

    1. Initial program 72.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+81}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-63}:\\ \;\;\;\;\frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot d\\ \mathbf{elif}\;d \leq 1.1 \cdot 10^{-5}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 63.7% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.25 \cdot 10^{-50} \lor \neg \left(d \leq 1.1 \cdot 10^{-5}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -1.25e-50) (not (<= d 1.1e-5))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.25e-50) || !(d <= 1.1e-5)) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((d <= (-1.25d-50)) .or. (.not. (d <= 1.1d-5))) then
        tmp = b / d
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.25e-50) || !(d <= 1.1e-5)) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.25e-50) or not (d <= 1.1e-5):
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1.25e-50) || !(d <= 1.1e-5))
		tmp = Float64(b / d);
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -1.25e-50) || ~((d <= 1.1e-5)))
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.25e-50], N[Not[LessEqual[d, 1.1e-5]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.25 \cdot 10^{-50} \lor \neg \left(d \leq 1.1 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.24999999999999992e-50 or 1.1e-5 < d

    1. Initial program 55.1%

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

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

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

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

    if -1.24999999999999992e-50 < d < 1.1e-5

    1. Initial program 72.2%

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

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

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Applied rewrites69.1%

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

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

Alternative 10: 42.2% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \frac{a}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
	return a / c;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = a / c
end function
public static double code(double a, double b, double c, double d) {
	return a / c;
}
def code(a, b, c, d):
	return a / c
function code(a, b, c, d)
	return Float64(a / c)
end
function tmp = code(a, b, c, d)
	tmp = a / c;
end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 63.2%

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

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  6. Final simplification42.3%

    \[\leadsto \frac{a}{c} \]
  7. Add Preprocessing

Developer Target 1: 99.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (< (fabs d) (fabs c))
   (/ (+ a (* b (/ d c))) (+ c (* d (/ d c))))
   (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a, b, c, d)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (abs(d) < abs(c)) then
        tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (Math.abs(d) < Math.abs(c)) {
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (abs(d) < abs(c))
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (abs(d) < abs(c))
		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024360 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))