If you go back to mathematics and consider (Newton's method)[http://en.wikipedia.org/wiki/Newtons_method], that seems like it might have been invented, but it's derived from a series of discoveries, and hence is considered a discovery rather than an invention. If you used the Newton-Rhapson method to calculate the zero of a function in code somewhere, you should feel safe that it's not protected by a patent (not to mention it was discovered ages ago).
Since computer science is applied mathematics, and mathematics are discovered rather than invented, it makes sense that it should be protected as well. I'm not the best at explaining things, but hopefully you can understand the difference.