Average Error: 25.2 → 12.5
Time: 26.7s
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.36398613215644 \cdot 10^{+156}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{if}\;d \le 2.4347391390427925 \cdot 10^{+164}:\\ \;\;\;\;\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.2
Target0.4
Herbie12.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 d < -2.36398613215644e+156

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

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

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

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

    if -2.36398613215644e+156 < d < 2.4347391390427925e+164

    1. Initial program 19.0

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

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

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

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

      \[\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 2.4347391390427925e+164 < 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-def29.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.8

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

Runtime

Time bar (total: 26.7s)Debug logProfile

herbie shell --seed '#(1070131407 1246090267 3027482374 2150728003 2026520792 2347815650)' +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))))