Complex division, real part

Percentage Accurate: 62.9% → 81.9%
Time: 6.1s
Alternatives: 11
Speedup: N/A×

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.9% 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: 81.9% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ t_1 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ t_2 := \frac{d}{t\_1}\\ t_3 := \frac{c}{t\_1}\\ \mathbf{if}\;d \leq -3.7 \cdot 10^{+153}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -2.6 \cdot 10^{-160}:\\ \;\;\;\;\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, b \cdot t\_2, -1 \cdot t\_3\right)\\ \mathbf{elif}\;d \leq 1.35 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{d \cdot b}{c} + a}{c}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+175}:\\ \;\;\;\;\mathsf{fma}\left(t\_2, b, \left(\frac{a}{b} \cdot t\_3\right) \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma a (/ c d) b) d))
        (t_1 (fma d d (* c c)))
        (t_2 (/ d t_1))
        (t_3 (/ c t_1)))
   (if (<= d -3.7e+153)
     t_0
     (if (<= d -2.6e-160)
       (* (* -1.0 a) (fma (/ -1.0 a) (* b t_2) (* -1.0 t_3)))
       (if (<= d 1.35e-107)
         (/ (+ (/ (* d b) c) a) c)
         (if (<= d 2.3e+175) (fma t_2 b (* (* (/ a b) t_3) b)) t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(a, (c / d), b) / d;
	double t_1 = fma(d, d, (c * c));
	double t_2 = d / t_1;
	double t_3 = c / t_1;
	double tmp;
	if (d <= -3.7e+153) {
		tmp = t_0;
	} else if (d <= -2.6e-160) {
		tmp = (-1.0 * a) * fma((-1.0 / a), (b * t_2), (-1.0 * t_3));
	} else if (d <= 1.35e-107) {
		tmp = (((d * b) / c) + a) / c;
	} else if (d <= 2.3e+175) {
		tmp = fma(t_2, b, (((a / b) * t_3) * b));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(a, Float64(c / d), b) / d)
	t_1 = fma(d, d, Float64(c * c))
	t_2 = Float64(d / t_1)
	t_3 = Float64(c / t_1)
	tmp = 0.0
	if (d <= -3.7e+153)
		tmp = t_0;
	elseif (d <= -2.6e-160)
		tmp = Float64(Float64(-1.0 * a) * fma(Float64(-1.0 / a), Float64(b * t_2), Float64(-1.0 * t_3)));
	elseif (d <= 1.35e-107)
		tmp = Float64(Float64(Float64(Float64(d * b) / c) + a) / c);
	elseif (d <= 2.3e+175)
		tmp = fma(t_2, b, Float64(Float64(Float64(a / b) * t_3) * b));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, Block[{t$95$1 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(d / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(c / t$95$1), $MachinePrecision]}, If[LessEqual[d, -3.7e+153], t$95$0, If[LessEqual[d, -2.6e-160], N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(-1.0 / a), $MachinePrecision] * N[(b * t$95$2), $MachinePrecision] + N[(-1.0 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.35e-107], N[(N[(N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.3e+175], N[(t$95$2 * b + N[(N[(N[(a / b), $MachinePrecision] * t$95$3), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -2.6 \cdot 10^{-160}:\\
\;\;\;\;\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, b \cdot t\_2, -1 \cdot t\_3\right)\\

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

\mathbf{elif}\;d \leq 2.3 \cdot 10^{+175}:\\
\;\;\;\;\mathsf{fma}\left(t\_2, b, \left(\frac{a}{b} \cdot t\_3\right) \cdot b\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -3.7000000000000002e153 or 2.3e175 < d

    1. Initial program 32.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{c \cdot a}{d} + b}{d} \]
      4. *-commutativeN/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. lower-fma.f64N/A

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

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

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

    if -3.7000000000000002e153 < d < -2.60000000000000003e-160

    1. Initial program 74.7%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites74.5%

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

    if -2.60000000000000003e-160 < d < 1.35e-107

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

    if 1.35e-107 < d < 2.3e175

    1. Initial program 70.8%

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

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

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

        \[\leadsto \left(\frac{d}{{c}^{2} + {d}^{2}} + \frac{a \cdot c}{b \cdot \left({c}^{2} + {d}^{2}\right)}\right) \cdot \color{blue}{b} \]
    4. Applied rewrites68.6%

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

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

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

Alternative 2: 81.6% accurate, N/A× speedup?

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

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

\mathbf{elif}\;d \leq -2.6 \cdot 10^{-160}:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;d \leq 2.3 \cdot 10^{+175}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.7000000000000002e153 or 2.3e175 < d

    1. Initial program 32.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{c \cdot a}{d} + b}{d} \]
      4. *-commutativeN/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. lower-fma.f64N/A

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

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

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

    if -3.7000000000000002e153 < d < -2.60000000000000003e-160 or 1.19999999999999997e-107 < d < 2.3e175

    1. Initial program 72.9%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites72.9%

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

    if -2.60000000000000003e-160 < d < 1.19999999999999997e-107

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

Alternative 3: 80.6% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ t_1 := \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, b \cdot \frac{d}{t\_0}, -1 \cdot \frac{c}{t\_0}\right)\\ \mathbf{if}\;d \leq -1.6 \cdot 10^{+153}:\\ \;\;\;\;\frac{\frac{c \cdot a}{d} + b}{d}\\ \mathbf{elif}\;d \leq -2.6 \cdot 10^{-160}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-107}:\\ \;\;\;\;\frac{\frac{d \cdot b}{c} + a}{c}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma d d (* c c)))
        (t_1
         (* (* -1.0 a) (fma (/ -1.0 a) (* b (/ d t_0)) (* -1.0 (/ c t_0))))))
   (if (<= d -1.6e+153)
     (/ (+ (/ (* c a) d) b) d)
     (if (<= d -2.6e-160)
       t_1
       (if (<= d 1.2e-107)
         (/ (+ (/ (* d b) c) a) c)
         (if (<= d 5.6e+132) t_1 (/ b d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(d, d, (c * c));
	double t_1 = (-1.0 * a) * fma((-1.0 / a), (b * (d / t_0)), (-1.0 * (c / t_0)));
	double tmp;
	if (d <= -1.6e+153) {
		tmp = (((c * a) / d) + b) / d;
	} else if (d <= -2.6e-160) {
		tmp = t_1;
	} else if (d <= 1.2e-107) {
		tmp = (((d * b) / c) + a) / c;
	} else if (d <= 5.6e+132) {
		tmp = t_1;
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(d, d, Float64(c * c))
	t_1 = Float64(Float64(-1.0 * a) * fma(Float64(-1.0 / a), Float64(b * Float64(d / t_0)), Float64(-1.0 * Float64(c / t_0))))
	tmp = 0.0
	if (d <= -1.6e+153)
		tmp = Float64(Float64(Float64(Float64(c * a) / d) + b) / d);
	elseif (d <= -2.6e-160)
		tmp = t_1;
	elseif (d <= 1.2e-107)
		tmp = Float64(Float64(Float64(Float64(d * b) / c) + a) / c);
	elseif (d <= 5.6e+132)
		tmp = t_1;
	else
		tmp = Float64(b / d);
	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[(-1.0 * a), $MachinePrecision] * N[(N[(-1.0 / a), $MachinePrecision] * N[(b * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.6e+153], N[(N[(N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -2.6e-160], t$95$1, If[LessEqual[d, 1.2e-107], N[(N[(N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.6e+132], t$95$1, N[(b / d), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -2.6 \cdot 10^{-160}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 33.6%

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

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

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

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

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

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

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

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

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

    if -1.6000000000000001e153 < d < -2.60000000000000003e-160 or 1.19999999999999997e-107 < d < 5.5999999999999998e132

    1. Initial program 74.9%

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

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

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

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

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

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

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

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

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

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

    if -2.60000000000000003e-160 < d < 1.19999999999999997e-107

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

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

    if 5.5999999999999998e132 < d

    1. Initial program 33.7%

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

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

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

Alternative 4: 78.5% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ t_1 := \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, b \cdot \frac{d}{t\_0}, -1 \cdot \frac{c}{t\_0}\right)\\ \mathbf{if}\;d \leq -1.6 \cdot 10^{+153}:\\ \;\;\;\;\frac{\frac{c \cdot a}{d} + b}{d}\\ \mathbf{elif}\;d \leq -4.7 \cdot 10^{-172}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{-109}:\\ \;\;\;\;\frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma d d (* c c)))
        (t_1
         (* (* -1.0 a) (fma (/ -1.0 a) (* b (/ d t_0)) (* -1.0 (/ c t_0))))))
   (if (<= d -1.6e+153)
     (/ (+ (/ (* c a) d) b) d)
     (if (<= d -4.7e-172)
       t_1
       (if (<= d 3.5e-109)
         (/ (* a (+ 1.0 (* (/ b a) (/ d c)))) c)
         (if (<= d 5.6e+132) t_1 (/ b d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(d, d, (c * c));
	double t_1 = (-1.0 * a) * fma((-1.0 / a), (b * (d / t_0)), (-1.0 * (c / t_0)));
	double tmp;
	if (d <= -1.6e+153) {
		tmp = (((c * a) / d) + b) / d;
	} else if (d <= -4.7e-172) {
		tmp = t_1;
	} else if (d <= 3.5e-109) {
		tmp = (a * (1.0 + ((b / a) * (d / c)))) / c;
	} else if (d <= 5.6e+132) {
		tmp = t_1;
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(d, d, Float64(c * c))
	t_1 = Float64(Float64(-1.0 * a) * fma(Float64(-1.0 / a), Float64(b * Float64(d / t_0)), Float64(-1.0 * Float64(c / t_0))))
	tmp = 0.0
	if (d <= -1.6e+153)
		tmp = Float64(Float64(Float64(Float64(c * a) / d) + b) / d);
	elseif (d <= -4.7e-172)
		tmp = t_1;
	elseif (d <= 3.5e-109)
		tmp = Float64(Float64(a * Float64(1.0 + Float64(Float64(b / a) * Float64(d / c)))) / c);
	elseif (d <= 5.6e+132)
		tmp = t_1;
	else
		tmp = Float64(b / d);
	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[(-1.0 * a), $MachinePrecision] * N[(N[(-1.0 / a), $MachinePrecision] * N[(b * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.6e+153], N[(N[(N[(N[(c * a), $MachinePrecision] / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -4.7e-172], t$95$1, If[LessEqual[d, 3.5e-109], N[(N[(a * N[(1.0 + N[(N[(b / a), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.6e+132], t$95$1, N[(b / d), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -4.7 \cdot 10^{-172}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq 3.5 \cdot 10^{-109}:\\
\;\;\;\;\frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c}\\

\mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 33.6%

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

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

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

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

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

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

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

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

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

    if -1.6000000000000001e153 < d < -4.69999999999999976e-172 or 3.5e-109 < d < 5.5999999999999998e132

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites74.9%

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

    if -4.69999999999999976e-172 < d < 3.5e-109

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{d \cdot b}{c} + a}{c}} \]
    5. Taylor expanded in a around inf

      \[\leadsto \frac{a \cdot \left(1 + \frac{b \cdot d}{a \cdot c}\right)}{c} \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

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

        \[\leadsto \frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c} \]
      6. lift-/.f6483.8

        \[\leadsto \frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c} \]
    7. Applied rewrites83.8%

      \[\leadsto \frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c} \]

    if 5.5999999999999998e132 < d

    1. Initial program 33.7%

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

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

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

Alternative 5: 78.1% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ t_1 := \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, b \cdot \frac{d}{t\_0}, -1 \cdot \frac{c}{t\_0}\right)\\ \mathbf{if}\;d \leq -1.34 \cdot 10^{+154}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -4.7 \cdot 10^{-172}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{-109}:\\ \;\;\;\;\frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma d d (* c c)))
        (t_1
         (* (* -1.0 a) (fma (/ -1.0 a) (* b (/ d t_0)) (* -1.0 (/ c t_0))))))
   (if (<= d -1.34e+154)
     (/ b d)
     (if (<= d -4.7e-172)
       t_1
       (if (<= d 3.5e-109)
         (/ (* a (+ 1.0 (* (/ b a) (/ d c)))) c)
         (if (<= d 5.6e+132) t_1 (/ b d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(d, d, (c * c));
	double t_1 = (-1.0 * a) * fma((-1.0 / a), (b * (d / t_0)), (-1.0 * (c / t_0)));
	double tmp;
	if (d <= -1.34e+154) {
		tmp = b / d;
	} else if (d <= -4.7e-172) {
		tmp = t_1;
	} else if (d <= 3.5e-109) {
		tmp = (a * (1.0 + ((b / a) * (d / c)))) / c;
	} else if (d <= 5.6e+132) {
		tmp = t_1;
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(d, d, Float64(c * c))
	t_1 = Float64(Float64(-1.0 * a) * fma(Float64(-1.0 / a), Float64(b * Float64(d / t_0)), Float64(-1.0 * Float64(c / t_0))))
	tmp = 0.0
	if (d <= -1.34e+154)
		tmp = Float64(b / d);
	elseif (d <= -4.7e-172)
		tmp = t_1;
	elseif (d <= 3.5e-109)
		tmp = Float64(Float64(a * Float64(1.0 + Float64(Float64(b / a) * Float64(d / c)))) / c);
	elseif (d <= 5.6e+132)
		tmp = t_1;
	else
		tmp = Float64(b / d);
	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[(-1.0 * a), $MachinePrecision] * N[(N[(-1.0 / a), $MachinePrecision] * N[(b * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.34e+154], N[(b / d), $MachinePrecision], If[LessEqual[d, -4.7e-172], t$95$1, If[LessEqual[d, 3.5e-109], N[(N[(a * N[(1.0 + N[(N[(b / a), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 5.6e+132], t$95$1, N[(b / d), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -4.7 \cdot 10^{-172}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq 3.5 \cdot 10^{-109}:\\
\;\;\;\;\frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c}\\

\mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.34000000000000001e154 or 5.5999999999999998e132 < d

    1. Initial program 33.6%

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

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

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

    if -1.34000000000000001e154 < d < -4.69999999999999976e-172 or 3.5e-109 < d < 5.5999999999999998e132

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites74.9%

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

    if -4.69999999999999976e-172 < d < 3.5e-109

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{d \cdot b}{c} + a}{c}} \]
    5. Taylor expanded in a around inf

      \[\leadsto \frac{a \cdot \left(1 + \frac{b \cdot d}{a \cdot c}\right)}{c} \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

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

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

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

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

        \[\leadsto \frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c} \]
      6. lift-/.f6483.8

        \[\leadsto \frac{a \cdot \left(1 + \frac{b}{a} \cdot \frac{d}{c}\right)}{c} \]
    7. Applied rewrites83.8%

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

Alternative 6: 77.8% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ t_1 := \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, b \cdot \frac{d}{t\_0}, -1 \cdot \frac{c}{t\_0}\right)\\ \mathbf{if}\;d \leq -1.34 \cdot 10^{+154}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -4.7 \cdot 10^{-172}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq 3.5 \cdot 10^{-109}:\\ \;\;\;\;\left(-1 \cdot a\right) \cdot \left(\frac{\mathsf{fma}\left(\frac{b}{a}, \frac{d}{c}, 1\right)}{c} \cdot -1\right)\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma d d (* c c)))
        (t_1
         (* (* -1.0 a) (fma (/ -1.0 a) (* b (/ d t_0)) (* -1.0 (/ c t_0))))))
   (if (<= d -1.34e+154)
     (/ b d)
     (if (<= d -4.7e-172)
       t_1
       (if (<= d 3.5e-109)
         (* (* -1.0 a) (* (/ (fma (/ b a) (/ d c) 1.0) c) -1.0))
         (if (<= d 5.6e+132) t_1 (/ b d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(d, d, (c * c));
	double t_1 = (-1.0 * a) * fma((-1.0 / a), (b * (d / t_0)), (-1.0 * (c / t_0)));
	double tmp;
	if (d <= -1.34e+154) {
		tmp = b / d;
	} else if (d <= -4.7e-172) {
		tmp = t_1;
	} else if (d <= 3.5e-109) {
		tmp = (-1.0 * a) * ((fma((b / a), (d / c), 1.0) / c) * -1.0);
	} else if (d <= 5.6e+132) {
		tmp = t_1;
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(d, d, Float64(c * c))
	t_1 = Float64(Float64(-1.0 * a) * fma(Float64(-1.0 / a), Float64(b * Float64(d / t_0)), Float64(-1.0 * Float64(c / t_0))))
	tmp = 0.0
	if (d <= -1.34e+154)
		tmp = Float64(b / d);
	elseif (d <= -4.7e-172)
		tmp = t_1;
	elseif (d <= 3.5e-109)
		tmp = Float64(Float64(-1.0 * a) * Float64(Float64(fma(Float64(b / a), Float64(d / c), 1.0) / c) * -1.0));
	elseif (d <= 5.6e+132)
		tmp = t_1;
	else
		tmp = Float64(b / d);
	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[(-1.0 * a), $MachinePrecision] * N[(N[(-1.0 / a), $MachinePrecision] * N[(b * N[(d / t$95$0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.34e+154], N[(b / d), $MachinePrecision], If[LessEqual[d, -4.7e-172], t$95$1, If[LessEqual[d, 3.5e-109], N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(N[(N[(b / a), $MachinePrecision] * N[(d / c), $MachinePrecision] + 1.0), $MachinePrecision] / c), $MachinePrecision] * -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.6e+132], t$95$1, N[(b / d), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;d \leq -4.7 \cdot 10^{-172}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d \leq 5.6 \cdot 10^{+132}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.34000000000000001e154 or 5.5999999999999998e132 < d

    1. Initial program 33.6%

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

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

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

    if -1.34000000000000001e154 < d < -4.69999999999999976e-172 or 3.5e-109 < d < 5.5999999999999998e132

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites74.9%

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

    if -4.69999999999999976e-172 < d < 3.5e-109

    1. Initial program 70.7%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites65.9%

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \left(\frac{\frac{b \cdot d}{a \cdot c} + 1}{c} \cdot -1\right) \]
      5. times-fracN/A

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

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

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

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

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

Alternative 7: 74.5% accurate, N/A× speedup?

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

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

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

\mathbf{elif}\;c \leq 2.4 \cdot 10^{+110}:\\
\;\;\;\;\frac{\frac{c \cdot a}{b} + d}{t\_0} \cdot b\\

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


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

    1. Initial program 30.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites32.1%

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \left(\frac{\frac{b \cdot d}{a \cdot c} + 1}{c} \cdot -1\right) \]
      5. times-fracN/A

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

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

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

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

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

    if -2.16e158 < c < -5.60000000000000047e-135

    1. Initial program 74.6%

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

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

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

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

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

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

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

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

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

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

    if -5.60000000000000047e-135 < c < 2.40000000000000012e110

    1. Initial program 73.2%

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

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

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

        \[\leadsto \left(\frac{d}{{c}^{2} + {d}^{2}} + \frac{a \cdot c}{b \cdot \left({c}^{2} + {d}^{2}\right)}\right) \cdot \color{blue}{b} \]
    4. Applied rewrites71.0%

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

    if 2.40000000000000012e110 < c

    1. Initial program 37.6%

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

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

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

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

Alternative 8: 74.2% accurate, N/A× speedup?

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

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

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

\mathbf{elif}\;c \leq 1.36 \cdot 10^{+88}:\\
\;\;\;\;\frac{\frac{c \cdot a}{b} + d}{t\_1} \cdot b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.16e158 or 1.3600000000000001e88 < c

    1. Initial program 37.0%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites41.2%

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \left(\frac{\frac{b \cdot d}{a \cdot c} + 1}{c} \cdot -1\right) \]
      5. times-fracN/A

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

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

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

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

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

    if -2.16e158 < c < -5.60000000000000047e-135

    1. Initial program 74.6%

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

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

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

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

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

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

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

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

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

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

    if -5.60000000000000047e-135 < c < 1.3600000000000001e88

    1. Initial program 73.2%

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

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

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

        \[\leadsto \left(\frac{d}{{c}^{2} + {d}^{2}} + \frac{a \cdot c}{b \cdot \left({c}^{2} + {d}^{2}\right)}\right) \cdot \color{blue}{b} \]
    4. Applied rewrites71.6%

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

Alternative 9: 72.6% accurate, N/A× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.16e158 or 3.89999999999999991e166 < c

    1. Initial program 31.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \left(\frac{\frac{b \cdot d}{a \cdot c} + 1}{c} \cdot -1\right) \]
      5. times-fracN/A

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

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

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

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

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

    if -2.16e158 < c < 3.89999999999999991e166

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-1}{a}, \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}}, -1 \cdot \frac{c}{{c}^{2} + {d}^{2}}\right) \]
    4. Applied rewrites70.7%

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

Alternative 10: 51.9% accurate, N/A× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -1.6500000000000001e-150 or 4.99999999999999971e-107 < a

    1. Initial program 57.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-1 \cdot a\right) \cdot \left(\frac{\frac{b \cdot d}{a \cdot c} + 1}{c} \cdot -1\right) \]
      5. times-fracN/A

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

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

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

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

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

    if -1.6500000000000001e-150 < a < 4.99999999999999971e-107

    1. Initial program 75.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{\mathsf{fma}\left(\frac{d}{c}, -1, \frac{a}{b} \cdot -1\right)}{c} \cdot -1\right) \cdot b \]
      10. lower-/.f6448.6

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

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

Alternative 11: 44.3% accurate, N/A× speedup?

\[\begin{array}{l} \\ \left(\frac{\mathsf{fma}\left(\frac{d}{c}, -1, \frac{a}{b} \cdot -1\right)}{c} \cdot -1\right) \cdot b \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (* (* (/ (fma (/ d c) -1.0 (* (/ a b) -1.0)) c) -1.0) b))
double code(double a, double b, double c, double d) {
	return ((fma((d / c), -1.0, ((a / b) * -1.0)) / c) * -1.0) * b;
}
function code(a, b, c, d)
	return Float64(Float64(Float64(fma(Float64(d / c), -1.0, Float64(Float64(a / b) * -1.0)) / c) * -1.0) * b)
end
code[a_, b_, c_, d_] := N[(N[(N[(N[(N[(d / c), $MachinePrecision] * -1.0 + N[(N[(a / b), $MachinePrecision] * -1.0), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] * -1.0), $MachinePrecision] * b), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{\mathsf{fma}\left(\frac{d}{c}, -1, \frac{a}{b} \cdot -1\right)}{c} \cdot -1\right) \cdot b
\end{array}
Derivation
  1. Initial program 62.9%

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

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

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

      \[\leadsto \left(\frac{d}{{c}^{2} + {d}^{2}} + \frac{a \cdot c}{b \cdot \left({c}^{2} + {d}^{2}\right)}\right) \cdot \color{blue}{b} \]
  4. Applied rewrites58.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\frac{\mathsf{fma}\left(\frac{d}{c}, -1, \frac{a}{b} \cdot -1\right)}{c} \cdot -1\right) \cdot b \]
    10. lower-/.f6444.3

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

    \[\leadsto \left(\frac{\mathsf{fma}\left(\frac{d}{c}, -1, \frac{a}{b} \cdot -1\right)}{c} \cdot -1\right) \cdot b \]
  8. Add Preprocessing

Reproduce

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