Computing The Discounted Return In Markov And Semi-Markov Chains