Average Error: 25.7 → 11.4
Time: 1.1m
Precision: 64
Internal Precision: 384
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.4085172178463586 \cdot 10^{+108}:\\ \;\;\;\;\frac{(\left(\frac{b}{c}\right) \cdot \left(-d\right) + \left(-a\right))_*}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;c \le 3.2092839043956334 \cdot 10^{-17}:\\ \;\;\;\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{(d \cdot \left(\frac{b}{c}\right) + a)_*}{\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
Herbie11.4
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if c < -1.4085172178463586e+108

    1. Initial program 40.9

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity40.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac40.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify40.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Applied simplify27.8

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{c^2 + d^2}^*}}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt28.0

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

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

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

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

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

    if -1.4085172178463586e+108 < c < 3.2092839043956334e-17

    1. Initial program 17.9

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity17.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac17.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify17.9

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Applied simplify10.3

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

    if 3.2092839043956334e-17 < c

    1. Initial program 31.6

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity31.6

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied simplify31.6

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c^2 + d^2}^*}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Applied simplify21.3

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{c^2 + d^2}^*}}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt21.8

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

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

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

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

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

Runtime

Time bar (total: 1.1m)Debug logProfile

herbie shell --seed '#(1070386091 2509006183 1430610344 1025408621 36622005 1425925650)' +o rules:numerics
(FPCore (a b c d)
  :name "Complex division, real part"

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))