Average Error: 25.8 → 24.2
Time: 35.3s
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \cdot d \le 6.810815928699 \cdot 10^{-313}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original25.8
Target0.4
Herbie24.2
\[\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 d) < 6.810815928699e-313

    1. Initial program 23.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub23.5

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

    if 6.810815928699e-313 < (* d d)

    1. Initial program 26.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub26.5

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt26.5

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied times-frac24.4

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

Runtime

Time bar (total: 35.3s)Debug logProfile

herbie shell --seed '#(1064269945 2896236262 301053905 1701069080 1701464310 1614783279)' 
(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))))