Average Error: 27.0 → 8.0
Time: 4.2s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -6.5063855279161376 \cdot 10^{152} \lor \neg \left(d \le 2.9116788974845384 \cdot 10^{85}\right):\\ \;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \le -6.5063855279161376 \cdot 10^{152} \lor \neg \left(d \le 2.9116788974845384 \cdot 10^{85}\right):\\
\;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{d}}\\

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

\end{array}
double code(double a, double b, double c, double d) {
	return ((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d))))));
}
double code(double a, double b, double c, double d) {
	double VAR;
	if (((d <= -6.506385527916138e+152) || !(d <= 2.9116788974845384e+85))) {
		VAR = ((double) (((double) (b / ((double) (((double) fma(c, c, ((double) (d * d)))) / c)))) - ((double) (a / ((double) (((double) hypot(c, d)) * ((double) (((double) hypot(c, d)) / d))))))));
	} else {
		VAR = ((double) (((double) (b / ((double) (((double) hypot(c, d)) * ((double) (((double) hypot(c, d)) / c)))))) - ((double) (a / ((double) (((double) fma(c, c, ((double) (d * d)))) / d))))));
	}
	return VAR;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original27.0
Target0.5
Herbie8.0
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \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}\]

Derivation

  1. Split input into 2 regimes
  2. if d < -6.506385527916138e+152 or 2.9116788974845384e+85 < d

    1. Initial program 42.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub42.3

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Simplified42.2

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

      \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \color{blue}{\frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity39.5

      \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\color{blue}{1 \cdot d}}}\]
    8. Applied add-sqr-sqrt39.5

      \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\frac{\color{blue}{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot \sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}}{1 \cdot d}}\]
    9. Applied times-frac39.5

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

      \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}{d}}\]
    11. Simplified11.9

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

    if -6.506385527916138e+152 < d < 2.9116788974845384e+85

    1. Initial program 19.7

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub19.7

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

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

      \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \color{blue}{\frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity16.4

      \[\leadsto \frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\color{blue}{1 \cdot c}}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\]
    8. Applied add-sqr-sqrt16.4

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

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

      \[\leadsto \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\sqrt{\mathsf{fma}\left(c, c, d \cdot d\right)}}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\]
    11. Simplified6.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le -6.5063855279161376 \cdot 10^{152} \lor \neg \left(d \le 2.9116788974845384 \cdot 10^{85}\right):\\ \;\;\;\;\frac{b}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{c}} - \frac{a}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right) \cdot \frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{d}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020123 +o rules:numerics
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :herbie-target
  (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))))