much more efficient type-level halving method