Given truth tables of two-variable three-valued functions, decide whether each is definable using AND, OR, IMPLIES, EQUALS.
Medium7MathBrute forceNo attempts yetTime limit10sMemory limit512 MBArtificial intelligence is taking over the world, or at least planning to do so soon. Machines will become clever enough to win every game, answer every question and make every decision for you. Because that sounds frightening, someone proposed giving the machines a bit of a human touch: from time to time a machine pretends not to know the answer and reports uncertainty instead.
In secret the machines still follow precise rules, those of a three-valued logic. It adds a third value U (uncertain) to the two values F (false) and T (true) of Boolean logic, and it extends the logic operators as shown in the tables below. In each table the row picks the first argument and the column picks the second, and both run through F, U, T in that order.
| ∧ (AND) | F | U | T |
|---|---|---|---|
| F | F | F | F |
| U | F | U | U |
| T | F | U | T |
| ∨ (OR) | F | U | T |
|---|---|---|---|
| F | F | U | T |
| U | U | U | T |
| T | T | T | T |
| → (IMPLIES) | F | U | T |
|---|---|---|---|
| F | T | T | T |
| U | U | U | T |
| T | F | U | T |
| ≡ (EQUALS) | F | U | T |
|---|---|---|---|
| F | T | F | F |
| U | F | T | F |
| T | F | F | T |
For example, F ∨ T = T as in Boolean logic, T ∧ U = U, and F → U = T.
The first three operators do not reach every function. Every function you can write in terms of x, y, AND, OR and IMPLIES takes the value U at x=y= U, so none of them is the constant T function. The fourth table is the operator EQUALS, which returns T when its two arguments are equal and F otherwise. Even with EQUALS at hand, no expression in x, y, AND, OR, IMPLIES and EQUALS is the constant F function.
Your task is to decide, for a function g(x,y) given as a table, whether it can be expressed in terms of x, y, AND, OR, IMPLIES and EQUALS. The machines need to know their own limits.
The first line contains an integer n (1 ≤ n ≤ 20000), the number of functions you have to consider. Then follow n function descriptions.
Each function description consists of four lines. The first of them is empty. The remaining three lines describe a function g as a table of its values g(x,y). The table has three rows and three columns, corresponding to the values F, U, T of x and of y respectively, laid out like the tables above. Each of these lines holds three entries separated by a single space, and every entry is F, U or T.
For each function description, in the same order as in the input, print one line. Print definable if the given function g(x,y) can be expressed in terms of x, y, AND, OR, IMPLIES and EQUALS. Print undefinable if it cannot.