Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

For example, a bit or a boolean can be either 0 or 1 so the number 2 is associated with it. Similarly, for a byte which is 8 bits, the maximum number of different assignments would be 2^8.

Is there a name for this number?

When we pass everything through our system that has ECMAScript, Java and MySQL, then a boolean does not have only two possible assignments. For instance, a false boolean gets saved as a 0 and the boxed value could be null so a boolean suddenly can get true, false, 0, 1, null or even undefined or <missing>.

I think it could get problematic in tests to guarantee that the values are not inconsistent. For instance, a value boolean locked could become null and then when a script or a layout template evaluates it then it will evaluate to false somewhere if the real value was null and similar problems.

So why don't we always assert that a boolean has the same number of possible values (2 values) and similarly for other types?

There is a mathematical term named "arity" that is something similar but not exactly, and statistics and probability theory also has the concept of "event space" that would be almost exactly what I mean. For instance, the event space for a boolean would be the set {0,1} which has cardinality 2 and that cardinality doesn't get preserved throughout the system, especially when data is passed as polyglots and/or serialized (json, jsonp, xml, yaml).

share|improve this question

closed as primarily opinion-based by gnat, Mathew Foscarini, GlenH7, pdr, Bart van Ingen Schenau Mar 22 at 19:02

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
format your question plz :) –  Songo Mar 22 at 13:59
    
This is a "name that thing" question. Those are off topic here. –  Mathew Foscarini Mar 22 at 16:31
    
This question appears to be off-topic because it is a "name that thing" question. "Name that thing" are bad questions for the same reasons that "identify this obscure TV show, film or book by its characters or story" are bad questions: you can't Google them, they aren't practical in any way, they don't help anyone else, and allowing them opens the door for the asking of other types of marginal questions. See blog.stackoverflow.com/2012/02/lets-play-the-guessing-game –  Bart van Ingen Schenau Mar 22 at 19:02
    
@bart: I chased down those references as far as Pee Wee Hermann. OP is 1608 and asks questions about naming things. By the tests I found, this question should be allowed. –  david.pfx Mar 23 at 0:43

2 Answers 2

I would call it cardinality (and indeed I have used it in that sense). It is strictly the cardinality of the set of all values a variable can take.

Edit: for example, a 16-bit integer can take exactly 65536 values. The cardinality of the set of all values that the integer can take is 655536.

Once you start to consider variables that have a range of valid values and also a range of invalid values (like a boolean with a bitwise value of 17), then you have to extend the concept somewhat, but you can still describe those values with set notation and the concept of cardinality still applies.

Edit: Yes, this is the mathematical set, not programming Set. If you were to apply the concept to the C# type short and derive the type short?, this would not have 65537 values, represented by the union of the set of 65536 values mentioned previously and one additional value, null.

share|improve this answer
    
I think cardinality is close, but not quite right, according to wikipedia: "In mathematics, the cardinality of a set is a measure of the "number of elements of the set"", so cardinality is the number of values the set currently has, not the number of possibilities. –  user50849 Mar 22 at 14:09
2  
@user50849: No, the cardinality is the number of elements the set has, where each element is a value the variable is allowed to take. –  david.pfx Mar 22 at 14:14
    
My understanding of the mathematical concepts here is limited, so that's not how I read it, but I'll take your word for it. Perhaps you could expand the answer a bit to explain this. :) –  user50849 Mar 22 at 14:18
    
@user50849: This might be a difference between a mathematical set, which is a fixed thing and a Set data structure which can be varied over time. –  Salix alba Mar 22 at 14:42
1  
In this case, the set is a theoretical one; i.e. the set that is 1-to-1 with the type of the variable. The cardinality of that set is the number of possible different values that the variable could take. –  Stephen C Mar 23 at 1:10

If you subscribe to the "types as a set of values" interpretation of type theory, then cardinality is in fact a good name.

So, the cardinality of bool would be 2, the cardinality of byte would be 256, and the cardinality of String would be ℵ0.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.