Set containment: , , ,
The set element containment symbol signals, that something is part of a set. It looks like an e for element.
In a statement like , the left side is the element that is contained in the set on the right side .
Sometimes it is written flipped (). In that case, the order of "element" and "set" is also switched.
If you want to specify that something is not in a set, you strike it out, resulting in and .
There are multiple uses for this. One example is seen in the section for iteration symbols with set notation. In that case the meaning is "for each element of ..." or "for each element not of ...".
It can also be used as a condition. For example, "If is an element of , do ... " is "if , do ...".
Code:
Depending on your data structure and language, the code might differ. Generally, you will likely find a function corresponding to as one of the following:
- contains
- find
- indexOf
- []
Sometimes, there are others or even operators called in. Attention: In JavaScript for example, the in operator checks, whether an object has a specific key, which is sometimes used to model a set, by just using keys. This might lead to unexpected behaviour when you are working with arrays or actual sets, in which the object values are the set elements, not the keys.
The implementation of is just a negation of , so for example the array case above becomes
// Implementation of the not in operator for sets made up of object keys.
// The other variants work the same way
function notIObject(element, objSet){
return !inObject(element,objSet);
}