src/HOL/Library/Permutation.thy
changeset 36903 489c1fbbb028
parent 35272 c283ae736bea
child 39075 a18e5946d63c
equal deleted inserted replaced
36902:c6bae4456741 36903:489c1fbbb028
    91   by (blast dest: perm_sym)
    91   by (blast dest: perm_sym)
    92 
    92 
    93 
    93 
    94 subsection {* Removing elements *}
    94 subsection {* Removing elements *}
    95 
    95 
    96 primrec remove :: "'a => 'a list => 'a list" where
    96 lemma perm_remove: "x \<in> set ys ==> ys <~~> x # remove1 x ys"
    97     "remove x [] = []"
       
    98   | "remove x (y # ys) = (if x = y then ys else y # remove x ys)"
       
    99 
       
   100 lemma perm_remove: "x \<in> set ys ==> ys <~~> x # remove x ys"
       
   101   by (induct ys) auto
    97   by (induct ys) auto
   102 
       
   103 lemma remove_commute: "remove x (remove y l) = remove y (remove x l)"
       
   104   by (induct l) auto
       
   105 
       
   106 lemma multiset_of_remove [simp]:
       
   107     "multiset_of (remove a x) = multiset_of x - {#a#}"
       
   108   apply (induct x)
       
   109    apply (auto simp: multiset_eq_conv_count_eq)
       
   110   done
       
   111 
    98 
   112 
    99 
   113 text {* \medskip Congruence rule *}
   100 text {* \medskip Congruence rule *}
   114 
   101 
   115 lemma perm_remove_perm: "xs <~~> ys ==> remove z xs <~~> remove z ys"
   102 lemma perm_remove_perm: "xs <~~> ys ==> remove1 z xs <~~> remove1 z ys"
   116   by (induct pred: perm) auto
   103   by (induct pred: perm) auto
   117 
   104 
   118 lemma remove_hd [simp]: "remove z (z # xs) = xs"
   105 lemma remove_hd [simp]: "remove1 z (z # xs) = xs"
   119   by auto
   106   by auto
   120 
   107 
   121 lemma cons_perm_imp_perm: "z # xs <~~> z # ys ==> xs <~~> ys"
   108 lemma cons_perm_imp_perm: "z # xs <~~> z # ys ==> xs <~~> ys"
   122   by (drule_tac z = z in perm_remove_perm) auto
   109   by (drule_tac z = z in perm_remove_perm) auto
   123 
   110 
   144 lemma multiset_of_eq_perm: "(multiset_of xs = multiset_of ys) = (xs <~~> ys) "
   131 lemma multiset_of_eq_perm: "(multiset_of xs = multiset_of ys) = (xs <~~> ys) "
   145   apply (rule iffI)
   132   apply (rule iffI)
   146   apply (erule_tac [2] perm.induct, simp_all add: union_ac)
   133   apply (erule_tac [2] perm.induct, simp_all add: union_ac)
   147   apply (erule rev_mp, rule_tac x=ys in spec)
   134   apply (erule rev_mp, rule_tac x=ys in spec)
   148   apply (induct_tac xs, auto)
   135   apply (induct_tac xs, auto)
   149   apply (erule_tac x = "remove a x" in allE, drule sym, simp)
   136   apply (erule_tac x = "remove1 a x" in allE, drule sym, simp)
   150   apply (subgoal_tac "a \<in> set x")
   137   apply (subgoal_tac "a \<in> set x")
   151   apply (drule_tac z=a in perm.Cons)
   138   apply (drule_tac z=a in perm.Cons)
   152   apply (erule perm.trans, rule perm_sym, erule perm_remove)
   139   apply (erule perm.trans, rule perm_sym, erule perm_remove)
   153   apply (drule_tac f=set_of in arg_cong, simp)
   140   apply (drule_tac f=set_of in arg_cong, simp)
   154   done
   141   done