Average Error: 25.8 → 13.6
Time: 25.7s
Precision: 64
Internal Precision: 384
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 9.190386957669971 \cdot 10^{+115}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{(c \cdot \left(\frac{b}{d}\right) + \left(-a\right))_*}{\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.8
Target0.5
Herbie13.6
\[\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 < 9.190386957669971e+115

    1. Initial program 23.2

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

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

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

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

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

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

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

      \[\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 simplify14.4

      \[\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 9.190386957669971e+115 < d

    1. Initial program 38.7

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

      \[\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-identity38.7

      \[\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-frac38.7

      \[\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 simplify38.7

      \[\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.4

      \[\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.4

      \[\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.4

      \[\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.4

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

      \[\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 0 29.4

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

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

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

Runtime

Time bar (total: 25.7s)Debug logProfile

herbie shell --seed '#(1064397287 3527694221 3797617954 1138343853 2854031332 1153838279)' +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))))