Average Error: 26.3 → 18.1
Time: 1.7m
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -9.476119299999374 \cdot 10^{+106}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{if}\;d \le 1.8299841684748482 \cdot 10^{+136}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{a}{d}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.3
Target0.5
Herbie18.1
\[\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 2 regimes
  2. if d < -9.476119299999374e+106 or 1.8299841684748482e+136 < d

    1. Initial program 40.8

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt[3]{\left(\left(c \cdot c + d \cdot d\right) \cdot \left(c \cdot c + d \cdot d\right)\right) \cdot \left(c \cdot c + d \cdot d\right)}}}\]
    4. Applied add-cbrt-cube53.3

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(b \cdot c - a \cdot d\right) \cdot \left(b \cdot c - a \cdot d\right)\right) \cdot \left(b \cdot c - a \cdot d\right)}}}{\sqrt[3]{\left(\left(c \cdot c + d \cdot d\right) \cdot \left(c \cdot c + d \cdot d\right)\right) \cdot \left(c \cdot c + d \cdot d\right)}}\]
    5. Applied cbrt-undiv53.3

      \[\leadsto \color{blue}{\sqrt[3]{\frac{\left(\left(b \cdot c - a \cdot d\right) \cdot \left(b \cdot c - a \cdot d\right)\right) \cdot \left(b \cdot c - a \cdot d\right)}{\left(\left(c \cdot c + d \cdot d\right) \cdot \left(c \cdot c + d \cdot d\right)\right) \cdot \left(c \cdot c + d \cdot d\right)}}}\]
    6. Applied simplify43.9

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\right)}^{3}}}\]
    7. Taylor expanded around 0 62.9

      \[\leadsto \color{blue}{e^{\left(\log a + \log -1\right) - \log d}}\]
    8. Applied simplify15.8

      \[\leadsto \color{blue}{-\frac{a}{d}}\]

    if -9.476119299999374e+106 < d < 1.8299841684748482e+136

    1. Initial program 19.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt19.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 associate-/r*19.1

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 1.7m)Debug logProfile

herbie shell --seed '#(1063313015 2771194459 1594909340 1344785158 2223560818 546365448)' 
(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))))