# HG changeset patch # User haftmann # Date 1620230942 0 # Node ID 5020054b3a169782dcfc327f18d7a888140f57d1 # Parent 4dc3baf45d6a5285fef3ef9d952dc52c88e48ffb tuned theory structure diff -r 4dc3baf45d6a -r 5020054b3a16 NEWS --- a/NEWS Wed May 05 16:09:02 2021 +0000 +++ b/NEWS Wed May 05 16:09:02 2021 +0000 @@ -94,6 +94,9 @@ * Lemma "permutes_induct" has been given stronger hypotheses and named premises. INCOMPATIBILITY. +* Combinator "Fun.swap" moved into separate theory "Transposition" in +HOL-Combinatorics. INCOMPATIBILITY. + *** ML *** diff -r 4dc3baf45d6a -r 5020054b3a16 src/HOL/Analysis/Cartesian_Space.thy --- a/src/HOL/Analysis/Cartesian_Space.thy Wed May 05 16:09:02 2021 +0000 +++ b/src/HOL/Analysis/Cartesian_Space.thy Wed May 05 16:09:02 2021 +0000 @@ -10,7 +10,7 @@ theory Cartesian_Space imports - Finite_Cartesian_Product Linear_Algebra + Finite_Cartesian_Product Linear_Algebra "HOL-Combinatorics.Transposition" begin subsection\<^marker>\tag unimportant\ \Type @{typ \'a ^ 'n\} and fields as vector spaces\ (*much of the following diff -r 4dc3baf45d6a -r 5020054b3a16 src/HOL/Combinatorics/Combinatorics.thy --- a/src/HOL/Combinatorics/Combinatorics.thy Wed May 05 16:09:02 2021 +0000 +++ b/src/HOL/Combinatorics/Combinatorics.thy Wed May 05 16:09:02 2021 +0000 @@ -3,6 +3,7 @@ theory Combinatorics imports + Transposition Stirling Permutations List_Permutation diff -r 4dc3baf45d6a -r 5020054b3a16 src/HOL/Combinatorics/Perm.thy --- a/src/HOL/Combinatorics/Perm.thy Wed May 05 16:09:02 2021 +0000 +++ b/src/HOL/Combinatorics/Perm.thy Wed May 05 16:09:02 2021 +0000 @@ -3,7 +3,8 @@ section \Permutations as abstract type\ theory Perm -imports Main + imports + Transposition begin text \ diff -r 4dc3baf45d6a -r 5020054b3a16 src/HOL/Combinatorics/Permutations.thy --- a/src/HOL/Combinatorics/Permutations.thy Wed May 05 16:09:02 2021 +0000 +++ b/src/HOL/Combinatorics/Permutations.thy Wed May 05 16:09:02 2021 +0000 @@ -7,6 +7,7 @@ imports "HOL-Library.Multiset" "HOL-Library.Disjoint_Sets" + Transposition begin subsection \Auxiliary\ diff -r 4dc3baf45d6a -r 5020054b3a16 src/HOL/Combinatorics/Transposition.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Combinatorics/Transposition.thy Wed May 05 16:09:02 2021 +0000 @@ -0,0 +1,110 @@ +section \Transposition function\ + +theory Transposition + imports Main +begin + +setup \Context.theory_map (Name_Space.map_naming (Name_Space.qualified_path true \<^binding>\Fun\))\ + +definition swap :: \'a \ 'a \ ('a \ 'b) \ ('a \ 'b)\ + where \swap a b f = f (a := f b, b:= f a)\ + +setup \Context.theory_map (Name_Space.map_naming (Name_Space.parent_path))\ + +lemma swap_apply [simp]: + "Fun.swap a b f a = f b" + "Fun.swap a b f b = f a" + "c \ a \ c \ b \ Fun.swap a b f c = f c" + by (simp_all add: Fun.swap_def) + +lemma swap_self [simp]: "Fun.swap a a f = f" + by (simp add: Fun.swap_def) + +lemma swap_commute: "Fun.swap a b f = Fun.swap b a f" + by (simp add: fun_upd_def Fun.swap_def fun_eq_iff) + +lemma swap_nilpotent [simp]: "Fun.swap a b (Fun.swap a b f) = f" + by (rule ext) (simp add: fun_upd_def Fun.swap_def) + +lemma swap_comp_involutory [simp]: "Fun.swap a b \ Fun.swap a b = id" + by (rule ext) simp + +lemma swap_triple: + assumes "a \ c" and "b \ c" + shows "Fun.swap a b (Fun.swap b c (Fun.swap a b f)) = Fun.swap a c f" + using assms by (simp add: fun_eq_iff Fun.swap_def) + +lemma comp_swap: "f \ Fun.swap a b g = Fun.swap a b (f \ g)" + by (rule ext) (simp add: fun_upd_def Fun.swap_def) + +lemma swap_image_eq [simp]: + assumes "a \ A" "b \ A" + shows "Fun.swap a b f ` A = f ` A" +proof - + have subset: "\f. Fun.swap a b f ` A \ f ` A" + using assms by (auto simp: image_iff Fun.swap_def) + then have "Fun.swap a b (Fun.swap a b f) ` A \ (Fun.swap a b f) ` A" . + with subset[of f] show ?thesis by auto +qed + +lemma inj_on_imp_inj_on_swap: "inj_on f A \ a \ A \ b \ A \ inj_on (Fun.swap a b f) A" + by (auto simp add: inj_on_def Fun.swap_def) + +lemma inj_on_swap_iff [simp]: + assumes A: "a \ A" "b \ A" + shows "inj_on (Fun.swap a b f) A \ inj_on f A" +proof + assume "inj_on (Fun.swap a b f) A" + with A have "inj_on (Fun.swap a b (Fun.swap a b f)) A" + by (iprover intro: inj_on_imp_inj_on_swap) + then show "inj_on f A" by simp +next + assume "inj_on f A" + with A show "inj_on (Fun.swap a b f) A" + by (iprover intro: inj_on_imp_inj_on_swap) +qed + +lemma surj_imp_surj_swap: "surj f \ surj (Fun.swap a b f)" + by simp + +lemma surj_swap_iff [simp]: "surj (Fun.swap a b f) \ surj f" + by simp + +lemma bij_betw_swap_iff [simp]: "x \ A \ y \ A \ bij_betw (Fun.swap x y f) A B \ bij_betw f A B" + by (auto simp: bij_betw_def) + +lemma bij_swap_iff [simp]: "bij (Fun.swap a b f) \ bij f" + by simp + +lemma swap_image: + \Fun.swap i j f ` A = f ` (A - {i, j} + \ (if i \ A then {j} else {}) \ (if j \ A then {i} else {}))\ + by (auto simp add: Fun.swap_def) + +lemma inv_swap_id: "inv (Fun.swap a b id) = Fun.swap a b id" + by (rule inv_unique_comp) (simp_all add: fun_eq_iff Fun.swap_def) + +lemma bij_swap_comp: + assumes "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 \bij p\]] + by (simp add: fun_eq_iff Fun.swap_def bij_inv_eq_iff[OF \bij p\]) + + +subsection \Transpositions\ + +lemma swap_id_eq: "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 swap_unfold: + \Fun.swap a b p = p \ Fun.swap a b id\ + by (simp add: fun_eq_iff Fun.swap_def) + +lemma swap_id_idempotent [simp]: "Fun.swap a b id \ Fun.swap a b id = id" + by (simp flip: swap_unfold) + +lemma bij_swap_compose_bij: + \bij (Fun.swap a b id \ p)\ if \bij p\ + using that by (rule bij_comp) simp + +end diff -r 4dc3baf45d6a -r 5020054b3a16 src/HOL/Fun.thy --- a/src/HOL/Fun.thy Wed May 05 16:09:02 2021 +0000 +++ b/src/HOL/Fun.thy Wed May 05 16:09:02 2021 +0000 @@ -855,104 +855,6 @@ by (simp add: override_on_def fun_eq_iff) -subsection \\swap\\ - -context -begin - -qualified definition swap :: \'a \ 'a \ ('a \ 'b) \ ('a \ 'b)\ - where \swap a b f = f (a := f b, b:= f a)\ - -lemma swap_apply [simp]: - "swap a b f a = f b" - "swap a b f b = f a" - "c \ a \ c \ b \ swap a b f c = f c" - by (simp_all add: swap_def) - -lemma swap_self [simp]: "swap a a f = f" - by (simp add: swap_def) - -lemma swap_commute: "swap a b f = swap b a f" - by (simp add: fun_upd_def swap_def fun_eq_iff) - -lemma swap_nilpotent [simp]: "swap a b (swap a b f) = f" - by (rule ext) (simp add: fun_upd_def swap_def) - -lemma swap_comp_involutory [simp]: "swap a b \ swap a b = id" - by (rule ext) simp - -lemma swap_triple: - assumes "a \ c" and "b \ c" - shows "swap a b (swap b c (swap a b f)) = swap a c f" - using assms by (simp add: fun_eq_iff swap_def) - -lemma comp_swap: "f \ swap a b g = swap a b (f \ g)" - by (rule ext) (simp add: fun_upd_def swap_def) - -lemma swap_image_eq [simp]: - assumes "a \ A" "b \ A" - shows "swap a b f ` A = f ` A" -proof - - have subset: "\f. swap a b f ` A \ f ` A" - using assms by (auto simp: image_iff swap_def) - then have "swap a b (swap a b f) ` A \ (swap a b f) ` A" . - with subset[of f] show ?thesis by auto -qed - -lemma inj_on_imp_inj_on_swap: "inj_on f A \ a \ A \ b \ A \ inj_on (swap a b f) A" - by (auto simp add: inj_on_def swap_def) - -lemma inj_on_swap_iff [simp]: - assumes A: "a \ A" "b \ A" - shows "inj_on (swap a b f) A \ inj_on f A" -proof - assume "inj_on (swap a b f) A" - with A have "inj_on (swap a b (swap a b f)) A" - by (iprover intro: inj_on_imp_inj_on_swap) - then show "inj_on f A" by simp -next - assume "inj_on f A" - with A show "inj_on (swap a b f) A" - by (iprover intro: inj_on_imp_inj_on_swap) -qed - -lemma surj_imp_surj_swap: "surj f \ surj (swap a b f)" - by simp - -lemma surj_swap_iff [simp]: "surj (swap a b f) \ surj f" - by simp - -lemma bij_betw_swap_iff [simp]: "x \ A \ y \ A \ bij_betw (swap x y f) A B \ bij_betw f A B" - by (auto simp: bij_betw_def) - -lemma bij_swap_iff [simp]: "bij (swap a b f) \ bij f" - by simp - -lemma swap_image: - \swap i j f ` A = f ` (A - {i, j} - \ (if i \ A then {j} else {}) \ (if j \ A then {i} else {}))\ - by (auto simp add: swap_def) - - -subsection \Transpositions\ - -lemma swap_id_eq: "swap a b id x = (if x = a then b else if x = b then a else x)" - by (simp add: swap_def) - -lemma swap_unfold: - \swap a b p = p \ swap a b id\ - by (simp add: fun_eq_iff swap_def) - -lemma swap_id_idempotent [simp]: "swap a b id \ swap a b id = id" - by (simp flip: swap_unfold) - -lemma bij_swap_compose_bij: - \bij (swap a b id \ p)\ if \bij p\ - using that by (rule bij_comp) simp - -end - - subsection \Inversion of injective functions\ definition the_inv_into :: "'a set \ ('a \ 'b) \ ('b \ 'a)" diff -r 4dc3baf45d6a -r 5020054b3a16 src/HOL/Hilbert_Choice.thy --- a/src/HOL/Hilbert_Choice.thy Wed May 05 16:09:02 2021 +0000 +++ b/src/HOL/Hilbert_Choice.thy Wed May 05 16:09:02 2021 +0000 @@ -636,15 +636,6 @@ shows "inv f = g" using fg gf inv_equality[of g f] by (auto simp add: fun_eq_iff) -lemma inv_swap_id: "inv (Fun.swap a b id) = Fun.swap a b id" - by (rule inv_unique_comp) simp_all - -lemma bij_swap_comp: - assumes "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 \bij p\]] - by (simp add: fun_eq_iff Fun.swap_def bij_inv_eq_iff[OF \bij p\]) - lemma subset_image_inj: "S \ f ` T \ (\U. U \ T \ inj_on f U \ S = f ` U)" proof safe