Average Error: 25.8 → 24.4
Time: 37.9s
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 -3.359940492079342 \cdot 10^{-277}:\\ \;\;\;\;\frac{c \cdot b}{(d \cdot d + \left(c \cdot c\right))_*} - \frac{a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\\ \mathbf{if}\;d \le 6.060978136660813 \cdot 10^{-134}:\\ \;\;\;\;\frac{c \cdot b}{(d \cdot d + \left(c \cdot c\right))_*} - \frac{a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot b}{(d \cdot d + \left(c \cdot c\right))_*} - \frac{a}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}} \cdot \frac{d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\\ \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.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 2 regimes
  2. if d < -3.359940492079342e-277 or 6.060978136660813e-134 < d

    1. Initial program 26.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify26.4

      \[\leadsto \color{blue}{\frac{c \cdot b - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied div-sub26.4

      \[\leadsto \color{blue}{\frac{c \cdot b}{(d \cdot d + \left(c \cdot c\right))_*} - \frac{a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt26.4

      \[\leadsto \frac{c \cdot b}{(d \cdot d + \left(c \cdot c\right))_*} - \frac{a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    7. Applied times-frac24.8

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

    if -3.359940492079342e-277 < d < 6.060978136660813e-134

    1. Initial program 22.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify22.2

      \[\leadsto \color{blue}{\frac{c \cdot b - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied div-sub22.3

      \[\leadsto \color{blue}{\frac{c \cdot b}{(d \cdot d + \left(c \cdot c\right))_*} - \frac{a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
  3. Recombined 2 regimes into one program.

Runtime

Time bar (total: 37.9s)Debug logProfile

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