Forward and backward reasoning in AI