Complex division, imag part

Percentage Accurate: 61.9% → 81.0%
Time: 9.4s
Alternatives: 9
Speedup: 1.5×

Specification

?
\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{b \cdot c - a \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 9 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.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * 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 = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 81.0% accurate, 0.5× speedup?

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

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

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

\mathbf{elif}\;c \leq 1.8 \cdot 10^{-26}:\\
\;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.20000000000000002e156 or 1.8000000000000001e-26 < c

    1. Initial program 38.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
      7. lower-*.f6484.7

        \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
    5. Applied rewrites84.7%

      \[\leadsto \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}} \]
    6. Step-by-step derivation
      1. Applied rewrites88.8%

        \[\leadsto \frac{b - a \cdot \frac{d}{c}}{c} \]

      if -3.20000000000000002e156 < c < -5.1999999999999999e-76

      1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -5.1999999999999999e-76 < c < 1.8000000000000001e-26

      1. Initial program 64.4%

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

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

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

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

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

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

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

          \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
        7. lower-*.f6431.1

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

        \[\leadsto \color{blue}{\frac{b - \frac{d \cdot a}{c}}{c}} \]
      6. Step-by-step derivation
        1. Applied rewrites31.2%

          \[\leadsto \frac{b - a \cdot \frac{d}{c}}{c} \]
        2. Step-by-step derivation
          1. Applied rewrites30.3%

            \[\leadsto \frac{b - d \cdot \left(\frac{1}{c} \cdot a\right)}{c} \]
          2. Taylor expanded in c around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{\frac{\color{blue}{c \cdot b}}{d} - a}{d} \]
            17. lower-*.f6482.8

              \[\leadsto \frac{\frac{\color{blue}{c \cdot b}}{d} - a}{d} \]
          4. Applied rewrites82.8%

            \[\leadsto \color{blue}{\frac{\frac{c \cdot b}{d} - a}{d}} \]
        3. Recombined 3 regimes into one program.
        4. Final simplification85.3%

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

        Alternative 2: 66.0% accurate, 0.7× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{+156}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-149}:\\ \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-26}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{elif}\;c \leq 7.5 \cdot 10^{+92}:\\ \;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
        (FPCore (a b c d)
         :precision binary64
         (if (<= c -3.2e+156)
           (/ b c)
           (if (<= c -2.5e-149)
             (* b (/ c (fma d d (* c c))))
             (if (<= c 1.25e-26)
               (/ a (- d))
               (if (<= c 7.5e+92) (/ (- (* c b) (* a d)) (* c c)) (/ b c))))))
        double code(double a, double b, double c, double d) {
        	double tmp;
        	if (c <= -3.2e+156) {
        		tmp = b / c;
        	} else if (c <= -2.5e-149) {
        		tmp = b * (c / fma(d, d, (c * c)));
        	} else if (c <= 1.25e-26) {
        		tmp = a / -d;
        	} else if (c <= 7.5e+92) {
        		tmp = ((c * b) - (a * d)) / (c * c);
        	} else {
        		tmp = b / c;
        	}
        	return tmp;
        }
        
        function code(a, b, c, d)
        	tmp = 0.0
        	if (c <= -3.2e+156)
        		tmp = Float64(b / c);
        	elseif (c <= -2.5e-149)
        		tmp = Float64(b * Float64(c / fma(d, d, Float64(c * c))));
        	elseif (c <= 1.25e-26)
        		tmp = Float64(a / Float64(-d));
        	elseif (c <= 7.5e+92)
        		tmp = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(c * c));
        	else
        		tmp = Float64(b / c);
        	end
        	return tmp
        end
        
        code[a_, b_, c_, d_] := If[LessEqual[c, -3.2e+156], N[(b / c), $MachinePrecision], If[LessEqual[c, -2.5e-149], N[(b * N[(c / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.25e-26], N[(a / (-d)), $MachinePrecision], If[LessEqual[c, 7.5e+92], N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / c), $MachinePrecision]]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;c \leq -3.2 \cdot 10^{+156}:\\
        \;\;\;\;\frac{b}{c}\\
        
        \mathbf{elif}\;c \leq -2.5 \cdot 10^{-149}:\\
        \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
        
        \mathbf{elif}\;c \leq 1.25 \cdot 10^{-26}:\\
        \;\;\;\;\frac{a}{-d}\\
        
        \mathbf{elif}\;c \leq 7.5 \cdot 10^{+92}:\\
        \;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c}\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{b}{c}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if c < -3.20000000000000002e156 or 7.49999999999999946e92 < c

          1. Initial program 35.4%

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

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

              \[\leadsto \color{blue}{\frac{b}{c}} \]
          5. Applied rewrites75.3%

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

          if -3.20000000000000002e156 < c < -2.49999999999999984e-149

          1. Initial program 73.4%

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

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

              \[\leadsto \color{blue}{\frac{b}{c}} \]
          5. Applied rewrites39.5%

            \[\leadsto \color{blue}{\frac{b}{c}} \]
          6. Taylor expanded in b around inf

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

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

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

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

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

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

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

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

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

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

          if -2.49999999999999984e-149 < c < 1.25000000000000005e-26

          1. Initial program 73.1%

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

            \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
          4. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)} \]
            2. distribute-neg-frac2N/A

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

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

              \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
            5. mul-1-negN/A

              \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
            6. lower-neg.f6469.3

              \[\leadsto \frac{a}{\color{blue}{-d}} \]
          5. Applied rewrites69.3%

            \[\leadsto \color{blue}{\frac{a}{-d}} \]

          if 1.25000000000000005e-26 < c < 7.49999999999999946e92

          1. Initial program 75.7%

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

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

              \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c}} \]
            2. lower-*.f6452.7

              \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c}} \]
          5. Applied rewrites52.7%

            \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c}} \]
        3. Recombined 4 regimes into one program.
        4. Final simplification66.0%

          \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{+156}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-149}:\\ \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-26}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{elif}\;c \leq 7.5 \cdot 10^{+92}:\\ \;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
        5. 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{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \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))
           (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
           (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
        double code(double a, double b, double c, double d) {
        	double tmp;
        	if (fabs(d) < fabs(c)) {
        		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
        	} else {
        		tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)))
            else
                tmp = (-a + (b * (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 = (b - (a * (d / c))) / (c + (d * (d / c)));
        	} else {
        		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
        	}
        	return tmp;
        }
        
        def code(a, b, c, d):
        	tmp = 0
        	if math.fabs(d) < math.fabs(c):
        		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
        	else:
        		tmp = (-a + (b * (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(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
        	else
        		tmp = Float64(Float64(Float64(-a) + Float64(b * 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 = (b - (a * (d / c))) / (c + (d * (d / c)));
        	else
        		tmp = (-a + (b * (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[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * 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{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
        
        
        \end{array}
        \end{array}
        

        Reproduce

        ?
        herbie shell --seed 2024230 
        (FPCore (a b c d)
          :name "Complex division, imag part"
          :precision binary64
        
          :alt
          (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
        
          (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))