Average Error: 26.0 → 26.0
Time: 17.8s
Precision: 64
Internal Precision: 128
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\frac{\sqrt{c \cdot c + d \cdot d}}{c \cdot b - d \cdot a}}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.0
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. Initial program 26.0

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

    \[\leadsto \color{blue}{\frac{1}{\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d}}}\]
  4. Using strategy rm
  5. Applied *-un-lft-identity26.1

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{c \cdot c + d \cdot d}}{1} \cdot \frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}\]
  8. Applied associate-/r*26.0

    \[\leadsto \color{blue}{\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{1}}}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}\]
  9. Final simplification26.0

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

Reproduce

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