diff -r 979cdfdf7a79 -r f3b905b2eee2 src/HOL/Library/Permutations.thy --- a/src/HOL/Library/Permutations.thy Thu Oct 13 18:36:06 2016 +0200 +++ b/src/HOL/Library/Permutations.thy Tue Oct 18 12:01:54 2016 +0200 @@ -22,6 +22,23 @@ "Fun.swap a b id x = (if x = a then b else if x = b then a else x)" by (simp add: Fun.swap_def) +lemma bij_inv_eq_iff: "bij p \ x = inv p y \ p x = y" + using surj_f_inv_f[of p] by (auto simp add: bij_def) + +lemma bij_swap_comp: + assumes bp: "bij p" + shows "Fun.swap a b id \ p = Fun.swap (inv p a) (inv p b) p" + using surj_f_inv_f[OF bij_is_surj[OF bp]] + by (simp add: fun_eq_iff Fun.swap_def bij_inv_eq_iff[OF bp]) + +lemma bij_swap_ompose_bij: "bij p \ bij (Fun.swap a b id \ p)" +proof - + assume H: "bij p" + show ?thesis + unfolding bij_swap_comp[OF H] bij_swap_iff + using H . +qed + subsection \Basic consequences of the definition\ @@ -30,7 +47,7 @@ lemma permutes_in_image: "p permutes S \ p x \ S \ x \ S" unfolding permutes_def by metis - + lemma permutes_not_in: assumes "f permutes S" "x \ S" shows "f x = x" using assms by (auto simp: permutes_def) @@ -107,7 +124,7 @@ (* Next three lemmas contributed by Lukas Bulwahn *) lemma permutes_bij_inv_into: - fixes A :: "'a set" and B :: "'b set" + fixes A :: "'a set" and B :: "'b set" assumes "p permutes A" assumes "bij_betw f A B" shows "(\x. if x \ B then f (p (inv_into A f x)) else x) permutes B" @@ -167,9 +184,9 @@ unfolding fun_eq_iff permutes_inv_eq[OF pS] permutes_inv_eq[OF permutes_inv[OF pS]] by blast -lemma permutes_invI: +lemma permutes_invI: assumes perm: "p permutes S" - and inv: "\x. x \ S \ p' (p x) = x" + and inv: "\x. x \ S \ p' (p x) = x" and outside: "\x. x \ S \ p' x = x" shows "inv p = p'" proof @@ -177,14 +194,14 @@ proof (cases "x \ S") assume [simp]: "x \ S" from assms have "p' x = p' (p (inv p x))" by (simp add: permutes_inverses) - also from permutes_inv[OF perm] + also from permutes_inv[OF perm] have "\ = inv p x" by (subst inv) (simp_all add: permutes_in_image) finally show "inv p x = p' x" .. qed (insert permutes_inv[OF perm], simp_all add: outside permutes_not_in) qed lemma permutes_vimage: "f permutes A \ f -` A = A" - by (simp add: bij_vimage_eq_inv_image permutes_bij permutes_image[OF permutes_inv]) + by (simp add: bij_vimage_eq_inv_image permutes_bij permutes_image[OF permutes_inv]) subsection \The number of permutations on a finite set\ @@ -329,7 +346,7 @@ lemma finite_permutations: assumes fS: "finite S" shows "finite {p. p permutes S}" - using card_permutations[OF refl fS] + using card_permutations[OF refl fS] by (auto intro: card_ge_0_finite) @@ -724,23 +741,6 @@ qed qed -lemma bij_inv_eq_iff: "bij p \ x = inv p y \ p x = y" - using surj_f_inv_f[of p] by (auto simp add: bij_def) - -lemma bij_swap_comp: - assumes bp: "bij p" - shows "Fun.swap a b id \ p = Fun.swap (inv p a) (inv p b) p" - using surj_f_inv_f[OF bij_is_surj[OF bp]] - by (simp add: fun_eq_iff Fun.swap_def bij_inv_eq_iff[OF bp]) - -lemma bij_swap_ompose_bij: "bij p \ bij (Fun.swap a b id \ p)" -proof - - assume H: "bij p" - show ?thesis - unfolding bij_swap_comp[OF H] bij_swap_iff - using H . -qed - lemma permutation_lemma: assumes fS: "finite S" and p: "bij p" @@ -881,7 +881,7 @@ lemma sign_idempotent: "sign p * sign p = 1" by (simp add: sign_def) - + subsection \Permuting a list\ text \This function permutes a list by applying a permutation to the indices.\ @@ -889,7 +889,7 @@ definition permute_list :: "(nat \ nat) \ 'a list \ 'a list" where "permute_list f xs = map (\i. xs ! (f i)) [0.. g) xs = permute_list g (permute_list f xs)" using assms[THEN permutes_in_image] by (auto simp add: permute_list_def) @@ -924,7 +924,7 @@ fix y :: 'a from assms have [simp]: "f x < length xs \ x < length xs" for x using permutes_in_image[OF assms] by auto - have "count (mset (permute_list f xs)) y = + have "count (mset (permute_list f xs)) y = card ((\i. xs ! f i) -` {y} \ {..i. xs ! f i) -` {y} \ {.. y = xs ! i}" @@ -935,7 +935,7 @@ finally show "count (mset (permute_list f xs)) y = count (mset xs) y" by simp qed -lemma set_permute_list [simp]: +lemma set_permute_list [simp]: assumes "f permutes {.. permutes fst ` set xs" shows "map_of xs \ \ = map_of (map (\(x,y). (inv \ x, y)) xs)" (is "_ = map_of (map ?f _)") proof @@ -993,7 +993,7 @@ from this have "count (image_mset f (mset_set (insert x F))) b = Suc (card {a \ F. f a = f x})" using insert.hyps by auto also have "\ = card (insert x {a \ F. f a = f x})" - using insert.hyps(1,2) by simp + using insert.hyps(1,2) by simp also have "card (insert x {a \ F. f a = f x}) = card {a \ insert x F. f a = b}" using \f x = b\ by (auto intro: arg_cong[where f="card"]) finally show ?thesis using insert by auto @@ -1003,7 +1003,7 @@ with insert A show ?thesis by simp qed qed - + (* Prove image_mset_eq_implies_permutes *) lemma image_mset_eq_implies_permutes: fixes f :: "'a \ 'b" @@ -1317,7 +1317,7 @@ subsection \Constructing permutations from association lists\ definition list_permutes where - "list_permutes xs A \ set (map fst xs) \ A \ set (map snd xs) = set (map fst xs) \ + "list_permutes xs A \ set (map fst xs) \ A \ set (map snd xs) = set (map fst xs) \ distinct (map fst xs) \ distinct (map snd xs)" lemma list_permutesI [simp]: @@ -1349,8 +1349,8 @@ proof (rule inj_onI) fix x y assume xy: "x \ set (map fst xs)" "y \ set (map fst xs)" assume eq: "map_of xs x = map_of xs y" - from xy obtain x' y' - where x'y': "map_of xs x = Some x'" "map_of xs y = Some y'" + from xy obtain x' y' + where x'y': "map_of xs x = Some x'" "map_of xs y = Some y'" by (cases "map_of xs x"; cases "map_of xs y") (simp_all add: map_of_eq_None_iff) moreover from x'y' have *: "(x,x') \ set xs" "(y,y') \ set xs" @@ -1398,7 +1398,7 @@ also from assms have "?f ` set (map fst xs) = (the \ map_of xs) ` set (map fst xs)" by (intro image_cong refl) (auto simp: permutation_of_list_def map_of_eq_None_iff split: option.splits) - also from assms have "\ = set (map fst xs)" + also from assms have "\ = set (map fst xs)" by (subst image_map_of') (simp_all add: list_permutes_def) finally show "bij_betw ?f (set (map fst xs)) (set (map fst xs))" . qed (force simp: permutation_of_list_def dest!: map_of_SomeD split: option.splits)+