An exact algorithm for first order probabilistic logic