Average Error: 25.9 → 25.6
Time: 1.0m
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d} \le -1.6490966697360884 \cdot 10^{-293}:\\ \;\;\;\;\frac{1}{\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d}}\\ \mathbf{if}\;\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d} \le 5.28628895379133 \cdot 10^{-310}:\\ \;\;\;\;\frac{-b}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c - 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

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.9
Target0.4
Herbie25.6
\[\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 3 regimes
  2. if (/ (+ (* c c) (* d d)) (- (* b c) (* a d))) < -1.6490966697360884e-293

    1. Initial program 11.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied clear-num11.4

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

    if -1.6490966697360884e-293 < (/ (+ (* c c) (* d d)) (- (* b c) (* a d))) < 5.28628895379133e-310

    1. Initial program 57.3

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

      \[\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 *-un-lft-identity57.3

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Taylor expanded around -inf 52.3

      \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \color{blue}{\left(-1 \cdot b\right)}\]
    7. Applied simplify52.3

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

    if 5.28628895379133e-310 < (/ (+ (* c c) (* d d)) (- (* b c) (* a d)))

    1. Initial program 30.9

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

Runtime

Time bar (total: 1.0m)Debug logProfile

herbie shell --seed 2020178 
(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))))