tuned
authornipkow
Sat May 11 22:19:28 2019 +0200 (8 days ago ago)
changeset 704500b813a1a833f
parent 70449 a8238fd25541
child 70451 9fa2cf7142b7
tuned
src/HOL/Data_Structures/Trie_Fun.thy
src/HOL/Data_Structures/Trie_Map.thy
     1.1 --- a/src/HOL/Data_Structures/Trie_Fun.thy	Sat May 11 19:08:26 2019 +0200
     1.2 +++ b/src/HOL/Data_Structures/Trie_Fun.thy	Sat May 11 22:19:28 2019 +0200
     1.3 @@ -10,6 +10,9 @@
     1.4  
     1.5  datatype 'a trie = Nd bool "'a \<Rightarrow> 'a trie option"
     1.6  
     1.7 +definition empty :: "'a trie" where
     1.8 +[simp]: "empty = Nd False (\<lambda>_. None)"
     1.9 +
    1.10  fun isin :: "'a trie \<Rightarrow> 'a list \<Rightarrow> bool" where
    1.11  "isin (Nd b m) [] = b" |
    1.12  "isin (Nd b m) (k # xs) = (case m k of None \<Rightarrow> False | Some t \<Rightarrow> isin t xs)"
    1.13 @@ -17,7 +20,7 @@
    1.14  fun insert :: "('a::linorder) list \<Rightarrow> 'a trie \<Rightarrow> 'a trie" where
    1.15  "insert [] (Nd b m) = Nd True m" |
    1.16  "insert (x#xs) (Nd b m) =
    1.17 -   Nd b (m(x := Some(insert xs (case m x of None \<Rightarrow> Nd False (\<lambda>_. None) | Some t \<Rightarrow> t))))"
    1.18 +   Nd b (m(x := Some(insert xs (case m x of None \<Rightarrow> empty | Some t \<Rightarrow> t))))"
    1.19  
    1.20  fun delete :: "('a::linorder) list \<Rightarrow> 'a trie \<Rightarrow> 'a trie" where
    1.21  "delete [] (Nd b m) = Nd False m" |
    1.22 @@ -73,7 +76,7 @@
    1.23  qed
    1.24  
    1.25  interpretation S: Set
    1.26 -where empty = "Nd False (\<lambda>_. None)" and isin = isin and insert = insert and delete = delete
    1.27 +where empty = empty and isin = isin and insert = insert and delete = delete
    1.28  and set = set and invar = "\<lambda>_. True"
    1.29  proof (standard, goal_cases)
    1.30    case 1 show ?case by (simp)
     2.1 --- a/src/HOL/Data_Structures/Trie_Map.thy	Sat May 11 19:08:26 2019 +0200
     2.2 +++ b/src/HOL/Data_Structures/Trie_Map.thy	Sat May 11 22:19:28 2019 +0200
     2.3 @@ -29,6 +29,10 @@
     2.4  apply(auto split: if_splits)
     2.5  done
     2.6  
     2.7 +
     2.8 +definition empty :: "'a trie_map" where
     2.9 +[simp]: "empty = Nd False Leaf"
    2.10 +
    2.11  fun isin :: "('a::linorder) trie_map \<Rightarrow> 'a list \<Rightarrow> bool" where
    2.12  "isin (Nd b m) [] = b" |
    2.13  "isin (Nd b m) (x # xs) = (case lookup m x of None \<Rightarrow> False | Some t \<Rightarrow> isin t xs)"
    2.14 @@ -36,7 +40,7 @@
    2.15  fun insert :: "('a::linorder) list \<Rightarrow> 'a trie_map \<Rightarrow> 'a trie_map" where
    2.16  "insert [] (Nd b m) = Nd True m" |
    2.17  "insert (x#xs) (Nd b m) =
    2.18 -  Nd b (update x (insert xs (case lookup m x of None \<Rightarrow> Nd False Leaf | Some t \<Rightarrow> t)) m)"
    2.19 +  Nd b (update x (insert xs (case lookup m x of None \<Rightarrow> empty | Some t \<Rightarrow> t)) m)"
    2.20  
    2.21  fun delete :: "('a::linorder) list \<Rightarrow> 'a trie_map \<Rightarrow> 'a trie_map" where
    2.22  "delete [] (Nd b m) = Nd False m" |
    2.23 @@ -84,7 +88,7 @@
    2.24  text \<open>Overall correctness w.r.t. the \<open>Set\<close> ADT:\<close>
    2.25  
    2.26  interpretation S2: Set
    2.27 -where empty = "Nd False Leaf" and isin = isin and insert = insert and delete = delete
    2.28 +where empty = empty and isin = isin and insert = insert and delete = delete
    2.29  and set = "set o abs" and invar = invar
    2.30  proof (standard, goal_cases)
    2.31    case 1 show ?case by (simp)