Average Error: 26.1 → 0.4
Time: 1.4m
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)}{\frac{\frac{\mathsf{hypot}\left(c, d\right)}{1}}{\sqrt[3]{1}}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)}{\frac{\frac{\mathsf{hypot}\left(c, d\right)}{1}}{\sqrt[3]{1}}}
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) {
	return ((double) (((double) (((double) (((double) cbrt(1.0)) * ((double) cbrt(1.0)))) * ((double) (((double) (b / ((double) (((double) hypot(c, d)) / c)))) - ((double) (a / ((double) (((double) hypot(c, d)) / d)))))))) / ((double) (((double) (((double) hypot(c, d)) / 1.0)) / ((double) cbrt(1.0))))));
}

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

Original26.1
Target0.3
Herbie0.4
\[\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. Initial program 26.1

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt26.1

    \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
  4. Applied *-un-lft-identity26.1

    \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
  5. Applied times-frac26.1

    \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
  6. Simplified26.1

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

    \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{1}} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right) \cdot 1}}\]
  8. Using strategy rm
  9. Applied div-sub16.7

    \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{1}} \cdot \color{blue}{\left(\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right) \cdot 1} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)}\]
  10. Simplified9.2

    \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{1}} \cdot \left(\color{blue}{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)\]
  11. Simplified0.6

    \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{1}} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \color{blue}{\frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}}\right)\]
  12. Using strategy rm
  13. Applied add-cube-cbrt0.6

    \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\mathsf{hypot}\left(c, d\right)}{1}} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)\]
  14. Applied associate-/l*0.6

    \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\frac{\mathsf{hypot}\left(c, d\right)}{1}}{\sqrt[3]{1}}}} \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)\]
  15. Applied associate-*l/0.4

    \[\leadsto \color{blue}{\frac{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)}{\frac{\frac{\mathsf{hypot}\left(c, d\right)}{1}}{\sqrt[3]{1}}}}\]
  16. Final simplification0.4

    \[\leadsto \frac{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \left(\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}} - \frac{a}{\frac{\mathsf{hypot}\left(c, d\right)}{d}}\right)}{\frac{\frac{\mathsf{hypot}\left(c, d\right)}{1}}{\sqrt[3]{1}}}\]

Reproduce

herbie shell --seed 2020113 +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))))