equal
deleted
inserted
replaced
256 "n_lists 0 xs = [[]]" | |
256 "n_lists 0 xs = [[]]" | |
257 "n_lists (Suc n) xs = concat (map (\<lambda>ys. map (\<lambda>y. y # ys) xs) (n_lists n xs))" |
257 "n_lists (Suc n) xs = concat (map (\<lambda>ys. map (\<lambda>y. y # ys) xs) (n_lists n xs))" |
258 |
258 |
259 hide_const (open) n_lists |
259 hide_const (open) n_lists |
260 |
260 |
261 fun splice :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
261 function splice :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
262 "splice [] ys = ys" | |
262 "splice [] ys = ys" | |
263 "splice xs [] = xs" | |
263 "splice (x#xs) ys = x # splice ys xs" |
264 "splice (x#xs) (y#ys) = x # y # splice xs ys" |
264 by pat_completeness auto |
|
265 |
|
266 termination |
|
267 by(relation "measure(\<lambda>(xs,ys). size xs + size ys)") auto |
265 |
268 |
266 function shuffle where |
269 function shuffle where |
267 "shuffle [] ys = {ys}" |
270 "shuffle [] ys = {ys}" |
268 | "shuffle xs [] = {xs}" |
271 | "shuffle xs [] = {xs}" |
269 | "shuffle (x # xs) (y # ys) = (#) x ` shuffle xs (y # ys) \<union> (#) y ` shuffle (x # xs) ys" |
272 | "shuffle (x # xs) (y # ys) = (#) x ` shuffle xs (y # ys) \<union> (#) y ` shuffle (x # xs) ys" |
4520 qed simp |
4523 qed simp |
4521 |
4524 |
4522 |
4525 |
4523 subsubsection \<open>@{const splice}\<close> |
4526 subsubsection \<open>@{const splice}\<close> |
4524 |
4527 |
4525 lemma splice_Nil2 [simp, code]: "splice xs [] = xs" |
4528 lemma splice_Nil2 [simp]: "splice xs [] = xs" |
4526 by (cases xs) simp_all |
4529 by (cases xs) simp_all |
4527 |
|
4528 declare splice.simps(1,3)[code] |
|
4529 declare splice.simps(2)[simp del] |
|
4530 |
4530 |
4531 lemma length_splice[simp]: "length(splice xs ys) = length xs + length ys" |
4531 lemma length_splice[simp]: "length(splice xs ys) = length xs + length ys" |
4532 by (induct xs ys rule: splice.induct) auto |
4532 by (induct xs ys rule: splice.induct) auto |
4533 |
4533 |
4534 |
4534 |
4535 subsubsection \<open>@{const shuffle}\<close> |
4535 subsubsection \<open>@{const shuffle}\<close> |
|
4536 |
|
4537 lemma shuffle_commutes: "shuffle xs ys = shuffle ys xs" |
|
4538 by (induction xs ys rule: shuffle.induct) (simp_all add: Un_commute) |
4536 |
4539 |
4537 lemma Nil_in_shuffle[simp]: "[] \<in> shuffle xs ys \<longleftrightarrow> xs = [] \<and> ys = []" |
4540 lemma Nil_in_shuffle[simp]: "[] \<in> shuffle xs ys \<longleftrightarrow> xs = [] \<and> ys = []" |
4538 by (induct xs ys rule: shuffle.induct) auto |
4541 by (induct xs ys rule: shuffle.induct) auto |
4539 |
4542 |
4540 lemma shuffleE: |
4543 lemma shuffleE: |
4550 (xs \<noteq> [] \<and> hd xs = z \<and> zs \<in> shuffle (tl xs) ys \<or> |
4553 (xs \<noteq> [] \<and> hd xs = z \<and> zs \<in> shuffle (tl xs) ys \<or> |
4551 ys \<noteq> [] \<and> hd ys = z \<and> zs \<in> shuffle xs (tl ys))" |
4554 ys \<noteq> [] \<and> hd ys = z \<and> zs \<in> shuffle xs (tl ys))" |
4552 by (induct xs ys rule: shuffle.induct) auto |
4555 by (induct xs ys rule: shuffle.induct) auto |
4553 |
4556 |
4554 lemma splice_in_shuffle [simp, intro]: "splice xs ys \<in> shuffle xs ys" |
4557 lemma splice_in_shuffle [simp, intro]: "splice xs ys \<in> shuffle xs ys" |
4555 by (induction xs ys rule: splice.induct) (simp_all add: Cons_in_shuffle_iff) |
4558 by (induction xs ys rule: splice.induct) (simp_all add: Cons_in_shuffle_iff shuffle_commutes) |
4556 |
4559 |
4557 lemma Nil_in_shuffleI: "xs = [] \<Longrightarrow> ys = [] \<Longrightarrow> [] \<in> shuffle xs ys" |
4560 lemma Nil_in_shuffleI: "xs = [] \<Longrightarrow> ys = [] \<Longrightarrow> [] \<in> shuffle xs ys" |
4558 by simp |
4561 by simp |
4559 |
4562 |
4560 lemma Cons_in_shuffle_leftI: "zs \<in> shuffle xs ys \<Longrightarrow> z # zs \<in> shuffle (z # xs) ys" |
4563 lemma Cons_in_shuffle_leftI: "zs \<in> shuffle xs ys \<Longrightarrow> z # zs \<in> shuffle (z # xs) ys" |
4582 proof (cases zs) |
4585 proof (cases zs) |
4583 case (Cons z zs') |
4586 case (Cons z zs') |
4584 with "3.prems" and "3.IH"[of zs'] show ?thesis by (force dest: set_shuffle) |
4587 with "3.prems" and "3.IH"[of zs'] show ?thesis by (force dest: set_shuffle) |
4585 qed simp_all |
4588 qed simp_all |
4586 qed simp_all |
4589 qed simp_all |
4587 |
|
4588 lemma shuffle_commutes: "shuffle xs ys = shuffle ys xs" |
|
4589 by (induction xs ys rule: shuffle.induct) (simp_all add: Un_commute) |
|
4590 |
4590 |
4591 lemma Cons_shuffle_subset1: "(#) x ` shuffle xs ys \<subseteq> shuffle (x # xs) ys" |
4591 lemma Cons_shuffle_subset1: "(#) x ` shuffle xs ys \<subseteq> shuffle (x # xs) ys" |
4592 by (cases ys) auto |
4592 by (cases ys) auto |
4593 |
4593 |
4594 lemma Cons_shuffle_subset2: "(#) y ` shuffle xs ys \<subseteq> shuffle xs (y # ys)" |
4594 lemma Cons_shuffle_subset2: "(#) y ` shuffle xs ys \<subseteq> shuffle xs (y # ys)" |