Average Error: 25.7 → 12.3
Time: 1.5m
Precision: 64
Internal Precision: 576
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -2.5393735001043034 \cdot 10^{+55}:\\ \;\;\;\;\frac{(\left(\frac{c}{d}\right) \cdot \left(-a\right) + \left(-b\right))_*}{\sqrt{d^2 + c^2}^*}\\ \mathbf{if}\;d \le 6.380244854218845 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{\sqrt{d^2 + c^2}^*} \cdot \left(\frac{1}{\sqrt[3]{\sqrt{d^2 + c^2}^*} \cdot \sqrt[3]{\sqrt{d^2 + c^2}^*}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt[3]{\sqrt{d^2 + c^2}^*}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d^2 + c^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
Herbie12.3
\[\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 d < -2.5393735001043034e+55

    1. Initial program 36.5

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify36.5

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

      \[\leadsto \frac{(b \cdot d + \left(c \cdot a\right))_*}{\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-identity36.5

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

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

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

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

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

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

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

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

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

    if -2.5393735001043034e+55 < d < 6.380244854218845e+154

    1. Initial program 18.2

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify18.2

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

      \[\leadsto \frac{(b \cdot d + \left(c \cdot a\right))_*}{\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.2

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

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

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

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

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

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

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

    if 6.380244854218845e+154 < d

    1. Initial program 44.4

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify44.4

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

      \[\leadsto \frac{(b \cdot d + \left(c \cdot a\right))_*}{\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-identity44.4

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b}{\sqrt{d^2 + c^2}^*}}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 1.5m)Debug logProfile

herbie shell --seed '#(1071215679 2002590028 935158157 1944352234 2656991306 2955288481)' +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))))