Average Error: 25.6 → 10.7
Time: 1.3m
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 -2.114794877571543 \cdot 10^{+145}:\\ \;\;\;\;\frac{(\left(\frac{b}{c}\right) \cdot \left(-d\right) + \left(-a\right))_*}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;c \le 1.5767625849600095 \cdot 10^{+154}:\\ \;\;\;\;\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.6
Target0.4
Herbie10.7
\[\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 < -2.114794877571543e+145

    1. Initial program 43.0

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

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

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

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

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

      \[\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-cbrt27.6

      \[\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-identity27.6

      \[\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-frac27.6

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

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

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

    if -2.114794877571543e+145 < c < 1.5767625849600095e+154

    1. Initial program 18.9

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt18.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-identity18.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-frac18.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 simplify18.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 simplify12.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 1.5767625849600095e+154 < c

    1. Initial program 44.6

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt44.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-identity44.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-frac44.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 simplify44.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 simplify27.9

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{\left(\frac{b \cdot d}{c} + a\right)}\]
    13. Applied simplify6.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.3m)Debug logProfile

herbie shell --seed '#(1070578969 3140398606 632207097 462683394 1189254563 964980650)' +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))))