clarification in tf-idf formula
A document is modeled as a set $d$ of words.  Since we're maximizing $f(w,d)$ over all $w\in d$, this means that $w$ ranges over all possible words contained in $d$.

In the future, please check a textbook before asking.  We expect you to do some research on your own before asking, and this is a standard topic that's well-covered in standard explanations of tf-idf.