Average Error: 26.4 → 26.4
Time: 42.7s
Precision: 64
Internal Precision: 576
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.7386260483318646 \cdot 10^{+62}:\\ \;\;\;\;a \cdot \frac{-1}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d \cdot b + c \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original26.4
Target0.4
Herbie26.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 < -1.7386260483318646e+62

    1. Initial program 37.3

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification37.3

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

      \[\leadsto \frac{b \cdot d + a \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    5. Applied associate-/r*37.2

      \[\leadsto \color{blue}{\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt37.3

      \[\leadsto \frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    8. Applied add-sqr-sqrt37.3

      \[\leadsto \frac{\frac{b \cdot d + a \cdot c}{\sqrt{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}\]
    9. Applied sqrt-prod37.4

      \[\leadsto \frac{\frac{b \cdot d + a \cdot c}{\color{blue}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}\]
    10. Applied *-un-lft-identity37.4

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}\]
    12. Applied times-frac37.4

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{\frac{b \cdot d + a \cdot c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
    13. Simplified37.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{\frac{b \cdot d + a \cdot c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}\]
    14. Simplified37.3

      \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \color{blue}{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    15. Taylor expanded around -inf 37.6

      \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \color{blue}{\left(-1 \cdot a\right)}\]
    16. Simplified37.6

      \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \color{blue}{\left(-a\right)}\]

    if -1.7386260483318646e+62 < c

    1. Initial program 23.5

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification23.5

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

      \[\leadsto \frac{b \cdot d + a \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    5. Applied associate-/r*23.4

      \[\leadsto \color{blue}{\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.7386260483318646 \cdot 10^{+62}:\\ \;\;\;\;a \cdot \frac{-1}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d \cdot b + c \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

Runtime

Time bar (total: 42.7s)Debug logProfile

herbie shell --seed 2018249 
(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))))