Compute sptree domain via domain_foldi.

Also add a Lib file, which contains some conversions.