I've been doing past paper questions and keep coming up against these questions that deal with 3 valued logic. My notes mention it but don't give examples that relate to those asked in exams.
I understand the basis that True = 1
, False = 0
& Unknown = 1/2
as well as And = Min
, Or = Max
and Not(x) = 1-x
. However I do not know how to apply it to questions such as those below:
In SQL, discuss the possible truth values of the following expression:
R.a > R.b OR R.a <= 0 OR R.b >= 0
Justify your answer.
And:
The phone and age fields of the Owner table might have null values in them. Considering all possible combinations, show which of the three truth values might be returned by the expression:
phone = ’141-3304913’ OR age <50 OR age >= 50
Any help in clarifying these for me would be really appreciated :)
I will focus on the concrete example, which is more proper for clarifying things. Put simply, your logical expression is made of a conjunction of three clauses
for which tri-boolean logic states that the result is
Consequently, if the value associated with True is the largest, with False is the smallest, and with Unknown is any intermediate value, then taking the
MAX
for a conjunction proves correct. Similarly, a disjunction works with theMIN
function. Negation works as long as we interpret any value between 0 and 1 (excluded) as Unknown; clearly, if we take 1/2 then the negation function is "stable", but that does not really matter in mathematical terms.More operatively, the clauses clearly react to the following values (instances) of your
phone
variableP
and yourage
variableA
:In terms of satisfaction of the clauses, we have
In general there exist 3*3 possible combinations, since each of your two variables takes three possible values:
In particular, since C2 and C3 are mutually exclusive, you never get False as a result of the conjunction.
The expression
R.a > R.b OR R.a <= 0 OR R.b >= 0
instead presents these cases:Apparently we have three variables and 27 possible cases, but several related to
R.a - R.b
can be trivially ruled out.