theory Induction = Main: section{*Case distinction and induction \label{sec:Induct}*} subsection{*Case distinction\label{sec:CaseDistinction}*} lemma "\ A \ A" proof cases assume "A" thus ?thesis .. next assume "\ A" thus ?thesis .. qed lemma "\ A \ A" proof (cases "A") case True thus ?thesis .. next case False thus ?thesis .. qed declare length_tl[simp del] lemma "length(tl xs) = length xs - 1" proof (cases xs) case Nil thus ?thesis by simp next case Cons thus ?thesis by simp qed subsection{*Structural induction*} lemma "2 * (\iii"} or @{text"\"}\label{sec:full-Ind}*} lemma assumes A: "(\n. (\m. m < n \ P m) \ P n)" shows "P(n::nat)" proof (rule A) show "\m. m < n \ P m" proof (induct n) case 0 thus ?case by simp next case (Suc n) show ?case proof cases assume eq: "m = n" from Suc and A have "P n" by blast with eq show "P m" by simp next assume "m \ n" with Suc have "m < n" by arith thus "P m" by(rule Suc) qed qed qed subsection{*Rule induction*} consts rtc :: "('a \ 'a)set \ ('a \ 'a)set" ("_*" [1000] 999) inductive "r*" intros refl: "(x,x) \ r*" step: "\ (x,y) \ r; (y,z) \ r* \ \ (x,z) \ r*" lemma assumes A: "(x,y) \ r*" shows "(y,z) \ r* \ (x,z) \ r*" using A proof induct case refl thus ?case . next case step thus ?case by(blast intro: rtc.step) qed lemma assumes A: "(x,y) \ r*" and B: "(y,z) \ r*" shows "(x,z) \ r*" proof - from A B show ?thesis proof induct fix x assume "(x,z) \ r*" thus "(x,z) \ r*" . next fix x' x y assume 1: "(x',x) \ r" and IH: "(y,z) \ r* \ (x,z) \ r*" and B: "(y,z) \ r*" from 1 IH[OF B] show "(x',z) \ r*" by(rule rtc.step) qed qed subsection{*More induction*} consts rot :: "'a list \ 'a list" recdef rot "measure length" "rot [] = []" "rot [x] = [x]" "rot (x#y#zs) = y # rot(x#zs)" lemma "xs \ [] \ rot xs = tl xs @ [hd xs]" proof (induct xs rule: rot.induct) case 1 thus ?case by simp next case 2 show ?case by simp next case (3 a b cs) have "rot (a # b # cs) = b # rot(a # cs)" by simp also have "\ = b # tl(a # cs) @ [hd(a # cs)]" by(simp add:3) also have "\ = tl (a # b # cs) @ [hd (a # b # cs)]" by simp finally show ?case . qed lemma "xs \ [] \ rot xs = tl xs @ [hd xs]" by (induct xs rule: rot.induct, simp_all) end