Average Error: 26.5 → 13.6
Time: 5.1m
Precision: 64
Internal Precision: 128
\[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -1.586349612154054 \cdot 10^{+218}:\\ \;\;\;\;\frac{-x.im}{\sqrt{y.re^2 + y.im^2}^*}\\ \mathbf{elif}\;y.re \le 6.788602011952196 \cdot 10^{+137}:\\ \;\;\;\;\frac{\left(x.im \cdot y.re - y.im \cdot x.re\right) \cdot \frac{1}{\sqrt{y.re^2 + y.im^2}^*}}{\sqrt{y.re^2 + y.im^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{y.re^2 + y.im^2}^*}\\ \end{array}\]

Error

Bits error versus x.re

Bits error versus x.im

Bits error versus y.re

Bits error versus y.im

Derivation

  1. Split input into 3 regimes
  2. if y.re < -1.586349612154054e+218

    1. Initial program 43.7

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt43.7

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied associate-/r*43.7

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied *-commutative43.7

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + \color{blue}{y.im \cdot y.im}}}\]
    7. Applied hypot-def43.7

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\sqrt{y.re^2 + y.im^2}^*}}\]
    8. Taylor expanded around -inf 11.1

      \[\leadsto \frac{\color{blue}{-1 \cdot x.im}}{\sqrt{y.re^2 + y.im^2}^*}\]
    9. Simplified11.1

      \[\leadsto \frac{\color{blue}{-x.im}}{\sqrt{y.re^2 + y.im^2}^*}\]

    if -1.586349612154054e+218 < y.re < 6.788602011952196e+137

    1. Initial program 21.4

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt21.4

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied associate-/r*21.3

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied *-commutative21.3

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + \color{blue}{y.im \cdot y.im}}}\]
    7. Applied hypot-def21.3

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\sqrt{y.re^2 + y.im^2}^*}}\]
    8. Using strategy rm
    9. Applied *-commutative21.3

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + \color{blue}{y.im \cdot y.im}}}}{\sqrt{y.re^2 + y.im^2}^*}\]
    10. Applied hypot-def13.3

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re^2 + y.im^2}^*}}}{\sqrt{y.re^2 + y.im^2}^*}\]
    11. Using strategy rm
    12. Applied div-inv13.4

      \[\leadsto \frac{\color{blue}{\left(x.im \cdot y.re - x.re \cdot y.im\right) \cdot \frac{1}{\sqrt{y.re^2 + y.im^2}^*}}}{\sqrt{y.re^2 + y.im^2}^*}\]

    if 6.788602011952196e+137 < y.re

    1. Initial program 44.0

      \[\frac{x.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt44.0

      \[\leadsto \frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    4. Applied associate-/r*44.0

      \[\leadsto \color{blue}{\frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    5. Using strategy rm
    6. Applied *-commutative44.0

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\sqrt{y.re \cdot y.re + \color{blue}{y.im \cdot y.im}}}\]
    7. Applied hypot-def44.0

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}{\color{blue}{\sqrt{y.re^2 + y.im^2}^*}}\]
    8. Using strategy rm
    9. Applied *-commutative44.0

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\sqrt{y.re \cdot y.re + \color{blue}{y.im \cdot y.im}}}}{\sqrt{y.re^2 + y.im^2}^*}\]
    10. Applied hypot-def27.9

      \[\leadsto \frac{\frac{x.im \cdot y.re - x.re \cdot y.im}{\color{blue}{\sqrt{y.re^2 + y.im^2}^*}}}{\sqrt{y.re^2 + y.im^2}^*}\]
    11. Taylor expanded around inf 16.1

      \[\leadsto \frac{\color{blue}{x.im}}{\sqrt{y.re^2 + y.im^2}^*}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -1.586349612154054 \cdot 10^{+218}:\\ \;\;\;\;\frac{-x.im}{\sqrt{y.re^2 + y.im^2}^*}\\ \mathbf{elif}\;y.re \le 6.788602011952196 \cdot 10^{+137}:\\ \;\;\;\;\frac{\left(x.im \cdot y.re - y.im \cdot x.re\right) \cdot \frac{1}{\sqrt{y.re^2 + y.im^2}^*}}{\sqrt{y.re^2 + y.im^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{y.re^2 + y.im^2}^*}\\ \end{array}\]

Reproduce

herbie shell --seed 2019088 +o rules:numerics
(FPCore (x.re x.im y.re y.im)
  :name "_divideComplex, imaginary part"
  (/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))