doc-src/TutorialI/IsarOverview/Isar/Logic.thy
changeset 13338 20ca66539bef
parent 13330 c9e9b6add754
child 13347 867f876589e7
equal deleted inserted replaced
13337:f75dfc606ac7 13338:20ca66539bef
   712 recdef rot "measure length"
   712 recdef rot "measure length"
   713 "rot [] = []"
   713 "rot [] = []"
   714 "rot [x] = [x]"
   714 "rot [x] = [x]"
   715 "rot (x#y#zs) = y # rot(x#zs)"
   715 "rot (x#y#zs) = y # rot(x#zs)"
   716 
   716 
   717 text{* The proof is trivial: all three cases go through by simplification.*}
   717 text{* In the first proof we set up each case explicitly, merely using
       
   718 pattern matching to abbreviate the statement: *}
       
   719 
   718 lemma "length(rot xs) = length xs" (is "?P xs")
   720 lemma "length(rot xs) = length xs" (is "?P xs")
   719 proof (induct xs rule: rot.induct)
   721 proof (induct xs rule: rot.induct)
   720   show "?P []" by simp
   722   show "?P []" by simp
   721 next
   723 next
   722   fix x show "?P [x]" by simp
   724   fix x show "?P [x]" by simp
   723 next
   725 next
   724   fix x y zs assume "?P (x#zs)"
   726   fix x y zs assume "?P (x#zs)"
   725   thus "?P (x#y#zs)" by simp
   727   thus "?P (x#y#zs)" by simp
   726 qed
   728 qed
   727 
   729 text{* This proof skeletons works for arbitrary induction rules, not just
   728 text{*\noindent This schema works for arbitrary induction rules instead of
       
   729 @{thm[source]rot.induct}.
   730 @{thm[source]rot.induct}.
   730 
   731 
   731 Of course the above proof is simple enough that it could be condensed to*}
   732 In the following proof we rely on a default naming scheme for cases: they are
   732 (*<*)lemma "length(rot xs) = length xs"(*>*)
   733 called 1, 2, etc, unless they have been named explicitly. The latter happens
       
   734 only with datatypes and inductively defined sets, but not with recursive
       
   735 functions. *}
       
   736 
       
   737 lemma "xs \<noteq> [] \<Longrightarrow> rot xs = tl xs @ [hd xs]"
       
   738 proof (induct xs rule: rot.induct)
       
   739   case 1 thus ?case by simp
       
   740 next
       
   741   case 2 show ?case by simp
       
   742 next
       
   743   case 3 thus ?case by simp
       
   744 qed
       
   745 
       
   746 text{*Of course both proofs are so simple that they can be condensed to*}
       
   747 (*<*)lemma "xs \<noteq> [] \<Longrightarrow> rot xs = tl xs @ [hd xs]"(*>*)
   733 by (induct xs rule: rot.induct, simp_all)
   748 by (induct xs rule: rot.induct, simp_all)
   734 
   749 
   735 (*<*)end(*>*)
   750 (*<*)end(*>*)