Average Error: 26.0 → 16.8
Time: 42.1s
Precision: 64
Internal Precision: 128
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{1}{\sqrt{d^2 + c^2}^*}}{\frac{\sqrt{d^2 + c^2}^*}{b \cdot c - a \cdot d}}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.0
Target0.5
Herbie16.8
\[\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.0

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Simplified26.0

    \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
  3. Using strategy rm
  4. Applied *-un-lft-identity26.0

    \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{(d \cdot d + \left(c \cdot c\right))_*}\]
  5. Applied associate-/l*26.1

    \[\leadsto \color{blue}{\frac{1}{\frac{(d \cdot d + \left(c \cdot c\right))_*}{b \cdot c - a \cdot d}}}\]
  6. Using strategy rm
  7. Applied *-un-lft-identity26.1

    \[\leadsto \frac{1}{\frac{(d \cdot d + \left(c \cdot c\right))_*}{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}}\]
  8. Applied add-sqr-sqrt26.1

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}{1} \cdot \frac{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}{b \cdot c - a \cdot d}}}\]
  10. Applied associate-/r*26.0

    \[\leadsto \color{blue}{\frac{\frac{1}{\frac{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}{1}}}{\frac{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}{b \cdot c - a \cdot d}}}\]
  11. Using strategy rm
  12. Applied fma-udef26.0

    \[\leadsto \frac{\frac{1}{\frac{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}{1}}}{\frac{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}{b \cdot c - a \cdot d}}\]
  13. Applied hypot-def26.0

    \[\leadsto \frac{\frac{1}{\frac{\color{blue}{\sqrt{d^2 + c^2}^*}}{1}}}{\frac{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}{b \cdot c - a \cdot d}}\]
  14. Using strategy rm
  15. Applied fma-udef26.0

    \[\leadsto \frac{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{1}}}{\frac{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}{b \cdot c - a \cdot d}}\]
  16. Applied hypot-def16.8

    \[\leadsto \frac{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{1}}}{\frac{\color{blue}{\sqrt{d^2 + c^2}^*}}{b \cdot c - a \cdot d}}\]
  17. Final simplification16.8

    \[\leadsto \frac{\frac{1}{\sqrt{d^2 + c^2}^*}}{\frac{\sqrt{d^2 + c^2}^*}{b \cdot c - a \cdot d}}\]

Reproduce

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

  :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))))