Average Error: 25.9 → 13.8
Time: 47.1s
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 2.318183842350395 \cdot 10^{+90}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{b}{d}\right) \cdot c + \left(-a\right))_*}{\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.9
Target0.5
Herbie13.8
\[\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 < 2.318183842350395e+90

    1. Initial program 23.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify23.0

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

      \[\leadsto \frac{c \cdot b - 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.9

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

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

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

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

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

    if 2.318183842350395e+90 < d

    1. Initial program 38.5

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

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

      \[\leadsto \frac{c \cdot b - 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*38.5

      \[\leadsto \color{blue}{\frac{\frac{c \cdot b - 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-udef38.5

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

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

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

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

Runtime

Time bar (total: 47.1s)Debug logProfile

herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' +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))))