Hacker News new | ask | show | jobs
by epolanski 33 days ago
Non-boolean logic is more than a century old.

We could bring quantum physics as a simple example of binary logic collapsing, but in programming there are countless ones.

A simple one is a table of users in SQL, where age can be `null` and not just a positive number.

For filters like "age < 18" and "age > 18" a binary answer cannot model business logic decisions on this set of data properly.

Thus SQL implements a third logic value, UNKNOWN.

Another simple example "is the room hot?".

This is by intuition a bad fit for binary logic. Even if you define "hot" as 30C it's quite clear that the problem is way too nuanced and context dependent to model with binary logic, you need more than two possible answers than yes/no.

2 comments

I took a course in advanced logic and there is actually a really broad and diverse world of them that is fascinating. Contextual logic for one.
For 3 values, don’t you just need a pair of booleans ? Known or unknown… If known: 0 or 1 …
unknown | yes | no has the same cardinality (3) of unknown | boolean as you can replace boolean with yes | no.

If you write code that has to handle it, you still need to consider 3 cases, you can never reduce it to two cases only.