Average Error: 25.7 → 22.9
Time: 22.5s
Precision: 64
Internal Precision: 128
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -1.1702457669974666 \cdot 10^{+36} \lor \neg \left(d \le 1.93993632877172 \cdot 10^{+28}\right):\\ \;\;\;\;\frac{b \cdot c}{d \cdot d + c \cdot c} - \frac{a}{\frac{d \cdot d + c \cdot c}{d}}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{c}{d \cdot d + c \cdot c} - \frac{d \cdot a}{d \cdot d + c \cdot c}\\ \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.7
Target0.4
Herbie22.9
\[\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 < -1.1702457669974666e+36 or 1.93993632877172e+28 < d

    1. Initial program 33.8

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub33.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 associate-/l*30.6

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

    if -1.1702457669974666e+36 < d < 1.93993632877172e+28

    1. Initial program 18.5

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

      \[\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-identity18.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le -1.1702457669974666 \cdot 10^{+36} \lor \neg \left(d \le 1.93993632877172 \cdot 10^{+28}\right):\\ \;\;\;\;\frac{b \cdot c}{d \cdot d + c \cdot c} - \frac{a}{\frac{d \cdot d + c \cdot c}{d}}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{c}{d \cdot d + c \cdot c} - \frac{d \cdot a}{d \cdot d + c \cdot c}\\ \end{array}\]

Runtime

Time bar (total: 22.5s)Debug logProfile

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