(* Title: Adaptation of Trie Implementation Author:PeterGammie<peteg42atgmaildotcom>
*)
(*<*) theory Trie2 imports
MapOps
ODList
Trie.Trie begin (*>*)
definition
trie_update_with :: "'key list ==> 'val ==> ('val ==> 'val) ==> ('key, 'val) trie ==> ('key, 'val) trie" where "trie_update_with ks v f ≡ update_with_trie ks (%vo. f(case vo of None ==> v | Some v ==> v))"
lemma [simp]: "trie_update_with [] v f (Trie vo ts) = Trie (Some (f (case vo of None ==> v | Some v' ==> v'))) ts" by(simp add: trie_update_with_def)
lemma [simp]: "trie_update_with (k#ks) v f (Trie vo ts) = Trie vo (AList.update_with_aux empty_trie k (trie_update_with ks v f) ts)" by(simp add: trie_update_with_def empty_trie_def)
abbreviation
trie_update_with' :: "'k list ==> ('k, 'v) trie ==> 'v ==> ('v ==> 'v) ==> ('k, 'v) trie" where "trie_update_with' ≡ (λk m v f. trie_update_with k v f m)"
definition
trie_update :: "'key list ==> 'val ==> ('key, 'val) trie ==> ('key, 'val) trie" where "trie_update k v t = trie_update_with k v (λv'. v) t"
lemma lookup_trie_update_with: "lookup_trie (trie_update_with ks v f t) ks' = (if ks = ks' then Some (f (case lookup_trie t ks of None ==> v | Some v' ==> v')) else lookup_trie t ks')" proof(induct ks "(%vo. f(case vo of None ==> v | Some v ==> v))" t arbitrary: v ks' rule: update_with_trie.induct) case (1 v ps vo ks') show ?caseby (fastforce simp add: neq_Nil_conv dest: not_sym) next case (2 k ks v ps vo ks') show ?caseby(cases ks')(auto simp add: map_of_update_with_aux "2" empty_trie_def split: option.split) qed
lemma lookup_trie_update: "lookup_trie (trie_update ks v t) ks' = (if ks = ks' then Some v else lookup_trie t ks')" unfolding trie_update_def by (auto simp add: lookup_trie_update_with)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.