Average Error: 26.1 → 12.7
Time: 31.3s
Precision: 64
Internal Precision: 128
\[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
\[\begin{array}{l} \mathbf{if}\;y.re \le -2.1110781218601205 \cdot 10^{+158}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 5.614617575965483 \cdot 10^{+189}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(y.im \cdot x.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\sqrt{y.im^2 + y.re^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 < -2.1110781218601205e+158

    1. Initial program 46.0

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified46.0

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt46.0

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied associate-/r*46.0

      \[\leadsto \color{blue}{\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    6. Using strategy rm
    7. Applied fma-udef46.0

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    8. Applied hypot-def46.0

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    9. Using strategy rm
    10. Applied fma-udef46.0

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

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    12. Taylor expanded around -inf 14.1

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

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

    if -2.1110781218601205e+158 < y.re < 5.614617575965483e+189

    1. Initial program 20.5

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified20.5

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt20.5

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied associate-/r*20.4

      \[\leadsto \color{blue}{\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    6. Using strategy rm
    7. Applied fma-udef20.4

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    8. Applied hypot-def20.4

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    9. Using strategy rm
    10. Applied fma-udef20.4

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    11. Applied hypot-def12.5

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

    if 5.614617575965483e+189 < y.re

    1. Initial program 42.9

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified42.9

      \[\leadsto \color{blue}{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt42.9

      \[\leadsto \frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    5. Applied associate-/r*42.9

      \[\leadsto \color{blue}{\frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}\]
    6. Using strategy rm
    7. Applied fma-udef42.9

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    8. Applied hypot-def42.9

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}}{\sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}\]
    9. Using strategy rm
    10. Applied fma-udef42.9

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    11. Applied hypot-def30.4

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    12. Taylor expanded around inf 11.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \le -2.1110781218601205 \cdot 10^{+158}:\\ \;\;\;\;\frac{-x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.re \le 5.614617575965483 \cdot 10^{+189}:\\ \;\;\;\;\frac{\frac{(x.re \cdot y.re + \left(y.im \cdot x.im\right))_*}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.re}{\sqrt{y.im^2 + y.re^2}^*}\\ \end{array}\]

Reproduce

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