This question is a follow up to the following question isabelle proving commutativity for add, my followup was too long to be a comment. The problem as stated was to show the commutativity of the add function defined as follows:
fun add :: "nat ⇒ nat ⇒ nat" where
"add 0 n = n" |
"add (Suc m) n = Suc(add m n)"
Trying
theorem "add m n = add n m"
apply(induct_tac m)
apply(auto)
gets stuck (on the inductive case) because of a missing lemma. I got curious about this problem, and was exploring alternative (albeit less efficient) way of proving it. Suppose we defined the Lemma
lemma Lemma1 [simp]: "add n (Suc 0) = Suc n
which Isabelle can automatically prove by induction Then the inductive step is to prove
Suc (add k m) = add m (Suc k)
which we could do by hand as follows
Suc (add k m)
= Suc (add m k) by the IH
= add (add m k) (Suc 0) by Lemma1 <--
= add m (add k (Suc 0)) by associativity (already proved)
= add m (Suc k) by the Lemma1 -->
However, Isabelle is unable to prove this, and it appears the simplifier is stuck at the 2nd line. However, using the more obvious
lemma Lemma2 [simp]: "add m (Suc n) = Suc (add m n)"
instead of Lemma1, the proof succeeds. It seems to be able to use Lemma2 in both directions but not the Lemma1 I defined above. Does anyone know why? I feel like I am overlooking something obvious somewhere..
Remarks: I realize the simplifier actually only applies definitions etc in one direction but uses heuristics to try and reduce both sides of the equation to the same term