Average Error: 26.5 → 12.7
Time: 20.9s
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 -9.728655515070008 \cdot 10^{+147}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{if}\;d \le 7.056149799876823 \cdot 10^{+176}:\\ \;\;\;\;\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

Original26.5
Target0.4
Herbie12.7
\[\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 < -9.728655515070008e+147

    1. Initial program 44.1

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

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

      \[\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 associate-/r*44.1

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

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

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

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

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

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

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

    if -9.728655515070008e+147 < d < 7.056149799876823e+176

    1. Initial program 20.5

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

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

      \[\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 associate-/r*20.4

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

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

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

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

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

    if 7.056149799876823e+176 < d

    1. Initial program 43.7

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify43.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-sqrt43.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 associate-/r*43.7

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

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

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

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

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

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

Runtime

Time bar (total: 20.9s)Debug logProfile

herbie shell --seed '#(1070100504 930361288 1279167582 284574201 1450237281 2578255382)' +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))))