mathematical representation of absence of a value
The distinction between the empty set and the number
is similar to that between
NULL and ZERO. For example, the set of real solutions (or informally "the solution") to is
, but the solution to
is
.
In my mind there is no need for a concept like NULL in mathematics if you think of NULL as in NULL-pointers.
NULL in this sense is a technical necessity because you cannot un-define a variable: Once a variable has been assigned a value, a certain bit of memory is reserved for this variable and this memory is marked as re-usable only if the variable goes out of scope (simplified speaking).
You cannot say "The variable with this name doesn't exist anymore." without letting it go out of scope, because that would make language interpretation much more complicated without many benefits. Therefore, to indicate that the value of the variable has no meaning, one uses NULL.
What NULL stands for in the end depends upon the programming language: In some it is a special keyword, but in some it is also just a different name for the integer .
You can assign an arbitrary value to NULL in mathematics as mentioned in the other replies (,
, etc.) but as mathematics has nothing to do with memory allocation there is really no need for such a thing as
NULL.
Videos
What is a null set example?
What is a null set called?
How do you define a null set?
From MSDN:
The predefined unary and binary operators and any user-defined operators that exist for value types may also be used by nullable types. These operators produce a null value if the operands are null; otherwise, the operator uses the contained value to calculate the result.
That's why all the test are passed, including the last one - no matter what the operand value is, if another operand is null, then the result is null.
The operators for Nullable<T> are so-called "lifted" operators]; the c# compiler takes the operators available for T and applies a set of pre-defined rules; for example, with +, the lifted + is null if either operand is null, else the sum of the inner values. Re the last; again, division is defined as null if either operand is null - it never performs the division.
Null: A value of NULL indicates that the value is unknown. A value of NULL is different from an empty or zero value. No two null values are equal. Comparisons between two null values, or between a NULL and any other value, return unknown because the value of each NULL is unknown.
If you do any arithmetic operations with null the whole expression evaluates to Null. In order to handle null you should use Isnull() or coalesce function like this.
select 1 - isnull(NULL,0) as result
Simply because NULL is not 0.
If it helps, consider NULL as a synonym for "unknown", and then it'll make perfect sense - the result of 1 minus an unknown number can only give an unknown result.
NULL (as far as my interpretation goes) is unrepresentable data. The only appropriate tests for null are IS NULL, IS NOT NULL, and several functions made specifically to handle NULL values: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html
You could say - IFNULL(col_c, 0)+col_d (COALESCE will work identically in this case).
More information on working with NULLs: http://dev.mysql.com/doc/refman/5.0/en/problems-with-null.html
Nate, NULL is NULL. MySQL is not going to do the type conversion automatically for you. A way around for that is change the table's column DEFAULT to 0. Or use a function IFNULL(col_c, 0) into your expression.
;-)
This is sufficiently rare, and handled in sufficiently many different ways, that you should always state explicitly how you're treating it. In my experience, the most common symbols are:
$\mathsf{null}$, $\mathsf{nil}$, $\mathsf{NaN}$ or similar on the more computer-sciencey side, and
$\perp$ or $\uparrow$ on the more logicy side.
- Note that "$\perp$" is also used to denote contradiction, and "$\uparrow$" is also used as a predicate to denote "is undefined" or "doesn't halt" with "$\downarrow$" denoting "is defined"/"does halt."
But again, I'd explicitly state which you're using - although admittedly multiple of these would almost certainly make it obvious from context.
You can use some kind of Many-valued logic, but you said you want to put it simply. In SQL there is 3-valued logic with "null"/"unknown", for example.
From the Fundamental methods of mathematical economics (4th ed.) by Chiang and Wainwright, page 10:
“The smallest possible subset of S is a set that contains no elements at all. Such a set is called the null set, or empty set, denoted by the symbol Ø or {}.”
“The reasoning for considering the null set as a subset of S is quite interesting: If the null set is not a subset of S (Ø ⊄ S), then Ø must contain at least one element 𝑥 such that 𝑥 ∉ S. But since by definition the null set has no element whatsoever, we cannot say that Ø ⊄ S; hence the null set is a subset of S”
Question:
Why do we define a subset this way, leading to the inclusion of the null set? Could we not (more intuitively) define a subset of S: containing at least one element 𝑥 such that 𝑥 ∈ S AND no one element 𝑥 such that 𝑥 ∉ S?
My intuitive thinking:
If I have an apple, an orange, and a kiwi, I usually don’t also go around thinking that I also have a ‘no fruit’. Feels wrong to claim that ‘no element’ is a good description of my set that definitely contains elements.
Edit: Wow, THANK YOU everyone for such a robust discussion. Lots to think on, lots to turn over in my mind.