This is the fortieth part of the ILP series. For your convenience you can find other parts in the table of contents in Part 1 – Boolean algebra
We already know how to implement binary logic in ILP, today we are going to utilize it to implement ternary logic.
Ternary logic is used widely in SQL databases. Zero and one (or false and true) are rather ordinary, third value is called
unknown and represent situation when we don’t know exact value. It usually has value . Truth tables for ternary logic goes as follows:
We are going to represent any ternary logic value as a pair of boolean flags. You can intuitively treat this as a number in binary system with values multiplied by two, so false is , unknown is , and true is . We know that disjunction can be calculated as a function and conjunction as a function and in theory we can implement operations in this way. However, simply checking all cases is faster. This is disjunction:
Conjunction goes this way:
Of course we need to destructure result to have two boolean flags at the end.