Average Error: 25.6 → 12.5
Time: 25.4s
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.im \le -3.8089825873777783 \cdot 10^{+211}:\\ \;\;\;\;\frac{-x.im}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.im \le 7.65041160355757 \cdot 10^{+208}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.re + x.im \cdot y.im}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\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.im < -3.8089825873777783e+211

    1. Initial program 41.9

      \[\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\]
    2. Simplified41.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-sqrt41.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*41.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-udef41.9

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def41.9

      \[\leadsto \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))_*}}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity41.9

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

      \[\leadsto \frac{\frac{(x.re \cdot y.re + \left(x.im \cdot y.im\right))_*}{\color{blue}{\sqrt{1} \cdot \sqrt{(y.im \cdot y.im + \left(y.re \cdot y.re\right))_*}}}}{\sqrt{y.im^2 + y.re^2}^*}\]
    12. Applied *-un-lft-identity41.9

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1}} \cdot \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^2 + y.re^2}^*}\]
    14. Simplified41.9

      \[\leadsto \frac{\color{blue}{1} \cdot \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^2 + y.re^2}^*}\]
    15. Simplified29.9

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

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

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

    if -3.8089825873777783e+211 < y.im < 7.65041160355757e+208

    1. Initial program 22.2

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

      \[\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-sqrt22.2

      \[\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*22.1

      \[\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-udef22.1

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def22.1

      \[\leadsto \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))_*}}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity22.1

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1}} \cdot \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^2 + y.re^2}^*}\]
    14. Simplified22.1

      \[\leadsto \frac{\color{blue}{1} \cdot \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^2 + y.re^2}^*}\]
    15. Simplified12.9

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

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

    if 7.65041160355757e+208 < y.im

    1. Initial program 41.2

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

      \[\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-sqrt41.2

      \[\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*41.2

      \[\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-udef41.2

      \[\leadsto \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{\color{blue}{y.im \cdot y.im + y.re \cdot y.re}}}\]
    8. Applied hypot-def41.2

      \[\leadsto \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))_*}}}{\color{blue}{\sqrt{y.im^2 + y.re^2}^*}}\]
    9. Taylor expanded around 0 9.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.im \le -3.8089825873777783 \cdot 10^{+211}:\\ \;\;\;\;\frac{-x.im}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{elif}\;y.im \le 7.65041160355757 \cdot 10^{+208}:\\ \;\;\;\;\frac{\frac{y.re \cdot x.re + x.im \cdot y.im}{\sqrt{y.im^2 + y.re^2}^*}}{\sqrt{y.im^2 + y.re^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{x.im}{\sqrt{y.im^2 + y.re^2}^*}\\ \end{array}\]

Reproduce

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