Average Error: 25.7 → 12.4
Time: 31.4s
Precision: 64
Internal Precision: 384
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -2.246615912939743 \cdot 10^{+120}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{if}\;d \le 8.350074476225983 \cdot 10^{+163}:\\ \;\;\;\;\frac{\frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original25.7
Target0.5
Herbie12.4
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if d < -2.246615912939743e+120

    1. Initial program 41.0

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify41.0

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

      \[\leadsto \frac{(b \cdot d + \left(c \cdot a\right))_*}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied *-un-lft-identity41.0

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}\]
    12. Applied hypot-def27.4

      \[\leadsto \frac{1}{\color{blue}{\sqrt{d^2 + c^2}^*}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}\]
    13. Taylor expanded around -inf 16.0

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\left(-1 \cdot b\right)}\]
    14. Applied simplify15.9

      \[\leadsto \color{blue}{\frac{-b}{\sqrt{d^2 + c^2}^*}}\]

    if -2.246615912939743e+120 < d < 8.350074476225983e+163

    1. Initial program 18.9

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify18.9

      \[\leadsto \color{blue}{\frac{(b \cdot d + \left(c \cdot a\right))_*}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt18.9

      \[\leadsto \frac{(b \cdot d + \left(c \cdot a\right))_*}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied *-un-lft-identity18.9

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    7. Using strategy rm
    8. Applied fma-udef18.9

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}\]
    12. Applied hypot-def11.5

      \[\leadsto \frac{1}{\color{blue}{\sqrt{d^2 + c^2}^*}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}\]
    13. Using strategy rm
    14. Applied associate-*r/11.5

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{d^2 + c^2}^*} \cdot (b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}}\]
    15. Applied simplify11.4

      \[\leadsto \frac{\color{blue}{\frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]

    if 8.350074476225983e+163 < d

    1. Initial program 44.8

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify44.8

      \[\leadsto \color{blue}{\frac{(b \cdot d + \left(c \cdot a\right))_*}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt44.8

      \[\leadsto \frac{(b \cdot d + \left(c \cdot a\right))_*}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied *-un-lft-identity44.8

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}\]
    12. Applied hypot-def27.4

      \[\leadsto \frac{1}{\color{blue}{\sqrt{d^2 + c^2}^*}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}\]
    13. Taylor expanded around inf 13.7

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{b}\]
    14. Applied simplify13.6

      \[\leadsto \color{blue}{\frac{b}{\sqrt{d^2 + c^2}^*}}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 31.4s)Debug logProfile

herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' +o rules:numerics
(FPCore (a b c d)
  :name "Complex division, real part"

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))