Average Error: 25.7 → 14.2
Time: 43.3s
Precision: 64
Internal Precision: 128
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 1.5435655476791597 \cdot 10^{+115}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\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

Original25.7
Target0.5
Herbie14.2
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if d < 1.5435655476791597e+115

    1. Initial program 22.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified22.5

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt22.5

      \[\leadsto \frac{b \cdot c - a \cdot d}{\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*22.4

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\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-udef22.4

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

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

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    11. Applied hypot-def14.0

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

    if 1.5435655476791597e+115 < d

    1. Initial program 41.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified41.3

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt41.3

      \[\leadsto \frac{b \cdot c - a \cdot d}{\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*41.3

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\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-udef41.3

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

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

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    11. Applied hypot-def26.7

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\color{blue}{\sqrt{d^2 + c^2}^*}}\]
    12. Taylor expanded around 0 15.3

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

      \[\leadsto \frac{\color{blue}{-a}}{\sqrt{d^2 + c^2}^*}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 1.5435655476791597 \cdot 10^{+115}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Reproduce

herbie shell --seed 2019089 +o rules:numerics
(FPCore (a b c d)
  :name "Complex division, imag part"

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))