For some reason, corporations seem to feel the need to compete in areas where they're clearly outmatched no matter what
Just because you can't see it, it doesn't mean that there is no strong rationale for that.
The reason why google keeps investing in projects different than search is simply to increase usage and accessibility of the internet. By increasing the value of the internet (gmail, orkut, latitude), the ways you can access it (android) and by improving the overall user experience (gwt, chrome), they are basically increasing their market and the appeal of the advertisement in their core search product.
Microsoft, on its turn, knows the value of a good monopoly and the leverage it gives in all your other products. They played this game very successfully in the desktop market, and they know that if they let google run free in the search market, it may eventually be powerful enough to crush any future source of revenue for microsoft in the web.
Don't fool yourself into thinking that any of these guys are doing anything simply out of stupidity, hubris or whatever other reason. They are doing it because there is money involved.