Average Error: 25.5 → 12.7
Time: 42.8s
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 -4.096634773283418 \cdot 10^{+142}:\\ \;\;\;\;\frac{-b}{\sqrt{c^2 + d^2}^*}\\ \mathbf{elif}\;c \le 3.2262988396523094 \cdot 10^{+184}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.5
Target0.5
Herbie12.7
\[\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 < -4.096634773283418e+142

    1. Initial program 43.0

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\sqrt{c^2 + d^2}^*}\]
    12. Simplified14.5

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

    if -4.096634773283418e+142 < c < 3.2262988396523094e+184

    1. Initial program 19.8

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

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

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

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

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

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

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

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

    if 3.2262988396523094e+184 < c

    1. Initial program 42.1

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{b}}{\sqrt{c^2 + d^2}^*}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -4.096634773283418 \cdot 10^{+142}:\\ \;\;\;\;\frac{-b}{\sqrt{c^2 + d^2}^*}\\ \mathbf{elif}\;c \le 3.2262988396523094 \cdot 10^{+184}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Runtime

Time bar (total: 42.8s)Debug logProfile

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