Complex division, real part

Percentage Accurate: 62.2% → 83.8%
Time: 7.1s
Alternatives: 11
Speedup: 1.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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.2% 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));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 83.8% accurate, 0.6× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.2800000000000001e154 or 5.4999999999999998e111 < d

    1. Initial program 40.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.2800000000000001e154 < d < -1.8500000000000001e-66

    1. Initial program 71.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.8500000000000001e-66 < d < 1.14e-58

    1. Initial program 66.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.14e-58 < d < 5.4999999999999998e111

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.28 \cdot 10^{+154}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{elif}\;d \leq -1.85 \cdot 10^{-66}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}, \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot c\right)\\ \mathbf{elif}\;d \leq 1.14 \cdot 10^{-58}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{+111}:\\ \;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{\mathsf{fma}\left(d, b, c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.8% accurate, 0.6× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.5000000000000001e91 or 5.4999999999999998e111 < d

    1. Initial program 43.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.5000000000000001e91 < d < -1.8500000000000001e-66

    1. Initial program 76.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.8500000000000001e-66 < d < 1.14e-58

    1. Initial program 66.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.14e-58 < d < 5.4999999999999998e111

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 82.8% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d \leq -1.85 \cdot 10^{-66}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{+106}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.5000000000000001e91 or 4.4999999999999997e106 < d

    1. Initial program 44.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.5000000000000001e91 < d < -1.8500000000000001e-66 or 1.20000000000000003e-57 < d < 4.4999999999999997e106

    1. Initial program 80.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.8500000000000001e-66 < d < 1.20000000000000003e-57

    1. Initial program 66.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 71.6% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -8e104 or 2.1000000000000002e152 < c

    1. Initial program 35.6%

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

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

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Applied rewrites84.2%

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

    if -8e104 < c < 135

    1. Initial program 74.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 135 < c < 2.1000000000000002e152

    1. Initial program 68.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 64.8% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.5e61 or 1.7999999999999998e110 < d

    1. Initial program 46.8%

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

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

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites74.6%

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

    if -1.5e61 < d < 6.49999999999999968e-49

    1. Initial program 68.2%

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

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

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

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

    if 6.49999999999999968e-49 < d < 1.7999999999999998e110

    1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 65.4% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.5e61 or 2.5499999999999999e138 < d

    1. Initial program 46.0%

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

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

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites75.2%

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

    if -1.5e61 < d < 5.59999999999999995e-49

    1. Initial program 68.2%

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

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

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

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

    if 5.59999999999999995e-49 < d < 2.5499999999999999e138

    1. Initial program 79.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.5% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.55e61 or 1.99999999999999989e34 < d

    1. Initial program 52.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.55e61 < d < 1.99999999999999989e34

    1. Initial program 69.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 75.7% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -9.79999999999999965e101 or 2.65000000000000009e-46 < c

    1. Initial program 46.5%

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

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

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

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

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

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

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

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

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

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

    if -9.79999999999999965e101 < c < 2.65000000000000009e-46

    1. Initial program 75.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 74.7% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -9.79999999999999965e101 or 2.65000000000000009e-46 < c

    1. Initial program 46.5%

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

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

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

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

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

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

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

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

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

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

    if -9.79999999999999965e101 < c < 2.65000000000000009e-46

    1. Initial program 75.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 64.2% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{+61}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2 \cdot 10^{+34}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.5e+61) (/ b d) (if (<= d 2e+34) (/ a c) (/ b d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.5e+61) {
		tmp = b / d;
	} else if (d <= 2e+34) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= (-1.5d+61)) then
        tmp = b / d
    else if (d <= 2d+34) then
        tmp = a / c
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.5e+61) {
		tmp = b / d;
	} else if (d <= 2e+34) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -1.5e+61:
		tmp = b / d
	elif d <= 2e+34:
		tmp = a / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -1.5e+61)
		tmp = Float64(b / d);
	elseif (d <= 2e+34)
		tmp = Float64(a / c);
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -1.5e+61)
		tmp = b / d;
	elseif (d <= 2e+34)
		tmp = a / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.5e+61], N[(b / d), $MachinePrecision], If[LessEqual[d, 2e+34], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.5e61 or 1.99999999999999989e34 < d

    1. Initial program 52.3%

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

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

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

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

    if -1.5e61 < d < 1.99999999999999989e34

    1. Initial program 69.5%

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

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

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

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

Alternative 11: 43.7% accurate, 3.2× speedup?

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

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

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

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]
  5. Applied rewrites45.2%

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

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

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

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

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


\end{array}
\end{array}

Reproduce

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

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

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