There are two ways to translate “exactly” into FOL, a long way and a short way.
Let’s say we want to write: “There are exactly two dogs.”
The long way uses the work we’ve already done: if we say there are at least two dogs, and at most two dogs, then that requires that there are exactly two dogs.
The long way looks like this:
∃x∃y(D(x)&D(y)&~x=y) & ∀x∀y∀z((D(x)&D(y)&D(z))→(x=y v x=z v y=z))
It is a wide-scope conjunction.
But you can tell from all the repetition that there’s a more efficient way of writing it.
For the short way, we still need two existential quantifiers. After all, exactly two is going to require the existence claims of two things.
But for the “at most” part, we can use one universal quantifier inside the scope of the existentials. I call this ∀ the catch-all.
It looks like this:
∃x∃y(D(x)&D(y)&~x=y & ∀x(D(z)→(x=z v y=z)))
This just says: there exist two dogs (at least), and if anything is a dog, it has to be one of those two (hence exactly two).
So on the short way, to say “exactly n“, we need n existential quantifiers and 1 universal.