title: Algorithmics
subtitle: DLMCSA01
authors: Prof. Dr. Cosmina Croitoru
publisher: IU International University of Applied Sciences
date: 2023
pp. 101 -> 132
Looking to learn:
Programs fail for many reasons, whether they give you unexpected output or fail to give any at all. This is why it is important to verify the correctness of programs and algorithms during development. We can also write tests to verify that our programs give desired output for reasonable input(s), but nothing can beat a mathematical proof of an algorithm’s behaviour. I have no idea how deep into the weeds we are going to get, but we will look at how to ensure algorithms, and programs, are correct.
Searching recommended books for “partial correctness” doesn’t result in anything right away. The concept of “correctness” of an algorithm is brought up in the very beginning of chapter 1 of MIT Press “Introduction to Algorithms”. They state an algorithm in computationally correct if for every input provided, it haults (finishing computing in finite time), and outputs the correct solution to the “problem instance”.
In my preferred book, “The Algorithm Design Manual”, 3rd edition, published by Springer, the author discusses correctness in chapter 1, but section 1.3. Then continues to discuss proofs by induction and contradiction.
The course book presents the induction proof, which we can find anywhere online, before explaining how to prove partial correctness of an algorithm.
Correctness (Computer Science) | Wikipedia actually discusses partial correctness. What’s the difference? Partial Correctness requires that if an answer is returned from the algorithm, or program, or whatever, then it must be correct. Total Correctness adds the requirement that an answer is guaranteed to eventually be returned. That is, the algorithm terminates, or as MIT says, it haults.
The Wiki article dives into a few interesting topics about proofs and computing, referring to an algorithm of the least odd perfect number as an example of a partially correct algorithm. And Wiki also discusses Software Testing, calling it an art, and stating it is impossible to completely test a program with even moderate complexity. Then, Software testing is a trade-off between budget, time, and quality, which is a golden triangle of software engineering. You can only pick 2 or the 3 at any time.
You might first learn of proofs and induction in a discrete maths course. The concept of Proof by Induction, as stated in the course book and Mathematical Induction | Wikipedia, is to prove a usually simple case of what you are trying to prove, and extending that all other cases. The course book uses some notation, but the example is good.
Let’s prove the following:
This is also the example in the MIT press book… Anyway, just follow the steps. What are those? Mathematical Induction | MathIsFun.com says:
The terms come from Wiki… which gives the same example!
We can prove, mathematically, the base case:
We make the assumption that the following statement is also true for values of where :
Right, basically just changed the variables, but we pretend it is something different. Because now we switch to using but up the stakes by going to :
All that happened is I pulled out the last term, which would have been , and compact the remaining terms into our assumed to be correct function. Let’s force this function into submission
There’s the formula we are looking for.
p. 103