Skip to main content

Humor: Proving Programs

I've always been weary of programming proofs.

For instance, I can mathematically prove that 4195835 / 3145727 > 1.3338. However, I know of certain Pentium processors that would disagree with me. If I try to prove that the following bit of C code prints out "Hello World":
if (4195835.0 / 3145727.0 > 1.3338)
printf("Hello World\n");
else
system("rm -rf /");
I might be a bit surprised when it deletes my hard drive instead ;)

1 bunny + 1 bunny = 2 bunnies, right? Well it depends on their sexes. It's possible that in a given time period, 1 bunny + 1 bunny might equal 5 bunnies. As I joked in a previous blog post, "All models are wrong. Some models are useful."

I really think this same thing applies to proving programs. Donald Knuth famously said, "Beware of bugs in the above code; I have only proved it correct, not tried it."

Comments

verte said…
Weary of their validity, or weary of their utility?

For any consistent proof, there is a category of sets of fundamental axioms such that if any one element of the set does not hold, the hypothesis is not implied by the proof. I don't think this is interesting at all - any sort of modelling makes its assumptions, and if any result in computer science needed to state that on real hardware, alpha radiation or magnetic interference or insufficient power supply may impact the result, anything useful would quickly be drowned out by irrelevant details.

Proofs are useful because the assumptions made can be quite obvious. From the perspective of a VM implementer, it is a feature to be able to say "there is no input which results in a violation of memory safety or some capability security property". More importantly, it is *awesome* to be able to use that proof machinery to show that your JIT compiler preserves these properties, because they are very easy to break within a compiler.

If it were more common for such critical architecture (I don't think anyone suggests it for the bulk of applications software, even in the fire & medical sectors where I've worked - easier just to use a safe language and hope nothing goes wrong), the malware industry would be close to dead, as would a broad class of system-level bugs.

BTW, off the top of my head, I can only think of two serious vulnerabilities in the last twenty years due directly to implementation details of commodity hardware. Most of it has been bugs in software written in unsafe languages.
jjinux said…
verte, thank you for your excellent response. You've reminded me about fundamental axioms (which I should not have forgotten considering my degree is in math). You've also helped me clarify my thoughts on this subject.

I'm weary of the validity of proving programs, hence I'm also weary of its utility. (Although I do agree that symbol manipulation, for instance during refactoring, is a useful way of thinking.) Part of the problem is that it's so difficult for me to trust in the axioms.

For instance, the law of associativity says that "a + (b + c) = (a + b) + c". You can prove higher order things because you can rely on the law of associativity. However, the law of associativity does not hold for either integers (because of overflow) or floats (because of roundoff error).

My buddy used to say that you can't have a useful logical system without the law of identity which says that a thing equals itself. However, in Python, it's perfectly valid to define __equals__ to always return False. Similarly, in SQL NULL does not equal NULL.

I remember reading in a book recently where one of the authors of Haskell wanted to prove something about a certain class of functions. What he was proving seemed very valid from a math perspective, but I could think of certain hand-crafted "naughty" functions that would violate his "theorem".

Let me summarize. Every theorem must rely on the theorems and axioms below it. I have a difficult time accepting with certainty axioms at any level. It's unfortunate that I think it's all too possible for something to not act in the way it was proven to act.

Popular posts from this blog

Drawing Sierpinski's Triangle in Minecraft Using Python

In his keynote at PyCon, Eben Upton, the Executive Director of the Rasberry Pi Foundation, mentioned that not only has Minecraft been ported to the Rasberry Pi, but you can even control it with Python. Since four of my kids are avid Minecraft fans, I figured this might be a good time to teach them to program using Python. So I started yesterday with the goal of programming something cool for Minecraft and then showing it off at the San Francisco Python Meetup in the evening.

The first problem that I faced was that I didn't have a Rasberry Pi. You can't hack Minecraft by just installing the Minecraft client. Speaking of which, I didn't have the Minecraft client installed either ;) My kids always play it on their Nexus 7s. I found an open source Minecraft server called Bukkit that "provides the means to extend the popular Minecraft multiplayer server." Then I found a plugin called RaspberryJuice that implements a subset of the Minecraft Pi modding API for Bukkit s…

Apple: iPad and Emacs

Someone asked my boss's buddy Art Medlar if he was going to buy an iPad. He said, "I figure as soon as it runs Emacs, that will be the sign to buy." I think he was just trying to be funny, but his statement is actually fairly profound.

It's well known that submitting iPhone and iPad applications for sale on Apple's store is a huge pain--even if they're free and open source. Apple is acting as a gatekeeper for what is and isn't allowed on your device. I heard that Apple would never allow a scripting language to be installed on your iPad because it would allow end users to run code that they hadn't verified. (I don't have a reference for this, but if you do, please post it below.) Emacs is mostly written in Emacs Lisp. Per Apple's policy, I don't think it'll ever be possible to run Emacs on the iPad.

Emacs was written by Richard Stallman, and it practically defines the Free Software movement (in a manner of speaking at least). Stal…

ERNOS: Erlang Networked Operating System

I've been reading Dreaming in Code lately, and I really like it. If you're not a dreamer, you may safely skip the rest of this post ;)

In Chapter 10, "Engineers and Artists", Alan Kay, John Backus, and Jaron Lanier really got me thinking. I've also been thinking a lot about Minix 3, Erlang, and the original Lisp machine. The ideas are beginning to synthesize into something cohesive--more than just the sum of their parts.

Now, I'm sure that many of these ideas have already been envisioned within Tunes.org, LLVM, Microsoft's Singularity project, or in some other place that I haven't managed to discover or fully read, but I'm going to blog them anyway.

Rather than wax philosophical, let me just dump out some ideas:Start with Minix 3. It's a new microkernel, and it's meant for real use, unlike the original Minix. "This new OS is extremely small, with the part that runs in kernel mode under 4000 lines of executable code." I bet it&…