How?
It is possible. Some software applications require a rigorous testing. Software for the military, for medical applications and flight control systems must be bug free.
If not, something like this can happen:
http://en.wikipedia.org/wiki/MIM-104_Patriot#Failure_at_Dhahran
You're wrong.
You can prove that a certain program has certain properties. This is fairly time consuming but it can be done for relatively small programs. Usually you don't prove the correctness in the actual programming language you're using so you'll need to translate it. That can introduce errors.
Then you need to compile it. Unless proven correct, the compiler can have errors that change the behavior of the program.
The compiler produces a program in machine code, that you need to run. You need to run it on an operating system. If the operating system is not proven correct, that can change the behavior of the program.
Finally, errors in the micro code or architeture of the CPU can change the behavior, such as the infamous Pentium bug some years ago.
That being said, for some usages very rigorous software testing is used, such as military software, medical equipment, space shuttles, CPUs etc. If your willing to pay 10 times more for your mac and accept that substantial new features will be decades in the making it would maybe be economically feasible for Apple to actually start proving the correctness of part of the OS.
That being said, Apple could definitely use some more resources on quality assurance. It's not like this is the first time.