Saturday, November 1, 2008

Eighth Week - Program Correctness for Iterative Functions

Hopefully everyone had a happy Halloween, and managed to get through October. It was pretty crazy at times and midterms and never fun, but things are letting up (a bit) and its a lot better now. And Chelsea's back at the top of the Premiership today, so I'm feeling pretty happy today.

Week eight continued on with program correctness, as Monday's lecture covered loop invariants, which are very handy in proving program correctness on iterative functions. A loop invariant, which I remember Paul talking about once or twice in 148, was a statement that was always true before and after each iteration of a loop.

Iterative functions, to be correct, need the precondition and termination of the loop to imply the post condition, and the precondition to imply termination of the loop. Termination is defined as a decreasing sequence of natural numbers. We saw examples of this in the power function rewritten iteratively, and it didn't seem too difficult, but Wednesday's example, a mysterious 'counter' program, involved a harder sequence to define as terminating. Friday involved nested loops, which are a little more bothersome but I didn't find them to particularly be that hard - just time consuming.

Test 2 is coming up this week, but I'm not too concerned about it right now. Maybe it's the CSC207 A2 and stats assignment due the same day, but I think this class is becoming my clear favourite, and I find I'm the least stressed for this out of any of my other classes while earning the highest marks. I still haven't written up a formal problem solving solution, however, and I need to find a problem to do it on soon, as this term will be over soon.

No comments: