Return the set of matches to xy whose total length is in Ns. We
    ask y only for lengths that are remainders after an x-match in
    0..max(Ns). (And we call neither x nor y if there are no Ns.)

def genseq(x, y, Ns):
    """Return the set of matches to xy whose total length is in Ns. We
    ask y only for lengths that are remainders after an x-match in
    0..max(Ns). (And we call neither x nor y if there are no Ns.)"""
    if not Ns:
        return null
    xmatches = x(set(range(max(Ns)+1)))
    Ns_x = set(len(m) for m in xmatches)
    Ns_y = set(n-m for n in Ns for m in Ns_x if n-m >= 0)
    ymatches = y(Ns_y)
    return set(m1+m2 for m1 in xmatches for m2 in ymatches if len(m1+m2) in Ns)