Average Error: 25.9 → 26.0
Time: 48.5s
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 4.5667974641861144 \cdot 10^{+70}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\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.9
Target0.5
Herbie26.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 d < 4.5667974641861144e+70

    1. Initial program 23.0

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

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

      \[\leadsto \frac{c \cdot b - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied associate-/r*23.0

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

    if 4.5667974641861144e+70 < d

    1. Initial program 36.9

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

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

      \[\leadsto \frac{c \cdot b - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied associate-/r*36.9

      \[\leadsto \color{blue}{\frac{\frac{c \cdot b - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    6. Taylor expanded around 0 37.6

      \[\leadsto \frac{\color{blue}{-1 \cdot a}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    7. Applied simplify37.6

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

Runtime

Time bar (total: 48.5s)Debug logProfile

herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' +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))))