# partition -- partition a set or list by values of a function

## Synopsis

• Usage:
partition(f,L)
partition(f,L,I)
• Inputs:
• f,
• L, , or
• Outputs:
• , whose keys are the possible values of the function f on the elements of the list, set or tally L, and the corresponding value of the hash table is the list, set or tally of elements of L which take that value under f. The optional third argument I is a list whose elements will be included as keys in the return value, allowing empty lists to appear in the partition.

## Description

 i1 : L = {1,3,6,5,3,1,2,8,8,8} o1 = {1, 3, 6, 5, 3, 1, 2, 8, 8, 8} o1 : List i2 : partition(odd, L) o2 = HashTable{false => {6, 2, 8, 8, 8}} true => {1, 3, 5, 3, 1} o2 : HashTable i3 : partition(odd, set L) o3 = HashTable{false => set {2, 6, 8}} true => set {1, 3, 5} o3 : HashTable i4 : partition(odd, tally L) o4 = HashTable{false => Tally{2 => 1}} 6 => 1 8 => 3 true => Tally{1 => 2} 3 => 2 5 => 1 o4 : HashTable i5 : partition (even, {3,3,5},{true,false}) o5 = HashTable{false => {3, 3, 5}} true => {} o5 : HashTable
The following example partitions the generators of an ideal by degree.
 i6 : R = QQ[a..f] o6 = R o6 : PolynomialRing i7 : I = ideal"ab,ade,ac3,d4,b3,adf,f4,e10" 3 4 3 4 10 o7 = ideal (a*b, a*d*e, a*c , d , b , a*d*f, f , e ) o7 : Ideal of R i8 : partition(f -> first degree f, flatten entries gens I) o8 = HashTable{2 => {a*b} } 3 3 => {a*d*e, b , a*d*f} 3 4 4 4 => {a*c , d , f } 10 10 => {e } o8 : HashTable

• tally -- tally the elements of a list or sequence
• partitions -- list the partitions of an integer
• sublists -- process interspersed subsequences of a visible list

## Ways to use partition :

• "partition(Function,VirtualTally)"
• "partition(Function,VirtualTally,VisibleList)"
• "partition(Function,VisibleList)"
• "partition(Function,VisibleList,VisibleList)"

## For the programmer

The object partition is .