In this challenge, a partition of a set
S means a collection of nonempty subsets of
S, which are mutually disjoint and whose union is
S. We say that a partition
p is finer than another partition
q is coarser than
p), if it can be obtained from
q by splitting some of its sets into smaller pieces. The join (or least upper bound) of two partitions is the finest partition which is coarser than both of them, and their meet (or greatest lower bound) is the coarsest partition which is finer than both of them. See the Wikipedia pages on partitions and lattices for more information and nice pictures.
One way to compute the join and meet of two partitions
q is the following. Form a graph whose vertex set is
S, and add an edge
a - b for each pair
a, b that are in the same set in either
q. Then the join of
q contains the connected components of this graph. The meet of
q consists of all nonempty intersections of a set in
p with a set in
For example, consider the partitions
S = [0,1,2,3]. The graph mentioned above is
0-1 |/ 2-3
where the edge
2 - 3 comes from the first partition (
3 are in the same set), and the triangle comes from the second one (
2 are in the same set). This means that the join is
[[0,1,2,3]]. The intersections of all the sets in the partitions are
[0,1] ∩ [0,1,2] = [0,1], [0,1] ∩  = , [2,3] ∩ [0,1,2] = , [2,3] ∩  = 
Removing the empty set, we have the meet
Two partitions of a finite set of integers, given as arrays of arrays.
The join and meet of the input partitions, in this order.
[] [] -> [] [] [[0,1],[2,3]] [[0,1,2],] -> [[0,1,2,3]] [[0,1],,] [,,[2,3,4,7,6]] [[2,3],[4,7],,[1,0]] -> [[0,1],[2,3,4,6,7]] [,,[2,3],[4,7],] [,[1,2],[5,4],[3,6]] [[0,3],[6,4],[5,2],] -> [[0,1,2,3,4,5,6]] [,,,,,,]
The order of the sets in the output partitions, and of the numbers in those sets, does not matter. You can assume that the inputs are correct, that is, they contain the same numbers, each exactly once, and no empty arrays. Note that the numbers do not necessarily form an interval (the third test case contains no
You can write either a full program or a function. You can also write two programs/functions in the same language, one of which computes the join and other the meet, but there's a bonus of -10 bytes if you don't choose this option. The shortest byte count wins, and standard loopholes are disallowed.