Average Error: 25.8 → 11.0
Time: 2.1m
Precision: 64
Internal Precision: 320
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -2.9830793252751902 \cdot 10^{+141}:\\ \;\;\;\;\frac{(a \cdot \left(\frac{d}{c}\right) + \left(-b\right))_*}{\sqrt{d^2 + c^2}^*}\\ \mathbf{if}\;c \le 7.202117007000063 \cdot 10^{+42}:\\ \;\;\;\;\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.8
Target0.5
Herbie11.0
\[\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 < -2.9830793252751902e+141

    1. Initial program 43.6

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

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

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

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

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

      \[\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 simplify28.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-sqrt28.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*28.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 11.5

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

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

    if -2.9830793252751902e+141 < c < 7.202117007000063e+42

    1. Initial program 18.2

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

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

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

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

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

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

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

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

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

    if 7.202117007000063e+42 < c

    1. Initial program 36.2

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

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

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

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

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

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

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

      \[\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*24.4

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

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\left(b - \frac{d \cdot a}{c}\right)}\]
    13. Applied simplify12.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.1m)Debug logProfile

herbie shell --seed '#(1071215679 2002590028 935158157 1944352234 2656991306 2955288481)' +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))))