src/HOL/ex/Fundefs.thy
changeset 36269 fa30cbb455df
parent 28584 58ac551ce1ce
child 36270 fd95c0514623
equal deleted inserted replaced
36268:65aabc2c89ae 36269:fa30cbb455df
     1 (*  Title:      HOL/ex/Fundefs.thy
     1 (*  Title:      HOL/ex/Fundefs.thy
     2     ID:         $Id$
       
     3     Author:     Alexander Krauss, TU Muenchen
     2     Author:     Alexander Krauss, TU Muenchen
     4 *)
     3 *)
     5 
     4 
     6 header {* Examples of function definitions *}
     5 header {* Examples of function definitions *}
     7 
     6 
   279 (* Simple Higher-Order Recursion *)
   278 (* Simple Higher-Order Recursion *)
   280 datatype 'a tree = 
   279 datatype 'a tree = 
   281   Leaf 'a 
   280   Leaf 'a 
   282   | Branch "'a tree list"
   281   | Branch "'a tree list"
   283 
   282 
   284 lemma lem:"x \<in> set l \<Longrightarrow> size x < Suc (list_size size l)"
   283 fun treemap :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a tree \<Rightarrow> 'a tree"
   285 by (induct l, auto)
       
   286 
       
   287 function treemap :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a tree \<Rightarrow> 'a tree"
       
   288 where
   284 where
   289   "treemap fn (Leaf n) = (Leaf (fn n))"
   285   "treemap fn (Leaf n) = (Leaf (fn n))"
   290 | "treemap fn (Branch l) = (Branch (map (treemap fn) l))"
   286 | "treemap fn (Branch l) = (Branch (map (treemap fn) l))"
   291 by pat_completeness auto
       
   292 termination by (lexicographic_order simp:lem)
       
   293 
       
   294 declare lem[simp]
       
   295 
   287 
   296 fun tinc :: "nat tree \<Rightarrow> nat tree"
   288 fun tinc :: "nat tree \<Rightarrow> nat tree"
   297 where
   289 where
   298   "tinc (Leaf n) = Leaf (Suc n)"
   290   "tinc (Leaf n) = Leaf (Suc n)"
   299 | "tinc (Branch l) = Branch (map tinc l)"
   291 | "tinc (Branch l) = Branch (map tinc l)"