Is there a name for "3-state Boolean"?

Asked

Viewed 252 times

4

But as such a "Boolean of 3 states"?

It is usually used in comparing dates, where possible results are -1, 0, 1.

I was in a similar situation and I was left with this doubt when I wanted to ask my colleague about a possible representation Enum in Java.

  • I’ve never seen this term, would it be 3 states? Can you cite an example of usage with comparison of dates.

  • Three-valued logic?

  • @Maniero if understood well, the idea is the same applied in the function strcmp C, which has the 3 possible returns; or the one used by Spaceship Operator in PHP.

  • @rray sounds good, but then in fact it doesn’t have a name? since you are inquiring.

  • Have you ever heard this term in a database, in case a column may have some value, nothing and null (unknown).

  • @Andersoncarloswoss yes, but there is nothing boolean of 3 states (or stages) there.

  • 1

    Yes, it is up to @Guilhermelautert to say what he asked. In my view, the term "3-state boolean" was used in a misleading way, even unintentionally, which possibly sidetracked the question. Or got it wrong :D

  • 1

    My colleague found the following in wiki which I think is very interesting. ""

Show 3 more comments

1 answer

6


A boolean of 3 states is the one that has the false, the true and the undefined. So in Java there is a natural that is the Boolean, not to be confused with boolean (What difference between Boolean and Boolean?). The first accepts a null, then there is a third state.

In C# you can use a bool?. There’s language that only has three-state boolean, and a lot of people don’t even realize it.

In languages that don’t have it, you’d have to create a convention or even an enumeration if it exists in the language, something like that:

enum tribool { false, true, maybe = -1 }

Some people say it shouldn’t be used, and if you have three states then it’s not a boolean, it’s something else. In fact this date thing seems to me to be something else. Something like this:

enum compara { igual, depois, antes = -1 }

I put in the Github for future reference.

Is there a name for the "3-phase Boolean"?

Apparently it is called trivalent or ternary logic (after all the boolean is the binary), according to Wikipedia (in more complete English). Other terms can be used as seen in the comments. There does not seem to be a universal name. And since its use is not so much encouraged, it might be better that way.

From what I understand no one received credit for the "invention" and so no one was honored. The binary might not call it boolean if you didn’t give George Boole so much credit.

  • In fact phases, not right, states seem better even. I put what I thought at the time.

  • I think you may like to see https://en.wikipedia.org/wiki/Three-valued_logic

  • It is the English version of the page that I Linkei :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.