Average Error: 26.1 → 13.4
Time: 1.1m
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\sqrt{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \left(\sqrt{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}\right) \le -1.7761824129243311 \cdot 10^{+308}:\\ \;\;\;\;\frac{(\left(\frac{c}{d}\right) \cdot b + \left(-a\right))_*}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;\sqrt{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \left(\sqrt{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}\right) \le 1.7795226370784402 \cdot 10^{+308}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{c}{d}\right) \cdot b + \left(-a\right))_*}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.1
Target0.5
Herbie13.4
\[\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 (* (sqrt (/ 1 (hypot c d))) (* (sqrt (/ 1 (hypot c d))) (/ (- (* c b) (* a d)) (hypot c d)))) < -1.7761824129243311e+308 or 1.7795226370784402e+308 < (* (sqrt (/ 1 (hypot c d))) (* (sqrt (/ 1 (hypot c d))) (/ (- (* c b) (* a d)) (hypot c d))))

    1. Initial program 62.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt62.5

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity62.5

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac62.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify62.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Applied simplify62.0

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}\]
    8. Using strategy rm
    9. Applied associate-*r/62.0

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(c \cdot b - a \cdot d\right)}{\sqrt{c^2 + d^2}^*}}\]
    10. Applied simplify62.0

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

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

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

    if -1.7761824129243311e+308 < (* (sqrt (/ 1 (hypot c d))) (* (sqrt (/ 1 (hypot c d))) (/ (- (* c b) (* a d)) (hypot c d)))) < 1.7795226370784402e+308

    1. Initial program 13.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt13.5

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity13.5

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac13.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify13.5

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Applied simplify1.6

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}\]
    8. Using strategy rm
    9. Applied associate-*r/1.6

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(c \cdot b - a \cdot d\right)}{\sqrt{c^2 + d^2}^*}}\]
    10. Applied simplify1.5

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

Runtime

Time bar (total: 1.1m)Debug logProfile

herbie shell --seed 2018178 +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))))