Average Error: 25.6 → 13.4
Time: 1.2m
Precision: 64
Internal Precision: 320
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \frac{\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}}{\sqrt{c^2 + d^2}^*}\right) \cdot \sqrt[3]{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}} \le -1.7787867425133029 \cdot 10^{+308}:\\ \;\;\;\;\frac{b}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;\left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \frac{\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}}{\sqrt{c^2 + d^2}^*}\right) \cdot \sqrt[3]{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}} \le 1.7733770411415807 \cdot 10^{+308}:\\ \;\;\;\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \frac{(c \cdot b + \left(-a \cdot d\right))_*}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\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

Original25.6
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 3 regimes
  2. if (* (* (cbrt (/ (- (* b c) (* a d)) (hypot c d))) (/ (cbrt (/ (- (* b c) (* a d)) (hypot c d))) (hypot c d))) (cbrt (/ (- (* c b) (* a d)) (hypot c d)))) < -1.7787867425133029e+308

    1. Initial program 62.9

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{b}\]
    9. Applied simplify48.7

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

    if -1.7787867425133029e+308 < (* (* (cbrt (/ (- (* b c) (* a d)) (hypot c d))) (/ (cbrt (/ (- (* b c) (* a d)) (hypot c d))) (hypot c d))) (cbrt (/ (- (* c b) (* a d)) (hypot c d)))) < 1.7733770411415807e+308

    1. Initial program 13.2

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

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

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

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

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

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

    if 1.7733770411415807e+308 < (* (* (cbrt (/ (- (* b c) (* a d)) (hypot c d))) (/ (cbrt (/ (- (* b c) (* a d)) (hypot c d))) (hypot c d))) (cbrt (/ (- (* c b) (* a d)) (hypot c d))))

    1. Initial program 62.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt62.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-identity62.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-frac62.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. Applied simplify62.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. 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. Taylor expanded around 0 48.2

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

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

Runtime

Time bar (total: 1.2m)Debug logProfile

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