# HG changeset patch # User nipkow # Date 1608676592 -3600 # Node ID e734cd65c92650ca6e24bfdf2947561a9e77d32a # Parent 7e7ed27fe62572eb43c427bd2242119714b33aa4 tuned diff -r 7e7ed27fe625 -r e734cd65c926 src/HOL/Data_Structures/Trie_Fun.thy --- a/src/HOL/Data_Structures/Trie_Fun.thy Mon Dec 21 23:22:14 2020 +0100 +++ b/src/HOL/Data_Structures/Trie_Fun.thy Tue Dec 22 23:36:32 2020 +0100 @@ -20,7 +20,7 @@ fun insert :: "'a list \ 'a trie \ 'a trie" where "insert [] (Nd b m) = Nd True m" | "insert (x#xs) (Nd b m) = - Nd b (m(x := Some(insert xs (case m x of None \ empty | Some t \ t))))" + (let s = (case m x of None \ empty | Some t \ t) in Nd b (m(x := Some(insert xs s))))" fun delete :: "'a list \ 'a trie \ 'a trie" where "delete [] (Nd b m) = Nd False m" | @@ -29,62 +29,39 @@ None \ m | Some t \ m(x := Some(delete xs t)))" -text \The actual definition of \set\ is a bit cryptic but canonical, to enable -primrec to prove termination:\ - -primrec set :: "'a trie \ 'a list set" where -"set (Nd b m) = (if b then {[]} else {}) \ - (\a. case (map_option set o m) a of None \ {} | Some t \ (#) a ` t)" +text \Use (a tuned version of) @{const isin} as an abstraction function:\ -text \This is the more human-readable version:\ +lemma isin_case: "isin (Nd b m) xs = + (case xs of + [] \ b | + x # ys \ (case m x of None \ False | Some t \ isin t ys))" +by(cases xs)auto -lemma set_Nd: - "set (Nd b m) = - (if b then {[]} else {}) \ - (\a. case m a of None \ {} | Some t \ (#) a ` set t)" -by (auto simp: split: option.splits) +definition set :: "'a trie \ 'a list set" where +[simp]: "set t = {xs. isin t xs}" lemma isin_set: "isin t xs = (xs \ set t)" -apply(induction t xs rule: isin.induct) -apply (auto split: option.split) -done +by simp lemma set_insert: "set (insert xs t) = set t \ {xs}" -proof(induction xs t rule: insert.induct) - case 1 thus ?case by simp -next - case 2 - thus ?case - apply(simp) - apply(subst set_eq_iff) - apply(auto split!: if_splits option.splits) - apply fastforce - by (metis imageI option.sel) -qed +by (induction xs t rule: insert.induct) + (auto simp: isin_case split!: if_splits option.splits list.splits) lemma set_delete: "set (delete xs t) = set t - {xs}" -proof(induction xs t rule: delete.induct) - case 1 thus ?case by (force split: option.splits) -next - case 2 - show ?case - apply (auto simp add: image_iff 2 split!: if_splits option.splits) - apply (metis DiffI empty_iff insert_iff option.inject) - apply (metis DiffI empty_iff insert_iff option.inject) - done -qed +by (induction xs t rule: delete.induct) + (auto simp: isin_case split!: if_splits option.splits list.splits) interpretation S: Set where empty = empty and isin = isin and insert = insert and delete = delete and set = set and invar = "\_. True" proof (standard, goal_cases) - case 1 show ?case by (simp) + case 1 show ?case by (simp add: isin_case split: list.split) next - case 2 thus ?case by(simp add: isin_set) + case 2 show ?case by(rule isin_set) next - case 3 thus ?case by(simp add: set_insert) + case 3 show ?case by(rule set_insert) next - case 4 thus ?case by(simp add: set_delete) + case 4 show ?case by(rule set_delete) qed (rule TrueI)+ end diff -r 7e7ed27fe625 -r e734cd65c926 src/HOL/Data_Structures/Trie_Map.thy --- a/src/HOL/Data_Structures/Trie_Map.thy Mon Dec 21 23:22:14 2020 +0100 +++ b/src/HOL/Data_Structures/Trie_Map.thy Tue Dec 22 23:36:32 2020 +0100 @@ -91,13 +91,13 @@ where empty = empty and isin = isin and insert = insert and delete = delete and set = "set o abs" and invar = invar proof (standard, goal_cases) - case 1 show ?case by (simp) + case 1 show ?case by (simp add: isin_case split: list.split) next - case 2 thus ?case by (simp add: isin_set isin_abs) + case 2 thus ?case by (simp add: isin_abs) next - case 3 thus ?case by (simp add: set_insert abs_insert) + case 3 thus ?case by (simp add: set_insert abs_insert del: set_def) next - case 4 thus ?case by (simp add: set_delete abs_delete) + case 4 thus ?case by (simp add: set_delete abs_delete del: set_def) next case 5 thus ?case by (simp add: M.map_specs RBT_Set.empty_def[symmetric]) next