Average Error: 25.4 → 10.9
Time: 2.0m
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.182260775010774 \cdot 10^{+97}:\\ \;\;\;\;\frac{(a \cdot \left(\frac{d}{c}\right) + \left(-b\right))_*}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 8.927282505690149 \cdot 10^{+75}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{d}{c}\right) \cdot \left(-a\right) + 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.4
Target0.5
Herbie10.9
\[\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 3 regimes
  2. if c < -1.182260775010774e+97

    1. Initial program 38.7

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

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

      \[\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 *-un-lft-identity38.7

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

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

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

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt25.1

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\sqrt{d^2 + c^2}^*} \cdot \sqrt{\sqrt{d^2 + c^2}^*}}}\]
    11. Applied associate-/r*25.1

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

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

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

    if -1.182260775010774e+97 < c < 8.927282505690149e+75

    1. Initial program 17.7

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

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

      \[\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 *-un-lft-identity17.7

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

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

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

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

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

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

    if 8.927282505690149e+75 < c

    1. Initial program 37.1

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

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

      \[\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 *-un-lft-identity37.1

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

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

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

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt25.0

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\sqrt{d^2 + c^2}^*} \cdot \sqrt{\sqrt{d^2 + c^2}^*}}}\]
    11. Applied associate-/r*25.0

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

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

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

Runtime

Time bar (total: 2.0m)Debug logProfile

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