###### Cookies disclaimer

Our site saves small pieces of text information (cookies) on your device in order to deliver better content and for statistical purposes. You can disable the usage of cookies by changing the settings of your browser. By browsing our website without changing the browser settings you grant us permission to store that information on your device.

# FDS Week 10 Homework 2

Week 10 homework 2.

## Resources

Download Files

### Definitions File

```theory Defs
imports "HOL-Library.List_Lexorder"
begin

datatype trie = Leaf | Node bool "trie * trie"

fun isin :: "trie \<Rightarrow> bool list \<Rightarrow> bool" where
"isin Leaf ks = False" |
"isin (Node b (l,r)) ks =
(case ks of
[] \<Rightarrow> b |
k#ks \<Rightarrow> isin (if k then r else l) ks)"

(* Alternative definition:

fun isin :: "trie \<Rightarrow> bool list \<Rightarrow> bool" where
"isin Leaf ks = False" |
"isin (Node b (l,r)) [] = b)"
"isin (Node b (l,r)) (k#ks) = isin (if k then r else l) ks)"

*)

end```

### Template File

```theory Template
imports Defs
begin

fun enum :: "trie \<Rightarrow> bool list list" where
"enum _ = undefined"

lemma enum_correct:
"set (enum t) = { xs. Defs.isin t xs } \<and> sorted_wrt (<) (enum t)"
sorry

end```

### Check File

```theory Check
imports Template
begin

lemma enum_correct:
"set (enum t) = { xs. Defs.isin t xs } \<and> sorted_wrt (<) (enum t)"
by(rule enum_correct)

end```

Terms and Conditions