A program is a tangible, physical arrangement of electrons, atoms, and/or electromagnetic fields. Just because it is easily rearranged and difficult to perceive with the naked eye does not make it mathematical or virtual or unreal.
In a sense, all possible computer programs for a given architecture are implied in that architecture, ...
All possible medicines are implied by the rules of chemistry obeyed by a liter of pond scum. Determining which potential medicine does what is a patentable invention.
One could likewise argue that math is a tangible physical arrangement of pencil marks on a page or of neurons in the brain. But the point remains that math is not patentable.
Should someone be able to patent a prime number? Discovering a new large prime number requires effort, skill, lots of compute cycles, etc., but it's not patentable. Discovering an algorithm that has novel properties also requires effort and skill, but it shouldn't be patentable either, because it's math.
All possible medicines are implied by the rules of chemistry
Maybe eventually we'll understand the rules of chemistry and human biology as well as we understand the rules of math, but until that happens the case of medicine is not really comparable to the case of software.
A tangible program is not what's being patented, only the concept of the program, which is not tangible. Concepts are patented, not code. Code gets copyright protection.
Similar to saying, "Hey! I thought of a cure for cancer. I didn't actually come up with a specific one, only the concept of one. If you actually come up with it, it's my property and I'll sue you if you don't recognize that.
This means that there are trivial concepts out there, that if I implement in software, I owe bank to some company. It's pretty fucked up when you think about it.