Average Error: 25.7 → 11.0
Time: 1.1m
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -3.240779654261542 \cdot 10^{+174}:\\ \;\;\;\;\frac{(a \cdot \left(\frac{d}{c}\right) + \left(-b\right))_*}{\sqrt{d^2 + c^2}^*}\\ \mathbf{if}\;c \le 2.8377443691515392 \cdot 10^{+147}:\\ \;\;\;\;\frac{1}{\sqrt{d^2 + c^2}^*} \cdot \frac{(b \cdot c + \left(-a \cdot d\right))_*}{\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.7
Target0.4
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 < -3.240779654261542e+174

    1. Initial program 44.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify44.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-sqrt44.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-identity44.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-frac44.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 simplify44.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 simplify29.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-cube-cbrt30.1

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

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

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

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

    if -3.240779654261542e+174 < c < 2.8377443691515392e+147

    1. Initial program 19.9

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

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

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

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

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

      \[\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 simplify12.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 fma-neg12.4

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

    if 2.8377443691515392e+147 < c

    1. Initial program 42.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify42.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-sqrt42.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 *-un-lft-identity42.5

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

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

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

      \[\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-cube-cbrt27.9

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

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

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

      \[\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: 1.1m)Debug logProfile

herbie shell --seed '#(1070960995 739739648 2531964651 3069671617 351857262 3877178482)' +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))))