Complex division, real part

Percentage Accurate: 61.8% → 85.3%
Time: 9.6s
Alternatives: 10
Speedup: 1.6×

Specification

?
\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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 10 alternatives:

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

Initial Program: 61.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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: 85.3% accurate, 0.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4.30000000000000002e-23 or 5.2e10 < a

    1. Initial program 56.3%

      \[\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. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-1}{\mathsf{fma}\left(\frac{\mathsf{neg}\left(d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}, d, \mathsf{neg}\left(\color{blue}{\frac{c}{a}}\right)\right)} \]
    10. Step-by-step derivation
      1. lower-/.f6487.5

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

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

    if -4.30000000000000002e-23 < a < 5.2e10

    1. Initial program 68.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. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-1}{\mathsf{fma}\left(\frac{1}{\mathsf{fma}\left(a, c, b \cdot d\right)} \cdot \left(\mathsf{neg}\left(c\right)\right), c, \frac{\color{blue}{\mathsf{neg}\left(d\right)}}{b}\right)} \]
      4. lower-neg.f6491.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -4.3 \cdot 10^{-23}:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(\frac{-d}{\mathsf{fma}\left(a, c, d \cdot b\right)}, d, -\frac{c}{a}\right)}\\ \mathbf{elif}\;a \leq 52000000000:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(c \cdot \frac{-1}{\mathsf{fma}\left(a, c, d \cdot b\right)}, c, -\frac{d}{b}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(\frac{-d}{\mathsf{fma}\left(a, c, d \cdot b\right)}, d, -\frac{c}{a}\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.9% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;c \leq -5.5 \cdot 10^{-62}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 5.9 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.10000000000000003e151 or 5.9000000000000001e119 < c

    1. Initial program 30.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 + \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. associate-/l*N/A

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

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

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

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

    if -1.10000000000000003e151 < c < -5.50000000000000022e-62 or 9.40000000000000007e-94 < c < 5.9000000000000001e119

    1. Initial program 79.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. lift-*.f64N/A

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

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

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

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

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

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

    if -5.50000000000000022e-62 < c < 9.40000000000000007e-94

    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 d around inf

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{b + \frac{-1 \cdot \frac{b \cdot {c}^{2}}{d} + a \cdot c}{d}}{d}} \]
    5. Applied rewrites92.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.1 \cdot 10^{+151}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;c \leq -5.5 \cdot 10^{-62}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 9.4 \cdot 10^{-94}:\\ \;\;\;\;\frac{b + \frac{\mathsf{fma}\left(b, -\frac{c \cdot c}{d}, a \cdot c\right)}{d}}{d}\\ \mathbf{elif}\;c \leq 5.9 \cdot 10^{+119}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.1% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;c \leq -2.35 \cdot 10^{-66}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 5.9 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.10000000000000003e151 or 5.9000000000000001e119 < c

    1. Initial program 30.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 + \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. associate-/l*N/A

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

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

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

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

    if -1.10000000000000003e151 < c < -2.35e-66 or 9.40000000000000007e-94 < c < 5.9000000000000001e119

    1. Initial program 79.6%

      \[\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. lift-*.f64N/A

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

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

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

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

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

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

    if -2.35e-66 < c < 9.40000000000000007e-94

    1. Initial program 69.1%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. 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. associate-/l*N/A

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

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

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

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

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

Alternative 4: 76.5% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.1500000000000001e99 or 2.25e15 < d

    1. Initial program 51.0%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. 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. associate-/l*N/A

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

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

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

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

    if -1.1500000000000001e99 < d < 2.25e15

    1. Initial program 70.1%

      \[\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. associate-/l*N/A

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

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

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

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

Alternative 5: 75.6% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.19999999999999982e-60 or 2.49999999999999981e-25 < c

    1. Initial program 56.6%

      \[\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. div-invN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-1}{\color{blue}{\frac{a \cdot c - b \cdot d}{\left(a \cdot c\right) \cdot \left(a \cdot c\right) - \left(b \cdot d\right) \cdot \left(b \cdot d\right)} \cdot \left(\mathsf{neg}\left(\left(c \cdot c + d \cdot d\right)\right)\right)}} \]
    4. Applied rewrites56.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{c + \frac{\color{blue}{d \cdot d}}{c}} \]
      5. lower-*.f6471.7

        \[\leadsto \frac{a}{c + \frac{\color{blue}{d \cdot d}}{c}} \]
    9. Applied rewrites71.7%

      \[\leadsto \color{blue}{\frac{a}{c + \frac{d \cdot d}{c}}} \]
    10. Step-by-step derivation
      1. Applied rewrites73.6%

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

      if -4.19999999999999982e-60 < c < 2.49999999999999981e-25

      1. Initial program 70.2%

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

        \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
      4. 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. associate-/l*N/A

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

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

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

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

    Alternative 6: 67.7% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{\mathsf{fma}\left(\frac{d}{c}, d, c\right)}\\ \mathbf{if}\;c \leq -2.1 \cdot 10^{-65}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-109}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (let* ((t_0 (/ a (fma (/ d c) d c))))
       (if (<= c -2.1e-65) t_0 (if (<= c 1.25e-109) (/ b d) t_0))))
    double code(double a, double b, double c, double d) {
    	double t_0 = a / fma((d / c), d, c);
    	double tmp;
    	if (c <= -2.1e-65) {
    		tmp = t_0;
    	} else if (c <= 1.25e-109) {
    		tmp = b / d;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    function code(a, b, c, d)
    	t_0 = Float64(a / fma(Float64(d / c), d, c))
    	tmp = 0.0
    	if (c <= -2.1e-65)
    		tmp = t_0;
    	elseif (c <= 1.25e-109)
    		tmp = Float64(b / d);
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / N[(N[(d / c), $MachinePrecision] * d + c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.1e-65], t$95$0, If[LessEqual[c, 1.25e-109], N[(b / d), $MachinePrecision], t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{a}{\mathsf{fma}\left(\frac{d}{c}, d, c\right)}\\
    \mathbf{if}\;c \leq -2.1 \cdot 10^{-65}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;c \leq 1.25 \cdot 10^{-109}:\\
    \;\;\;\;\frac{b}{d}\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if c < -2.10000000000000003e-65 or 1.25000000000000005e-109 < c

      1. Initial program 59.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. div-invN/A

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{-1}{\color{blue}{\frac{a \cdot c - b \cdot d}{\left(a \cdot c\right) \cdot \left(a \cdot c\right) - \left(b \cdot d\right) \cdot \left(b \cdot d\right)} \cdot \left(\mathsf{neg}\left(\left(c \cdot c + d \cdot d\right)\right)\right)}} \]
      4. Applied rewrites58.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{a}{c + \frac{d \cdot d}{c}}} \]
      10. Step-by-step derivation
        1. Applied rewrites72.2%

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

        if -2.10000000000000003e-65 < c < 1.25000000000000005e-109

        1. Initial program 68.6%

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

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

          \[\leadsto \color{blue}{\frac{b}{d}} \]
      11. Recombined 2 regimes into one program.
      12. Add Preprocessing

      Alternative 7: 64.3% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.6 \cdot 10^{+100}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -7.2 \cdot 10^{-65}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{c \cdot c}\\ \mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (<= c -2.6e+100)
         (/ a c)
         (if (<= c -7.2e-65)
           (/ (fma d b (* a c)) (* c c))
           (if (<= c 4.8e-42) (/ b d) (/ a c)))))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if (c <= -2.6e+100) {
      		tmp = a / c;
      	} else if (c <= -7.2e-65) {
      		tmp = fma(d, b, (a * c)) / (c * c);
      	} else if (c <= 4.8e-42) {
      		tmp = b / d;
      	} else {
      		tmp = a / c;
      	}
      	return tmp;
      }
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if (c <= -2.6e+100)
      		tmp = Float64(a / c);
      	elseif (c <= -7.2e-65)
      		tmp = Float64(fma(d, b, Float64(a * c)) / Float64(c * c));
      	elseif (c <= 4.8e-42)
      		tmp = Float64(b / d);
      	else
      		tmp = Float64(a / c);
      	end
      	return tmp
      end
      
      code[a_, b_, c_, d_] := If[LessEqual[c, -2.6e+100], N[(a / c), $MachinePrecision], If[LessEqual[c, -7.2e-65], N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.8e-42], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;c \leq -2.6 \cdot 10^{+100}:\\
      \;\;\;\;\frac{a}{c}\\
      
      \mathbf{elif}\;c \leq -7.2 \cdot 10^{-65}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{c \cdot c}\\
      
      \mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\
      \;\;\;\;\frac{b}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{a}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if c < -2.6000000000000002e100 or 4.80000000000000005e-42 < c

        1. Initial program 51.2%

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

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

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

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

        if -2.6000000000000002e100 < c < -7.1999999999999996e-65

        1. Initial program 75.9%

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

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

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

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

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

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

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

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

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

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

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

        if -7.1999999999999996e-65 < c < 4.80000000000000005e-42

        1. Initial program 70.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}} \]
        4. Step-by-step derivation
          1. lower-/.f6471.1

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

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

      Alternative 8: 63.5% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -8 \cdot 10^{+150}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{-65}:\\ \;\;\;\;\frac{a \cdot c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (<= c -8e+150)
         (/ a c)
         (if (<= c -2.1e-65)
           (/ (* a c) (fma d d (* c c)))
           (if (<= c 4.8e-42) (/ b d) (/ a c)))))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if (c <= -8e+150) {
      		tmp = a / c;
      	} else if (c <= -2.1e-65) {
      		tmp = (a * c) / fma(d, d, (c * c));
      	} else if (c <= 4.8e-42) {
      		tmp = b / d;
      	} else {
      		tmp = a / c;
      	}
      	return tmp;
      }
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if (c <= -8e+150)
      		tmp = Float64(a / c);
      	elseif (c <= -2.1e-65)
      		tmp = Float64(Float64(a * c) / fma(d, d, Float64(c * c)));
      	elseif (c <= 4.8e-42)
      		tmp = Float64(b / d);
      	else
      		tmp = Float64(a / c);
      	end
      	return tmp
      end
      
      code[a_, b_, c_, d_] := If[LessEqual[c, -8e+150], N[(a / c), $MachinePrecision], If[LessEqual[c, -2.1e-65], N[(N[(a * c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.8e-42], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;c \leq -8 \cdot 10^{+150}:\\
      \;\;\;\;\frac{a}{c}\\
      
      \mathbf{elif}\;c \leq -2.1 \cdot 10^{-65}:\\
      \;\;\;\;\frac{a \cdot c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
      
      \mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\
      \;\;\;\;\frac{b}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{a}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if c < -7.99999999999999985e150 or 4.80000000000000005e-42 < c

        1. Initial program 46.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-/.f6472.3

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

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

        if -7.99999999999999985e150 < c < -2.10000000000000003e-65

        1. Initial program 78.8%

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

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

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

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

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

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

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

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

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

        if -2.10000000000000003e-65 < c < 4.80000000000000005e-42

        1. Initial program 70.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}} \]
        4. Step-by-step derivation
          1. lower-/.f6471.1

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

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

      Alternative 9: 63.5% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -3.7 \cdot 10^{+14}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (<= c -3.7e+14) (/ a c) (if (<= c 4.8e-42) (/ b d) (/ a c))))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if (c <= -3.7e+14) {
      		tmp = a / c;
      	} else if (c <= 4.8e-42) {
      		tmp = b / d;
      	} else {
      		tmp = a / c;
      	}
      	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 (c <= (-3.7d+14)) then
              tmp = a / c
          else if (c <= 4.8d-42) then
              tmp = b / d
          else
              tmp = a / c
          end if
          code = tmp
      end function
      
      public static double code(double a, double b, double c, double d) {
      	double tmp;
      	if (c <= -3.7e+14) {
      		tmp = a / c;
      	} else if (c <= 4.8e-42) {
      		tmp = b / d;
      	} else {
      		tmp = a / c;
      	}
      	return tmp;
      }
      
      def code(a, b, c, d):
      	tmp = 0
      	if c <= -3.7e+14:
      		tmp = a / c
      	elif c <= 4.8e-42:
      		tmp = b / d
      	else:
      		tmp = a / c
      	return tmp
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if (c <= -3.7e+14)
      		tmp = Float64(a / c);
      	elseif (c <= 4.8e-42)
      		tmp = Float64(b / d);
      	else
      		tmp = Float64(a / c);
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b, c, d)
      	tmp = 0.0;
      	if (c <= -3.7e+14)
      		tmp = a / c;
      	elseif (c <= 4.8e-42)
      		tmp = b / d;
      	else
      		tmp = a / c;
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_, c_, d_] := If[LessEqual[c, -3.7e+14], N[(a / c), $MachinePrecision], If[LessEqual[c, 4.8e-42], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;c \leq -3.7 \cdot 10^{+14}:\\
      \;\;\;\;\frac{a}{c}\\
      
      \mathbf{elif}\;c \leq 4.8 \cdot 10^{-42}:\\
      \;\;\;\;\frac{b}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{a}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if c < -3.7e14 or 4.80000000000000005e-42 < c

        1. Initial program 53.4%

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

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

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

        if -3.7e14 < c < 4.80000000000000005e-42

        1. Initial program 73.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-/.f6468.2

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

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

      Alternative 10: 41.8% 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 62.4%

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

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

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

      Developer Target 1: 99.3% 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 2024233 
      (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))))