functions for calculating term probabilities