Average Error: 25.5 → 13.2
Time: 1.3m
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 -4.469138644879418 \cdot 10^{+120}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{if}\;d \le 7.153026398352661 \cdot 10^{+105}:\\ \;\;\;\;\frac{1}{\sqrt{d^2 + c^2}^*} \cdot \left(\frac{1}{\sqrt{\sqrt{d^2 + c^2}^*}} \cdot \frac{(b \cdot d + \left(c \cdot a\right))_*}{\sqrt{\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.5
Target0.5
Herbie13.2
\[\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 < -4.469138644879418e+120

    1. Initial program 42.1

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

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

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

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

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

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

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

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

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

    if -4.469138644879418e+120 < d < 7.153026398352661e+105

    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.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-sqr-sqrt11.9

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

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

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

    if 7.153026398352661e+105 < d

    1. Initial program 38.4

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Applied simplify38.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-sqrt38.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-identity38.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-frac38.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 simplify38.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 simplify24.0

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

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

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

Runtime

Time bar (total: 1.3m)Debug logProfile

herbie shell --seed '#(1071821486 549052472 3784827256 1559736200 3548510075 881134285)' +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))))