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 2 homework

FDS homework 2

## Resources

### Definitions File

```theory Defs
imports Main
begin

datatype 'a ltree =
Leaf 'a | Node "'a ltree" "'a ltree"

end```

### Template File

```theory Submission
imports Defs
begin

text \<open>Homework 2.1\<close>

fun add ::"nat \<Rightarrow> nat \<Rightarrow> nat" where

sorry

sorry

sorry

text \<open>Homework 2.2\<close>

fun lheight :: "'a ltree \<Rightarrow> nat" where
"lheight _ = undefined"

fun num_leafs :: "'a ltree \<Rightarrow> nat" where
"num_leafs _ = undefined"

lemma height_lt_leaves: "lheight t < num_leafs t"
sorry

text \<open>Homework 2.3\<close>

fun rlenc :: "'a \<Rightarrow> nat \<Rightarrow> 'a list \<Rightarrow> ('a \<times> nat) list" where
"rlenc _ = undefined"

fun rldec :: "('a \<times> nat) list \<Rightarrow> 'a list" where
"rldec _ = undefined"

lemma rlenc_dec_works: "rldec (rlenc a 0 l) = l"
sorry

end```

### Check File

```theory Check
imports Submission
begin

text \<open>Homework 2.2\<close>

lemma height_lt_leaves: "lheight t < num_leafs t"
by (rule Submission.height_lt_leaves)

text \<open>Homework 2.3\<close>

lemma rlenc_dec_works: "rldec (rlenc a 0 l) = l"
by (rule Submission.rlenc_dec_works)

end```

Terms and Conditions