Average Error: 25.6 → 24.0
Time: 33.6s
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;b \le 2.176663814799802 \cdot 10^{+217}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - a \cdot \frac{d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{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.6
Target0.4
Herbie24.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 2 regimes
  2. if b < 2.176663814799802e+217

    1. Initial program 24.6

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

      \[\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 *-un-lft-identity24.6

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

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{\frac{a}{1} \cdot \frac{d}{c \cdot c + d \cdot d}}\]
    7. Applied simplify23.3

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

    if 2.176663814799802e+217 < b

    1. Initial program 40.8

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

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

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

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

Runtime

Time bar (total: 33.6s)Debug logProfile

herbie shell --seed '#(1071725047 233389029 2036512464 3988615230 2972226563 1111574017)' 
(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))))