can you help turn this into a math formula?

I have a set of numbers e.g.

X = {1, 2, 3 ,4 ,10, 11, 12}

what would be the math notation for splitting the set into a list or sequence of smaller sets depending on some condition

e.g f(x, y) = |x - y| < 5

psudo code would be like this:-

function f(x, y):

return |x - y| < 5

Set X = {1, 2, 3 ,4, 10, 11, 12}

List<Set> lst = Empty

for(i = 1; i < X.Length; i = i+1) // i=1, iterate while i < X.Length, increment i by 1 every iteration

{

Set Tmp = Empty

while( f(X[i-1], X[i]) ) // keep adding members to set while function returns true

{

Tmp.Add(X[i]) // add member from X to Temp set

i = i + 1 // increment i

}

lst.Add(Tmp) // add temp set to list of sets

}

If this is not clear please let me know.

P.s. i think i migth need a memebrship function but i'm not sure how to write this out.

Thanks in advance.