diff --git a/lib/Heap_List.thy b/lib/Heap_List.thy index e8bae311db..9f91b08a9c 100644 --- a/lib/Heap_List.thy +++ b/lib/Heap_List.thy @@ -83,14 +83,25 @@ lemma heap_path_end_unique: "heap_path hp x xs y \ heap_path hp x xs y' \ y = y'" by (induct xs arbitrary: x; clarsimp) -lemma heap_path_head: - "heap_path hp x xs y \ xs \ [] \ x = Some (hd xs)" - by (induct xs arbitrary: x; clarsimp) +lemma heap_path_head': + "heap_path hp st xs y \ xs \ [] \ st = Some (hd xs)" + by (induct xs arbitrary: st; clarsimp) + +lemmas heap_path_head = heap_path_head'[rule_format] lemma heap_path_non_nil_lookup_next: "heap_path hp x (xs@z#ys) y \ hp z = (case ys of [] \ y | _ \ Some (hd ys))" by (cases ys; fastforce) +lemma heap_ls_next_of_hd: + "\a = hd ls; heap_ls hp st ls; Suc 0 < length ls\ \ hp a = Some (hd (tl ls))" + apply (cut_tac hp=hp and xs="[]" and z=a and ys="tl ls" in heap_path_non_nil_lookup_next) + apply (prop_tac "ls \ []", fastforce) + apply fastforce + apply (cases "tl ls"; clarsimp) + apply (cases ls; clarsimp) + done + lemma heap_path_prefix: "heap_path hp st ls ed \ \xs\ls. heap_path hp st xs (if xs = [] then st else hp (last xs))" apply clarsimp @@ -235,6 +246,28 @@ lemma heap_path_sym_heap_non_nil_lookup_prev: apply (fastforce dest: sym_heapD1) done +lemma heap_ls_prev_of_last: + "\t = last ls; Suc 0 < length ls; heap_ls hp st ls; sym_heap hp hp'\ + \ hp' t = Some (last (butlast ls))" + apply (cut_tac hp=hp and xs="butlast ls" and z=t and ys="[]" + in heap_path_sym_heap_non_nil_lookup_prev) + apply (prop_tac "ls \ []", fastforce) + apply fastforce + apply fastforce + apply (fastforce intro!: length_gt_1_imp_butlast_nonempty) + apply assumption + done + +lemma ptr_in_middle_prev_next: + "\heap_ls hp st (xs @ ptr # ys); xs \ []; ys \ []; sym_heap hp hp'\ + \ hp' ptr = Some (last xs) \ hp ptr = Some (hd ys)" + apply (rule conjI) + apply (fastforce dest: heap_path_sym_heap_non_nil_lookup_prev) + apply (cut_tac hp=hp in heap_path_non_nil_lookup_next) + apply fastforce + apply (cases ys; clarsimp) + done + lemma heap_ls_no_loops: "\heap_ls hp st xs; p \ set xs\ \ hp p \ Some p" apply (frule heap_ls_distinct)