A Formal Basis for Analogical Reasoning