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");
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."


wleslie 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

Ubuntu 20.04 on a 2015 15" MacBook Pro

I decided to give Ubuntu 20.04 a try on my 2015 15" MacBook Pro. I didn't actually install it; I just live booted from a USB thumb drive which was enough to try out everything I wanted. In summary, it's not perfect, and issues with my camera would prevent me from switching, but given the right hardware, I think it's a really viable option. The first thing I wanted to try was what would happen if I plugged in a non-HiDPI screen given that my laptop has a HiDPI screen. Without sub-pixel scaling, whatever scale rate I picked for one screen would apply to the other. However, once I turned on sub-pixel scaling, I was able to pick different scale rates for the internal and external displays. That looked ok. I tried plugging in and unplugging multiple times, and it didn't crash. I doubt it'd work with my Thunderbolt display at work, but it worked fine for my HDMI displays at home. I even plugged it into my TV, and it stuck to the 100% scaling I picked for the othe

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 , 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.&quo

Haskell or Erlang?

I've coded in both Erlang and Haskell. Erlang is practical, efficient, and useful. It's got a wonderful niche in the distributed world, and it has some real success stories such as CouchDB and Haskell is elegant and beautiful. It's been successful in various programming language competitions. I have some experience in both, but I'm thinking it's time to really commit to learning one of them on a professional level. They both have good books out now, and it's probably time I read one of those books cover to cover. My question is which? Back in 2000, Perl had established a real niche for systems administration, CGI, and text processing. The syntax wasn't exactly beautiful (unless you're into that sort of thing), but it was popular and mature. Python hadn't really become popular, nor did it really have a strong niche (at least as far as I could see). I went with Python because of its elegance, but since then, I've coded both p