Cookies disclaimer

I agree 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 7 Homework

Week 7 homework.

Resources

Download Files

Definitions File

theory Defs
  imports Main
begin

type_synonym intervals = "(nat*nat) list"

fun inv' :: "nat \<Rightarrow> intervals \<Rightarrow> bool" where
  "inv' x [] \<longleftrightarrow> True"
| "inv' x ((a,b)#is) \<longleftrightarrow> (x\<le>a \<and> a\<le>b \<and> inv' (Suc (Suc b)) is)"

definition inv where "inv \<equiv> inv' 0"

fun set_of :: "intervals => nat set" where
  "set_of [] = {}"
| "set_of ((a,b)#is) = {a..b} \<union> set_of is"

end

Template File

theory Template
  imports Defs
begin

fun del :: "nat \<Rightarrow> intervals \<Rightarrow> intervals" where
  "del _ _ = undefined"

lemma del_correct_1:
  "inv is \<Longrightarrow> inv (del x is)"
  sorry

lemma del_correct_2:
  "inv is \<Longrightarrow> set_of (del x is) = (set_of is) - {x}"
  sorry

fun addi :: "nat \<Rightarrow> nat \<Rightarrow> intervals \<Rightarrow> intervals" where
  "addi _ _ _ = undefined"

lemma addi_correct_1:
  "inv is \<Longrightarrow> i\<le>j \<Longrightarrow> inv (addi i j is)"
  sorry

lemma addi_correct_2:
  "inv is \<Longrightarrow> i\<le>j \<Longrightarrow> set_of (addi i j is) = {i..j} \<union> (set_of is)"
  sorry

end

Check File

theory Check
  imports Template
begin

lemma del_correct_1:
  "Defs.inv is \<Longrightarrow> Defs.inv (del x is)"
  by(rule del_correct_1)

lemma del_correct_2:
  "Defs.inv is \<Longrightarrow> Defs.set_of (del x is) = (Defs.set_of is) - {x}"
  by(rule del_correct_2)

lemma addi_correct_1:
  "Defs.inv is \<Longrightarrow> i\<le>j \<Longrightarrow> Defs.inv (addi i j is)"
  by(rule addi_correct_1)

lemma addi_correct_2:
  "Defs.inv is \<Longrightarrow> i\<le>j \<Longrightarrow> Defs.set_of (addi i j is) = {i..j} \<union> (Defs.set_of is)"
  by(rule addi_correct_2)

end

Terms and Conditions