Upper and lower bounds for ranks of matrix expressions using generalized inverses