Counting objects in generalized quantifier theory, modal logic and knowledge representation