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

Original26.0
Target0.5
Herbie13.8
\[\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 2 regimes
  2. if (* (/ (/ 1 (hypot d c)) (sqrt (hypot d c))) (/ (fma b d (* c a)) (sqrt (hypot d c)))) < -inf.0 or +inf.0 < (* (/ (/ 1 (hypot d c)) (sqrt (hypot d c))) (/ (fma b d (* c a)) (sqrt (hypot d c))))

    1. Initial program 62.7

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify62.7

      \[\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-sqrt62.7

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

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

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

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

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

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

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

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

    1. Initial program 16.2

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

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

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

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

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

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

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

      \[\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}^*}}\]
    11. Applied simplify4.7

      \[\leadsto \frac{\color{blue}{\frac{(d \cdot b + \left(c \cdot a\right))_*}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
  3. Recombined 2 regimes into one program.

Runtime

Time bar (total: 52.9s)Debug logProfile

herbie shell --seed '#(1072107073 2127697367 3936270018 2300570620 2134894798 4023771849)' +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))))