When Logic goes Wrong

What is logic? Logic is where you take one or more statements you know to be true, and from them deduce further statements that must also be true. 

For example, if a is equal to b and b is equal to c, it logically follows that a must also be equal to c.

Computer programs can use logic to take one or more pieces of data, and from them, deduce other pieces of data.

For example, a piece of code can take today’s date and determine that it is a Saturday. And from the day being Saturday, it can determine that it is a weekend. The code may then perform certain actions according to it being a weekend, such as not triggering an 8am alarm.

So far, so good. But can this go wrong? Can logic, that completely rational process of deduction, possibly go wrong?

Yes, it most certainly can. And here’s why:

Logic is only as good as the base assumptions it’s working from.

What do I mean by that? In my very first sentence I defined logic as taking one or more statements you know to be true, and deducing further statements that must also be true.

This means that all logic is based upon a set of true statements. The rest of the logical framework hinges on those statements being absolutely true. So what if they are not?

If the base ‘true’ statements that a logical framework hinges on are actually false, we start to get into trouble.

In our first example, this would mean that perhaps a is not actually equal to b. So even if b is really equal to c, the logical deduction that a is equal to c would be wrong.

In our second example, we have used the base assumption that Saturday is a day in the weekend. But in some countries, Saturday is a working day like any other. Therefore, the code is not triggering the 8am alarm because it has deduced that the day is a weekend; a non-working day. Poor Juan in Mexico who set up his weekday alarm has now overslept and is late for work!

So, when setting up your program, or using logic in general, you need to be careful about what base assumptions; what supposed ‘truths’, you are using. Are you sure they are universally true?

A real-world example of using false base assumptions in software is this news story here. In this case, a piece of software that calculated the take-off weight of an aircraft used the base assumption that any passengers with the title ‘Miss’ were children. Average weights for children were used for those passengers. The result was that the plane’s calculated take-off weight was far lower than it should have been. It is imperative to have accurate take-off weights for aircraft, as it affects how the plane flies if the pilots have incorrect data. In the worst case it could cause the pilots to lose control of the aircraft. Fortunately, on this occasion, it did not cause a problem. 

In the country where the code was written, ‘Miss’ was the title used only for girls under eighteen. It was a base assumption that was true, but not universally true. When the code was applied to British passengers, for whom any unmarried woman could have the title ‘Miss’, the base assumption no longer held. The logical framework fell down – inaccurate weights were calculated as a result.

What have we learned? When writing code, or making logical deductions of any kind, always make sure that the ‘universal truths’ you are basing your logic on are actually true, and actually universally true. And, if you can, don’t infer data from other data. In the case of the airline passengers, their ages should not have been inferred from their titles. A much better solution would have been to use the date of birth on their passports to calculate their ages instead.