# HG changeset patch # User haftmann # Date 1620151036 0 # Node ID b4b70d13c9959990bbd65baf7a0b68643c98af74 # Parent 58aed6f71f903b72c5f97b77cad73fc2ff857143 collected lemmas on permutations diff -r 58aed6f71f90 -r b4b70d13c995 src/HOL/Combinatorics/Permutations.thy --- a/src/HOL/Combinatorics/Permutations.thy Mon May 03 21:49:30 2021 +0100 +++ b/src/HOL/Combinatorics/Permutations.thy Tue May 04 17:57:16 2021 +0000 @@ -860,6 +860,10 @@ lemma evenperm_id[simp]: "evenperm id = True" by (rule evenperm_unique[where n = 0]) simp_all +lemma evenperm_identity [simp]: + \evenperm (\x. x)\ + using evenperm_id by (simp add: id_def [abs_def]) + lemma evenperm_swap: "evenperm (Fun.swap a b id) = (a = b)" by (rule evenperm_unique[where n="if a = b then 0 else 1"]) (simp_all add: swapidseq_swap) @@ -1034,12 +1038,20 @@ subsection \Sign of a permutation as a real number\ definition sign :: \('a \ 'a) \ int\ \ \TODO: prefer less generic name\ - where \sign p = (if evenperm p then (1::int) else -1)\ + where \sign p = (if evenperm p then 1 else - 1)\ -lemma sign_nz: "sign p \ 0" +lemma sign_cases [case_names even odd]: + obtains \sign p = 1\ | \sign p = - 1\ + by (cases \evenperm p\) (simp_all add: sign_def) + +lemma sign_nz [simp]: "sign p \ 0" + by (cases p rule: sign_cases) simp_all + +lemma sign_id [simp]: "sign id = 1" by (simp add: sign_def) -lemma sign_id: "sign id = 1" +lemma sign_identity [simp]: + \sign (\x. x) = 1\ by (simp add: sign_def) lemma sign_inverse: "permutation p \ sign (inv p) = sign p" @@ -1048,12 +1060,18 @@ lemma sign_compose: "permutation p \ permutation q \ sign (p \ q) = sign p * sign q" by (simp add: sign_def evenperm_comp) -lemma sign_swap_id: "sign (Fun.swap a b id) = (if a = b then 1 else -1)" +lemma sign_swap_id: "sign (Fun.swap a b id) = (if a = b then 1 else - 1)" by (simp add: sign_def evenperm_swap) -lemma sign_idempotent: "sign p * sign p = 1" +lemma sign_idempotent [simp]: "sign p * sign p = 1" by (simp add: sign_def) +lemma sign_left_idempotent [simp]: + \sign p * (sign p * sign q) = sign q\ + by (simp add: sign_def) + +term "(bij, bij_betw, permutation)" + subsection \Permuting a list\ @@ -1472,6 +1490,97 @@ by (simp only:) qed +lemma inv_inj_on_permutes: + \inj_on inv {p. p permutes S}\ +proof (intro inj_onI, unfold mem_Collect_eq) + fix p q + assume p: "p permutes S" and q: "q permutes S" and eq: "inv p = inv q" + have "inv (inv p) = inv (inv q)" using eq by simp + thus "p = q" + using inv_inv_eq[OF permutes_bij] p q by metis +qed + +lemma permutes_pair_eq: + \{(p s, s) |s. s \ S} = {(s, inv p s) |s. s \ S}\ (is \?L = ?R\) if \p permutes S\ +proof + show "?L \ ?R" + proof + fix x assume "x \ ?L" + then obtain s where x: "x = (p s, s)" and s: "s \ S" by auto + note x + also have "(p s, s) = (p s, Hilbert_Choice.inv p (p s))" + using permutes_inj [OF that] inv_f_f by auto + also have "... \ ?R" using s permutes_in_image[OF that] by auto + finally show "x \ ?R". + qed + show "?R \ ?L" + proof + fix x assume "x \ ?R" + then obtain s + where x: "x = (s, Hilbert_Choice.inv p s)" (is "_ = (s, ?ips)") + and s: "s \ S" by auto + note x + also have "(s, ?ips) = (p ?ips, ?ips)" + using inv_f_f[OF permutes_inj[OF permutes_inv[OF that]]] + using inv_inv_eq[OF permutes_bij[OF that]] by auto + also have "... \ ?L" + using s permutes_in_image[OF permutes_inv[OF that]] by auto + finally show "x \ ?L". + qed +qed + +context + fixes p and n i :: nat + assumes p: \p permutes {0.. and i: \i < n\ +begin + +lemma permutes_nat_less: + \p i < n\ +proof - + have \?thesis \ p i \ {0.. + by simp + also from p have \p i \ {0.. i \ {0.. + by (rule permutes_in_image) + finally show ?thesis + using i by simp +qed + +lemma permutes_nat_inv_less: + \inv p i < n\ +proof - + from p have \inv p permutes {0.. + by (rule permutes_inv) + then show ?thesis + using i by (rule Permutations.permutes_nat_less) +qed + +end + +context comm_monoid_set +begin + +lemma permutes_inv: + \F (\s. g (p s) s) S = F (\s. g s (inv p s)) S\ (is \?l = ?r\) + if \p permutes S\ +proof - + let ?g = "\(x, y). g x y" + let ?ps = "\s. (p s, s)" + let ?ips = "\s. (s, inv p s)" + have inj1: "inj_on ?ps S" by (rule inj_onI) auto + have inj2: "inj_on ?ips S" by (rule inj_onI) auto + have "?l = F ?g (?ps ` S)" + using reindex [OF inj1, of ?g] by simp + also have "?ps ` S = {(p s, s) |s. s \ S}" by auto + also have "... = {(s, inv p s) |s. s \ S}" + unfolding permutes_pair_eq [OF that] by simp + also have "... = ?ips ` S" by auto + also have "F ?g ... = ?r" + using reindex [OF inj2, of ?g] by simp + finally show ?thesis. +qed + +end + subsection \Sum over a set of permutations (could generalize to iteration)\