Nominal/Nominal2_Base.thy
changeset 2735 d97e04126a3d
parent 2733 5f6fefdbf055
child 2742 f1192e3474e0
equal deleted inserted replaced
2734:eee5deb35aa8 2735:d97e04126a3d
    78 lemma atom_components_eq_iff:
    78 lemma atom_components_eq_iff:
    79   fixes a b :: atom
    79   fixes a b :: atom
    80   shows "a = b \<longleftrightarrow> sort_of a = sort_of b \<and> nat_of a = nat_of b"
    80   shows "a = b \<longleftrightarrow> sort_of a = sort_of b \<and> nat_of a = nat_of b"
    81   by (induct a, induct b, simp)
    81   by (induct a, induct b, simp)
    82 
    82 
       
    83 
    83 section {* Sort-Respecting Permutations *}
    84 section {* Sort-Respecting Permutations *}
    84 
    85 
    85 typedef perm =
    86 typedef perm =
    86   "{f. bij f \<and> finite {a. f a \<noteq> a} \<and> (\<forall>a. sort_of (f a) = sort_of a)}"
    87   "{f. bij f \<and> finite {a. f a \<noteq> a} \<and> (\<forall>a. sort_of (f a) = sort_of a)}"
    87 proof
    88 proof
   148   "Rep_perm p1 = Rep_perm p2 \<Longrightarrow> p1 = p2"
   149   "Rep_perm p1 = Rep_perm p2 \<Longrightarrow> p1 = p2"
   149   by (simp add: fun_eq_iff Rep_perm_inject [symmetric])
   150   by (simp add: fun_eq_iff Rep_perm_inject [symmetric])
   150 
   151 
   151 instance perm :: size ..
   152 instance perm :: size ..
   152 
   153 
       
   154 
   153 subsection {* Permutations form a (multiplicative) group *}
   155 subsection {* Permutations form a (multiplicative) group *}
   154 
       
   155 
   156 
   156 instantiation perm :: group_add
   157 instantiation perm :: group_add
   157 begin
   158 begin
   158 
   159 
   159 definition
   160 definition
   379 lemma pemute_minus_self:
   380 lemma pemute_minus_self:
   380   shows "- p \<bullet> p = p"
   381   shows "- p \<bullet> p = p"
   381   unfolding permute_perm_def 
   382   unfolding permute_perm_def 
   382   by (simp add: diff_minus add_assoc)
   383   by (simp add: diff_minus add_assoc)
   383 
   384 
   384 lemma permute_eqvt:
       
   385   shows "p \<bullet> (q \<bullet> x) = (p \<bullet> q) \<bullet> (p \<bullet> x)"
       
   386   unfolding permute_perm_def by simp
       
   387 
       
   388 lemma zero_perm_eqvt:
       
   389   shows "p \<bullet> (0::perm) = 0"
       
   390   unfolding permute_perm_def by simp
       
   391 
       
   392 lemma add_perm_eqvt:
       
   393   fixes p p1 p2 :: perm
       
   394   shows "p \<bullet> (p1 + p2) = p \<bullet> p1 + p \<bullet> p2"
       
   395   unfolding permute_perm_def
       
   396   by (simp add: perm_eq_iff)
       
   397 
       
   398 lemma swap_eqvt:
       
   399   shows "p \<bullet> (a \<rightleftharpoons> b) = (p \<bullet> a \<rightleftharpoons> p \<bullet> b)"
       
   400   unfolding permute_perm_def
       
   401   by (auto simp add: swap_atom perm_eq_iff)
       
   402 
       
   403 lemma uminus_eqvt:
       
   404   fixes p q::"perm"
       
   405   shows "p \<bullet> (- q) = - (p \<bullet> q)"
       
   406   unfolding permute_perm_def
       
   407   by (simp add: diff_minus minus_add add_assoc)
       
   408 
   385 
   409 subsection {* Permutations for functions *}
   386 subsection {* Permutations for functions *}
   410 
   387 
   411 instantiation "fun" :: (pt, pt) pt
   388 instantiation "fun" :: (pt, pt) pt
   412 begin
   389 begin
   472   unfolding permute_fun_def permute_bool_def
   449   unfolding permute_fun_def permute_bool_def
   473   unfolding vimage_def Collect_def mem_def ..
   450   unfolding vimage_def Collect_def mem_def ..
   474 
   451 
   475 lemma permute_finite [simp]:
   452 lemma permute_finite [simp]:
   476   shows "finite (p \<bullet> X) = finite X"
   453   shows "finite (p \<bullet> X) = finite X"
   477 apply(simp add: permute_set_eq_image)
   454   unfolding permute_set_eq_vimage
   478 apply(rule iffI)
   455   using bij_permute by (rule finite_vimage_iff)
   479 apply(drule finite_imageD)
       
   480 using inj_permute[where p="p"]
       
   481 apply(simp add: inj_on_def)
       
   482 apply(assumption)
       
   483 apply(rule finite_imageI)
       
   484 apply(assumption)
       
   485 done
       
   486 
   456 
   487 lemma swap_set_not_in:
   457 lemma swap_set_not_in:
   488   assumes a: "a \<notin> S" "b \<notin> S"
   458   assumes a: "a \<notin> S" "b \<notin> S"
   489   shows "(a \<rightleftharpoons> b) \<bullet> S = S"
   459   shows "(a \<rightleftharpoons> b) \<bullet> S = S"
   490   unfolding permute_set_eq
   460   unfolding permute_set_eq
   520 
   490 
   521 lemma insert_eqvt:
   491 lemma insert_eqvt:
   522   shows "p \<bullet> (insert x A) = insert (p \<bullet> x) (p \<bullet> A)"
   492   shows "p \<bullet> (insert x A) = insert (p \<bullet> x) (p \<bullet> A)"
   523   unfolding permute_set_eq_image image_insert ..
   493   unfolding permute_set_eq_image image_insert ..
   524 
   494 
   525 subsection {* Permutations for units *}
   495 
       
   496 subsection {* Permutations for @{typ unit} *}
   526 
   497 
   527 instantiation unit :: pt
   498 instantiation unit :: pt
   528 begin
   499 begin
   529 
   500 
   530 definition "p \<bullet> (u::unit) = u"
   501 definition "p \<bullet> (u::unit) = u"
   564 instance 
   535 instance 
   565 by (default) (case_tac [!] x, simp_all)
   536 by (default) (case_tac [!] x, simp_all)
   566 
   537 
   567 end
   538 end
   568 
   539 
   569 subsection {* Permutations for lists *}
   540 subsection {* Permutations for @{typ "'a list"} *}
   570 
   541 
   571 instantiation list :: (pt) pt
   542 instantiation list :: (pt) pt
   572 begin
   543 begin
   573 
   544 
   574 primrec 
   545 primrec 
   586   shows "p \<bullet> (set xs) = set (p \<bullet> xs)"
   557   shows "p \<bullet> (set xs) = set (p \<bullet> xs)"
   587   by (induct xs) (simp_all add: empty_eqvt insert_eqvt)
   558   by (induct xs) (simp_all add: empty_eqvt insert_eqvt)
   588 
   559 
   589 
   560 
   590 
   561 
   591 subsection {* Permutations for options *}
   562 subsection {* Permutations for @{typ "'a option"} *}
   592 
   563 
   593 instantiation option :: (pt) pt
   564 instantiation option :: (pt) pt
   594 begin
   565 begin
   595 
   566 
   596 primrec 
   567 primrec 
   603 by (default) (induct_tac [!] x, simp_all)
   574 by (default) (induct_tac [!] x, simp_all)
   604 
   575 
   605 end
   576 end
   606 
   577 
   607 
   578 
   608 subsection {* Permutations for fsets *}
   579 subsection {* Permutations for @{typ "'a fset"} *}
   609 
       
   610 
       
   611 
   580 
   612 lemma permute_fset_rsp[quot_respect]:
   581 lemma permute_fset_rsp[quot_respect]:
   613   shows "(op = ===> list_eq ===> list_eq) permute permute"
   582   shows "(op = ===> list_eq ===> list_eq) permute permute"
   614   unfolding fun_rel_def
   583   unfolding fun_rel_def
   615   by (simp add: set_eqvt[symmetric])
   584   by (simp add: set_eqvt[symmetric])
   639 
   608 
   640 lemma fset_eqvt: 
   609 lemma fset_eqvt: 
   641   shows "p \<bullet> (fset S) = fset (p \<bullet> S)"
   610   shows "p \<bullet> (fset S) = fset (p \<bullet> S)"
   642   by (lifting set_eqvt)
   611   by (lifting set_eqvt)
   643 
   612 
       
   613 
   644 subsection {* Permutations for @{typ char}, @{typ nat}, and @{typ int} *}
   614 subsection {* Permutations for @{typ char}, @{typ nat}, and @{typ int} *}
   645 
   615 
   646 instantiation char :: pt
   616 instantiation char :: pt
   647 begin
   617 begin
   648 
   618 
   718 
   688 
   719 instance int :: pure
   689 instance int :: pure
   720 proof qed (rule permute_int_def)
   690 proof qed (rule permute_int_def)
   721 
   691 
   722 
   692 
       
   693 section {* Infrastructure for Equivariance and Perm_simp *}
   723 
   694 
   724 subsection {* Basic functions about permutations *}
   695 subsection {* Basic functions about permutations *}
   725 
   696 
   726 use "nominal_basics.ML"
   697 use "nominal_basics.ML"
   727 
   698 
   728 
   699 
   729 subsection {* Equivariance infrastructure *}
   700 subsection {* Eqvt infrastructure *}
   730 
   701 
   731 text {* Setup of the theorem attributes @{text eqvt} and @{text eqvt_raw} *}
   702 text {* Setup of the theorem attributes @{text eqvt} and @{text eqvt_raw} *}
   732 
   703 
   733 use "nominal_thmdecls.ML"
   704 use "nominal_thmdecls.ML"
   734 setup "Nominal_ThmDecls.setup"
   705 setup "Nominal_ThmDecls.setup"
   735 
   706 
   736 
   707 
   737 lemmas [eqvt] =
   708 lemmas [eqvt] =
   738   (* permutations *)
   709   (* pt types *)
   739   uminus_eqvt add_perm_eqvt swap_eqvt 
   710   permute_prod.simps 
   740 
       
   741   (* datatypes *)
       
   742   Pair_eqvt 
       
   743   permute_list.simps 
   711   permute_list.simps 
   744   permute_option.simps 
   712   permute_option.simps 
   745   permute_sum.simps
   713   permute_sum.simps
   746 
   714 
   747   (* sets *)
   715   (* sets *)
   782  {* pushes permutations inside. *}
   750  {* pushes permutations inside. *}
   783 
   751 
   784 method_setup perm_strict_simp =
   752 method_setup perm_strict_simp =
   785  {* Nominal_Permeq.args_parser >> Nominal_Permeq.perm_strict_simp_meth *}
   753  {* Nominal_Permeq.args_parser >> Nominal_Permeq.perm_strict_simp_meth *}
   786  {* pushes permutations inside, raises an error if it cannot solve all permutations. *}
   754  {* pushes permutations inside, raises an error if it cannot solve all permutations. *}
       
   755 
       
   756 
       
   757 subsubsection {* Equivariance for permutations and swapping *}
       
   758 
       
   759 lemma permute_eqvt:
       
   760   shows "p \<bullet> (q \<bullet> x) = (p \<bullet> q) \<bullet> (p \<bullet> x)"
       
   761   unfolding permute_perm_def by simp
   787 
   762 
   788 (* the normal version of this lemma would cause loops *)
   763 (* the normal version of this lemma would cause loops *)
   789 lemma permute_eqvt_raw[eqvt_raw]:
   764 lemma permute_eqvt_raw[eqvt_raw]:
   790   shows "p \<bullet> permute \<equiv> permute"
   765   shows "p \<bullet> permute \<equiv> permute"
   791 apply(simp add: fun_eq_iff permute_fun_def)
   766 apply(simp add: fun_eq_iff permute_fun_def)
   792 apply(subst permute_eqvt)
   767 apply(subst permute_eqvt)
   793 apply(simp)
   768 apply(simp)
   794 done
   769 done
   795 
   770 
       
   771 lemma zero_perm_eqvt [eqvt]:
       
   772   shows "p \<bullet> (0::perm) = 0"
       
   773   unfolding permute_perm_def by simp
       
   774 
       
   775 lemma add_perm_eqvt [eqvt]:
       
   776   fixes p p1 p2 :: perm
       
   777   shows "p \<bullet> (p1 + p2) = p \<bullet> p1 + p \<bullet> p2"
       
   778   unfolding permute_perm_def
       
   779   by (simp add: perm_eq_iff)
       
   780 
       
   781 lemma swap_eqvt [eqvt]:
       
   782   shows "p \<bullet> (a \<rightleftharpoons> b) = (p \<bullet> a \<rightleftharpoons> p \<bullet> b)"
       
   783   unfolding permute_perm_def
       
   784   by (auto simp add: swap_atom perm_eq_iff)
       
   785 
       
   786 lemma uminus_eqvt [eqvt]:
       
   787   fixes p q::"perm"
       
   788   shows "p \<bullet> (- q) = - (p \<bullet> q)"
       
   789   unfolding permute_perm_def
       
   790   by (simp add: diff_minus minus_add add_assoc)
       
   791 
       
   792 
   796 subsubsection {* Equivariance of Logical Operators *}
   793 subsubsection {* Equivariance of Logical Operators *}
   797 
   794 
   798 lemma eq_eqvt [eqvt]:
   795 lemma eq_eqvt [eqvt]:
   799   shows "p \<bullet> (x = y) \<longleftrightarrow> (p \<bullet> x) = (p \<bullet> y)"
   796   shows "p \<bullet> (x = y) \<longleftrightarrow> (p \<bullet> x) = (p \<bullet> y)"
   800   unfolding permute_eq_iff permute_bool_def ..
   797   unfolding permute_eq_iff permute_bool_def ..
   801 
   798 
   802 lemma Not_eqvt [eqvt]:
   799 lemma Not_eqvt [eqvt]:
   803   shows "p \<bullet> (\<not> A) = (\<not> (p \<bullet> A))"
   800   shows "p \<bullet> (\<not> A) \<longleftrightarrow> \<not> (p \<bullet> A)"
   804 by (simp add: permute_bool_def)
   801   by (simp add: permute_bool_def)
   805 
   802 
   806 lemma conj_eqvt [eqvt]:
   803 lemma conj_eqvt [eqvt]:
   807   shows "p \<bullet> (A \<and> B) = ((p \<bullet> A) \<and> (p \<bullet> B))"
   804   shows "p \<bullet> (A \<and> B) \<longleftrightarrow> (p \<bullet> A) \<and> (p \<bullet> B)"
   808   by (simp add: permute_bool_def)
   805   by (simp add: permute_bool_def)
   809 
   806 
   810 lemma imp_eqvt [eqvt]:
   807 lemma imp_eqvt [eqvt]:
   811   shows "p \<bullet> (A \<longrightarrow> B) = ((p \<bullet> A) \<longrightarrow> (p \<bullet> B))"
   808   shows "p \<bullet> (A \<longrightarrow> B) \<longleftrightarrow> (p \<bullet> A) \<longrightarrow> (p \<bullet> B)"
   812   by (simp add: permute_bool_def)
   809   by (simp add: permute_bool_def)
   813 
   810 
   814 declare imp_eqvt[folded induct_implies_def, eqvt]
   811 declare imp_eqvt[folded induct_implies_def, eqvt]
   815 
   812 
   816 lemma ex_eqvt [eqvt]:
   813 lemma ex_eqvt [eqvt]:
   836   by (simp add: permute_fun_app_eq)
   833   by (simp add: permute_fun_app_eq)
   837 
   834 
   838 lemma Collect_eqvt [eqvt]:
   835 lemma Collect_eqvt [eqvt]:
   839   shows "p \<bullet> {x. P x} = {x. (p \<bullet> P) x}"
   836   shows "p \<bullet> {x. P x} = {x. (p \<bullet> P) x}"
   840   unfolding Collect_def permute_fun_def ..
   837   unfolding Collect_def permute_fun_def ..
   841 
       
   842 
       
   843 
   838 
   844 lemma inter_eqvt [eqvt]:
   839 lemma inter_eqvt [eqvt]:
   845   shows "p \<bullet> (A \<inter> B) = (p \<bullet> A) \<inter> (p \<bullet> B)"
   840   shows "p \<bullet> (A \<inter> B) = (p \<bullet> A) \<inter> (p \<bullet> B)"
   846   unfolding Int_def
   841   unfolding Int_def
   847   by (perm_simp) (rule refl)
   842   by (perm_simp) (rule refl)
   863 lemma False_eqvt [eqvt]:
   858 lemma False_eqvt [eqvt]:
   864   shows "p \<bullet> False = False"
   859   shows "p \<bullet> False = False"
   865   unfolding permute_bool_def ..
   860   unfolding permute_bool_def ..
   866 
   861 
   867 lemma disj_eqvt [eqvt]:
   862 lemma disj_eqvt [eqvt]:
   868   shows "p \<bullet> (A \<or> B) = ((p \<bullet> A) \<or> (p \<bullet> B))"
   863   shows "p \<bullet> (A \<or> B) \<longleftrightarrow> (p \<bullet> A) \<or> (p \<bullet> B)"
   869   by (simp add: permute_bool_def)
   864   by (simp add: permute_bool_def)
   870 
   865 
   871 lemma all_eqvt2:
   866 lemma all_eqvt2:
   872   shows "p \<bullet> (\<forall>x. P x) = (\<forall>x. p \<bullet> P (- p \<bullet> x))"
   867   shows "p \<bullet> (\<forall>x. P x) = (\<forall>x. p \<bullet> P (- p \<bullet> x))"
   873   by (perm_simp add: permute_minus_cancel) (rule refl)
   868   by (perm_simp add: permute_minus_cancel) (rule refl)
   900   apply(simp add: permute_bool_def unique)
   895   apply(simp add: permute_bool_def unique)
   901   apply(simp add: permute_bool_def)
   896   apply(simp add: permute_bool_def)
   902   apply(rule theI'[OF unique])
   897   apply(rule theI'[OF unique])
   903   done
   898   done
   904 
   899 
   905 subsubsection {* Equivariance Set Operations *}
   900 subsubsection {* Equivariance set operations *}
   906 
   901 
   907 lemma Bex_eqvt[eqvt]:
   902 lemma Bex_eqvt [eqvt]:
   908   shows "p \<bullet> (\<exists>x \<in> S. P x) = (\<exists>x \<in> (p \<bullet> S). (p \<bullet> P) x)"
   903   shows "p \<bullet> (\<exists>x \<in> S. P x) = (\<exists>x \<in> (p \<bullet> S). (p \<bullet> P) x)"
   909   unfolding Bex_def
   904   unfolding Bex_def
   910   by (perm_simp) (rule refl)
   905   by (perm_simp) (rule refl)
   911 
   906 
   912 lemma Ball_eqvt[eqvt]:
   907 lemma Ball_eqvt [eqvt]:
   913   shows "p \<bullet> (\<forall>x \<in> S. P x) = (\<forall>x \<in> (p \<bullet> S). (p \<bullet> P) x)"
   908   shows "p \<bullet> (\<forall>x \<in> S. P x) = (\<forall>x \<in> (p \<bullet> S). (p \<bullet> P) x)"
   914   unfolding Ball_def
   909   unfolding Ball_def
   915   by (perm_simp) (rule refl)
   910   by (perm_simp) (rule refl)
   916 
   911 
   917 lemma UNIV_eqvt[eqvt]:
   912 lemma UNIV_eqvt [eqvt]:
   918   shows "p \<bullet> UNIV = UNIV"
   913   shows "p \<bullet> UNIV = UNIV"
   919   unfolding UNIV_def
   914   unfolding UNIV_def
   920   by (perm_simp) (rule refl)
   915   by (perm_simp) (rule refl)
   921 
   916 
   922 lemma union_eqvt[eqvt]:
   917 lemma union_eqvt [eqvt]:
   923   shows "p \<bullet> (A \<union> B) = (p \<bullet> A) \<union> (p \<bullet> B)"
   918   shows "p \<bullet> (A \<union> B) = (p \<bullet> A) \<union> (p \<bullet> B)"
   924   unfolding Un_def
   919   unfolding Un_def
   925   by (perm_simp) (rule refl)
   920   by (perm_simp) (rule refl)
   926 
   921 
   927 lemma Diff_eqvt[eqvt]:
   922 lemma Diff_eqvt [eqvt]:
   928   fixes A B :: "'a::pt set"
   923   fixes A B :: "'a::pt set"
   929   shows "p \<bullet> (A - B) = p \<bullet> A - p \<bullet> B"
   924   shows "p \<bullet> (A - B) = (p \<bullet> A) - (p \<bullet> B)"
   930   unfolding set_diff_eq
   925   unfolding set_diff_eq
   931   by (perm_simp) (rule refl)
   926   by (perm_simp) (rule refl)
   932 
   927 
   933 lemma Compl_eqvt[eqvt]:
   928 lemma Compl_eqvt [eqvt]:
   934   fixes A :: "'a::pt set"
   929   fixes A :: "'a::pt set"
   935   shows "p \<bullet> (- A) = - (p \<bullet> A)"
   930   shows "p \<bullet> (- A) = - (p \<bullet> A)"
   936   unfolding Compl_eq_Diff_UNIV
   931   unfolding Compl_eq_Diff_UNIV
   937   by (perm_simp) (rule refl)
   932   by (perm_simp) (rule refl)
   938 
   933 
   939 lemma subset_eqvt[eqvt]:
   934 lemma subset_eqvt [eqvt]:
   940   shows "p \<bullet> (S \<subseteq> T) \<longleftrightarrow> (p \<bullet> S) \<subseteq> (p \<bullet> T)"
   935   shows "p \<bullet> (S \<subseteq> T) \<longleftrightarrow> (p \<bullet> S) \<subseteq> (p \<bullet> T)"
   941   unfolding subset_eq
   936   unfolding subset_eq
   942   by (perm_simp) (rule refl)
   937   by (perm_simp) (rule refl)
   943 
   938 
   944 lemma psubset_eqvt[eqvt]:
   939 lemma psubset_eqvt [eqvt]:
   945   shows "p \<bullet> (S \<subset> T) \<longleftrightarrow> (p \<bullet> S) \<subset> (p \<bullet> T)"
   940   shows "p \<bullet> (S \<subset> T) \<longleftrightarrow> (p \<bullet> S) \<subset> (p \<bullet> T)"
   946   unfolding psubset_eq
   941   unfolding psubset_eq
   947   by (perm_simp) (rule refl)
   942   by (perm_simp) (rule refl)
   948 
   943 
   949 lemma vimage_eqvt[eqvt]:
   944 lemma vimage_eqvt [eqvt]:
   950   shows "p \<bullet> (f -` A) = (p \<bullet> f) -` (p \<bullet> A)"
   945   shows "p \<bullet> (f -` A) = (p \<bullet> f) -` (p \<bullet> A)"
   951   unfolding vimage_def
   946   unfolding vimage_def
   952   by (perm_simp) (rule refl)
   947   by (perm_simp) (rule refl)
   953 
   948 
   954 lemma Union_eqvt[eqvt]:
   949 lemma Union_eqvt [eqvt]:
   955   shows "p \<bullet> (\<Union> S) = \<Union> (p \<bullet> S)"
   950   shows "p \<bullet> (\<Union> S) = \<Union> (p \<bullet> S)"
   956   unfolding Union_eq 
   951   unfolding Union_eq 
   957   by (perm_simp) (rule refl)
   952   by (perm_simp) (rule refl)
   958 
   953 
       
   954 (* FIXME: eqvt attribute *)
   959 lemma Sigma_eqvt:
   955 lemma Sigma_eqvt:
   960   shows "(p \<bullet> (X \<times> Y)) = (p \<bullet> X) \<times> (p \<bullet> Y)"
   956   shows "(p \<bullet> (X \<times> Y)) = (p \<bullet> X) \<times> (p \<bullet> Y)"
   961 unfolding Sigma_def
   957 unfolding Sigma_def
   962 unfolding UNION_eq_Union_image
   958 unfolding UNION_eq_Union_image
   963 by (perm_simp) (rule refl)
   959 by (perm_simp) (rule refl)
   964 
   960 
   965 lemma finite_permute_iff:
   961 lemma finite_eqvt [eqvt]:
   966   shows "finite (p \<bullet> A) \<longleftrightarrow> finite A"
       
   967   unfolding permute_set_eq_vimage
       
   968   using bij_permute by (rule finite_vimage_iff)
       
   969 
       
   970 lemma finite_eqvt[eqvt]:
       
   971   shows "p \<bullet> finite A = finite (p \<bullet> A)"
   962   shows "p \<bullet> finite A = finite (p \<bullet> A)"
   972   unfolding finite_permute_iff permute_bool_def ..
   963   unfolding permute_finite permute_bool_def ..
   973 
   964 
   974 
   965 subsubsection {* Equivariance for product operations *}
   975 subsubsection {* Product Operations *}
   966 
   976 
   967 lemma fst_eqvt [eqvt]:
   977 lemma fst_eqvt[eqvt]:
       
   978   "p \<bullet> (fst x) = fst (p \<bullet> x)"
   968   "p \<bullet> (fst x) = fst (p \<bullet> x)"
   979  by (cases x) simp
   969  by (cases x) simp
   980 
   970 
   981 lemma snd_eqvt[eqvt]:
   971 lemma snd_eqvt [eqvt]:
   982   "p \<bullet> (snd x) = snd (p \<bullet> x)"
   972   "p \<bullet> (snd x) = snd (p \<bullet> x)"
   983  by (cases x) simp
   973  by (cases x) simp
   984 
   974 
   985 lemma split_eqvt[eqvt]: 
   975 lemma split_eqvt [eqvt]: 
   986   shows "p \<bullet> (split P x) = split (p \<bullet> P) (p \<bullet> x)"
   976   shows "p \<bullet> (split P x) = split (p \<bullet> P) (p \<bullet> x)"
   987   unfolding split_def
   977   unfolding split_def
   988   by (perm_simp) (rule refl)
   978   by (perm_simp) (rule refl)
   989 
   979 
   990 
   980 
   991 
   981 subsubsection {* Equivariance for list operations *}
   992 
   982 
   993 subsection {* Supp, Freshness and Supports *}
   983 lemma append_eqvt [eqvt]:
       
   984   shows "p \<bullet> (xs @ ys) = (p \<bullet> xs) @ (p \<bullet> ys)"
       
   985   by (induct xs) auto
       
   986 
       
   987 lemma rev_eqvt [eqvt]:
       
   988   shows "p \<bullet> (rev xs) = rev (p \<bullet> xs)"
       
   989   by (induct xs) (simp_all add: append_eqvt)
       
   990 
       
   991 lemma map_eqvt [eqvt]: 
       
   992   shows "p \<bullet> (map f xs) = map (p \<bullet> f) (p \<bullet> xs)"
       
   993   by (induct xs) (simp_all, simp only: permute_fun_app_eq)
       
   994 
       
   995 lemma removeAll_eqvt [eqvt]:
       
   996   shows "p \<bullet> (removeAll x xs) = removeAll (p \<bullet> x) (p \<bullet> xs)"
       
   997   by (induct xs) (auto)
       
   998 
       
   999 lemma filter_eqvt [eqvt]:
       
  1000   shows "p \<bullet> (filter f xs) = filter (p \<bullet> f) (p \<bullet> xs)"
       
  1001 apply(induct xs)
       
  1002 apply(simp)
       
  1003 apply(simp only: filter.simps permute_list.simps if_eqvt)
       
  1004 apply(simp only: permute_fun_app_eq)
       
  1005 done
       
  1006 
       
  1007 lemma distinct_eqvt [eqvt]:
       
  1008   shows "p \<bullet> (distinct xs) = distinct (p \<bullet> xs)"
       
  1009 apply(induct xs)
       
  1010 apply(simp add: permute_bool_def)
       
  1011 apply(simp add: conj_eqvt Not_eqvt mem_eqvt set_eqvt)
       
  1012 done
       
  1013 
       
  1014 lemma length_eqvt [eqvt]:
       
  1015   shows "p \<bullet> (length xs) = length (p \<bullet> xs)"
       
  1016 by (induct xs) (simp_all add: permute_pure)
       
  1017 
       
  1018 
       
  1019 subsubsection {* Equivariance for @{typ "'a fset"} *}
       
  1020 
       
  1021 lemma in_fset_eqvt [eqvt]:
       
  1022   shows "(p \<bullet> (x |\<in>| S)) = ((p \<bullet> x) |\<in>| (p \<bullet> S))"
       
  1023 unfolding in_fset
       
  1024 by (perm_simp) (simp)
       
  1025 
       
  1026 lemma union_fset_eqvt [eqvt]:
       
  1027   shows "(p \<bullet> (S |\<union>| T)) = ((p \<bullet> S) |\<union>| (p \<bullet> T))"
       
  1028 by (induct S) (simp_all)
       
  1029 
       
  1030 lemma map_fset_eqvt [eqvt]: 
       
  1031   shows "p \<bullet> (map_fset f S) = map_fset (p \<bullet> f) (p \<bullet> S)"
       
  1032   by (lifting map_eqvt)
       
  1033 
       
  1034 
       
  1035 section {* Supp, Freshness and Supports *}
   994 
  1036 
   995 context pt
  1037 context pt
   996 begin
  1038 begin
   997 
  1039 
   998 definition
  1040 definition
  1094   then have "p \<bullet> - p \<bullet> a \<sharp> p \<bullet> x" by (simp only: fresh_permute_iff)
  1136   then have "p \<bullet> - p \<bullet> a \<sharp> p \<bullet> x" by (simp only: fresh_permute_iff)
  1095   then show "a \<sharp> p \<bullet> x" by simp
  1137   then show "a \<sharp> p \<bullet> x" by simp
  1096 qed
  1138 qed
  1097 
  1139 
  1098 
  1140 
  1099 subsection {* supports *}
  1141 section {* supports *}
  1100 
  1142 
  1101 definition
  1143 definition
  1102   supports :: "atom set \<Rightarrow> 'a::pt \<Rightarrow> bool" (infixl "supports" 80)
  1144   supports :: "atom set \<Rightarrow> 'a::pt \<Rightarrow> bool" (infixl "supports" 80)
  1103 where  
  1145 where  
  1104   "S supports x \<equiv> \<forall>a b. (a \<notin> S \<and> b \<notin> S \<longrightarrow> (a \<rightleftharpoons> b) \<bullet> x = x)"
  1146   "S supports x \<equiv> \<forall>a b. (a \<notin> S \<and> b \<notin> S \<longrightarrow> (a \<rightleftharpoons> b) \<bullet> x = x)"
  1196 
  1238 
  1197 definition 
  1239 definition 
  1198   "supp_rel R x = {a. infinite {b. \<not>(R ((a \<rightleftharpoons> b) \<bullet> x) x)}}"
  1240   "supp_rel R x = {a. infinite {b. \<not>(R ((a \<rightleftharpoons> b) \<bullet> x) x)}}"
  1199 
  1241 
  1200 
  1242 
       
  1243 
  1201 section {* Finitely-supported types *}
  1244 section {* Finitely-supported types *}
  1202 
  1245 
  1203 class fs = pt +
  1246 class fs = pt +
  1204   assumes finite_supp: "finite (supp x)"
  1247   assumes finite_supp: "finite (supp x)"
  1205 
  1248 
  1206 lemma pure_supp: 
  1249 lemma pure_supp: 
  1207   shows "supp (x::'a::pure) = {}"
  1250   fixes x::"'a::pure"
       
  1251   shows "supp x = {}"
  1208   unfolding supp_def by (simp add: permute_pure)
  1252   unfolding supp_def by (simp add: permute_pure)
  1209 
  1253 
  1210 lemma pure_fresh:
  1254 lemma pure_fresh:
  1211   fixes x::"'a::pure"
  1255   fixes x::"'a::pure"
  1212   shows "a \<sharp> x"
  1256   shows "a \<sharp> x"
  1303 lemma supp_minus_perm:
  1347 lemma supp_minus_perm:
  1304   fixes p::perm
  1348   fixes p::perm
  1305   shows "supp (- p) = supp p"
  1349   shows "supp (- p) = supp p"
  1306   unfolding supp_conv_fresh
  1350   unfolding supp_conv_fresh
  1307   by (simp add: fresh_minus_perm)
  1351   by (simp add: fresh_minus_perm)
  1308 
       
  1309 instance perm :: fs
       
  1310 by default (simp add: supp_perm finite_perm_lemma)
       
  1311 
  1352 
  1312 lemma plus_perm_eq:
  1353 lemma plus_perm_eq:
  1313   fixes p q::"perm"
  1354   fixes p q::"perm"
  1314   assumes asm: "supp p \<inter> supp q = {}"
  1355   assumes asm: "supp p \<inter> supp q = {}"
  1315   shows "p + q  = q + p"
  1356   shows "p + q  = q + p"
  1365     by blast
  1406     by blast
  1366   then show "supp (p + q) = supp p \<union> supp q" using supp_plus_perm
  1407   then show "supp (p + q) = supp p \<union> supp q" using supp_plus_perm
  1367     by blast
  1408     by blast
  1368 qed
  1409 qed
  1369 
  1410 
       
  1411 instance perm :: fs
       
  1412 by default (simp add: supp_perm finite_perm_lemma)
       
  1413 
       
  1414 
  1370 
  1415 
  1371 section {* Finite Support instances for other types *}
  1416 section {* Finite Support instances for other types *}
  1372 
  1417 
  1373 
  1418 
  1374 subsection {* Type @{typ "'a \<times> 'b"} is finitely-supported. *}
  1419 subsection {* Type @{typ "'a \<times> 'b"} is finitely-supported. *}
  1470 
  1515 
  1471 lemma fresh_append:
  1516 lemma fresh_append:
  1472   shows "a \<sharp> (xs @ ys) \<longleftrightarrow> a \<sharp> xs \<and> a \<sharp> ys"
  1517   shows "a \<sharp> (xs @ ys) \<longleftrightarrow> a \<sharp> xs \<and> a \<sharp> ys"
  1473   by (induct xs) (simp_all add: fresh_Nil fresh_Cons)
  1518   by (induct xs) (simp_all add: fresh_Nil fresh_Cons)
  1474 
  1519 
  1475 
       
  1476 subsubsection {* List Operations *}
       
  1477 
       
  1478 lemma append_eqvt[eqvt]:
       
  1479   shows "p \<bullet> (xs @ ys) = (p \<bullet> xs) @ (p \<bullet> ys)"
       
  1480   by (induct xs) auto
       
  1481 
       
  1482 lemma rev_eqvt[eqvt]:
       
  1483   shows "p \<bullet> (rev xs) = rev (p \<bullet> xs)"
       
  1484   by (induct xs) (simp_all add: append_eqvt)
       
  1485 
       
  1486 lemma supp_rev:
  1520 lemma supp_rev:
  1487   shows "supp (rev xs) = supp xs"
  1521   shows "supp (rev xs) = supp xs"
  1488   by (induct xs) (auto simp add: supp_append supp_Cons supp_Nil)
  1522   by (induct xs) (auto simp add: supp_append supp_Cons supp_Nil)
  1489 
  1523 
  1490 lemma fresh_rev:
  1524 lemma fresh_rev:
  1491   shows "a \<sharp> rev xs \<longleftrightarrow> a \<sharp> xs"
  1525   shows "a \<sharp> rev xs \<longleftrightarrow> a \<sharp> xs"
  1492   by (induct xs) (auto simp add: fresh_append fresh_Cons fresh_Nil)
  1526   by (induct xs) (auto simp add: fresh_append fresh_Cons fresh_Nil)
  1493 
       
  1494 lemma map_eqvt[eqvt]: 
       
  1495   shows "p \<bullet> (map f xs) = map (p \<bullet> f) (p \<bullet> xs)"
       
  1496   by (induct xs) (simp_all, simp only: permute_fun_app_eq)
       
  1497 
       
  1498 lemma removeAll_eqvt[eqvt]:
       
  1499   shows "p \<bullet> (removeAll x xs) = removeAll (p \<bullet> x) (p \<bullet> xs)"
       
  1500   by (induct xs) (auto)
       
  1501 
  1527 
  1502 lemma supp_removeAll:
  1528 lemma supp_removeAll:
  1503   fixes x::"atom"
  1529   fixes x::"atom"
  1504   shows "supp (removeAll x xs) = supp xs - {x}"
  1530   shows "supp (removeAll x xs) = supp xs - {x}"
  1505   by (induct xs)
  1531   by (induct xs)
  1506      (auto simp add: supp_Nil supp_Cons supp_atom)
  1532      (auto simp add: supp_Nil supp_Cons supp_atom)
  1507 
  1533 
  1508 lemma filter_eqvt[eqvt]:
  1534 lemma supp_of_atom_list:
  1509   shows "p \<bullet> (filter f xs) = filter (p \<bullet> f) (p \<bullet> xs)"
  1535   fixes as::"atom list"
  1510 apply(induct xs)
  1536   shows "supp as = set as"
  1511 apply(simp)
  1537 by (induct as)
  1512 apply(simp only: filter.simps permute_list.simps if_eqvt)
  1538    (simp_all add: supp_Nil supp_Cons supp_atom)
  1513 apply(simp only: permute_fun_app_eq)
       
  1514 done
       
  1515 
       
  1516 lemma distinct_eqvt[eqvt]:
       
  1517   shows "p \<bullet> (distinct xs) = distinct (p \<bullet> xs)"
       
  1518 apply(induct xs)
       
  1519 apply(simp add: permute_bool_def)
       
  1520 apply(simp add: conj_eqvt Not_eqvt mem_eqvt set_eqvt)
       
  1521 done
       
  1522 
       
  1523 lemma length_eqvt[eqvt]:
       
  1524   shows "p \<bullet> (length xs) = length (p \<bullet> xs)"
       
  1525 by (induct xs) (simp_all add: permute_pure)
       
  1526 
       
  1527 
  1539 
  1528 instance list :: (fs) fs
  1540 instance list :: (fs) fs
  1529 apply default
  1541 apply default
  1530 apply (induct_tac x)
  1542 apply (induct_tac x)
  1531 apply (simp_all add: supp_Nil supp_Cons finite_supp)
  1543 apply (simp_all add: supp_Nil supp_Cons finite_supp)
  1532 done
  1544 done
  1533 
       
  1534 lemma supp_of_atom_list:
       
  1535   fixes as::"atom list"
       
  1536   shows "supp as = set as"
       
  1537 by (induct as)
       
  1538    (simp_all add: supp_Nil supp_Cons supp_atom)
       
  1539 
  1545 
  1540 
  1546 
  1541 section {* Support and Freshness for Applications *}
  1547 section {* Support and Freshness for Applications *}
  1542 
  1548 
  1543 lemma fresh_conv_MOST: 
  1549 lemma fresh_conv_MOST: 
  1558   using fresh_fun_app
  1564   using fresh_fun_app
  1559   unfolding fresh_def
  1565   unfolding fresh_def
  1560   by auto
  1566   by auto
  1561 
  1567 
  1562 
  1568 
  1563 subsection {* Equivariance *}
  1569 subsection {* Equivariance Predicate @{text eqvt} and @{text eqvt_at}*}
  1564 
  1570 
  1565 definition
  1571 definition
  1566   "eqvt f \<equiv> \<forall>p. p \<bullet> f = f"
  1572   "eqvt f \<equiv> \<forall>p. p \<bullet> f = f"
       
  1573 
       
  1574 
       
  1575 text {* equivariance of a function at a given argument *}
       
  1576 
       
  1577 definition
       
  1578  "eqvt_at f x \<equiv> \<forall>p. p \<bullet> (f x) = f (p \<bullet> x)"
       
  1579 
  1567 
  1580 
  1568 lemma eqvtI:
  1581 lemma eqvtI:
  1569   shows "(\<And>p. p \<bullet> f \<equiv> f) \<Longrightarrow> eqvt f"
  1582   shows "(\<And>p. p \<bullet> f \<equiv> f) \<Longrightarrow> eqvt f"
  1570 unfolding eqvt_def
  1583 unfolding eqvt_def
  1571 by simp
  1584 by simp
  1589 qed
  1602 qed
  1590 
  1603 
  1591 lemma supp_fun_app_eqvt:
  1604 lemma supp_fun_app_eqvt:
  1592   assumes a: "eqvt f"
  1605   assumes a: "eqvt f"
  1593   shows "supp (f x) \<subseteq> supp x"
  1606   shows "supp (f x) \<subseteq> supp x"
  1594 proof -
  1607   using fresh_fun_eqvt_app[OF a]
  1595   from a have "supp f = {}" by (simp add: supp_fun_eqvt)
  1608   unfolding fresh_def
  1596   then show "supp (f x) \<subseteq> supp x" using supp_fun_app by blast
  1609   by auto
  1597 qed
       
  1598 
       
  1599 
       
  1600 
       
  1601 text {* equivariance of a function at a given argument *}
       
  1602 
       
  1603 definition
       
  1604  "eqvt_at f x \<equiv> \<forall>p. p \<bullet> (f x) = f (p \<bullet> x)"
       
  1605 
  1610 
  1606 lemma supp_eqvt_at:
  1611 lemma supp_eqvt_at:
  1607   assumes asm: "eqvt_at f x"
  1612   assumes asm: "eqvt_at f x"
  1608   and     fin: "finite (supp x)"
  1613   and     fin: "finite (supp x)"
  1609   shows "supp (f x) \<subseteq> supp x"
  1614   shows "supp (f x) \<subseteq> supp x"
  1696   assumes ex1: "\<exists>!y. G x y"
  1701   assumes ex1: "\<exists>!y. G x y"
  1697   shows "eqvt_at f x"
  1702   shows "eqvt_at f x"
  1698   unfolding eqvt_at_def
  1703   unfolding eqvt_at_def
  1699   using assms
  1704   using assms
  1700   by (auto intro: fundef_ex1_eqvt)
  1705   by (auto intro: fundef_ex1_eqvt)
       
  1706 
  1701 
  1707 
  1702 section {* Support of Finite Sets of Finitely Supported Elements *}
  1708 section {* Support of Finite Sets of Finitely Supported Elements *}
  1703 
  1709 
  1704 text {* support and freshness for atom sets *}
  1710 text {* support and freshness for atom sets *}
  1705 
  1711 
  1861 lemma fset_finite_supp:
  1867 lemma fset_finite_supp:
  1862   fixes S::"('a::fs) fset"
  1868   fixes S::"('a::fs) fset"
  1863   shows "finite (supp S)"
  1869   shows "finite (supp S)"
  1864   by (induct S) (simp_all add: finite_supp)
  1870   by (induct S) (simp_all add: finite_supp)
  1865 
  1871 
  1866 
       
  1867 instance fset :: (fs) fs
       
  1868   apply (default)
       
  1869   apply (rule fset_finite_supp)
       
  1870   done
       
  1871 
       
  1872 
       
  1873 lemma in_fset_eqvt[eqvt]:
       
  1874   shows "(p \<bullet> (x |\<in>| S)) = ((p \<bullet> x) |\<in>| (p \<bullet> S))"
       
  1875 unfolding in_fset
       
  1876 by (perm_simp) (simp)
       
  1877 
       
  1878 lemma union_fset_eqvt[eqvt]:
       
  1879   shows "(p \<bullet> (S |\<union>| T)) = ((p \<bullet> S) |\<union>| (p \<bullet> T))"
       
  1880 by (induct S) (simp_all)
       
  1881 
       
  1882 lemma supp_union_fset:
  1872 lemma supp_union_fset:
  1883   fixes S T::"'a::fs fset"
  1873   fixes S T::"'a::fs fset"
  1884   shows "supp (S |\<union>| T) = supp S \<union> supp T"
  1874   shows "supp (S |\<union>| T) = supp S \<union> supp T"
  1885 by (induct S) (auto)
  1875 by (induct S) (auto)
  1886 
  1876 
  1888   fixes S T::"'a::fs fset"
  1878   fixes S T::"'a::fs fset"
  1889   shows "a \<sharp> S |\<union>| T \<longleftrightarrow> a \<sharp> S \<and> a \<sharp> T"
  1879   shows "a \<sharp> S |\<union>| T \<longleftrightarrow> a \<sharp> S \<and> a \<sharp> T"
  1890 unfolding fresh_def
  1880 unfolding fresh_def
  1891 by (simp add: supp_union_fset)
  1881 by (simp add: supp_union_fset)
  1892 
  1882 
  1893 lemma map_fset_eqvt[eqvt]: 
  1883 instance fset :: (fs) fs
  1894   shows "p \<bullet> (map_fset f S) = map_fset (p \<bullet> f) (p \<bullet> S)"
  1884   apply (default)
  1895   by (lifting map_eqvt)
  1885   apply (rule fset_finite_supp)
       
  1886   done
       
  1887 
  1896 
  1888 
  1897 section {* Freshness and Fresh-Star *}
  1889 section {* Freshness and Fresh-Star *}
  1898 
  1890 
  1899 lemma fresh_Unit_elim: 
  1891 lemma fresh_Unit_elim: 
  1900   shows "(a \<sharp> () \<Longrightarrow> PROP C) \<equiv> PROP C"
  1892   shows "(a \<sharp> () \<Longrightarrow> PROP C) \<equiv> PROP C"
  2037 
  2029 
  2038 lemma fresh_star_eqvt [eqvt]:
  2030 lemma fresh_star_eqvt [eqvt]:
  2039   shows "p \<bullet> (as \<sharp>* x) \<longleftrightarrow> (p \<bullet> as) \<sharp>* (p \<bullet> x)"
  2031   shows "p \<bullet> (as \<sharp>* x) \<longleftrightarrow> (p \<bullet> as) \<sharp>* (p \<bullet> x)"
  2040 unfolding fresh_star_def
  2032 unfolding fresh_star_def
  2041 by (perm_simp) (rule refl)
  2033 by (perm_simp) (rule refl)
       
  2034 
  2042 
  2035 
  2043 
  2036 
  2044 section {* Induction principle for permutations *}
  2037 section {* Induction principle for permutations *}
  2045 
  2038 
  2046 
  2039