Average Error: 25.8 → 12.9
Time: 29.0s
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 -6.688971833544892 \cdot 10^{+197}:\\ \;\;\;\;\frac{-b}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;d \le 8.556308424750498 \cdot 10^{+182}:\\ \;\;\;\;\frac{(b \cdot d + \left(a \cdot c\right))_* \cdot \frac{1}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original25.8
Target0.5
Herbie12.9
\[\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 < -6.688971833544892e+197

    1. Initial program 42.2

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt42.2

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity42.2

      \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac42.2

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify42.2

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Applied simplify28.8

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

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

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

    if -6.688971833544892e+197 < d < 8.556308424750498e+182

    1. Initial program 21.3

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt21.3

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity21.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac21.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify21.3

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

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

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\sqrt{c^2 + d^2}^*}\right)}^{1}} \cdot {\left(\frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{c^2 + d^2}^*}\right)}^{1}\]
    11. Applied pow-prod-down13.2

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

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

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

    if 8.556308424750498e+182 < d

    1. Initial program 44.3

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt44.3

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity44.3

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify44.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Applied simplify31.0

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

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{b}\]
    9. Applied simplify11.5

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;d \le -6.688971833544892 \cdot 10^{+197}:\\ \;\;\;\;\frac{-b}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;d \le 8.556308424750498 \cdot 10^{+182}:\\ \;\;\;\;\frac{(b \cdot d + \left(a \cdot c\right))_* \cdot \frac{1}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c^2 + d^2}^*}\\ \end{array}}\]

Runtime

Time bar (total: 29.0s)Debug logProfile

herbie shell --seed '#(1064300848 3212030778 2049303162 3567222883 2277747821 1384278011)' +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))))