Patents cover inventions that are applications of knowledge. For example, chemistry is certainly discovered, but applying the use of a certain molecule as a glue or as a drug is very much patentable. Physics is also discovered, but a special lever system that is a direct application of Newtonian mechanics is patentable. The knowledge that a certain mathematical formula could be written and has certain properties is not patentable, but a device that employs that formula as an algorithm for, say, predicting stock prices, is (in certain countries at least).
I don't see how you are distinguishing between inventions and discoveries. The "discovery" of a mathematical proof is just an application of knowledge, why aren't they patentable? The "invention" of the light bulb, on the other hand, is just the discovery that putting various particles together in a certain configuration produces light in a predictable manner, why is this patentable? I don't see how a clear delineation between the two can be made.
I'm not. I'm saying that devices whose function is derived from mathematics (algorithms) have the same status as devices that derive their function from physics or chemistry. In either case, "application" doesn't mean some intellectual use but commercial use. The purpose of patents is to protect commercial applications in exchange for sharing the knowledge that led to their creation. The knowledge itself is never protected.
When the lightbulb was patented, everyone was free to learn, study, and disseminate the physical knowledge of how a lightbulb works. What you couldn't do is build one and sell it. Whether mathematics is invented or discovered, the knowledge itself is never protected, but if some non-obvious algorithm has a commercial application, it can be patented so to protect building devices that apply that knowledge for commercial use.
But that's the whole point, patents are awarded to things deemed inventions not things deemed discoveries. If you can't delineate between the two you can't say what is and what is not patentable.
Fourier analysis couldn't have been patented, despite numerous commercial applications. It's just the patent system is setup to only reward low-level innovation, so it arbitrarily excludes research level innovation by terming it discovery.
Yes, what is patented is some commercial application of some knowledge, and that application is the invention. It doesn't matter whether the knowledge itself is invented or discovered. When an algorithm is patented, we're no more patenting math than we're patenting Newton's laws when a car brake is invented. We're patenting a commercial application of either, and that must be the invention.
Commercial application is irrelevant to a patent law. Patent applications need only demonstrate "eligibility, utility, novelty, and non-obviousness." Math and other basic research are ruled out on eligibility grounds, not for being non-commercial, but rather for being "abstract ideas."
Also, algorithms are a bad example, as they are just mathematical functions, i.e. "abstract ideas." They should not be patentable. Although I realize patent law is not actually logically consistent.
Commercial application is the motivation behind patent law, and logical consistency is not the point, but rather legal consistency. When you patent an algorithm you do not patent the idea any more than you patent thermodynamics when you patent an engine. You patent a particular application of an idea that performs some function or functions. The algorithm -- or thermodynamics -- stay completely free for anyone to know, study and disseminate. In fact, patents are designed to make the knowledge public so that they could be studied and improved upon.
Whether or not it works is a separate question (and I completely agree that software patents do not perform their role), but patenting a device to predict stock prices is not patenting math, just as patenting a drug is not patenting chemistry.