Average Error: 25.6 → 12.7
Time: 1.0m
Precision: 64
Internal Precision: 576
\[\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 -2.2338905140810537 \cdot 10^{+190}:\\ \;\;\;\;\frac{-x.im}{\sqrt{y.re^2 + y.im^2}^*}\\ \mathbf{if}\;y.im \le 2.933025686790968 \cdot 10^{+143}:\\ \;\;\;\;\frac{\frac{(y.im \cdot x.im + \left(x.re \cdot y.re\right))_*}{\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

Try it out

  1. Inputs

  2. Original Output:

    Herbie Output:

Derivation

  1. Split input into 3 regimes
  2. if y.im < -2.2338905140810537e+190

    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. Using strategy rm
    3. Applied add-sqr-sqrt42.9

      \[\leadsto \frac{x.re \cdot y.re + x.im \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 *-un-lft-identity42.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac42.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Applied simplify42.9

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

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

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

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

    if -2.2338905140810537e+190 < y.im < 2.933025686790968e+143

    1. Initial program 20.2

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

      \[\leadsto \frac{x.re \cdot y.re + x.im \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 *-un-lft-identity20.2

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Applied simplify20.2

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

      \[\leadsto \frac{1}{\sqrt{y.re^2 + y.im^2}^*} \cdot \color{blue}{\frac{(x.im \cdot y.im + \left(y.re \cdot x.re\right))_*}{\sqrt{y.re^2 + y.im^2}^*}}\]
    8. Using strategy rm
    9. Applied associate-*r/12.6

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

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

    if 2.933025686790968e+143 < y.im

    1. Initial program 42.0

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

      \[\leadsto \frac{x.re \cdot y.re + x.im \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 *-un-lft-identity42.0

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x.re \cdot y.re + x.im \cdot y.im\right)}}{\sqrt{y.re \cdot y.re + y.im \cdot y.im} \cdot \sqrt{y.re \cdot y.re + y.im \cdot y.im}}\]
    5. Applied times-frac42.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}} \cdot \frac{x.re \cdot y.re + x.im \cdot y.im}{\sqrt{y.re \cdot y.re + y.im \cdot y.im}}}\]
    6. Applied simplify42.0

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

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

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

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

Runtime

Time bar (total: 1.0m)Debug logProfile

herbie shell --seed '#(1072361757 3390613284 2339397988 1175251238 145061547 3101881848)' +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))))