5 section \<open> Length of a list \<close>
7 why3_open "list/Length.xml"
9 why3_vc lengthqtdef by (cases l) simp_all
11 why3_vc Length_nil by simp
13 why3_vc Length_nonnegative by simp
18 section \<open> Membership in a list \<close>
20 why3_open "list/Mem.xml"
22 why3_vc memqtdef by (simp split: list.split)
27 section \<open> Nth element of a list \<close>
29 why3_open "list/Nth.xml"
31 lemma nth_eq: "0 \<le> i \<Longrightarrow> nat i < length xs \<Longrightarrow> nth i xs = Some (xs ! nat i)"
32 by (induct xs arbitrary: i) (auto simp add: nat_diff_distrib)
35 by (simp add: is_none_def split: option.split)
40 why3_open "list/NthNoOpt.xml"
42 why3_vc nth_cons_0 by simp
46 by (simp add: nat_diff_distrib)
51 why3_open "list/NthLength.xml"
55 by (induct l arbitrary: i) simp_all
59 by (induct l arbitrary: i) simp_all
63 proof (induct l arbitrary: i)
65 then show ?case by simp arith
71 with Cons have "0 < i" by (simp split: if_split_asm)
72 with Cons have "Nth.nth (i - 1) xs = None" by simp
73 then have "i - 1 < 0 \<or> int (length xs) \<le> i - 1"
75 with `0 < i` show ?thesis by auto
80 by (simp add: is_none_def split: option.split)
85 section \<open> Head and tail \<close>
87 why3_open "list/HdTl.xml"
90 by (simp add: is_none_def split: option.split)
95 why3_open "list/HdTlNoOpt.xml"
97 why3_vc hd_cons by simp
99 why3_vc tl_cons by simp
104 section \<open> Relation between head, tail, and nth \<close>
106 why3_open "list/NthHdTl.xml"
110 by (simp add: tl_def split: list.split_asm)
113 by (simp add: hd_def split: list.split)
115 why3_vc is_noneqtspec
116 by (simp add: is_none_def split: option.split)
121 section \<open> Appending two lists \<close>
123 why3_open "list/Append.xml"
125 why3_vc infix_plplqtdef by (simp split: list.split)
127 why3_vc Append_assoc by simp
129 why3_vc Append_l_nil by simp
131 why3_vc Append_length by simp
133 why3_vc mem_append by simp
137 by (simp add: in_set_conv_decomp)
142 why3_open "list/NthLengthAppend.xml"
145 proof (cases "0 \<le> i")
147 with assms have "nat i < length l1" by simp
148 with True show ?thesis
149 by (simp add: nth_eq nth_append)
152 then show ?thesis by (simp add: nth_none_1)
156 proof (cases "nat i < length (l1 @ l2)")
158 with assms show ?thesis
159 by (auto simp add: nth_eq nth_append nat_diff_distrib)
162 with assms show ?thesis by (simp add: nth_none_2)
165 why3_vc is_noneqtspec
166 by (simp add: is_none_def split: option.split)
171 section \<open> Reversing a list \<close>
173 why3_open "list/Reverse.xml"
175 why3_vc reverseqtdef by (simp split: list.split)
177 why3_vc Reverse_length by simp
179 why3_vc reverse_append by simp
181 why3_vc reverse_reverse by simp
183 why3_vc reverse_mem by simp
185 why3_vc reverse_cons by simp
187 why3_vc cons_reverse by simp
192 section \<open> Reverse append \<close>
194 why3_open "list/RevAppend.xml"
196 why3_vc rev_append_append_l
197 by (induct r arbitrary: t) simp_all
199 why3_vc rev_append_append_r
200 proof (induct s arbitrary: r)
202 show ?case by (simp add: Cons [symmetric])
205 why3_vc rev_append_length
206 by (induct s arbitrary: t) simp_all
208 why3_vc rev_append_def
209 by (induct r arbitrary: s) simp_all
214 section \<open> Zip \<close>
216 why3_open "list/Combine.xml"
221 section \<open> List with pairwise distinct elements \<close>
223 why3_open "list/Distinct.xml"
225 why3_vc distinct_zero by simp
227 why3_vc distinct_one by simp
229 why3_vc distinct_many using assms by simp
231 why3_vc distinct_append using assms by auto
236 section \<open> Number of occurrences in a list \<close>
238 why3_open "list/NumOcc.xml"
240 why3_vc Num_Occ_NonNeg
241 by (induct l) simp_all
246 from Num_Occ_NonNeg [of y ys]
247 have "0 < 1 + num_occ y ys" by simp
248 with Cons show ?case by simp
251 why3_vc Append_Num_Occ
252 by (induct l1) simp_all
254 why3_vc reverse_num_occ
255 by (induct l) (simp_all add: Append_Num_Occ)
260 section \<open> Permutation of lists \<close>
262 why3_open "list/Permut.xml"
264 why3_vc Permut_refl by (simp add: permut_def)
266 why3_vc Permut_sym using assms by (simp add: permut_def)
268 why3_vc Permut_trans using assms by (simp add: permut_def)
270 why3_vc Permut_cons using assms by (simp add: permut_def)
272 why3_vc Permut_swap by (simp add: permut_def)
274 why3_vc Permut_cons_append by (simp add: permut_def Append_Num_Occ)
276 why3_vc Permut_assoc by (simp add: permut_def)
278 why3_vc Permut_append using assms by (simp add: permut_def Append_Num_Occ)
280 why3_vc Permut_append_swap by (simp add: permut_def Append_Num_Occ)
282 why3_vc Permut_mem using assms by (simp add: permut_def Mem_Num_Occ)
284 why3_vc Permut_length
286 proof (induct l1 arbitrary: l2)
291 with Nil Num_Occ_NonNeg [of x xs]
292 show ?thesis by (auto simp add: permut_def dest: spec [of _ x])
296 from `permut (x # xs) l2` have "x \<in> set l2"
297 by (rule Permut_mem) simp
298 then obtain ys zs where "l2 = ys @ x # zs"
299 by (auto simp add: in_set_conv_decomp)
300 with Cons have "permut (x # xs) (ys @ x # zs)" by simp
301 moreover have "permut (ys @ x # zs) ((x # zs) @ ys)"
302 by (rule Permut_append_swap)
303 ultimately have "permut (x # xs) ((x # zs) @ ys)"
304 by (rule Permut_trans)
305 then have "permut xs (zs @ ys)" by (simp add: permut_def)
306 then have "int (length xs) = int (length (zs @ ys))" by (rule Cons)
307 with `l2 = ys @ x # zs` show ?case by simp