Nominal/FSet.thy
changeset 2541 d7269488c4b5
parent 2540 135ac0fb2686
child 2542 1f5c8e85c41f
equal deleted inserted replaced
2540:135ac0fb2686 2541:d7269488c4b5
   448 lemma map_prs [quot_preserve]: 
   448 lemma map_prs [quot_preserve]: 
   449   shows "(abs_fset \<circ> map f) [] = abs_fset []"
   449   shows "(abs_fset \<circ> map f) [] = abs_fset []"
   450   by simp
   450   by simp
   451 
   451 
   452 lemma insert_fset_rsp [quot_preserve]:
   452 lemma insert_fset_rsp [quot_preserve]:
   453   "(rep_fset ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op # = insert_fset"
   453   "(rep_fset ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) Cons = insert_fset"
   454   by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
   454   by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
   455       abs_o_rep[OF Quotient_fset] map_id insert_fset_def)
   455       abs_o_rep[OF Quotient_fset] map_id insert_fset_def)
   456 
   456 
   457 lemma union_fset_rsp [quot_preserve]:
   457 lemma union_fset_rsp [quot_preserve]:
   458   "((map rep_fset \<circ> rep_fset) ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op @ = union_fset"
   458   "((map rep_fset \<circ> rep_fset) ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) 
       
   459   append = union_fset"
   459   by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
   460   by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
   460       abs_o_rep[OF Quotient_fset] map_id sup_fset_def)
   461       abs_o_rep[OF Quotient_fset] map_id sup_fset_def)
   461 
   462 
   462 lemma list_all2_app_l:
   463 lemma list_all2_app_l:
   463   assumes a: "reflp R"
   464   assumes a: "reflp R"
   517 
   518 
   518 
   519 
   519 
   520 
   520 section {* Lifted theorems *}
   521 section {* Lifted theorems *}
   521 
   522 
       
   523 subsection {* fset *}
       
   524 
       
   525 lemma fset_simps [simp]:
       
   526   "fset {||} = ({} :: 'a set)"
       
   527   "fset (insert_fset (x :: 'a) S) = insert x (fset S)"
       
   528   by (lifting set.simps)
       
   529 
       
   530 lemma finite_fset [simp]: 
       
   531   shows "finite (fset S)"
       
   532   by (descending) (simp)
       
   533 
       
   534 lemma fset_cong:
       
   535   shows "fset S = fset T \<longleftrightarrow> S = T"
       
   536   by (descending) (simp)
       
   537 
       
   538 lemma filter_fset [simp]: 
       
   539   shows "fset (filter_fset P xs) = P \<inter> fset xs"
       
   540   by (descending) (auto simp add: mem_def)
       
   541 
       
   542 lemma remove_fset [simp]: 
       
   543   shows "fset (remove_fset x xs) = fset xs - {x}"
       
   544   by (descending) (simp)
       
   545 
       
   546 lemma inter_fset [simp]: 
       
   547   shows "fset (xs |\<inter>| ys) = fset xs \<inter> fset ys"
       
   548   by (descending) (auto simp add: inter_list_def)
       
   549 
       
   550 lemma union_fset [simp]: 
       
   551   shows "fset (xs |\<union>| ys) = fset xs \<union> fset ys"
       
   552   by (lifting set_append)
       
   553 
       
   554 lemma minus_fset [simp]: 
       
   555   shows "fset (xs - ys) = fset xs - fset ys"
       
   556   by (descending) (auto simp add: diff_list_def)
       
   557 
   522 
   558 
   523 subsection {* in_fset *}
   559 subsection {* in_fset *}
   524 
       
   525 lemma notin_empty_fset: 
       
   526   shows "x |\<notin>| {||}"
       
   527   by (descending) (simp add: memb_def)
       
   528 
   560 
   529 lemma in_fset: 
   561 lemma in_fset: 
   530   shows "x |\<in>| S \<longleftrightarrow> x \<in> fset S"
   562   shows "x |\<in>| S \<longleftrightarrow> x \<in> fset S"
   531   by (descending) (simp add: memb_def)
   563   by (descending) (simp add: memb_def)
   532 
   564 
   533 lemma notin_fset: 
   565 lemma notin_fset: 
   534   shows "x |\<notin>| S \<longleftrightarrow> x \<notin> fset S"
   566   shows "x |\<notin>| S \<longleftrightarrow> x \<notin> fset S"
   535   by (descending) (simp add: memb_def)
   567   by (simp add: in_fset)
       
   568 
       
   569 lemma notin_empty_fset: 
       
   570   shows "x |\<notin>| {||}"
       
   571   by (simp add: in_fset)
   536 
   572 
   537 lemma fset_eq_iff:
   573 lemma fset_eq_iff:
   538   shows "S = T \<longleftrightarrow> (\<forall>x. (x |\<in>| S) = (x |\<in>| T))"
   574   shows "S = T \<longleftrightarrow> (\<forall>x. (x |\<in>| S) = (x |\<in>| T))"
   539   by (descending) (auto simp add: memb_def)
   575   by (descending) (auto simp add: memb_def)
   540 
   576 
   543   by (descending) (simp add: memb_def)
   579   by (descending) (simp add: memb_def)
   544 
   580 
   545 
   581 
   546 subsection {* insert_fset *}
   582 subsection {* insert_fset *}
   547 
   583 
   548 lemma in_insert_fset_iff[simp]:
   584 lemma in_insert_fset_iff [simp]:
   549   shows "x |\<in>| insert_fset y S \<longleftrightarrow> x = y \<or> x |\<in>| S"
   585   shows "x |\<in>| insert_fset y S \<longleftrightarrow> x = y \<or> x |\<in>| S"
   550   by (descending) (simp add: memb_def)
   586   by (descending) (simp add: memb_def)
   551 
   587 
   552 lemma
   588 lemma
   553   shows insert_fsetI1: "x |\<in>| insert_fset x S"
   589   shows insert_fsetI1: "x |\<in>| insert_fset x S"
   554   and   insert_fsetI2: "x |\<in>| S \<Longrightarrow> x |\<in>| insert_fset y S"
   590   and   insert_fsetI2: "x |\<in>| S \<Longrightarrow> x |\<in>| insert_fset y S"
   555   by (descending, simp add: memb_def)+
   591   by simp_all
   556 
   592 
   557 lemma insert_absorb_fset[simp]:
   593 lemma insert_absorb_fset [simp]:
   558   shows "x |\<in>| S \<Longrightarrow> insert_fset x S = S"
   594   shows "x |\<in>| S \<Longrightarrow> insert_fset x S = S"
   559   by (descending) (auto simp add: memb_def)
   595   by (descending) (auto simp add: memb_def)
   560 
   596 
   561 lemma empty_not_insert_fset[simp]:
   597 lemma empty_not_insert_fset[simp]:
   562   shows "{||} \<noteq> insert_fset x S"
   598   shows "{||} \<noteq> insert_fset x S"
   574 lemma singleton_fset_eq[simp]:
   610 lemma singleton_fset_eq[simp]:
   575   shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
   611   shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
   576   by (descending) (auto)
   612   by (descending) (auto)
   577 
   613 
   578 
   614 
   579 (* FIXME: is this in any case a useful lemma *)
   615 (* FIXME: is this a useful lemma ? *)
   580 lemma in_fset_mdef:
   616 lemma in_fset_mdef:
   581   shows "x |\<in>| F \<longleftrightarrow> x |\<notin>| (F - {|x|}) \<and> F = insert_fset x (F - {|x|})"
   617   shows "x |\<in>| F \<longleftrightarrow> x |\<notin>| (F - {|x|}) \<and> F = insert_fset x (F - {|x|})"
   582   by (descending) (auto simp add: memb_def diff_list_def)
   618   by (descending) (auto simp add: memb_def diff_list_def)
   583 
   619 
   584 
   620 
   585 subsection {* fset *}
       
   586 
       
   587 lemma fset_simps [simp]:
       
   588   "fset {||} = ({} :: 'a set)"
       
   589   "fset (insert_fset (x :: 'a) S) = insert x (fset S)"
       
   590   by (lifting set.simps)
       
   591 
       
   592 lemma finite_fset [simp]: 
       
   593   shows "finite (fset S)"
       
   594   by (descending) (simp)
       
   595 
       
   596 lemma fset_cong:
       
   597   shows "fset S = fset T \<longleftrightarrow> S = T"
       
   598   by (descending) (simp)
       
   599 
       
   600 lemma filter_fset [simp]: 
       
   601   shows "fset (filter_fset P xs) = P \<inter> fset xs"
       
   602   by (descending) (auto simp add: mem_def)
       
   603 
       
   604 lemma remove_fset [simp]: 
       
   605   shows "fset (remove_fset x xs) = fset xs - {x}"
       
   606   by (descending) (simp)
       
   607 
       
   608 lemma inter_fset [simp]: 
       
   609   shows "fset (xs |\<inter>| ys) = fset xs \<inter> fset ys"
       
   610   by (descending) (auto simp add: inter_list_def)
       
   611 
       
   612 lemma union_fset [simp]: 
       
   613   shows "fset (xs |\<union>| ys) = fset xs \<union> fset ys"
       
   614   by (lifting set_append)
       
   615 
       
   616 lemma minus_fset [simp]: 
       
   617   shows "fset (xs - ys) = fset xs - fset ys"
       
   618   by (descending) (auto simp add: diff_list_def)
       
   619 
       
   620 
       
   621 subsection {* union_fset *}
   621 subsection {* union_fset *}
   622 
   622 
   623 lemmas [simp] =
   623 lemmas [simp] =
   624   sup_bot_left[where 'a="'a fset", standard]
   624   sup_bot_left[where 'a="'a fset", standard]
   625   sup_bot_right[where 'a="'a fset", standard]
   625   sup_bot_right[where 'a="'a fset", standard]
   657 
   657 
   658 lemma minus_insert_notin_fset[simp]: 
   658 lemma minus_insert_notin_fset[simp]: 
   659   shows "x |\<notin>| ys \<Longrightarrow> insert_fset x xs - ys = insert_fset x (xs - ys)"
   659   shows "x |\<notin>| ys \<Longrightarrow> insert_fset x xs - ys = insert_fset x (xs - ys)"
   660   by (simp add: minus_insert_fset)
   660   by (simp add: minus_insert_fset)
   661 
   661 
   662 lemma in_fset_minus_fset_notin_fset: 
   662 lemma in_minus_fset: 
   663   shows "x |\<in>| F - S \<Longrightarrow> x |\<notin>| S"
   663   shows "x |\<in>| F - S \<Longrightarrow> x |\<notin>| S"
   664   unfolding in_fset minus_fset
   664   unfolding in_fset minus_fset
   665   by blast
   665   by blast
   666 
   666 
   667 lemma in_fset_notin_fset_minus_fset: 
   667 lemma notin_minus_fset: 
   668   shows "x |\<in>| S \<Longrightarrow> x |\<notin>| F - S"
   668   shows "x |\<in>| S \<Longrightarrow> x |\<notin>| F - S"
   669   unfolding in_fset minus_fset
   669   unfolding in_fset minus_fset
   670   by blast
   670   by blast
   671 
   671 
   672 
   672 
   729 
   729 
   730 lemma subset_empty_fset:
   730 lemma subset_empty_fset:
   731   shows "xs |\<subseteq>| {||} \<longleftrightarrow> xs = {||}"
   731   shows "xs |\<subseteq>| {||} \<longleftrightarrow> xs = {||}"
   732   by (descending) (simp add: sub_list_def)
   732   by (descending) (simp add: sub_list_def)
   733 
   733 
   734 lemma not_psubset_fset_fnil: 
   734 lemma not_psubset_empty_fset: 
   735   shows "\<not> xs |\<subset>| {||}"
   735   shows "\<not> xs |\<subset>| {||}"
   736   by (metis fset_simps(1) psubset_fset not_psubset_empty)
   736   by (metis fset_simps(1) psubset_fset not_psubset_empty)
   737 
   737 
   738 
   738 
   739 subsection {* map_fset *}
   739 subsection {* map_fset *}
   745 
   745 
   746 lemma map_fset_image [simp]:
   746 lemma map_fset_image [simp]:
   747   shows "fset (map_fset f S) = f ` (fset S)"
   747   shows "fset (map_fset f S) = f ` (fset S)"
   748   by (descending) (simp)
   748   by (descending) (simp)
   749 
   749 
   750 lemma inj_map_fset_eq_iff:
   750 lemma nj_map_fset_cong:
   751   shows "inj f \<Longrightarrow> map_fset f S = map_fset f T \<longleftrightarrow> S = T"
   751   shows "inj f \<Longrightarrow> map_fset f S = map_fset f T \<longleftrightarrow> S = T"
   752   by (descending) (metis inj_vimage_image_eq list_eq.simps set_map)
   752   by (descending) (metis inj_vimage_image_eq list_eq.simps set_map)
   753 
   753 
   754 lemma map_union_fset: 
   754 lemma map_union_fset: 
   755   shows "map_fset f (S |\<union>| T) = map_fset f S |\<union>| map_fset f T"
   755   shows "map_fset f (S |\<union>| T) = map_fset f S |\<union>| map_fset f T"
   760 
   760 
   761 lemma card_fset: 
   761 lemma card_fset: 
   762   shows "card_fset xs = card (fset xs)"
   762   shows "card_fset xs = card (fset xs)"
   763   by (lifting card_list_def)
   763   by (lifting card_list_def)
   764 
   764 
   765 lemma card_insert_fset_if [simp]:
   765 lemma card_insert_fset_iff [simp]:
   766   shows "card_fset (insert_fset x S) = (if x |\<in>| S then card_fset S else Suc (card_fset S))"
   766   shows "card_fset (insert_fset x S) = (if x |\<in>| S then card_fset S else Suc (card_fset S))"
   767   by (descending) (auto simp add: card_list_def memb_def insert_absorb)
   767   by (descending) (auto simp add: card_list_def memb_def insert_absorb)
   768 
   768 
   769 lemma card_fset_0[simp]:
   769 lemma card_fset_0[simp]:
   770   shows "card_fset S = 0 \<longleftrightarrow> S = {||}"
   770   shows "card_fset S = 0 \<longleftrightarrow> S = {||}"
   771   by (descending) (simp add: card_list_def)
   771   by (descending) (simp add: card_list_def)
   772 
   772 
   773 lemma card_empty_fset[simp]:
   773 lemma card_empty_fset[simp]:
   774   shows "card_fset {||} = 0"
   774   shows "card_fset {||} = 0"
   775   by (simp add: card_fset_0)
   775   by (simp add: card_fset)
   776 
   776 
   777 lemma card_fset_1:
   777 lemma card_fset_1:
   778   shows "card_fset S = 1 \<longleftrightarrow> (\<exists>x. S = {|x|})"
   778   shows "card_fset S = 1 \<longleftrightarrow> (\<exists>x. S = {|x|})"
   779   by (descending) (auto simp add: card_list_def card_Suc_eq)
   779   by (descending) (auto simp add: card_list_def card_Suc_eq)
   780 
   780 
   782   shows "x \<in> fset S \<Longrightarrow> 0 < card_fset S"
   782   shows "x \<in> fset S \<Longrightarrow> 0 < card_fset S"
   783   by (descending) (auto simp add: card_list_def card_gt_0_iff)
   783   by (descending) (auto simp add: card_list_def card_gt_0_iff)
   784   
   784   
   785 lemma card_notin_fset:
   785 lemma card_notin_fset:
   786   shows "(x |\<notin>| S) = (card_fset (insert_fset x S) = Suc (card_fset S))"
   786   shows "(x |\<notin>| S) = (card_fset (insert_fset x S) = Suc (card_fset S))"
   787   by (descending) (auto simp add: memb_def card_list_def insert_absorb)
   787   by simp
   788 
   788 
   789 lemma card_fset_Suc: 
   789 lemma card_fset_Suc: 
   790   shows "card_fset S = Suc n \<Longrightarrow> \<exists>x T. x |\<notin>| T \<and> S = insert_fset x T \<and> card_fset T = n"
   790   shows "card_fset S = Suc n \<Longrightarrow> \<exists>x T. x |\<notin>| T \<and> S = insert_fset x T \<and> card_fset T = n"
   791   apply(descending)
   791   apply(descending)
   792   apply(auto simp add: card_list_def memb_def dest!: card_eq_SucD)
   792   apply(auto simp add: card_list_def memb_def dest!: card_eq_SucD)
   793   by (metis Diff_insert_absorb set_removeAll)
   793   by (metis Diff_insert_absorb set_removeAll)
   794 
   794 
   795 lemma card_rsemove_fset:
   795 lemma card_remove_fset_iff [simp]:
   796   shows "card_fset (remove_fset y S) = (if y |\<in>| S then card_fset S - 1 else card_fset S)"
   796   shows "card_fset (remove_fset y S) = (if y |\<in>| S then card_fset S - 1 else card_fset S)"
   797   by (descending) (simp add: card_list_def memb_def)
   797   by (descending) (simp add: card_list_def memb_def)
   798 
   798 
   799 lemma card_Suc_in_fset: 
   799 lemma card_Suc_exists_in_fset: 
   800   shows "card_fset A = Suc n \<Longrightarrow> \<exists>a. a |\<in>| A"
   800   shows "card_fset S = Suc n \<Longrightarrow> \<exists>a. a |\<in>| S"
   801   apply(descending)
   801   by (drule card_fset_Suc) (auto)
   802   apply(simp add: card_list_def memb_def)
   802 
   803   apply(drule card_eq_SucD)
   803 lemma in_card_fset_not_0: 
   804   apply(auto)
       
   805   done
       
   806 
       
   807 lemma in_fset_card_fset_not_0: 
       
   808   shows "a |\<in>| A \<Longrightarrow> card_fset A \<noteq> 0"
   804   shows "a |\<in>| A \<Longrightarrow> card_fset A \<noteq> 0"
   809   by (descending) (auto simp add: card_list_def memb_def)
   805   by (descending) (auto simp add: card_list_def memb_def)
   810 
   806 
   811 lemma card_fset_mono: 
   807 lemma card_fset_mono: 
   812   shows "xs |\<subseteq>| ys \<Longrightarrow> card_fset xs \<le> card_fset ys"
   808   shows "xs |\<subseteq>| ys \<Longrightarrow> card_fset xs \<le> card_fset ys"
   837 lemma card_remove_fset_less1: 
   833 lemma card_remove_fset_less1: 
   838   shows "x |\<in>| xs \<Longrightarrow> card_fset (remove_fset x xs) < card_fset xs"
   834   shows "x |\<in>| xs \<Longrightarrow> card_fset (remove_fset x xs) < card_fset xs"
   839   unfolding card_fset in_fset remove_fset 
   835   unfolding card_fset in_fset remove_fset 
   840   by (rule card_Diff1_less[OF finite_fset])
   836   by (rule card_Diff1_less[OF finite_fset])
   841 
   837 
   842 lemma card_rsemove_fset_less2: 
   838 lemma card_remove_fset_less2: 
   843   shows "x |\<in>| xs \<Longrightarrow> y |\<in>| xs \<Longrightarrow> card_fset (remove_fset y (remove_fset x xs)) < card_fset xs"
   839   shows "x |\<in>| xs \<Longrightarrow> y |\<in>| xs \<Longrightarrow> card_fset (remove_fset y (remove_fset x xs)) < card_fset xs"
   844   unfolding card_fset remove_fset in_fset
   840   unfolding card_fset remove_fset in_fset
   845   by (rule card_Diff2_less[OF finite_fset])
   841   by (rule card_Diff2_less[OF finite_fset])
   846 
   842 
   847 lemma card_rsemove_fset_le1: 
   843 lemma card_remove_fset_le1: 
   848   shows "card_fset (remove_fset x xs) \<le> card_fset xs"
   844   shows "card_fset (remove_fset x xs) \<le> card_fset xs"
   849   unfolding remove_fset card_fset
   845   unfolding remove_fset card_fset
   850   by (rule card_Diff1_le[OF finite_fset])
   846   by (rule card_Diff1_le[OF finite_fset])
   851 
   847 
   852 lemma card_psubset_fset: 
   848 lemma card_psubset_fset: 
   871   shows "card_fset (A - B) = card_fset A - card_fset B"
   867   shows "card_fset (A - B) = card_fset A - card_fset B"
   872   using assms 
   868   using assms 
   873   unfolding subset_fset card_fset minus_fset
   869   unfolding subset_fset card_fset minus_fset
   874   by (rule card_Diff_subset[OF finite_fset])
   870   by (rule card_Diff_subset[OF finite_fset])
   875 
   871 
   876 lemma card_minus_subset_inter_fset:
   872 lemma card_minus_fset:
   877   shows "card_fset (A - B) = card_fset A - card_fset (A |\<inter>| B)"
   873   shows "card_fset (A - B) = card_fset A - card_fset (A |\<inter>| B)"
   878   unfolding inter_fset card_fset minus_fset
   874   unfolding inter_fset card_fset minus_fset
   879   by (rule card_Diff_subset_Int) (simp)
   875   by (rule card_Diff_subset_Int) (simp)
   880 
   876 
   881 
   877 
   882 subsection {* concat_fset *}
   878 subsection {* concat_fset *}
   883 
   879 
   884 lemma concat_empty_fset:
   880 lemma concat_empty_fset [simp]:
   885   shows "concat_fset {||} = {||}"
   881   shows "concat_fset {||} = {||}"
   886   by (lifting concat.simps(1))
   882   by (lifting concat.simps(1))
   887 
   883 
   888 lemma concat_insert_fset:
   884 lemma concat_insert_fset [simp]:
   889   shows "concat_fset (insert_fset x S) = x |\<union>| concat_fset S"
   885   shows "concat_fset (insert_fset x S) = x |\<union>| concat_fset S"
   890   by (lifting concat.simps(2))
   886   by (lifting concat.simps(2))
   891 
   887 
   892 lemma concat_inter_fset:
   888 lemma concat_inter_fset [simp]:
   893   shows "concat_fset (xs |\<union>| ys) = concat_fset xs |\<union>| concat_fset ys"
   889   shows "concat_fset (xs |\<union>| ys) = concat_fset xs |\<union>| concat_fset ys"
   894   by (lifting concat_append)
   890   by (lifting concat_append)
   895 
   891 
   896 
   892 
   897 subsection {* filter_fset *}
   893 subsection {* filter_fset *}