Complex division, real part

Percentage Accurate: 62.5% → 83.1%
Time: 9.2s
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: 62.5% 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.1% accurate, 0.6× 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)}\\ \mathbf{if}\;d \leq -9.8 \cdot 10^{+101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -7.4 \cdot 10^{-76}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-126}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+38}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{1}{\frac{d}{a}}, b\right)}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma a c (* d b)) (fma c c (* d d)))))
   (if (<= d -9.8e+101)
     (/ (fma c (/ a d) b) d)
     (if (<= d -7.4e-76)
       t_0
       (if (<= d 5.8e-126)
         (/ (+ a (/ (* d b) c)) c)
         (if (<= d 3.3e+38) t_0 (/ (fma c (/ 1.0 (/ d a)) b) d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(a, c, (d * b)) / fma(c, c, (d * d));
	double tmp;
	if (d <= -9.8e+101) {
		tmp = fma(c, (a / d), b) / d;
	} else if (d <= -7.4e-76) {
		tmp = t_0;
	} else if (d <= 5.8e-126) {
		tmp = (a + ((d * b) / c)) / c;
	} else if (d <= 3.3e+38) {
		tmp = t_0;
	} else {
		tmp = fma(c, (1.0 / (d / a)), b) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d)))
	tmp = 0.0
	if (d <= -9.8e+101)
		tmp = Float64(fma(c, Float64(a / d), b) / d);
	elseif (d <= -7.4e-76)
		tmp = t_0;
	elseif (d <= 5.8e-126)
		tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c);
	elseif (d <= 3.3e+38)
		tmp = t_0;
	else
		tmp = Float64(fma(c, Float64(1.0 / Float64(d / a)), b) / d);
	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]}, If[LessEqual[d, -9.8e+101], N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -7.4e-76], t$95$0, If[LessEqual[d, 5.8e-126], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.3e+38], t$95$0, N[(N[(c * N[(1.0 / N[(d / a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\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)}\\
\mathbf{if}\;d \leq -9.8 \cdot 10^{+101}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\

\mathbf{elif}\;d \leq -7.4 \cdot 10^{-76}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 3.3 \cdot 10^{+38}:\\
\;\;\;\;t\_0\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    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}{c \cdot \frac{a}{d}} + b}{d} \]
      5. lower-fma.f64N/A

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

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

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

    if -9.79999999999999965e101 < d < -7.40000000000000023e-76 or 5.79999999999999975e-126 < d < 3.2999999999999999e38

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

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

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

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      7. lift-/.f6482.4

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{c \cdot c} + d \cdot d} \]
      13. lower-fma.f6482.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 rewrites82.4%

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

    if -7.40000000000000023e-76 < d < 5.79999999999999975e-126

    1. Initial program 71.3%

      \[\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 + \left(-1 \cdot \frac{a \cdot {d}^{2}}{{c}^{2}} + \frac{b \cdot d}{c}\right)}{c}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{a + \frac{\color{blue}{b \cdot d}}{c}}{c} \]
    7. Step-by-step derivation
      1. lower-*.f6494.1

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

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

    if 3.2999999999999999e38 < d

    1. Initial program 54.8%

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

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

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      7. lift-/.f6454.8

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    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}{c \cdot \frac{a}{d}} + b}{d} \]
      5. lower-fma.f64N/A

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.8 \cdot 10^{+101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -7.4 \cdot 10^{-76}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-126}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+38}:\\ \;\;\;\;\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(c, \frac{1}{\frac{d}{a}}, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 82.9% 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)}\\ \mathbf{if}\;d \leq -9.8 \cdot 10^{+101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -7.4 \cdot 10^{-76}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-126}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+38}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma a c (* d b)) (fma c c (* d d)))))
   (if (<= d -9.8e+101)
     (/ (fma c (/ a d) b) d)
     (if (<= d -7.4e-76)
       t_0
       (if (<= d 5.8e-126)
         (/ (+ a (/ (* d b) c)) c)
         (if (<= d 3.3e+38) t_0 (/ (fma a (/ c d) b) d)))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(a, c, (d * b)) / fma(c, c, (d * d));
	double tmp;
	if (d <= -9.8e+101) {
		tmp = fma(c, (a / d), b) / d;
	} else if (d <= -7.4e-76) {
		tmp = t_0;
	} else if (d <= 5.8e-126) {
		tmp = (a + ((d * b) / c)) / c;
	} else if (d <= 3.3e+38) {
		tmp = t_0;
	} else {
		tmp = fma(a, (c / d), b) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d)))
	tmp = 0.0
	if (d <= -9.8e+101)
		tmp = Float64(fma(c, Float64(a / d), b) / d);
	elseif (d <= -7.4e-76)
		tmp = t_0;
	elseif (d <= 5.8e-126)
		tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c);
	elseif (d <= 3.3e+38)
		tmp = t_0;
	else
		tmp = Float64(fma(a, Float64(c / d), b) / d);
	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]}, If[LessEqual[d, -9.8e+101], N[(N[(c * N[(a / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, -7.4e-76], t$95$0, If[LessEqual[d, 5.8e-126], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 3.3e+38], t$95$0, N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]]]]]]
\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)}\\
\mathbf{if}\;d \leq -9.8 \cdot 10^{+101}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\

\mathbf{elif}\;d \leq -7.4 \cdot 10^{-76}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 3.3 \cdot 10^{+38}:\\
\;\;\;\;t\_0\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    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}{c \cdot \frac{a}{d}} + b}{d} \]
      5. lower-fma.f64N/A

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

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

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

    if -9.79999999999999965e101 < d < -7.40000000000000023e-76 or 5.79999999999999975e-126 < d < 3.2999999999999999e38

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

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

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

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      7. lift-/.f6482.4

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{c \cdot c} + d \cdot d} \]
      13. lower-fma.f6482.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 rewrites82.4%

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

    if -7.40000000000000023e-76 < d < 5.79999999999999975e-126

    1. Initial program 71.3%

      \[\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 + \left(-1 \cdot \frac{a \cdot {d}^{2}}{{c}^{2}} + \frac{b \cdot d}{c}\right)}{c}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{a + \frac{\color{blue}{b \cdot d}}{c}}{c} \]
    7. Step-by-step derivation
      1. lower-*.f6494.1

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

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

    if 3.2999999999999999e38 < d

    1. Initial program 54.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.8 \cdot 10^{+101}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -7.4 \cdot 10^{-76}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;d \leq 5.8 \cdot 10^{-126}:\\ \;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\ \mathbf{elif}\;d \leq 3.3 \cdot 10^{+38}:\\ \;\;\;\;\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(a, \frac{c}{d}, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 64.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3.4 \cdot 10^{-41}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-118}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+105}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, d, 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 -3.4e-41)
   (/ b d)
   (if (<= d 2.6e-118)
     (/ a c)
     (if (<= d 8e+105) (/ (fma b d (* c a)) (* d d)) (/ b d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -3.4e-41) {
		tmp = b / d;
	} else if (d <= 2.6e-118) {
		tmp = a / c;
	} else if (d <= 8e+105) {
		tmp = fma(b, d, (c * a)) / (d * d);
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -3.4e-41)
		tmp = Float64(b / d);
	elseif (d <= 2.6e-118)
		tmp = Float64(a / c);
	elseif (d <= 8e+105)
		tmp = Float64(fma(b, d, Float64(c * a)) / Float64(d * d));
	else
		tmp = Float64(b / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.4e-41], N[(b / d), $MachinePrecision], If[LessEqual[d, 2.6e-118], N[(a / c), $MachinePrecision], If[LessEqual[d, 8e+105], N[(N[(b * d + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.4 \cdot 10^{-41}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 8 \cdot 10^{+105}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, 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 < -3.3999999999999998e-41 or 7.9999999999999995e105 < d

    1. Initial program 55.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-/.f6475.8

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

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

    if -3.3999999999999998e-41 < d < 2.6e-118

    1. Initial program 72.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-/.f6478.0

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Applied rewrites78.0%

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

    if 2.6e-118 < d < 7.9999999999999995e105

    1. Initial program 80.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-/.f6464.4

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.4 \cdot 10^{-41}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-118}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+105}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 64.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.4 \cdot 10^{-41}:\\
\;\;\;\;\frac{b}{d}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.3999999999999998e-41 or 7.9999999999999995e105 < d

    1. Initial program 55.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-/.f6475.8

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

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

    if -3.3999999999999998e-41 < d < 2.6e-118

    1. Initial program 72.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-/.f6478.0

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Applied rewrites78.0%

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

    if 2.6e-118 < d < 7.9999999999999995e105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.4 \cdot 10^{-41}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-118}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+105}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.3% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -6.8e10

    1. Initial program 54.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 \frac{\color{blue}{a \cdot c} + b \cdot d}{c \cdot c + d \cdot d} \]
      2. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    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}{c \cdot \frac{a}{d}} + b}{d} \]
      5. lower-fma.f64N/A

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

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

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

    if -6.8e10 < d < 2.0999999999999999e-81

    1. Initial program 74.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 + \left(-1 \cdot \frac{a \cdot {d}^{2}}{{c}^{2}} + \frac{b \cdot d}{c}\right)}{c}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.0999999999999999e-81 < d

    1. Initial program 60.9%

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

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

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

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

Alternative 6: 77.3% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -6.8e10

    1. Initial program 54.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 \frac{\color{blue}{a \cdot c} + b \cdot d}{c \cdot c + d \cdot d} \]
      2. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
    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}{c \cdot \frac{a}{d}} + b}{d} \]
      5. lower-fma.f64N/A

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

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

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

    if -6.8e10 < d < 2.0999999999999999e-81

    1. Initial program 74.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 + \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-/.f6487.0

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

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

    if 2.0999999999999999e-81 < d

    1. Initial program 60.9%

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

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

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

Alternative 7: 77.1% 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 -68000000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-81}:\\ \;\;\;\;\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 -68000000000.0)
     t_0
     (if (<= d 2.1e-81) (/ (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 <= -68000000000.0) {
		tmp = t_0;
	} else if (d <= 2.1e-81) {
		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 <= -68000000000.0)
		tmp = t_0;
	elseif (d <= 2.1e-81)
		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, -68000000000.0], t$95$0, If[LessEqual[d, 2.1e-81], 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 -68000000000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 2.1 \cdot 10^{-81}:\\
\;\;\;\;\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 < -6.8e10 or 2.0999999999999999e-81 < d

    1. Initial program 58.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-/.f6481.3

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

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

    if -6.8e10 < d < 2.0999999999999999e-81

    1. Initial program 74.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 + \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-/.f6487.0

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

      \[\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 8: 69.4% 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 -3.3 \cdot 10^{-41}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-118}:\\ \;\;\;\;\frac{a}{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 -3.3e-41) t_0 (if (<= d 2.6e-118) (/ 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 <= -3.3e-41) {
		tmp = t_0;
	} else if (d <= 2.6e-118) {
		tmp = 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 <= -3.3e-41)
		tmp = t_0;
	elseif (d <= 2.6e-118)
		tmp = Float64(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, -3.3e-41], t$95$0, If[LessEqual[d, 2.6e-118], N[(a / 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 -3.3 \cdot 10^{-41}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.30000000000000024e-41 or 2.6e-118 < d

    1. Initial program 61.4%

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

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

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

    if -3.30000000000000024e-41 < d < 2.6e-118

    1. Initial program 72.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-/.f6478.0

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Applied rewrites78.0%

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

Alternative 9: 62.7% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.4 \cdot 10^{-41}:\\
\;\;\;\;\frac{b}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.3999999999999998e-41 or 2.3000000000000001e-103 < d

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

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

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

    if -3.3999999999999998e-41 < d < 2.3000000000000001e-103

    1. Initial program 73.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}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6477.5

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

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

Alternative 10: 43.1% 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 65.8%

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

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

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

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