Average Error: 26.0 → 14.5
Time: 57.4s
Precision: 64
Internal Precision: 384
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\left(\frac{\sqrt[3]{(d \cdot b + \left(a \cdot c\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*}} \cdot \frac{\sqrt[3]{(d \cdot b + \left(a \cdot c\right))_*}}{\sqrt{c^2 + d^2}^* \cdot \sqrt[3]{\sqrt{c^2 + d^2}^*}}\right) \cdot \frac{\sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*}} = -\infty:\\ \;\;\;\;\frac{b}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;\left(\frac{\sqrt[3]{(d \cdot b + \left(a \cdot c\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*}} \cdot \frac{\sqrt[3]{(d \cdot b + \left(a \cdot c\right))_*}}{\sqrt{c^2 + d^2}^* \cdot \sqrt[3]{\sqrt{c^2 + d^2}^*}}\right) \cdot \frac{\sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*}} \le +\infty:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \left(\sqrt{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{c^2 + d^2}^*}\right)\\ \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

Original26.0
Target0.4
Herbie14.5
\[\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 (* (* (/ (cbrt (fma d b (* a c))) (cbrt (hypot c d))) (/ (cbrt (fma d b (* a c))) (* (hypot c d) (cbrt (hypot c d))))) (/ (cbrt (fma b d (* c a))) (cbrt (hypot c d)))) < -inf.0

    1. Initial program 62.5

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

      \[\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-identity62.5

      \[\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-frac62.5

      \[\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 simplify62.5

      \[\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 simplify61.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. Taylor expanded around inf 48.0

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

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

    if -inf.0 < (* (* (/ (cbrt (fma d b (* a c))) (cbrt (hypot c d))) (/ (cbrt (fma d b (* a c))) (* (hypot c d) (cbrt (hypot c d))))) (/ (cbrt (fma b d (* c a))) (cbrt (hypot c d)))) < +inf.0

    1. Initial program 17.2

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt17.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-identity17.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-frac17.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 simplify17.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 simplify6.1

      \[\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 add-sqr-sqrt6.3

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

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

    if +inf.0 < (* (* (/ (cbrt (fma d b (* a c))) (cbrt (hypot c d))) (/ (cbrt (fma d b (* a c))) (* (hypot c d) (cbrt (hypot c d))))) (/ (cbrt (fma b d (* c a))) (cbrt (hypot c d))))

    1. Initial program 62.9

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

      \[\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-identity62.9

      \[\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-frac62.9

      \[\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 simplify62.9

      \[\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 simplify62.4

      \[\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 49.4

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

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

Runtime

Time bar (total: 57.4s)Debug logProfile

herbie shell --seed '#(1070706311 3771791028 4128836681 4194990999 2341756049 504035650)' +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))))