Average Error: 26.0 → 13.4
Time: 35.9s
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}\right)\right) \le -1.7827479515024495 \cdot 10^{+308}:\\ \;\;\;\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(-a\right)\\ \mathbf{elif}\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}\right)\right) \le 1.7723426321790147 \cdot 10^{+308}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*} \cdot \frac{1}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\sqrt{c^2 + d^2}^*}\\ \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

Original26.0
Target0.5
Herbie13.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 3 regimes
  2. if (* (/ 1 (hypot c d)) (* (* (cbrt (/ (- (* c b) (* a d)) (hypot c d))) (cbrt (/ (- (* c b) (* a d)) (hypot c d)))) (cbrt (/ (- (* c b) (* a d)) (hypot c d))))) < -1.7827479515024495e+308

    1. Initial program 63.0

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

      \[\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-identity63.0

      \[\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-frac63.0

      \[\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. Simplified63.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Simplified62.0

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}\]
    8. Taylor expanded around 0 48.9

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\left(-1 \cdot a\right)}\]
    9. Simplified48.9

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

    if -1.7827479515024495e+308 < (* (/ 1 (hypot c d)) (* (* (cbrt (/ (- (* c b) (* a d)) (hypot c d))) (cbrt (/ (- (* c b) (* a d)) (hypot c d)))) (cbrt (/ (- (* c b) (* a d)) (hypot c d))))) < 1.7723426321790147e+308

    1. Initial program 13.8

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

      \[\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-identity13.8

      \[\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-frac13.8

      \[\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. Simplified13.8

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Simplified1.5

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

    if 1.7723426321790147e+308 < (* (/ 1 (hypot c d)) (* (* (cbrt (/ (- (* c b) (* a d)) (hypot c d))) (cbrt (/ (- (* c b) (* a d)) (hypot c d)))) (cbrt (/ (- (* c b) (* a d)) (hypot c d)))))

    1. Initial program 62.0

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

      \[\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-identity62.0

      \[\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-frac62.0

      \[\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. Simplified62.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Simplified62.0

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}\]
    8. Taylor expanded around inf 49.1

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{b}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}\right)\right) \le -1.7827479515024495 \cdot 10^{+308}:\\ \;\;\;\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(-a\right)\\ \mathbf{elif}\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}} \cdot \sqrt[3]{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}\right)\right) \le 1.7723426321790147 \cdot 10^{+308}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*} \cdot \frac{1}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Runtime

Time bar (total: 35.9s)Debug logProfile

herbie shell --seed 2018215 +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))))