Average Error: 26.0 → 13.5
Time: 48.5s
Precision: 64
Internal Precision: 576
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(\frac{\sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*} \cdot \sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*} \cdot \sqrt[3]{\sqrt{c^2 + d^2}^*}} \cdot \frac{\sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*}}\right) = -\infty:\\ \;\;\;\;\frac{a}{\sqrt{c^2 + d^2}^*}\\ \mathbf{if}\;\frac{1}{\sqrt{c^2 + d^2}^*} \cdot \left(\frac{\sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*} \cdot \sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*} \cdot \sqrt[3]{\sqrt{c^2 + d^2}^*}} \cdot \frac{\sqrt[3]{(b \cdot d + \left(c \cdot a\right))_*}}{\sqrt[3]{\sqrt{c^2 + d^2}^*}}\right) \le 1.439579894583305 \cdot 10^{+302}:\\ \;\;\;\;\frac{\frac{(d \cdot b + \left(a \cdot c\right))_*}{\sqrt{c^2 + d^2}^*}}{\sqrt{c^2 + d^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{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

Original26.0
Target0.5
Herbie13.5
\[\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 2 regimes
  2. if (* (/ 1 (hypot c d)) (* (/ (* (cbrt (fma b d (* c a))) (cbrt (fma b d (* c a)))) (* (cbrt (hypot c d)) (cbrt (hypot c d)))) (/ (cbrt (fma b d (* c a))) (cbrt (hypot c d))))) < -inf.0 or 1.439579894583305e+302 < (* (/ 1 (hypot c d)) (* (/ (* (cbrt (fma b d (* c a))) (cbrt (fma b d (* c a)))) (* (cbrt (hypot c d)) (cbrt (hypot c d)))) (/ (cbrt (fma b d (* c a))) (cbrt (hypot c d)))))

    1. Initial program 62.1

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

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

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

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

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

      \[\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. Taylor expanded around 0 48.5

      \[\leadsto \frac{1}{\sqrt{c^2 + d^2}^*} \cdot \color{blue}{a}\]
    9. Applied simplify48.5

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

    if -inf.0 < (* (/ 1 (hypot c d)) (* (/ (* (cbrt (fma b d (* c a))) (cbrt (fma b d (* c a)))) (* (cbrt (hypot c d)) (cbrt (hypot c d)))) (/ (cbrt (fma b d (* c a))) (cbrt (hypot c d))))) < 1.439579894583305e+302

    1. Initial program 13.5

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

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

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

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

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

      \[\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 associate-*r/1.5

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

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

Runtime

Time bar (total: 48.5s)Debug logProfile

herbie shell --seed '#(1072936661 1621281212 3440817831 3219514234 460296804 1258167384)' +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))))