An algorithm that infers theories from facts