Average Error: 25.9 → 14.4
Time: 22.0s
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 9.263907382191759 \cdot 10^{+167}:\\ \;\;\;\;\frac{\frac{(b \cdot d + \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

Original25.9
Target0.4
Herbie14.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 2 regimes
  2. if c < 9.263907382191759e+167

    1. Initial program 23.4

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

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

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

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

      \[\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 simplify14.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 pow114.9

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

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

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

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

    if 9.263907382191759e+167 < c

    1. Initial program 43.3

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;c \le 9.263907382191759 \cdot 10^{+167}:\\ \;\;\;\;\frac{\frac{(b \cdot d + \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}}\]

Runtime

Time bar (total: 22.0s)Debug logProfile

herbie shell --seed '#(1064173506 2580572819 2847706409 4129882574 1125180799 1845288547)' +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))))