Fast matrix rank algorithms and applications