It seems many programming languages have a function similar to groupBy. Does anyone know whether there is a general mathematical name for this function? I.e., if f is a function (in the set theory sense) mapping set X to Y, f inverse may not exist, but I certainly can pair every element y in the range with the set of elements x, in the domain which f(x) = y.

If f maps X to Y, then groupBy(f) (for lack of better notation) maps Y to the power set of X, and is a well-defined function.

If I’m not mistaken, I believe such an operator also exists in relational algebra. Perhaps that name might be useful and evocative.

Does anyone know if this function has a name? I’m tempted to call it the reciprocal function.

Yes, and my question is if f maps X to Y then what is the mathematical name for the function X.groupBy(f) called? I.e., X.groupBy(f) returns something which behaves like a function which can be called with a value from Y and it returns a subset of X. In scala it returns a List of elements from X, but mathematically/semantically it is a subset of X.

val strings = List("a","aa","abc","bb","c")
val g:Int=>List[String] = strings.groupBy(_.length)
g(2) // returns List("aa","bb")

The surjective map x |-> [x] from X onto X / R , which maps each element to its equivalence class, is called the canonical surjection or the canonical projection map .

X / R is the quotient set. X is your space and R the relation