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.

Homework 7

This is the task corresponding to homework 7.

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 [] = True"
| "inv' x ((l,r)#ins) = (x\<le>l \<and> l\<le>r \<and> inv' (Suc (Suc r)) ins)"

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

fun set_of :: "intervals \<Rightarrow> nat set" where
  "set_of [] = {}"
| "set_of ((l,r)#ins) = {l..r} \<union> set_of ins"

fun merge_fst2 where
  "merge_fst2 [] = []"
| "merge_fst2 [i] = [i]"
| "merge_fst2 ((l1,r1)#(l2,r2)#ins) = (if Suc r1 = l2 then (l1,r2)#ins else ((l1,r1)#(l2,r2)#ins))"

lemma [simp]: "\<lbrakk>a\<le>b; inv' (Suc b) is\<rbrakk> \<Longrightarrow> set_of (merge_fst2 ((a,b)#is)) = {a..b} \<union> set_of is"
  apply (cases "is" rule: merge_fst2.cases)
  apply (auto split: if_splits)
  done


consts del :: "nat \<Rightarrow> intervals \<Rightarrow> intervals"

consts addi :: "nat \<Rightarrow> nat \<Rightarrow> intervals \<Rightarrow> intervals"


end

Template File

theory Submission
  imports Defs
begin

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

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 _ _ _ = []"

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 Submission
begin

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

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

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

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

end

Terms and Conditions