Average Error: 25.9 → 4.5
Time: 50.0s
Precision: 64
Internal Precision: 576
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -2.085099206562825 \cdot 10^{+129} \lor \neg \left(c \le 1.2579039748165442 \cdot 10^{+126}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{\sqrt{d^2 + c^2}^*} - \frac{d \cdot a}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot c}{\sqrt{d^2 + c^2}^*} - \frac{a}{\frac{\sqrt{d^2 + c^2}^*}{d}}}{\sqrt{d^2 + c^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

Original25.9
Target0.4
Herbie4.5
\[\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 c < -2.085099206562825e+129 or 1.2579039748165442e+126 < c

    1. Initial program 42.4

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification42.4

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

      \[\leadsto \frac{b \cdot c - 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 *-un-lft-identity42.4

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

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

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

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/28.1

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    12. Using strategy rm
    13. Applied div-sub28.1

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b}{\sqrt{d^2 + c^2}^*} - \frac{a \cdot d}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    14. Using strategy rm
    15. Applied *-un-lft-identity28.1

      \[\leadsto \frac{\frac{c \cdot b}{\color{blue}{1 \cdot \sqrt{d^2 + c^2}^*}} - \frac{a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\]
    16. Applied times-frac7.8

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

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

    if -2.085099206562825e+129 < c < 1.2579039748165442e+126

    1. Initial program 18.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification18.6

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

      \[\leadsto \frac{b \cdot c - 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 *-un-lft-identity18.6

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

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

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

      \[\leadsto \frac{1}{\sqrt{d^2 + c^2}^*} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}\]
    9. Using strategy rm
    10. Applied associate-*l/12.0

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    12. Using strategy rm
    13. Applied div-sub12.0

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b}{\sqrt{d^2 + c^2}^*} - \frac{a \cdot d}{\sqrt{d^2 + c^2}^*}}}{\sqrt{d^2 + c^2}^*}\]
    14. Using strategy rm
    15. Applied associate-/l*3.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -2.085099206562825 \cdot 10^{+129} \lor \neg \left(c \le 1.2579039748165442 \cdot 10^{+126}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{\sqrt{d^2 + c^2}^*} - \frac{d \cdot a}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot c}{\sqrt{d^2 + c^2}^*} - \frac{a}{\frac{\sqrt{d^2 + c^2}^*}{d}}}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Runtime

Time bar (total: 50.0s)Debug logProfile

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