Average Error: 25.7 → 10.4
Time: 37.6s
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -2.1803526342689262 \cdot 10^{+101}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{-\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;c \le 3.186542051972063 \cdot 10^{+128}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{d}{c}\right) \cdot \left(-a\right) + b)_*}{\sqrt{c^2 + d^2}^*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original25.7
Target0.5
Herbie10.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 c < -2.1803526342689262e+101

    1. Initial program 39.8

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt39.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-identity39.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-frac39.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. Applied simplify39.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. Applied simplify27.3

      \[\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 30.6

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

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

    if -2.1803526342689262e+101 < c < 3.186542051972063e+128

    1. Initial program 18.1

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

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

      \[\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-frac18.2

      \[\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. Applied simplify18.1

      \[\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. Applied simplify11.3

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}\]
    8. Using strategy rm
    9. Applied pow111.3

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\sqrt{c^2 + d^2}^*}\right)}^{1}} \cdot {\left(\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}\right)}^{1}\]
    11. Applied pow-prod-down11.3

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

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

    if 3.186542051972063e+128 < c

    1. Initial program 41.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt41.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-identity41.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-frac41.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. Applied simplify41.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. Applied simplify26.7

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}}\]
    8. Using strategy rm
    9. Applied pow126.7

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

      \[\leadsto \color{blue}{{\left(\frac{1}{\sqrt{c^2 + d^2}^*}\right)}^{1}} \cdot {\left(\frac{c \cdot b - a \cdot d}{\sqrt{c^2 + d^2}^*}\right)}^{1}\]
    11. Applied pow-prod-down26.7

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

      \[\leadsto {\color{blue}{\left(\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\right)}}^{1}\]
    13. Taylor expanded around inf 29.2

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

      \[\leadsto \color{blue}{\frac{(\left(\frac{d}{c}\right) \cdot \left(-a\right) + b)_*}{\sqrt{c^2 + d^2}^*}}\]
  3. Recombined 3 regimes into one program.
  4. Applied simplify10.4

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;c \le -2.1803526342689262 \cdot 10^{+101}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{-\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;c \le 3.186542051972063 \cdot 10^{+128}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{d}{c}\right) \cdot \left(-a\right) + b)_*}{\sqrt{c^2 + d^2}^*}\\ \end{array}}\]

Runtime

Time bar (total: 37.6s)Debug logProfile

herbie shell --seed '#(1064173506 2580572819 2847706409 4129882574 1125180799 1845288547)' +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))))