# Three-valued logic solver?

This is not my area, so apologizes if I am asking nonsense!

I know that there are very good solver/theorem provers for solving 1st order logic.

Now I have a problem, using 3-valued logic, but I am not sure if there are some practical ways of solving 3-valued logic (or converting it to a bigger 2-valued logic problem?)

EDIT1: Is it possible to translated (~reduce?) any 3-valued logic to 2-valued logic? Can this be generalized to K-valued logic, where K is any arbitrary integer? (What about the case when K is infinity?)

Any idea or reference is appreciated.

• Isn't this a special case of CSP: en.wikipedia.org/wiki/Constraint_satisfaction_problem – joro Aug 8 '14 at 8:33
• There is more than one system of 3-valued logic, but all of them have straightforward translations to 2-valued logic, replacing each atomic formula with a pair of formulas (that can be seen as implementing the original formula and its negation, in case the logic has Kleene negation). – Emil Jeřábek supports Monica Aug 8 '14 at 10:25
• @joro: 3-valued propositional logic is CSP. 3-valued first-order logic obviously isn't, as it is just as undecidable as in the 2-valued case. – Emil Jeřábek supports Monica Aug 8 '14 at 10:29
• @EmilJeřábek thanks for the explanation. Could you point me to some of the translations to the 2-valued logic? I updated the question with some relevant details. – Daniel Aug 8 '14 at 21:54
• A finite-valued logic may be algorithmically translated into a 2-valued setting as soon as its language is sufficiently expressive (negation might help on that). Such expressiveness condition may be checked by way of a fixed-point construction, and failure in expressivity may be fixed by appropriate conservative extensions. The resulting 2-valued semantics is based on a generalized notion of compositionality, and is amenable to fully automated implementations. One detailed reference for the above is this paper. – J Marcos Aug 11 '14 at 22:20

## 1 Answer

Let's assume that your three-valued logic consists of the truth values Yes, No and "unknown". We can think of these truth values as the sets $\{\top\}, \{\bot\}, \{\top,\bot\}$, and then the logical operations result in all possible values. For example, Yes and Unknown is Unknown while No and Unknown is No.

A trick known as "double rail logic" uses two binary variables to represent each truth value: Yes is 1,1; No is 0,0; and Unknown is 1;0. The connectives And and Or are implemented using two matching gates, and Not by two negation gates followed by a swap.

More generally, $k$-valued logic can be implemented by encoding each truth value using $\lceil\log_2 k\rceil$ bits. The logical operations are implemented using constant-size Boolean circuits. The advantage of the encoding above is that the circuits are very simple, in particular they read each input only once.

• Interesting example. But in your example, I don't understand to the output corresponding to 0;1. How do we treat that case? – Daniel Aug 9 '14 at 5:33
• Let me clarify. By this conversion, the resulting thing semi-decidable (right?), i.e. for any algorithm and given logical 3-valued logical statement, it can evaluate it for us, only when it is {T}, not the other two cases. How do you handle this? (i.e. how do you do resolution for this?) – Daniel Aug 11 '14 at 0:41
• Basically how you formalize CWA suggested model? en.wikipedia.org/wiki/Closed_world_assumption – Daniel Aug 11 '14 at 5:56
• We have embedded your three-valued logic into ordinary Boolean logic, do now you can use whatever algorithm you want that can handle Boolean logic. For example, there is an algorithm for the stable marriage problem which is based on three-valued logic. Using this conversion, you can implement it with Boolean variables. – Yuval Filmus Aug 15 '14 at 17:39
• If you have other logic in mind, say one corresponding to CWA, you need to specify then first. I can't read your mind. Whatever the logic is, if it has reasonable semantics then the same encoding idea would work. – Yuval Filmus Aug 15 '14 at 17:43