--- a/Quot/Examples/Terms.thy Tue Jan 26 16:30:51 2010 +0100
+++ b/Quot/Examples/Terms.thy Tue Jan 26 20:07:50 2010 +0100
@@ -62,7 +62,9 @@
where
a1: "a = b \<Longrightarrow> (Vr1 a) \<approx>1 (Vr1 b)"
| a2: "\<lbrakk>t1 \<approx>1 t2; s1 \<approx>1 s2\<rbrakk> \<Longrightarrow> Ap1 t1 s1 \<approx>1 Ap1 t2 s2"
-| a3: "\<exists>pi::name prm. (fv_trm1 t - {a} = fv_trm1 s - {b} \<and> (fv_trm1 t - {a})\<sharp>* pi \<and> (pi \<bullet> t) \<approx>1 s \<and> (pi \<bullet> a) = b)
+| a3: "\<exists>pi::name prm. (fv_trm1 t - {a} = fv_trm1 s - {b} \<and>
+ (fv_trm1 t - {a})\<sharp>* pi \<and>
+ (pi \<bullet> t) \<approx>1 s \<and> (pi \<bullet> a) = b)
\<Longrightarrow> Lm1 a t \<approx>1 Lm1 b s"
| a4: "\<exists>pi::name prm.(
t1 \<approx>1 t2 \<and>
@@ -125,7 +127,10 @@
where
a1: "a = b \<Longrightarrow> (Vr2 a) \<approx>2 (Vr2 b)"
| a2: "\<lbrakk>t1 \<approx>2 t2; s1 \<approx>2 s2\<rbrakk> \<Longrightarrow> Ap2 t1 s1 \<approx>2 Ap2 t2 s2"
-| a3: "\<exists>pi::name prm. (fv_trm2 t - {a} = fv_trm2 s - {b} \<and> (fv_trm2 t - {a})\<sharp>* pi \<and> (pi \<bullet> t) \<approx>2 s \<and> (pi \<bullet> a) = b)
+| a3: "\<exists>pi::name prm. (fv_trm2 t - {a} = fv_trm2 s - {b} \<and>
+ (fv_trm2 t - {a})\<sharp>* pi \<and>
+ (pi \<bullet> t) \<approx>2 s \<and>
+ (pi \<bullet> a) = b)
\<Longrightarrow> Lm2 a t \<approx>2 Lm2 b s"
| a4: "\<exists>pi::name prm. (
fv_trm2 t1 - fv_assign b1 = fv_trm2 t2 - fv_assign b2 \<and>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Quot/Nominal/LamEx.thy Tue Jan 26 20:07:50 2010 +0100
@@ -0,0 +1,540 @@
+theory LamEx
+imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "../QuotMain"
+begin
+
+
+(* lemmas that should be in Nominal \<dots>\<dots>must be cleaned *)
+lemma in_permute_iff:
+ shows "(p \<bullet> x) \<in> (p \<bullet> X) \<longleftrightarrow> x \<in> X"
+apply(unfold mem_def permute_fun_def)[1]
+apply(simp add: permute_bool_def)
+done
+
+lemma fresh_star_permute_iff:
+ shows "(p \<bullet> a) \<sharp>* (p \<bullet> x) \<longleftrightarrow> a \<sharp>* x"
+apply(simp add: fresh_star_def)
+apply(auto)
+apply(drule_tac x="p \<bullet> xa" in bspec)
+apply(unfold mem_def permute_fun_def)[1]
+apply(simp add: eqvts)
+apply(simp add: fresh_permute_iff)
+apply(rule_tac ?p1="- p" in fresh_permute_iff[THEN iffD1])
+apply(simp)
+apply(drule_tac x="- p \<bullet> xa" in bspec)
+apply(rule_tac ?p1="p" in in_permute_iff[THEN iffD1])
+apply(simp)
+apply(simp)
+done
+
+lemma fresh_minus_perm:
+ fixes p::perm
+ shows "a \<sharp> (- p) \<longleftrightarrow> a \<sharp> p"
+ apply(simp add: fresh_def)
+ apply(simp only: supp_minus_perm)
+ done
+
+lemma fresh_plus:
+ fixes p q::perm
+ shows "\<lbrakk>a \<sharp> p; a \<sharp> q\<rbrakk> \<Longrightarrow> a \<sharp> (p + q)"
+unfolding fresh_def
+using supp_plus_perm
+apply(auto)
+done
+
+lemma fresh_star_plus:
+ fixes p q::perm
+ shows "\<lbrakk>a \<sharp>* p; a \<sharp>* q\<rbrakk> \<Longrightarrow> a \<sharp>* (p + q)"
+unfolding fresh_star_def
+by (simp add: fresh_plus)
+
+
+
+atom_decl name
+
+datatype rlam =
+ rVar "name"
+| rApp "rlam" "rlam"
+| rLam "name" "rlam"
+
+fun
+ rfv :: "rlam \<Rightarrow> atom set"
+where
+ rfv_var: "rfv (rVar a) = {atom a}"
+| rfv_app: "rfv (rApp t1 t2) = (rfv t1) \<union> (rfv t2)"
+| rfv_lam: "rfv (rLam a t) = (rfv t) - {atom a}"
+
+instantiation rlam :: pt
+begin
+
+primrec
+ permute_rlam
+where
+ "permute_rlam pi (rVar a) = rVar (pi \<bullet> a)"
+| "permute_rlam pi (rApp t1 t2) = rApp (permute_rlam pi t1) (permute_rlam pi t2)"
+| "permute_rlam pi (rLam a t) = rLam (pi \<bullet> a) (permute_rlam pi t)"
+
+instance
+apply default
+apply(induct_tac [!] x)
+apply(simp_all)
+done
+
+end
+
+instantiation rlam :: fs
+begin
+
+lemma neg_conj:
+ "\<not>(P \<and> Q) \<longleftrightarrow> (\<not>P) \<or> (\<not>Q)"
+ by simp
+
+lemma infinite_Un:
+ "infinite (S \<union> T) \<longleftrightarrow> infinite S \<or> infinite T"
+ by simp
+
+instance
+apply default
+apply(induct_tac x)
+(* var case *)
+apply(simp add: supp_def)
+apply(fold supp_def)[1]
+apply(simp add: supp_at_base)
+(* app case *)
+apply(simp only: supp_def)
+apply(simp only: permute_rlam.simps)
+apply(simp only: rlam.inject)
+apply(simp only: neg_conj)
+apply(simp only: Collect_disj_eq)
+apply(simp only: infinite_Un)
+apply(simp only: Collect_disj_eq)
+apply(simp)
+(* lam case *)
+apply(simp only: supp_def)
+apply(simp only: permute_rlam.simps)
+apply(simp only: rlam.inject)
+apply(simp only: neg_conj)
+apply(simp only: Collect_disj_eq)
+apply(simp only: infinite_Un)
+apply(simp only: Collect_disj_eq)
+apply(simp)
+apply(fold supp_def)[1]
+apply(simp add: supp_at_base)
+done
+
+end
+
+
+(* for the eqvt proof of the alpha-equivalence *)
+declare permute_rlam.simps[eqvt]
+
+lemma rfv_eqvt[eqvt]:
+ shows "(pi\<bullet>rfv t) = rfv (pi\<bullet>t)"
+apply(induct t)
+apply(simp_all)
+apply(simp add: permute_set_eq atom_eqvt)
+apply(simp add: union_eqvt)
+apply(simp add: Diff_eqvt)
+apply(simp add: permute_set_eq atom_eqvt)
+done
+
+inductive
+ alpha :: "rlam \<Rightarrow> rlam \<Rightarrow> bool" ("_ \<approx> _" [100, 100] 100)
+where
+ a1: "a = b \<Longrightarrow> (rVar a) \<approx> (rVar b)"
+| a2: "\<lbrakk>t1 \<approx> t2; s1 \<approx> s2\<rbrakk> \<Longrightarrow> rApp t1 s1 \<approx> rApp t2 s2"
+| a3: "\<exists>pi. (rfv t - {atom a} = rfv s - {atom b} \<and> (rfv t - {atom a})\<sharp>* pi \<and> (pi \<bullet> t) \<approx> s \<and> (pi \<bullet> a) = b)
+ \<Longrightarrow> rLam a t \<approx> rLam b s"
+
+text {* should be automatic with new version of eqvt-machinery *}
+lemma alpha_eqvt:
+ shows "t \<approx> s \<Longrightarrow> (pi \<bullet> t) \<approx> (pi \<bullet> s)"
+apply(induct rule: alpha.induct)
+apply(simp add: a1)
+apply(simp add: a2)
+apply(simp)
+apply(rule a3)
+apply(erule conjE)
+apply(erule exE)
+apply(erule conjE)
+apply(rule_tac x="pi \<bullet> pia" in exI)
+apply(rule conjI)
+apply(rule_tac ?p1="- pi" in permute_eq_iff[THEN iffD1])
+apply(simp add: eqvts atom_eqvt)
+apply(rule conjI)
+apply(rule_tac ?p1="- pi" in fresh_star_permute_iff[THEN iffD1])
+apply(simp add: eqvts atom_eqvt)
+apply(rule conjI)
+apply(subst permute_eqvt[symmetric])
+apply(simp)
+apply(subst permute_eqvt[symmetric])
+apply(simp)
+done
+
+lemma alpha_refl:
+ shows "t \<approx> t"
+apply(induct t rule: rlam.induct)
+apply(simp add: a1)
+apply(simp add: a2)
+apply(rule a3)
+apply(rule_tac x="0" in exI)
+apply(simp_all add: fresh_star_def fresh_zero_perm)
+done
+
+lemma alpha_sym:
+ shows "t \<approx> s \<Longrightarrow> s \<approx> t"
+apply(induct rule: alpha.induct)
+apply(simp add: a1)
+apply(simp add: a2)
+apply(rule a3)
+apply(erule exE)
+apply(rule_tac x="- pi" in exI)
+apply(simp)
+apply(simp add: fresh_star_def fresh_minus_perm)
+apply(rule conjI)
+apply(erule conjE)+
+apply(rotate_tac 3)
+apply(drule_tac pi="- pi" in alpha_eqvt)
+apply(simp)
+apply(clarify)
+apply(simp)
+done
+
+lemma alpha_trans:
+ shows "t1 \<approx> t2 \<Longrightarrow> t2 \<approx> t3 \<Longrightarrow> t1 \<approx> t3"
+apply(induct arbitrary: t3 rule: alpha.induct)
+apply(erule alpha.cases)
+apply(simp_all)
+apply(simp add: a1)
+apply(rotate_tac 4)
+apply(erule alpha.cases)
+apply(simp_all)
+apply(simp add: a2)
+apply(rotate_tac 1)
+apply(erule alpha.cases)
+apply(simp_all)
+apply(erule conjE)+
+apply(erule exE)+
+apply(erule conjE)+
+apply(rule a3)
+apply(rule_tac x="pia + pi" in exI)
+apply(simp add: fresh_star_plus)
+apply(drule_tac x="- pia \<bullet> sa" in spec)
+apply(drule mp)
+apply(rotate_tac 8)
+apply(drule_tac pi="- pia" in alpha_eqvt)
+apply(simp)
+apply(rotate_tac 11)
+apply(drule_tac pi="pia" in alpha_eqvt)
+apply(simp)
+done
+
+lemma alpha_equivp:
+ shows "equivp alpha"
+apply(rule equivpI)
+unfolding reflp_def symp_def transp_def
+apply(auto intro: alpha_refl alpha_sym alpha_trans)
+done
+
+lemma alpha_rfv:
+ shows "t \<approx> s \<Longrightarrow> rfv t = rfv s"
+apply(induct rule: alpha.induct)
+apply(simp)
+apply(simp)
+apply(simp)
+done
+
+(* PROBABLY NOT TRUE !!! needed for lifting
+lemma alpha_fresh:
+ assumes a: "t \<approx> s"
+ shows "a\<sharp>t \<Longrightarrow> a\<sharp>s"
+using a
+apply(induct)
+*)
+
+quotient_type lam = rlam / alpha
+ by (rule alpha_equivp)
+
+quotient_definition
+ "Var :: name \<Rightarrow> lam"
+as
+ "rVar"
+
+quotient_definition
+ "App :: lam \<Rightarrow> lam \<Rightarrow> lam"
+as
+ "rApp"
+
+quotient_definition
+ "Lam :: name \<Rightarrow> lam \<Rightarrow> lam"
+as
+ "rLam"
+
+quotient_definition
+ "fv :: lam \<Rightarrow> atom set"
+as
+ "rfv"
+
+lemma perm_rsp[quot_respect]:
+ "(op = ===> alpha ===> alpha) permute permute"
+ apply(auto)
+ apply(rule alpha_eqvt)
+ apply(simp)
+ done
+
+lemma rVar_rsp[quot_respect]:
+ "(op = ===> alpha) rVar rVar"
+ by (auto intro: a1)
+
+lemma rApp_rsp[quot_respect]:
+ "(alpha ===> alpha ===> alpha) rApp rApp"
+ by (auto intro: a2)
+
+lemma rLam_rsp[quot_respect]:
+ "(op = ===> alpha ===> alpha) rLam rLam"
+ apply(auto)
+ apply(rule a3)
+ apply(rule_tac x="0" in exI)
+ unfolding fresh_star_def
+ apply(simp add: fresh_star_def fresh_zero_perm)
+ apply(simp add: alpha_rfv)
+ done
+
+lemma rfv_rsp[quot_respect]:
+ "(alpha ===> op =) rfv rfv"
+apply(simp add: alpha_rfv)
+done
+
+
+
+(* NOT SURE see above
+lemma fresh_rsp:
+ "(op = ===> alpha ===> op =) fresh fresh"
+ apply(auto)
+*)
+
+section {* lifted theorems *}
+
+lemma lam_induct:
+ "\<lbrakk>\<And>name. P (Var name);
+ \<And>lam1 lam2. \<lbrakk>P lam1; P lam2\<rbrakk> \<Longrightarrow> P (App lam1 lam2);
+ \<And>name lam. P lam \<Longrightarrow> P (Lam name lam)\<rbrakk>
+ \<Longrightarrow> P lam"
+ apply (lifting rlam.induct)
+ done
+
+instantiation lam :: pt
+begin
+
+quotient_definition
+ "permute_lam :: perm \<Rightarrow> lam \<Rightarrow> lam"
+as
+ "permute :: perm \<Rightarrow> rlam \<Rightarrow> rlam"
+
+lemma permute_lam [simp]:
+ shows "pi \<bullet> Var a = Var (pi \<bullet> a)"
+ and "pi \<bullet> App t1 t2 = App (pi \<bullet> t1) (pi \<bullet> t2)"
+ and "pi \<bullet> Lam a t = Lam (pi \<bullet> a) (pi \<bullet> t)"
+apply(lifting permute_rlam.simps)
+done
+
+instance
+apply default
+apply(induct_tac [!] x rule: lam_induct)
+apply(simp_all)
+done
+
+end
+
+lemma fv_lam [simp]:
+ shows "fv (Var a) = {atom a}"
+ and "fv (App t1 t2) = fv t1 \<union> fv t2"
+ and "fv (Lam a t) = fv t - {atom a}"
+apply(lifting rfv_var rfv_app rfv_lam)
+done
+
+lemma a1:
+ "a = b \<Longrightarrow> Var a = Var b"
+ by (lifting a1)
+
+lemma a2:
+ "\<lbrakk>x = xa; xb = xc\<rbrakk> \<Longrightarrow> App x xb = App xa xc"
+ by (lifting a2)
+
+lemma a3:
+ "\<lbrakk>\<exists>pi. (fv t - {atom a} = fv s - {atom b} \<and> (fv t - {atom a})\<sharp>* pi \<and> (pi \<bullet> t) = s \<and> (pi \<bullet> a) = b)\<rbrakk>
+ \<Longrightarrow> Lam a t = Lam b s"
+ apply (lifting a3)
+ done
+
+lemma alpha_cases:
+ "\<lbrakk>a1 = a2; \<And>a b. \<lbrakk>a1 = Var a; a2 = Var b; a = b\<rbrakk> \<Longrightarrow> P;
+ \<And>x xa xb xc. \<lbrakk>a1 = App x xb; a2 = App xa xc; x = xa; xb = xc\<rbrakk> \<Longrightarrow> P;
+ \<And>t a s b. \<lbrakk>a1 = Lam a t; a2 = Lam b s;
+ \<exists>pi. fv t - {atom a} = fv s - {atom b} \<and> (fv t - {atom a}) \<sharp>* pi \<and> (pi \<bullet> t) = s \<and> pi \<bullet> a = b\<rbrakk>
+ \<Longrightarrow> P\<rbrakk>
+ \<Longrightarrow> P"
+ by (lifting alpha.cases)
+
+lemma alpha_induct:
+ "\<lbrakk>qx = qxa; \<And>a b. a = b \<Longrightarrow> qxb (Var a) (Var b);
+ \<And>x xa xb xc. \<lbrakk>x = xa; qxb x xa; xb = xc; qxb xb xc\<rbrakk> \<Longrightarrow> qxb (App x xb) (App xa xc);
+ \<And>t a s b.
+ \<lbrakk>\<exists>pi. fv t - {atom a} = fv s - {atom b} \<and>
+ (fv t - {atom a}) \<sharp>* pi \<and> ((pi \<bullet> t) = s \<and> qxb (pi \<bullet> t) s) \<and> pi \<bullet> a = b\<rbrakk>
+ \<Longrightarrow> qxb (Lam a t) (Lam b s)\<rbrakk>
+ \<Longrightarrow> qxb qx qxa"
+ by (lifting alpha.induct)
+
+(* should they lift automatically *)
+lemma lam_inject [simp]:
+ shows "(Var a = Var b) = (a = b)"
+ and "(App t1 t2 = App s1 s2) = (t1 = s1 \<and> t2 = s2)"
+apply(lifting rlam.inject(1) rlam.inject(2))
+apply(auto)
+apply(drule alpha.cases)
+apply(simp_all)
+apply(simp add: alpha.a1)
+apply(drule alpha.cases)
+apply(simp_all)
+apply(drule alpha.cases)
+apply(simp_all)
+apply(rule alpha.a2)
+apply(simp_all)
+done
+
+lemma rlam_distinct:
+ shows "\<not>(rVar nam \<approx> rApp rlam1' rlam2')"
+ and "\<not>(rApp rlam1' rlam2' \<approx> rVar nam)"
+ and "\<not>(rVar nam \<approx> rLam nam' rlam')"
+ and "\<not>(rLam nam' rlam' \<approx> rVar nam)"
+ and "\<not>(rApp rlam1 rlam2 \<approx> rLam nam' rlam')"
+ and "\<not>(rLam nam' rlam' \<approx> rApp rlam1 rlam2)"
+apply auto
+apply(erule alpha.cases)
+apply simp_all
+apply(erule alpha.cases)
+apply simp_all
+apply(erule alpha.cases)
+apply simp_all
+apply(erule alpha.cases)
+apply simp_all
+apply(erule alpha.cases)
+apply simp_all
+apply(erule alpha.cases)
+apply simp_all
+done
+
+lemma lam_distinct[simp]:
+ shows "Var nam \<noteq> App lam1' lam2'"
+ and "App lam1' lam2' \<noteq> Var nam"
+ and "Var nam \<noteq> Lam nam' lam'"
+ and "Lam nam' lam' \<noteq> Var nam"
+ and "App lam1 lam2 \<noteq> Lam nam' lam'"
+ and "Lam nam' lam' \<noteq> App lam1 lam2"
+apply(lifting rlam_distinct(1) rlam_distinct(2) rlam_distinct(3) rlam_distinct(4) rlam_distinct(5) rlam_distinct(6))
+done
+
+lemma var_supp1:
+ shows "(supp (Var a)) = (supp a)"
+ apply (simp add: supp_def)
+ done
+
+lemma var_supp:
+ shows "(supp (Var a)) = {a:::name}"
+ using var_supp1 by (simp add: supp_at_base)
+
+lemma app_supp:
+ shows "supp (App t1 t2) = (supp t1) \<union> (supp t2)"
+apply(simp only: permute_lam supp_def lam_inject)
+apply(simp add: Collect_imp_eq Collect_neg_eq)
+done
+
+(* needs thinking *)
+lemma lam_supp:
+ shows "supp (Lam x t) = ((supp t) - {atom x})"
+apply(simp add: supp_def)
+sorry
+
+
+instance lam :: fs
+apply(default)
+apply(induct_tac x rule: lam_induct)
+apply(simp add: var_supp)
+apply(simp add: app_supp)
+apply(simp add: lam_supp)
+done
+
+lemma fresh_lam:
+ "(atom a \<sharp> Lam b t) \<longleftrightarrow> (a = b) \<or> (a \<noteq> b \<and> atom a \<sharp> t)"
+apply(simp add: fresh_def)
+apply(simp add: lam_supp)
+apply(auto)
+done
+
+lemma lam_induct_strong:
+ fixes a::"'a::fs"
+ assumes a1: "\<And>name b. P b (Var name)"
+ and a2: "\<And>lam1 lam2 b. \<lbrakk>\<And>c. P c lam1; \<And>c. P c lam2\<rbrakk> \<Longrightarrow> P b (App lam1 lam2)"
+ and a3: "\<And>name lam b. \<lbrakk>\<And>c. P c lam; (atom name) \<sharp> b\<rbrakk> \<Longrightarrow> P b (Lam name lam)"
+ shows "P a lam"
+proof -
+ have "\<And>pi a. P a (pi \<bullet> lam)"
+ proof (induct lam rule: lam_induct)
+ case (1 name pi)
+ show "P a (pi \<bullet> Var name)"
+ apply (simp)
+ apply (rule a1)
+ done
+ next
+ case (2 lam1 lam2 pi)
+ have b1: "\<And>pi a. P a (pi \<bullet> lam1)" by fact
+ have b2: "\<And>pi a. P a (pi \<bullet> lam2)" by fact
+ show "P a (pi \<bullet> App lam1 lam2)"
+ apply (simp)
+ apply (rule a2)
+ apply (rule b1)
+ apply (rule b2)
+ done
+ next
+ case (3 name lam pi a)
+ have b: "\<And>pi a. P a (pi \<bullet> lam)" by fact
+ obtain c::name where fr: "atom c\<sharp>(a, pi\<bullet>name, pi\<bullet>lam)"
+ apply(rule obtain_atom)
+ apply(auto)
+ sorry
+ from b fr have p: "P a (Lam c (((c \<leftrightarrow> (pi \<bullet> name)) + pi)\<bullet>lam))"
+ apply -
+ apply(rule a3)
+ apply(blast)
+ apply(simp add: fresh_Pair)
+ done
+ have eq: "(atom c \<rightleftharpoons> atom (pi\<bullet>name)) \<bullet> Lam (pi \<bullet> name) (pi \<bullet> lam) = Lam (pi \<bullet> name) (pi \<bullet> lam)"
+ apply(rule swap_fresh_fresh)
+ using fr
+ apply(simp add: fresh_lam fresh_Pair)
+ apply(simp add: fresh_lam fresh_Pair)
+ done
+ show "P a (pi \<bullet> Lam name lam)"
+ apply (simp)
+ apply(subst eq[symmetric])
+ using p
+ apply(simp only: permute_lam)
+ apply(simp add: flip_def)
+ done
+ qed
+ then have "P a (0 \<bullet> lam)" by blast
+ then show "P a lam" by simp
+qed
+
+
+lemma var_fresh:
+ fixes a::"name"
+ shows "(atom a \<sharp> (Var b)) = (atom a \<sharp> b)"
+ apply(simp add: fresh_def)
+ apply(simp add: var_supp1)
+ done
+
+
+
+end
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Quot/Nominal/Nominal2_Atoms.thy Tue Jan 26 20:07:50 2010 +0100
@@ -0,0 +1,221 @@
+(* Title: Nominal2_Atoms
+ Authors: Brian Huffman, Christian Urban
+
+ Definitions for concrete atom types.
+*)
+theory Nominal2_Atoms
+imports Nominal2_Base
+uses ("atom_decl.ML")
+begin
+
+section {* Concrete atom types *}
+
+text {*
+ Class @{text at_base} allows types containing multiple sorts of atoms.
+ Class @{text at} only allows types with a single sort.
+*}
+
+class at_base = pt +
+ fixes atom :: "'a \<Rightarrow> atom"
+ assumes atom_eq_iff [simp]: "atom a = atom b \<longleftrightarrow> a = b"
+ assumes atom_eqvt: "p \<bullet> (atom a) = atom (p \<bullet> a)"
+
+class at = at_base +
+ assumes sort_of_atom_eq [simp]: "sort_of (atom a) = sort_of (atom b)"
+
+instance at < at_base ..
+
+lemma supp_at_base:
+ fixes a::"'a::at_base"
+ shows "supp a = {atom a}"
+ by (simp add: supp_atom [symmetric] supp_def atom_eqvt)
+
+lemma fresh_at:
+ shows "a \<sharp> b \<longleftrightarrow> a \<noteq> atom b"
+ unfolding fresh_def by (simp add: supp_at_base)
+
+instance at_base < fs
+proof qed (simp add: supp_at_base)
+
+
+lemma at_base_infinite [simp]:
+ shows "infinite (UNIV :: 'a::at_base set)" (is "infinite ?U")
+proof
+ obtain a :: 'a where "True" by auto
+ assume "finite ?U"
+ hence "finite (atom ` ?U)"
+ by (rule finite_imageI)
+ then obtain b where b: "b \<notin> atom ` ?U" "sort_of b = sort_of (atom a)"
+ by (rule obtain_atom)
+ from b(2) have "b = atom ((atom a \<rightleftharpoons> b) \<bullet> a)"
+ unfolding atom_eqvt [symmetric]
+ by (simp add: swap_atom)
+ hence "b \<in> atom ` ?U" by simp
+ with b(1) show "False" by simp
+qed
+
+lemma swap_at_base_simps [simp]:
+ fixes x y::"'a::at_base"
+ shows "sort_of (atom x) = sort_of (atom y) \<Longrightarrow> (atom x \<rightleftharpoons> atom y) \<bullet> x = y"
+ and "sort_of (atom x) = sort_of (atom y) \<Longrightarrow> (atom x \<rightleftharpoons> atom y) \<bullet> y = x"
+ and "atom x \<noteq> a \<Longrightarrow> atom x \<noteq> b \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> x = x"
+ unfolding atom_eq_iff [symmetric]
+ unfolding atom_eqvt [symmetric]
+ by simp_all
+
+lemma obtain_at_base:
+ assumes X: "finite X"
+ obtains a::"'a::at_base" where "atom a \<notin> X"
+proof -
+ have "inj (atom :: 'a \<Rightarrow> atom)"
+ by (simp add: inj_on_def)
+ with X have "finite (atom -` X :: 'a set)"
+ by (rule finite_vimageI)
+ with at_base_infinite have "atom -` X \<noteq> (UNIV :: 'a set)"
+ by auto
+ then obtain a :: 'a where "atom a \<notin> X"
+ by auto
+ thus ?thesis ..
+qed
+
+
+section {* A swapping operation for concrete atoms *}
+
+definition
+ flip :: "'a::at_base \<Rightarrow> 'a \<Rightarrow> perm" ("'(_ \<leftrightarrow> _')")
+where
+ "(a \<leftrightarrow> b) = (atom a \<rightleftharpoons> atom b)"
+
+lemma flip_self [simp]: "(a \<leftrightarrow> a) = 0"
+ unfolding flip_def by (rule swap_self)
+
+lemma flip_commute: "(a \<leftrightarrow> b) = (b \<leftrightarrow> a)"
+ unfolding flip_def by (rule swap_commute)
+
+lemma minus_flip [simp]: "- (a \<leftrightarrow> b) = (a \<leftrightarrow> b)"
+ unfolding flip_def by (rule minus_swap)
+
+lemma add_flip_cancel: "(a \<leftrightarrow> b) + (a \<leftrightarrow> b) = 0"
+ unfolding flip_def by (rule swap_cancel)
+
+lemma permute_flip_cancel [simp]: "(a \<leftrightarrow> b) \<bullet> (a \<leftrightarrow> b) \<bullet> x = x"
+ unfolding permute_plus [symmetric] add_flip_cancel by simp
+
+lemma permute_flip_cancel2 [simp]: "(a \<leftrightarrow> b) \<bullet> (b \<leftrightarrow> a) \<bullet> x = x"
+ by (simp add: flip_commute)
+
+lemma flip_eqvt:
+ fixes a b c::"'a::at_base"
+ shows "p \<bullet> (a \<leftrightarrow> b) = (p \<bullet> a \<leftrightarrow> p \<bullet> b)"
+ unfolding flip_def
+ by (simp add: swap_eqvt atom_eqvt)
+
+lemma flip_at_base_simps [simp]:
+ shows "sort_of (atom a) = sort_of (atom b) \<Longrightarrow> (a \<leftrightarrow> b) \<bullet> a = b"
+ and "sort_of (atom a) = sort_of (atom b) \<Longrightarrow> (a \<leftrightarrow> b) \<bullet> b = a"
+ and "\<lbrakk>a \<noteq> c; b \<noteq> c\<rbrakk> \<Longrightarrow> (a \<leftrightarrow> b) \<bullet> c = c"
+ and "sort_of (atom a) \<noteq> sort_of (atom b) \<Longrightarrow> (a \<leftrightarrow> b) \<bullet> x = x"
+ unfolding flip_def
+ unfolding atom_eq_iff [symmetric]
+ unfolding atom_eqvt [symmetric]
+ by simp_all
+
+text {* the following two lemmas do not hold for at_base,
+ only for single sort atoms from at *}
+
+lemma permute_flip_at:
+ fixes a b c::"'a::at"
+ shows "(a \<leftrightarrow> b) \<bullet> c = (if c = a then b else if c = b then a else c)"
+ unfolding flip_def
+ apply (rule atom_eq_iff [THEN iffD1])
+ apply (subst atom_eqvt [symmetric])
+ apply (simp add: swap_atom)
+ done
+
+lemma flip_at_simps [simp]:
+ fixes a b::"'a::at"
+ shows "(a \<leftrightarrow> b) \<bullet> a = b"
+ and "(a \<leftrightarrow> b) \<bullet> b = a"
+ unfolding permute_flip_at by simp_all
+
+
+subsection {* Syntax for coercing at-elements to the atom-type *}
+
+syntax
+ "_atom_constrain" :: "logic \<Rightarrow> type \<Rightarrow> logic" ("_:::_" [4, 0] 3)
+
+translations
+ "_atom_constrain a t" => "atom (_constrain a t)"
+
+
+subsection {* A lemma for proving instances of class @{text at}. *}
+
+setup {* Sign.add_const_constraint (@{const_name "permute"}, NONE) *}
+setup {* Sign.add_const_constraint (@{const_name "atom"}, NONE) *}
+
+text {*
+ New atom types are defined as subtypes of @{typ atom}.
+*}
+
+lemma exists_eq_sort:
+ shows "\<exists>a. a \<in> {a. sort_of a = s}"
+ by (rule_tac x="Atom s 0" in exI, simp)
+
+lemma at_base_class:
+ fixes s :: atom_sort
+ fixes Rep :: "'a \<Rightarrow> atom" and Abs :: "atom \<Rightarrow> 'a"
+ assumes type: "type_definition Rep Abs {a. P (sort_of a)}"
+ assumes atom_def: "\<And>a. atom a = Rep a"
+ assumes permute_def: "\<And>p a. p \<bullet> a = Abs (p \<bullet> Rep a)"
+ shows "OFCLASS('a, at_base_class)"
+proof
+ interpret type_definition Rep Abs "{a. P (sort_of a)}" by (rule type)
+ have sort_of_Rep: "\<And>a. P (sort_of (Rep a))" using Rep by simp
+ fix a b :: 'a and p p1 p2 :: perm
+ show "0 \<bullet> a = a"
+ unfolding permute_def by (simp add: Rep_inverse)
+ show "(p1 + p2) \<bullet> a = p1 \<bullet> p2 \<bullet> a"
+ unfolding permute_def by (simp add: Abs_inverse sort_of_Rep)
+ show "atom a = atom b \<longleftrightarrow> a = b"
+ unfolding atom_def by (simp add: Rep_inject)
+ show "p \<bullet> atom a = atom (p \<bullet> a)"
+ unfolding permute_def atom_def by (simp add: Abs_inverse sort_of_Rep)
+qed
+
+lemma at_class:
+ fixes s :: atom_sort
+ fixes Rep :: "'a \<Rightarrow> atom" and Abs :: "atom \<Rightarrow> 'a"
+ assumes type: "type_definition Rep Abs {a. sort_of a = s}"
+ assumes atom_def: "\<And>a. atom a = Rep a"
+ assumes permute_def: "\<And>p a. p \<bullet> a = Abs (p \<bullet> Rep a)"
+ shows "OFCLASS('a, at_class)"
+proof
+ interpret type_definition Rep Abs "{a. sort_of a = s}" by (rule type)
+ have sort_of_Rep: "\<And>a. sort_of (Rep a) = s" using Rep by simp
+ fix a b :: 'a and p p1 p2 :: perm
+ show "0 \<bullet> a = a"
+ unfolding permute_def by (simp add: Rep_inverse)
+ show "(p1 + p2) \<bullet> a = p1 \<bullet> p2 \<bullet> a"
+ unfolding permute_def by (simp add: Abs_inverse sort_of_Rep)
+ show "sort_of (atom a) = sort_of (atom b)"
+ unfolding atom_def by (simp add: sort_of_Rep)
+ show "atom a = atom b \<longleftrightarrow> a = b"
+ unfolding atom_def by (simp add: Rep_inject)
+ show "p \<bullet> atom a = atom (p \<bullet> a)"
+ unfolding permute_def atom_def by (simp add: Abs_inverse sort_of_Rep)
+qed
+
+setup {* Sign.add_const_constraint
+ (@{const_name "permute"}, SOME @{typ "perm \<Rightarrow> 'a::pt \<Rightarrow> 'a"}) *}
+setup {* Sign.add_const_constraint
+ (@{const_name "atom"}, SOME @{typ "'a::at_base \<Rightarrow> atom"}) *}
+
+
+section {* Automation for creating concrete atom types *}
+
+text {* at the moment only single-sort concrete atoms are supported *}
+
+use "atom_decl.ML"
+
+
+end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Quot/Nominal/Nominal2_Base.thy Tue Jan 26 20:07:50 2010 +0100
@@ -0,0 +1,959 @@
+(* Title: Nominal2_Base
+ Authors: Brian Huffman, Christian Urban
+
+ Basic definitions and lemma infrastructure for
+ Nominal Isabelle.
+*)
+theory Nominal2_Base
+imports Main Infinite_Set
+begin
+
+section {* Atoms and Sorts *}
+
+text {* A simple implementation for atom_sorts is strings. *}
+(* types atom_sort = string *)
+
+text {* To deal with Church-like binding we use trees of
+ strings as sorts. *}
+
+datatype atom_sort = Sort "string" "atom_sort list"
+
+datatype atom = Atom atom_sort nat
+
+
+text {* Basic projection function. *}
+
+primrec
+ sort_of :: "atom \<Rightarrow> atom_sort"
+where
+ "sort_of (Atom s i) = s"
+
+
+text {* There are infinitely many atoms of each sort. *}
+lemma INFM_sort_of_eq:
+ shows "INFM a. sort_of a = s"
+proof -
+ have "INFM i. sort_of (Atom s i) = s" by simp
+ moreover have "inj (Atom s)" by (simp add: inj_on_def)
+ ultimately show "INFM a. sort_of a = s" by (rule INFM_inj)
+qed
+
+lemma infinite_sort_of_eq:
+ shows "infinite {a. sort_of a = s}"
+ using INFM_sort_of_eq unfolding INFM_iff_infinite .
+
+lemma atom_infinite [simp]:
+ shows "infinite (UNIV :: atom set)"
+ using subset_UNIV infinite_sort_of_eq
+ by (rule infinite_super)
+
+lemma obtain_atom:
+ fixes X :: "atom set"
+ assumes X: "finite X"
+ obtains a where "a \<notin> X" "sort_of a = s"
+proof -
+ from X have "MOST a. a \<notin> X"
+ unfolding MOST_iff_cofinite by simp
+ with INFM_sort_of_eq
+ have "INFM a. sort_of a = s \<and> a \<notin> X"
+ by (rule INFM_conjI)
+ then obtain a where "a \<notin> X" "sort_of a = s"
+ by (auto elim: INFM_E)
+ then show ?thesis ..
+qed
+
+section {* Sort-Respecting Permutations *}
+
+typedef perm =
+ "{f. bij f \<and> finite {a. f a \<noteq> a} \<and> (\<forall>a. sort_of (f a) = sort_of a)}"
+proof
+ show "id \<in> ?perm" by simp
+qed
+
+lemma permI:
+ assumes "bij f" and "MOST x. f x = x" and "\<And>a. sort_of (f a) = sort_of a"
+ shows "f \<in> perm"
+ using assms unfolding perm_def MOST_iff_cofinite by simp
+
+lemma perm_is_bij: "f \<in> perm \<Longrightarrow> bij f"
+ unfolding perm_def by simp
+
+lemma perm_is_finite: "f \<in> perm \<Longrightarrow> finite {a. f a \<noteq> a}"
+ unfolding perm_def by simp
+
+lemma perm_is_sort_respecting: "f \<in> perm \<Longrightarrow> sort_of (f a) = sort_of a"
+ unfolding perm_def by simp
+
+lemma perm_MOST: "f \<in> perm \<Longrightarrow> MOST x. f x = x"
+ unfolding perm_def MOST_iff_cofinite by simp
+
+lemma perm_id: "id \<in> perm"
+ unfolding perm_def by simp
+
+lemma perm_comp:
+ assumes f: "f \<in> perm" and g: "g \<in> perm"
+ shows "(f \<circ> g) \<in> perm"
+apply (rule permI)
+apply (rule bij_comp)
+apply (rule perm_is_bij [OF g])
+apply (rule perm_is_bij [OF f])
+apply (rule MOST_rev_mp [OF perm_MOST [OF g]])
+apply (rule MOST_rev_mp [OF perm_MOST [OF f]])
+apply (simp)
+apply (simp add: perm_is_sort_respecting [OF f])
+apply (simp add: perm_is_sort_respecting [OF g])
+done
+
+lemma perm_inv:
+ assumes f: "f \<in> perm"
+ shows "(inv f) \<in> perm"
+apply (rule permI)
+apply (rule bij_imp_bij_inv)
+apply (rule perm_is_bij [OF f])
+apply (rule MOST_mono [OF perm_MOST [OF f]])
+apply (erule subst, rule inv_f_f)
+apply (rule bij_is_inj [OF perm_is_bij [OF f]])
+apply (rule perm_is_sort_respecting [OF f, THEN sym, THEN trans])
+apply (simp add: surj_f_inv_f [OF bij_is_surj [OF perm_is_bij [OF f]]])
+done
+
+lemma bij_Rep_perm: "bij (Rep_perm p)"
+ using Rep_perm [of p] unfolding perm_def by simp
+
+lemma finite_Rep_perm: "finite {a. Rep_perm p a \<noteq> a}"
+ using Rep_perm [of p] unfolding perm_def by simp
+
+lemma sort_of_Rep_perm: "sort_of (Rep_perm p a) = sort_of a"
+ using Rep_perm [of p] unfolding perm_def by simp
+
+lemma Rep_perm_ext:
+ "Rep_perm p1 = Rep_perm p2 \<Longrightarrow> p1 = p2"
+ by (simp add: expand_fun_eq Rep_perm_inject [symmetric])
+
+
+subsection {* Permutations form a group *}
+
+instantiation perm :: group_add
+begin
+
+definition
+ "0 = Abs_perm id"
+
+definition
+ "- p = Abs_perm (inv (Rep_perm p))"
+
+definition
+ "p + q = Abs_perm (Rep_perm p \<circ> Rep_perm q)"
+
+definition
+ "(p1::perm) - p2 = p1 + - p2"
+
+lemma Rep_perm_0: "Rep_perm 0 = id"
+ unfolding zero_perm_def
+ by (simp add: Abs_perm_inverse perm_id)
+
+lemma Rep_perm_add:
+ "Rep_perm (p1 + p2) = Rep_perm p1 \<circ> Rep_perm p2"
+ unfolding plus_perm_def
+ by (simp add: Abs_perm_inverse perm_comp Rep_perm)
+
+lemma Rep_perm_uminus:
+ "Rep_perm (- p) = inv (Rep_perm p)"
+ unfolding uminus_perm_def
+ by (simp add: Abs_perm_inverse perm_inv Rep_perm)
+
+instance
+apply default
+unfolding Rep_perm_inject [symmetric]
+unfolding minus_perm_def
+unfolding Rep_perm_add
+unfolding Rep_perm_uminus
+unfolding Rep_perm_0
+by (simp_all add: o_assoc inv_o_cancel [OF bij_is_inj [OF bij_Rep_perm]])
+
+end
+
+
+section {* Implementation of swappings *}
+
+definition
+ swap :: "atom \<Rightarrow> atom \<Rightarrow> perm" ("'(_ \<rightleftharpoons> _')")
+where
+ "(a \<rightleftharpoons> b) =
+ Abs_perm (if sort_of a = sort_of b
+ then (\<lambda>c. if a = c then b else if b = c then a else c)
+ else id)"
+
+lemma Rep_perm_swap:
+ "Rep_perm (a \<rightleftharpoons> b) =
+ (if sort_of a = sort_of b
+ then (\<lambda>c. if a = c then b else if b = c then a else c)
+ else id)"
+unfolding swap_def
+apply (rule Abs_perm_inverse)
+apply (rule permI)
+apply (auto simp add: bij_def inj_on_def surj_def)[1]
+apply (rule MOST_rev_mp [OF MOST_neq(1) [of a]])
+apply (rule MOST_rev_mp [OF MOST_neq(1) [of b]])
+apply (simp)
+apply (simp)
+done
+
+lemmas Rep_perm_simps =
+ Rep_perm_0
+ Rep_perm_add
+ Rep_perm_uminus
+ Rep_perm_swap
+
+lemma swap_different_sorts [simp]:
+ "sort_of a \<noteq> sort_of b \<Longrightarrow> (a \<rightleftharpoons> b) = 0"
+ by (rule Rep_perm_ext) (simp add: Rep_perm_simps)
+
+lemma swap_cancel:
+ "(a \<rightleftharpoons> b) + (a \<rightleftharpoons> b) = 0"
+by (rule Rep_perm_ext)
+ (simp add: Rep_perm_simps expand_fun_eq)
+
+lemma swap_self [simp]:
+ "(a \<rightleftharpoons> a) = 0"
+ by (rule Rep_perm_ext, simp add: Rep_perm_simps expand_fun_eq)
+
+lemma minus_swap [simp]:
+ "- (a \<rightleftharpoons> b) = (a \<rightleftharpoons> b)"
+ by (rule minus_unique [OF swap_cancel])
+
+lemma swap_commute:
+ "(a \<rightleftharpoons> b) = (b \<rightleftharpoons> a)"
+ by (rule Rep_perm_ext)
+ (simp add: Rep_perm_swap expand_fun_eq)
+
+lemma swap_triple:
+ assumes "a \<noteq> b" and "c \<noteq> b"
+ assumes "sort_of a = sort_of b" "sort_of b = sort_of c"
+ shows "(a \<rightleftharpoons> c) + (b \<rightleftharpoons> c) + (a \<rightleftharpoons> c) = (a \<rightleftharpoons> b)"
+ using assms
+ by (rule_tac Rep_perm_ext)
+ (auto simp add: Rep_perm_simps expand_fun_eq)
+
+
+section {* Permutation Types *}
+
+text {*
+ Infix syntax for @{text permute} has higher precedence than
+ addition, but lower than unary minus.
+*}
+
+class pt =
+ fixes permute :: "perm \<Rightarrow> 'a \<Rightarrow> 'a" ("_ \<bullet> _" [76, 75] 75)
+ assumes permute_zero [simp]: "0 \<bullet> x = x"
+ assumes permute_plus [simp]: "(p + q) \<bullet> x = p \<bullet> (q \<bullet> x)"
+begin
+
+lemma permute_diff [simp]:
+ shows "(p - q) \<bullet> x = p \<bullet> - q \<bullet> x"
+ unfolding diff_minus by simp
+
+lemma permute_minus_cancel [simp]:
+ shows "p \<bullet> - p \<bullet> x = x"
+ and "- p \<bullet> p \<bullet> x = x"
+ unfolding permute_plus [symmetric] by simp_all
+
+lemma permute_swap_cancel [simp]:
+ shows "(a \<rightleftharpoons> b) \<bullet> (a \<rightleftharpoons> b) \<bullet> x = x"
+ unfolding permute_plus [symmetric]
+ by (simp add: swap_cancel)
+
+lemma permute_swap_cancel2 [simp]:
+ shows "(a \<rightleftharpoons> b) \<bullet> (b \<rightleftharpoons> a) \<bullet> x = x"
+ unfolding permute_plus [symmetric]
+ by (simp add: swap_commute)
+
+lemma inj_permute [simp]:
+ shows "inj (permute p)"
+ by (rule inj_on_inverseI)
+ (rule permute_minus_cancel)
+
+lemma surj_permute [simp]:
+ shows "surj (permute p)"
+ by (rule surjI, rule permute_minus_cancel)
+
+lemma bij_permute [simp]:
+ shows "bij (permute p)"
+ by (rule bijI [OF inj_permute surj_permute])
+
+lemma inv_permute:
+ shows "inv (permute p) = permute (- p)"
+ by (rule inv_equality) (simp_all)
+
+lemma permute_minus:
+ shows "permute (- p) = inv (permute p)"
+ by (simp add: inv_permute)
+
+lemma permute_eq_iff [simp]:
+ shows "p \<bullet> x = p \<bullet> y \<longleftrightarrow> x = y"
+ by (rule inj_permute [THEN inj_eq])
+
+end
+
+subsection {* Permutations for atoms *}
+
+instantiation atom :: pt
+begin
+
+definition
+ "p \<bullet> a = Rep_perm p a"
+
+instance
+apply(default)
+apply(simp_all add: permute_atom_def Rep_perm_simps)
+done
+
+end
+
+lemma sort_of_permute [simp]:
+ shows "sort_of (p \<bullet> a) = sort_of a"
+ unfolding permute_atom_def by (rule sort_of_Rep_perm)
+
+lemma swap_atom:
+ shows "(a \<rightleftharpoons> b) \<bullet> c =
+ (if sort_of a = sort_of b
+ then (if c = a then b else if c = b then a else c) else c)"
+ unfolding permute_atom_def
+ by (simp add: Rep_perm_swap)
+
+lemma swap_atom_simps [simp]:
+ "sort_of a = sort_of b \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> a = b"
+ "sort_of a = sort_of b \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> b = a"
+ "c \<noteq> a \<Longrightarrow> c \<noteq> b \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> c = c"
+ unfolding swap_atom by simp_all
+
+lemma expand_perm_eq:
+ fixes p q :: "perm"
+ shows "p = q \<longleftrightarrow> (\<forall>a::atom. p \<bullet> a = q \<bullet> a)"
+ unfolding permute_atom_def
+ by (metis Rep_perm_ext ext)
+
+
+subsection {* Permutations for permutations *}
+
+instantiation perm :: pt
+begin
+
+definition
+ "p \<bullet> q = p + q - p"
+
+instance
+apply default
+apply (simp add: permute_perm_def)
+apply (simp add: permute_perm_def diff_minus minus_add add_assoc)
+done
+
+end
+
+lemma permute_self: "p \<bullet> p = p"
+unfolding permute_perm_def by (simp add: diff_minus add_assoc)
+
+lemma permute_eqvt:
+ shows "p \<bullet> (q \<bullet> x) = (p \<bullet> q) \<bullet> (p \<bullet> x)"
+ unfolding permute_perm_def by simp
+
+lemma zero_perm_eqvt:
+ shows "p \<bullet> (0::perm) = 0"
+ unfolding permute_perm_def by simp
+
+lemma add_perm_eqvt:
+ fixes p p1 p2 :: perm
+ shows "p \<bullet> (p1 + p2) = p \<bullet> p1 + p \<bullet> p2"
+ unfolding permute_perm_def
+ by (simp add: expand_perm_eq)
+
+lemma swap_eqvt:
+ shows "p \<bullet> (a \<rightleftharpoons> b) = (p \<bullet> a \<rightleftharpoons> p \<bullet> b)"
+ unfolding permute_perm_def
+ by (auto simp add: swap_atom expand_perm_eq)
+
+
+subsection {* Permutations for functions *}
+
+instantiation "fun" :: (pt, pt) pt
+begin
+
+definition
+ "p \<bullet> f = (\<lambda>x. p \<bullet> (f (- p \<bullet> x)))"
+
+instance
+apply default
+apply (simp add: permute_fun_def)
+apply (simp add: permute_fun_def minus_add)
+done
+
+end
+
+lemma permute_fun_app_eq:
+ shows "p \<bullet> (f x) = (p \<bullet> f) (p \<bullet> x)"
+unfolding permute_fun_def by simp
+
+
+subsection {* Permutations for booleans *}
+
+instantiation bool :: pt
+begin
+
+definition "p \<bullet> (b::bool) = b"
+
+instance
+apply(default)
+apply(simp_all add: permute_bool_def)
+done
+
+end
+
+lemma Not_eqvt:
+ shows "p \<bullet> (\<not> A) = (\<not> (p \<bullet> A))"
+by (simp add: permute_bool_def)
+
+
+subsection {* Permutations for sets *}
+
+lemma permute_set_eq:
+ fixes x::"'a::pt"
+ and p::"perm"
+ shows "(p \<bullet> X) = {p \<bullet> x | x. x \<in> X}"
+ apply(auto simp add: permute_fun_def permute_bool_def mem_def)
+ apply(rule_tac x="- p \<bullet> x" in exI)
+ apply(simp)
+ done
+
+lemma permute_set_eq_image:
+ shows "p \<bullet> X = permute p ` X"
+unfolding permute_set_eq by auto
+
+lemma permute_set_eq_vimage:
+ shows "p \<bullet> X = permute (- p) -` X"
+unfolding permute_fun_def permute_bool_def
+unfolding vimage_def Collect_def mem_def ..
+
+subsection {* Permutations for units *}
+
+instantiation unit :: pt
+begin
+
+definition "p \<bullet> (u::unit) = u"
+
+instance proof
+qed (simp_all add: permute_unit_def)
+
+end
+
+
+subsection {* Permutations for products *}
+
+instantiation "*" :: (pt, pt) pt
+begin
+
+primrec
+ permute_prod
+where
+ Pair_eqvt: "p \<bullet> (x, y) = (p \<bullet> x, p \<bullet> y)"
+
+instance
+by default auto
+
+end
+
+
+subsection {* Permutations for sums *}
+
+instantiation "+" :: (pt, pt) pt
+begin
+
+primrec
+ permute_sum
+where
+ "p \<bullet> (Inl x) = Inl (p \<bullet> x)"
+| "p \<bullet> (Inr y) = Inr (p \<bullet> y)"
+
+instance proof
+qed (case_tac [!] x, simp_all)
+
+end
+
+subsection {* Permutations for lists *}
+
+instantiation list :: (pt) pt
+begin
+
+primrec
+ permute_list
+where
+ "p \<bullet> [] = []"
+| "p \<bullet> (x # xs) = p \<bullet> x # p \<bullet> xs"
+
+instance proof
+qed (induct_tac [!] x, simp_all)
+
+end
+
+subsection {* Permutations for options *}
+
+instantiation option :: (pt) pt
+begin
+
+primrec
+ permute_option
+where
+ "p \<bullet> None = None"
+| "p \<bullet> (Some x) = Some (p \<bullet> x)"
+
+instance proof
+qed (induct_tac [!] x, simp_all)
+
+end
+
+subsection {* Permutations for @{typ char}, @{typ nat}, and @{typ int} *}
+
+instantiation char :: pt
+begin
+
+definition "p \<bullet> (c::char) = c"
+
+instance proof
+qed (simp_all add: permute_char_def)
+
+end
+
+instantiation nat :: pt
+begin
+
+definition "p \<bullet> (n::nat) = n"
+
+instance proof
+qed (simp_all add: permute_nat_def)
+
+end
+
+instantiation int :: pt
+begin
+
+definition "p \<bullet> (i::int) = i"
+
+instance proof
+qed (simp_all add: permute_int_def)
+
+end
+
+
+section {* Pure types *}
+
+text {* Pure types will have always empty support. *}
+
+class pure = pt +
+ assumes permute_pure: "p \<bullet> x = x"
+
+text {* Types @{typ unit} and @{typ bool} are pure. *}
+
+instance unit :: pure
+proof qed (rule permute_unit_def)
+
+instance bool :: pure
+proof qed (rule permute_bool_def)
+
+text {* Other type constructors preserve purity. *}
+
+instance "fun" :: (pure, pure) pure
+by default (simp add: permute_fun_def permute_pure)
+
+instance "*" :: (pure, pure) pure
+by default (induct_tac x, simp add: permute_pure)
+
+instance "+" :: (pure, pure) pure
+by default (induct_tac x, simp_all add: permute_pure)
+
+instance list :: (pure) pure
+by default (induct_tac x, simp_all add: permute_pure)
+
+instance option :: (pure) pure
+by default (induct_tac x, simp_all add: permute_pure)
+
+
+subsection {* Types @{typ char}, @{typ nat}, and @{typ int} *}
+
+instance char :: pure
+proof qed (rule permute_char_def)
+
+instance nat :: pure
+proof qed (rule permute_nat_def)
+
+instance int :: pure
+proof qed (rule permute_int_def)
+
+
+subsection {* Supp, Freshness and Supports *}
+
+context pt
+begin
+
+definition
+ supp :: "'a \<Rightarrow> atom set"
+where
+ "supp x = {a. infinite {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}}"
+
+end
+
+definition
+ fresh :: "atom \<Rightarrow> 'a::pt \<Rightarrow> bool" ("_ \<sharp> _" [55, 55] 55)
+where
+ "a \<sharp> x \<equiv> a \<notin> supp x"
+
+lemma supp_conv_fresh:
+ shows "supp x = {a. \<not> a \<sharp> x}"
+ unfolding fresh_def by simp
+
+lemma swap_rel_trans:
+ assumes "sort_of a = sort_of b"
+ assumes "sort_of b = sort_of c"
+ assumes "(a \<rightleftharpoons> c) \<bullet> x = x"
+ assumes "(b \<rightleftharpoons> c) \<bullet> x = x"
+ shows "(a \<rightleftharpoons> b) \<bullet> x = x"
+proof (cases)
+ assume "a = b \<or> c = b"
+ with assms show "(a \<rightleftharpoons> b) \<bullet> x = x" by auto
+next
+ assume *: "\<not> (a = b \<or> c = b)"
+ have "((a \<rightleftharpoons> c) + (b \<rightleftharpoons> c) + (a \<rightleftharpoons> c)) \<bullet> x = x"
+ using assms by simp
+ also have "(a \<rightleftharpoons> c) + (b \<rightleftharpoons> c) + (a \<rightleftharpoons> c) = (a \<rightleftharpoons> b)"
+ using assms * by (simp add: swap_triple)
+ finally show "(a \<rightleftharpoons> b) \<bullet> x = x" .
+qed
+
+lemma swap_fresh_fresh:
+ assumes a: "a \<sharp> x"
+ and b: "b \<sharp> x"
+ shows "(a \<rightleftharpoons> b) \<bullet> x = x"
+proof (cases)
+ assume asm: "sort_of a = sort_of b"
+ have "finite {c. (a \<rightleftharpoons> c) \<bullet> x \<noteq> x}" "finite {c. (b \<rightleftharpoons> c) \<bullet> x \<noteq> x}"
+ using a b unfolding fresh_def supp_def by simp_all
+ then have "finite ({c. (a \<rightleftharpoons> c) \<bullet> x \<noteq> x} \<union> {c. (b \<rightleftharpoons> c) \<bullet> x \<noteq> x})" by simp
+ then obtain c
+ where "(a \<rightleftharpoons> c) \<bullet> x = x" "(b \<rightleftharpoons> c) \<bullet> x = x" "sort_of c = sort_of b"
+ by (rule obtain_atom) (auto)
+ then show "(a \<rightleftharpoons> b) \<bullet> x = x" using asm by (rule_tac swap_rel_trans) (simp_all)
+next
+ assume "sort_of a \<noteq> sort_of b"
+ then show "(a \<rightleftharpoons> b) \<bullet> x = x" by simp
+qed
+
+
+subsection {* supp and fresh are equivariant *}
+
+lemma finite_Collect_bij:
+ assumes a: "bij f"
+ shows "finite {x. P (f x)} = finite {x. P x}"
+by (metis a finite_vimage_iff vimage_Collect_eq)
+
+lemma fresh_permute_iff:
+ shows "(p \<bullet> a) \<sharp> (p \<bullet> x) \<longleftrightarrow> a \<sharp> x"
+proof -
+ have "(p \<bullet> a) \<sharp> (p \<bullet> x) \<longleftrightarrow> finite {b. (p \<bullet> a \<rightleftharpoons> b) \<bullet> p \<bullet> x \<noteq> p \<bullet> x}"
+ unfolding fresh_def supp_def by simp
+ also have "\<dots> \<longleftrightarrow> finite {b. (p \<bullet> a \<rightleftharpoons> p \<bullet> b) \<bullet> p \<bullet> x \<noteq> p \<bullet> x}"
+ using bij_permute by (rule finite_Collect_bij [symmetric])
+ also have "\<dots> \<longleftrightarrow> finite {b. p \<bullet> (a \<rightleftharpoons> b) \<bullet> x \<noteq> p \<bullet> x}"
+ by (simp only: permute_eqvt [of p] swap_eqvt)
+ also have "\<dots> \<longleftrightarrow> finite {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}"
+ by (simp only: permute_eq_iff)
+ also have "\<dots> \<longleftrightarrow> a \<sharp> x"
+ unfolding fresh_def supp_def by simp
+ finally show ?thesis .
+qed
+
+lemma fresh_eqvt:
+ shows "p \<bullet> (a \<sharp> x) = (p \<bullet> a) \<sharp> (p \<bullet> x)"
+ by (simp add: permute_bool_def fresh_permute_iff)
+
+lemma supp_eqvt:
+ fixes p :: "perm"
+ and x :: "'a::pt"
+ shows "p \<bullet> (supp x) = supp (p \<bullet> x)"
+ unfolding supp_conv_fresh
+ unfolding permute_fun_def Collect_def
+ by (simp add: Not_eqvt fresh_eqvt)
+
+subsection {* supports *}
+
+definition
+ supports :: "atom set \<Rightarrow> 'a::pt \<Rightarrow> bool" (infixl "supports" 80)
+where
+ "S supports x \<equiv> \<forall>a b. (a \<notin> S \<and> b \<notin> S \<longrightarrow> (a \<rightleftharpoons> b) \<bullet> x = x)"
+
+lemma supp_is_subset:
+ fixes S :: "atom set"
+ and x :: "'a::pt"
+ assumes a1: "S supports x"
+ and a2: "finite S"
+ shows "(supp x) \<subseteq> S"
+proof (rule ccontr)
+ assume "\<not>(supp x \<subseteq> S)"
+ then obtain a where b1: "a \<in> supp x" and b2: "a \<notin> S" by auto
+ from a1 b2 have "\<forall>b. b \<notin> S \<longrightarrow> (a \<rightleftharpoons> b) \<bullet> x = x" by (unfold supports_def) (auto)
+ hence "{b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x} \<subseteq> S" by auto
+ with a2 have "finite {b. (a \<rightleftharpoons> b)\<bullet>x \<noteq> x}" by (simp add: finite_subset)
+ then have "a \<notin> (supp x)" unfolding supp_def by simp
+ with b1 show False by simp
+qed
+
+lemma supports_finite:
+ fixes S :: "atom set"
+ and x :: "'a::pt"
+ assumes a1: "S supports x"
+ and a2: "finite S"
+ shows "finite (supp x)"
+proof -
+ have "(supp x) \<subseteq> S" using a1 a2 by (rule supp_is_subset)
+ then show "finite (supp x)" using a2 by (simp add: finite_subset)
+qed
+
+lemma supp_supports:
+ fixes x :: "'a::pt"
+ shows "(supp x) supports x"
+proof (unfold supports_def, intro strip)
+ fix a b
+ assume "a \<notin> (supp x) \<and> b \<notin> (supp x)"
+ then have "a \<sharp> x" and "b \<sharp> x" by (simp_all add: fresh_def)
+ then show "(a \<rightleftharpoons> b) \<bullet> x = x" by (rule swap_fresh_fresh)
+qed
+
+lemma supp_is_least_supports:
+ fixes S :: "atom set"
+ and x :: "'a::pt"
+ assumes a1: "S supports x"
+ and a2: "finite S"
+ and a3: "\<And>S'. finite S' \<Longrightarrow> (S' supports x) \<Longrightarrow> S \<subseteq> S'"
+ shows "(supp x) = S"
+proof (rule equalityI)
+ show "(supp x) \<subseteq> S" using a1 a2 by (rule supp_is_subset)
+ with a2 have fin: "finite (supp x)" by (rule rev_finite_subset)
+ have "(supp x) supports x" by (rule supp_supports)
+ with fin a3 show "S \<subseteq> supp x" by blast
+qed
+
+lemma subsetCI:
+ shows "(\<And>x. x \<in> A \<Longrightarrow> x \<notin> B \<Longrightarrow> False) \<Longrightarrow> A \<subseteq> B"
+ by auto
+
+lemma finite_supp_unique:
+ assumes a1: "S supports x"
+ assumes a2: "finite S"
+ assumes a3: "\<And>a b. \<lbrakk>a \<in> S; b \<notin> S; sort_of a = sort_of b\<rbrakk> \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> x \<noteq> x"
+ shows "(supp x) = S"
+ using a1 a2
+proof (rule supp_is_least_supports)
+ fix S'
+ assume "finite S'" and "S' supports x"
+ show "S \<subseteq> S'"
+ proof (rule subsetCI)
+ fix a
+ assume "a \<in> S" and "a \<notin> S'"
+ have "finite (S \<union> S')"
+ using `finite S` `finite S'` by simp
+ then obtain b where "b \<notin> S \<union> S'" and "sort_of b = sort_of a"
+ by (rule obtain_atom)
+ then have "b \<notin> S" and "b \<notin> S'" and "sort_of a = sort_of b"
+ by simp_all
+ then have "(a \<rightleftharpoons> b) \<bullet> x = x"
+ using `a \<notin> S'` `S' supports x` by (simp add: supports_def)
+ moreover have "(a \<rightleftharpoons> b) \<bullet> x \<noteq> x"
+ using `a \<in> S` `b \<notin> S` `sort_of a = sort_of b`
+ by (rule a3)
+ ultimately show "False" by simp
+ qed
+qed
+
+section {* Finitely-supported types *}
+
+class fs = pt +
+ assumes finite_supp: "finite (supp x)"
+
+lemma pure_supp:
+ shows "supp (x::'a::pure) = {}"
+ unfolding supp_def by (simp add: permute_pure)
+
+lemma pure_fresh:
+ fixes x::"'a::pure"
+ shows "a \<sharp> x"
+ unfolding fresh_def by (simp add: pure_supp)
+
+instance pure < fs
+by default (simp add: pure_supp)
+
+
+subsection {* Type @{typ atom} is finitely-supported. *}
+
+lemma supp_atom:
+ shows "supp a = {a}"
+apply (rule finite_supp_unique)
+apply (clarsimp simp add: supports_def)
+apply simp
+apply simp
+done
+
+lemma fresh_atom:
+ shows "a \<sharp> b \<longleftrightarrow> a \<noteq> b"
+ unfolding fresh_def supp_atom by simp
+
+instance atom :: fs
+by default (simp add: supp_atom)
+
+
+section {* Type @{typ perm} is finitely-supported. *}
+
+lemma perm_swap_eq:
+ shows "(a \<rightleftharpoons> b) \<bullet> p = p \<longleftrightarrow> (p \<bullet> (a \<rightleftharpoons> b)) = (a \<rightleftharpoons> b)"
+unfolding permute_perm_def
+by (metis add_diff_cancel minus_perm_def)
+
+lemma supports_perm:
+ shows "{a. p \<bullet> a \<noteq> a} supports p"
+ unfolding supports_def
+ by (simp add: perm_swap_eq swap_eqvt)
+
+lemma finite_perm_lemma:
+ shows "finite {a::atom. p \<bullet> a \<noteq> a}"
+ using finite_Rep_perm [of p]
+ unfolding permute_atom_def .
+
+lemma supp_perm:
+ shows "supp p = {a. p \<bullet> a \<noteq> a}"
+apply (rule finite_supp_unique)
+apply (rule supports_perm)
+apply (rule finite_perm_lemma)
+apply (simp add: perm_swap_eq swap_eqvt)
+apply (auto simp add: expand_perm_eq swap_atom)
+done
+
+lemma fresh_perm:
+ shows "a \<sharp> p \<longleftrightarrow> p \<bullet> a = a"
+unfolding fresh_def by (simp add: supp_perm)
+
+lemma supp_swap:
+ shows "supp (a \<rightleftharpoons> b) = (if a = b \<or> sort_of a \<noteq> sort_of b then {} else {a, b})"
+ by (auto simp add: supp_perm swap_atom)
+
+lemma fresh_zero_perm:
+ shows "a \<sharp> (0::perm)"
+ unfolding fresh_perm by simp
+
+lemma supp_zero_perm:
+ shows "supp (0::perm) = {}"
+ unfolding supp_perm by simp
+
+lemma supp_plus_perm:
+ fixes p q::perm
+ shows "supp (p + q) \<subseteq> supp p \<union> supp q"
+ by (auto simp add: supp_perm)
+
+lemma supp_minus_perm:
+ fixes p::perm
+ shows "supp (- p) = supp p"
+ apply(auto simp add: supp_perm)
+ apply(metis permute_minus_cancel)+
+ done
+
+instance perm :: fs
+by default (simp add: supp_perm finite_perm_lemma)
+
+
+section {* Finite Support instances for other types *}
+
+subsection {* Type @{typ "'a \<times> 'b"} is finitely-supported. *}
+
+lemma supp_Pair:
+ shows "supp (x, y) = supp x \<union> supp y"
+ by (simp add: supp_def Collect_imp_eq Collect_neg_eq)
+
+lemma fresh_Pair:
+ shows "a \<sharp> (x, y) \<longleftrightarrow> a \<sharp> x \<and> a \<sharp> y"
+ by (simp add: fresh_def supp_Pair)
+
+instance "*" :: (fs, fs) fs
+apply default
+apply (induct_tac x)
+apply (simp add: supp_Pair finite_supp)
+done
+
+
+subsection {* Type @{typ "'a + 'b"} is finitely supported *}
+
+lemma supp_Inl:
+ shows "supp (Inl x) = supp x"
+ by (simp add: supp_def)
+
+lemma supp_Inr:
+ shows "supp (Inr x) = supp x"
+ by (simp add: supp_def)
+
+lemma fresh_Inl:
+ shows "a \<sharp> Inl x \<longleftrightarrow> a \<sharp> x"
+ by (simp add: fresh_def supp_Inl)
+
+lemma fresh_Inr:
+ shows "a \<sharp> Inr y \<longleftrightarrow> a \<sharp> y"
+ by (simp add: fresh_def supp_Inr)
+
+instance "+" :: (fs, fs) fs
+apply default
+apply (induct_tac x)
+apply (simp_all add: supp_Inl supp_Inr finite_supp)
+done
+
+subsection {* Type @{typ "'a option"} is finitely supported *}
+
+lemma supp_None:
+ shows "supp None = {}"
+by (simp add: supp_def)
+
+lemma supp_Some:
+ shows "supp (Some x) = supp x"
+ by (simp add: supp_def)
+
+lemma fresh_None:
+ shows "a \<sharp> None"
+ by (simp add: fresh_def supp_None)
+
+lemma fresh_Some:
+ shows "a \<sharp> Some x \<longleftrightarrow> a \<sharp> x"
+ by (simp add: fresh_def supp_Some)
+
+instance option :: (fs) fs
+apply default
+apply (induct_tac x)
+apply (simp_all add: supp_None supp_Some finite_supp)
+done
+
+subsubsection {* Type @{typ "'a list"} is finitely supported *}
+
+lemma supp_Nil:
+ shows "supp [] = {}"
+ by (simp add: supp_def)
+
+lemma supp_Cons:
+ shows "supp (x # xs) = supp x \<union> supp xs"
+by (simp add: supp_def Collect_imp_eq Collect_neg_eq)
+
+lemma fresh_Nil:
+ shows "a \<sharp> []"
+ by (simp add: fresh_def supp_Nil)
+
+lemma fresh_Cons:
+ shows "a \<sharp> (x # xs) \<longleftrightarrow> a \<sharp> x \<and> a \<sharp> xs"
+ by (simp add: fresh_def supp_Cons)
+
+instance list :: (fs) fs
+apply default
+apply (induct_tac x)
+apply (simp_all add: supp_Nil supp_Cons finite_supp)
+done
+
+end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Quot/Nominal/Nominal2_Eqvt.thy Tue Jan 26 20:07:50 2010 +0100
@@ -0,0 +1,370 @@
+(* Title: Nominal2_Eqvt
+ Authors: Brian Huffman, Christian Urban
+
+ Equivariance, Supp and Fresh Lemmas for Operators.
+*)
+theory Nominal2_Eqvt
+imports Nominal2_Base
+uses ("nominal_thmdecls.ML")
+begin
+
+section {* Logical Operators *}
+
+lemma eq_eqvt:
+ shows "p \<bullet> (x = y) \<longleftrightarrow> (p \<bullet> x) = (p \<bullet> y)"
+ unfolding permute_eq_iff permute_bool_def ..
+
+lemma if_eqvt:
+ shows "p \<bullet> (if b then x else y) = (if p \<bullet> b then p \<bullet> x else p \<bullet> y)"
+ by (simp add: permute_fun_def permute_bool_def)
+
+lemma True_eqvt:
+ shows "p \<bullet> True = True"
+ unfolding permute_bool_def ..
+
+lemma False_eqvt:
+ shows "p \<bullet> False = False"
+ unfolding permute_bool_def ..
+
+lemma imp_eqvt:
+ shows "p \<bullet> (A \<longrightarrow> B) = ((p \<bullet> A) \<longrightarrow> (p \<bullet> B))"
+ by (simp add: permute_bool_def)
+
+lemma conj_eqvt:
+ shows "p \<bullet> (A \<and> B) = ((p \<bullet> A) \<and> (p \<bullet> B))"
+ by (simp add: permute_bool_def)
+
+lemma disj_eqvt:
+ shows "p \<bullet> (A \<or> B) = ((p \<bullet> A) \<or> (p \<bullet> B))"
+ by (simp add: permute_bool_def)
+
+lemma Not_eqvt:
+ shows "p \<bullet> (\<not> A) = (\<not> (p \<bullet> A))"
+ by (simp add: permute_bool_def)
+
+lemma all_eqvt:
+ shows "p \<bullet> (\<forall>x. P x) = (\<forall>x. p \<bullet> P (- p \<bullet> x))"
+ unfolding permute_fun_def permute_bool_def
+ by (auto, drule_tac x="p \<bullet> x" in spec, simp)
+
+lemma ex_eqvt:
+ shows "p \<bullet> (\<exists>x. P x) = (\<exists>x. p \<bullet> P (- p \<bullet> x))"
+ unfolding permute_fun_def permute_bool_def
+ by (auto, rule_tac x="p \<bullet> x" in exI, simp)
+
+lemma ex1_eqvt:
+ shows "p \<bullet> (\<exists>!x. P x) = (\<exists>!x. p \<bullet> P (- p \<bullet> x))"
+ unfolding Ex1_def ex_eqvt conj_eqvt all_eqvt imp_eqvt eq_eqvt
+ by simp
+
+lemma the_eqvt:
+ assumes unique: "\<exists>!x. P x"
+ shows "p \<bullet> (THE x. P x) = (THE x. p \<bullet> P (- p \<bullet> x))"
+ apply(rule the1_equality [symmetric])
+ apply(simp add: ex1_eqvt[symmetric])
+ apply(simp add: permute_bool_def unique)
+ apply(simp add: permute_bool_def)
+ apply(rule theI'[OF unique])
+ done
+
+section {* Set Operations *}
+
+lemma mem_eqvt:
+ shows "p \<bullet> (x \<in> A) \<longleftrightarrow> (p \<bullet> x) \<in> (p \<bullet> A)"
+ unfolding mem_def permute_fun_def by simp
+
+lemma not_mem_eqvt:
+ shows "p \<bullet> (x \<notin> A) \<longleftrightarrow> (p \<bullet> x) \<notin> (p \<bullet> A)"
+ unfolding mem_def permute_fun_def by (simp add: Not_eqvt)
+
+lemma Collect_eqvt:
+ shows "p \<bullet> {x. P x} = {x. p \<bullet> (P (-p \<bullet> x))}"
+ unfolding Collect_def permute_fun_def ..
+
+lemma empty_eqvt:
+ shows "p \<bullet> {} = {}"
+ unfolding empty_def Collect_eqvt False_eqvt ..
+
+lemma supp_set_empty:
+ shows "supp {} = {}"
+ by (simp add: supp_def empty_eqvt)
+
+lemma fresh_set_empty:
+ shows "a \<sharp> {}"
+ by (simp add: fresh_def supp_set_empty)
+
+lemma UNIV_eqvt:
+ shows "p \<bullet> UNIV = UNIV"
+ unfolding UNIV_def Collect_eqvt True_eqvt ..
+
+lemma union_eqvt:
+ shows "p \<bullet> (A \<union> B) = (p \<bullet> A) \<union> (p \<bullet> B)"
+ unfolding Un_def Collect_eqvt disj_eqvt mem_eqvt by simp
+
+lemma inter_eqvt:
+ shows "p \<bullet> (A \<inter> B) = (p \<bullet> A) \<inter> (p \<bullet> B)"
+ unfolding Int_def Collect_eqvt conj_eqvt mem_eqvt by simp
+
+lemma Diff_eqvt:
+ fixes A B :: "'a::pt set"
+ shows "p \<bullet> (A - B) = p \<bullet> A - p \<bullet> B"
+ unfolding set_diff_eq Collect_eqvt conj_eqvt Not_eqvt mem_eqvt by simp
+
+lemma Compl_eqvt:
+ fixes A :: "'a::pt set"
+ shows "p \<bullet> (- A) = - (p \<bullet> A)"
+ unfolding Compl_eq_Diff_UNIV Diff_eqvt UNIV_eqvt ..
+
+lemma insert_eqvt:
+ shows "p \<bullet> (insert x A) = insert (p \<bullet> x) (p \<bullet> A)"
+ unfolding permute_set_eq_image image_insert ..
+
+lemma vimage_eqvt:
+ shows "p \<bullet> (f -` A) = (p \<bullet> f) -` (p \<bullet> A)"
+ unfolding vimage_def permute_fun_def [where f=f]
+ unfolding Collect_eqvt mem_eqvt ..
+
+lemma image_eqvt:
+ shows "p \<bullet> (f ` A) = (p \<bullet> f) ` (p \<bullet> A)"
+ unfolding permute_set_eq_image
+ unfolding permute_fun_def [where f=f]
+ by (simp add: image_image)
+
+lemma finite_permute_iff:
+ shows "finite (p \<bullet> A) \<longleftrightarrow> finite A"
+ unfolding permute_set_eq_vimage
+ using bij_permute by (rule finite_vimage_iff)
+
+lemma finite_eqvt:
+ shows "p \<bullet> finite A = finite (p \<bullet> A)"
+ unfolding finite_permute_iff permute_bool_def ..
+
+lemma supp_eqvt: "p \<bullet> supp S = supp (p \<bullet> S)"
+ unfolding supp_def
+ by (simp only: Collect_eqvt Not_eqvt finite_eqvt eq_eqvt
+ permute_eqvt [of p] swap_eqvt permute_minus_cancel)
+
+
+section {* List Operations *}
+
+lemma append_eqvt:
+ shows "p \<bullet> (xs @ ys) = (p \<bullet> xs) @ (p \<bullet> ys)"
+ by (induct xs) auto
+
+lemma supp_append:
+ shows "supp (xs @ ys) = supp xs \<union> supp ys"
+ by (induct xs) (auto simp add: supp_Nil supp_Cons)
+
+lemma fresh_append:
+ shows "a \<sharp> (xs @ ys) \<longleftrightarrow> a \<sharp> xs \<and> a \<sharp> ys"
+ by (induct xs) (simp_all add: fresh_Nil fresh_Cons)
+
+lemma rev_eqvt:
+ shows "p \<bullet> (rev xs) = rev (p \<bullet> xs)"
+ by (induct xs) (simp_all add: append_eqvt)
+
+lemma supp_rev:
+ shows "supp (rev xs) = supp xs"
+ by (induct xs) (auto simp add: supp_append supp_Cons supp_Nil)
+
+lemma fresh_rev:
+ shows "a \<sharp> rev xs \<longleftrightarrow> a \<sharp> xs"
+ by (induct xs) (auto simp add: fresh_append fresh_Cons fresh_Nil)
+
+lemma set_eqvt:
+ shows "p \<bullet> (set xs) = set (p \<bullet> xs)"
+ by (induct xs) (simp_all add: empty_eqvt insert_eqvt)
+
+(* needs finite support premise
+lemma supp_set:
+ fixes x :: "'a::pt"
+ shows "supp (set xs) = supp xs"
+*)
+
+
+section {* Product Operations *}
+
+lemma fst_eqvt:
+ "p \<bullet> (fst x) = fst (p \<bullet> x)"
+ by (cases x) simp
+
+lemma snd_eqvt:
+ "p \<bullet> (snd x) = snd (p \<bullet> x)"
+ by (cases x) simp
+
+
+section {* Units *}
+
+lemma supp_unit:
+ shows "supp () = {}"
+ by (simp add: supp_def)
+
+lemma fresh_unit:
+ shows "a \<sharp> ()"
+ by (simp add: fresh_def supp_unit)
+
+section {* Equivariance automation *}
+
+text {*
+ below is a construction site for a conversion that
+ pushes permutations into a term as far as possible
+*}
+
+text {* Setup of the theorem attributes @{text eqvt} and @{text eqvt_force} *}
+
+use "nominal_thmdecls.ML"
+setup "NominalThmDecls.setup"
+
+lemmas [eqvt] =
+ (* connectives *)
+ eq_eqvt if_eqvt imp_eqvt disj_eqvt conj_eqvt Not_eqvt
+ True_eqvt False_eqvt
+ imp_eqvt [folded induct_implies_def]
+
+ (* datatypes *)
+ permute_prod.simps
+ fst_eqvt snd_eqvt
+
+ (* sets *)
+ empty_eqvt UNIV_eqvt union_eqvt inter_eqvt
+ Diff_eqvt Compl_eqvt insert_eqvt
+
+(* A simple conversion pushing permutations into a term *)
+
+ML {*
+fun OF1 thm1 thm2 = thm2 RS thm1
+
+fun get_eqvt_thms ctxt =
+ map (OF1 @{thm eq_reflection}) (NominalThmDecls.get_eqvt_thms ctxt)
+*}
+
+ML {*
+fun eqvt_conv ctxt ctrm =
+ case (term_of ctrm) of
+ (Const (@{const_name "permute"}, _) $ _ $ t) =>
+ (if is_Const (head_of t)
+ then (More_Conv.rewrs_conv (get_eqvt_thms ctxt)
+ then_conv eqvt_conv ctxt) ctrm
+ else Conv.comb_conv (eqvt_conv ctxt) ctrm)
+ | _ $ _ => Conv.comb_conv (eqvt_conv ctxt) ctrm
+ | Abs _ => Conv.abs_conv (fn (_, ctxt) => eqvt_conv ctxt) ctxt ctrm
+ | _ => Conv.all_conv ctrm
+*}
+
+ML {*
+fun eqvt_tac ctxt =
+ CONVERSION (More_Conv.bottom_conv (fn ctxt => eqvt_conv ctxt) ctxt)
+*}
+
+lemma "p \<bullet> (A \<longrightarrow> B = (C::bool))"
+apply(tactic {* eqvt_tac @{context} 1 *})
+oops
+
+text {*
+ Another conversion for pushing permutations into a term.
+ It is designed not to apply rules like @{term permute_pure} to
+ applications or abstractions, only to constants or free
+ variables. Thus permutations are not removed too early, and they
+ have a chance to cancel with bound variables.
+*}
+
+definition
+ "unpermute p = permute (- p)"
+
+lemma push_apply:
+ fixes f :: "'a::pt \<Rightarrow> 'b::pt" and x :: "'a::pt"
+ shows "p \<bullet> (f x) \<equiv> (p \<bullet> f) (p \<bullet> x)"
+ unfolding permute_fun_def by simp
+
+lemma push_lambda:
+ fixes f :: "'a::pt \<Rightarrow> 'b::pt"
+ shows "p \<bullet> (\<lambda>x. f x) \<equiv> (\<lambda>x. p \<bullet> (f (unpermute p x)))"
+ unfolding permute_fun_def unpermute_def by simp
+
+lemma push_bound:
+ shows "p \<bullet> unpermute p x \<equiv> x"
+ unfolding unpermute_def by simp
+
+ML {*
+structure PushData = Named_Thms
+(
+ val name = "push"
+ val description = "push permutations"
+)
+
+local
+
+fun push_apply_conv ctxt ct =
+ case (term_of ct) of
+ (Const (@{const_name "permute"}, _) $ _ $ (_ $ _)) =>
+ let
+ val (perm, t) = Thm.dest_comb ct
+ val (_, p) = Thm.dest_comb perm
+ val (f, x) = Thm.dest_comb t
+ val a = ctyp_of_term x;
+ val b = ctyp_of_term t;
+ val ty_insts = map SOME [b, a]
+ val term_insts = map SOME [p, f, x]
+ in
+ Drule.instantiate' ty_insts term_insts @{thm push_apply}
+ end
+ | _ => Conv.no_conv ct
+
+fun push_lambda_conv ctxt ct =
+ case (term_of ct) of
+ (Const (@{const_name "permute"}, _) $ _ $ Abs _) =>
+ Conv.rewr_conv @{thm push_lambda} ct
+ | _ => Conv.no_conv ct
+
+in
+
+fun push_conv ctxt ct =
+ Conv.first_conv
+ [ Conv.rewr_conv @{thm push_bound},
+ push_apply_conv ctxt
+ then_conv Conv.comb_conv (push_conv ctxt),
+ push_lambda_conv ctxt
+ then_conv Conv.abs_conv (fn (v, ctxt) => push_conv ctxt) ctxt,
+ More_Conv.rewrs_conv (PushData.get ctxt),
+ Conv.all_conv
+ ] ct
+
+fun push_tac ctxt =
+ CONVERSION (More_Conv.bottom_conv (fn ctxt => push_conv ctxt) ctxt)
+
+end
+*}
+
+setup PushData.setup
+
+declare permute_pure [THEN eq_reflection, push]
+
+lemma push_eq [THEN eq_reflection, push]:
+ "p \<bullet> (op =) = (op =)"
+ by (simp add: expand_fun_eq permute_fun_def eq_eqvt)
+
+lemma push_All [THEN eq_reflection, push]:
+ "p \<bullet> All = All"
+ by (simp add: expand_fun_eq permute_fun_def all_eqvt)
+
+lemma push_Ex [THEN eq_reflection, push]:
+ "p \<bullet> Ex = Ex"
+ by (simp add: expand_fun_eq permute_fun_def ex_eqvt)
+
+lemma "p \<bullet> (A \<longrightarrow> B = (C::bool))"
+apply (tactic {* push_tac @{context} 1 *})
+oops
+
+lemma "p \<bullet> (\<lambda>x. A \<longrightarrow> B x = (C::bool)) = foo"
+apply (tactic {* push_tac @{context} 1 *})
+oops
+
+lemma "p \<bullet> (\<lambda>x y. \<exists>z. x = z \<and> x = y \<longrightarrow> z \<noteq> x) = foo"
+apply (tactic {* push_tac @{context} 1 *})
+oops
+
+lemma "p \<bullet> (\<lambda>f x. f (g (f x))) = foo"
+apply (tactic {* push_tac @{context} 1 *})
+oops
+
+end
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Quot/Nominal/Nominal2_Supp.thy Tue Jan 26 20:07:50 2010 +0100
@@ -0,0 +1,383 @@
+(* Title: Nominal2_Supp
+ Authors: Brian Huffman, Christian Urban
+
+ Supplementary Lemmas and Definitions for
+ Nominal Isabelle.
+*)
+theory Nominal2_Supp
+imports Nominal2_Base Nominal2_Eqvt Nominal2_Atoms
+begin
+
+
+section {* Fresh-Star *}
+
+text {* The fresh-star generalisation of fresh is used in strong
+ induction principles. *}
+
+definition
+ fresh_star :: "atom set \<Rightarrow> 'a::pt \<Rightarrow> bool" ("_ \<sharp>* _" [80,80] 80)
+where
+ "xs \<sharp>* c \<equiv> \<forall>x \<in> xs. x \<sharp> c"
+
+lemma fresh_star_prod:
+ fixes xs::"atom set"
+ shows "xs \<sharp>* (a, b) = (xs \<sharp>* a \<and> xs \<sharp>* b)"
+ by (auto simp add: fresh_star_def fresh_Pair)
+
+lemma fresh_star_union:
+ shows "(xs \<union> ys) \<sharp>* c = (xs \<sharp>* c \<and> ys \<sharp>* c)"
+ by (auto simp add: fresh_star_def)
+
+lemma fresh_star_insert:
+ shows "(insert x ys) \<sharp>* c = (x \<sharp> c \<and> ys \<sharp>* c)"
+ by (auto simp add: fresh_star_def)
+
+lemma fresh_star_Un_elim:
+ "((S \<union> T) \<sharp>* c \<Longrightarrow> PROP C) \<equiv> (S \<sharp>* c \<Longrightarrow> T \<sharp>* c \<Longrightarrow> PROP C)"
+ unfolding fresh_star_def
+ apply(rule)
+ apply(erule meta_mp)
+ apply(auto)
+ done
+
+lemma fresh_star_insert_elim:
+ "(insert x S \<sharp>* c \<Longrightarrow> PROP C) \<equiv> (x \<sharp> c \<Longrightarrow> S \<sharp>* c \<Longrightarrow> PROP C)"
+ unfolding fresh_star_def
+ by rule (simp_all add: fresh_star_def)
+
+lemma fresh_star_empty_elim:
+ "({} \<sharp>* c \<Longrightarrow> PROP C) \<equiv> PROP C"
+ by (simp add: fresh_star_def)
+
+lemma fresh_star_unit_elim:
+ shows "(a \<sharp>* () \<Longrightarrow> PROP C) \<equiv> PROP C"
+ by (simp add: fresh_star_def fresh_unit)
+
+lemma fresh_star_prod_elim:
+ shows "(a \<sharp>* (x, y) \<Longrightarrow> PROP C) \<equiv> (a \<sharp>* x \<Longrightarrow> a \<sharp>* y \<Longrightarrow> PROP C)"
+ by (rule, simp_all add: fresh_star_prod)
+
+
+section {* Avoiding of atom sets *}
+
+text {*
+ For every set of atoms, there is another set of atoms
+ avoiding a finitely supported c and there is a permutation
+ which 'translates' between both sets.
+*}
+
+lemma swap_set_fresh:
+ assumes a: "a \<notin> S" "b \<notin> S"
+ shows "(a \<rightleftharpoons> b) \<bullet> S = S"
+ using a
+ by (auto simp add: permute_set_eq swap_atom)
+
+lemma at_set_avoiding_aux:
+ fixes Xs::"atom set"
+ and As::"atom set"
+ assumes b: "Xs \<subseteq> As"
+ and c: "finite As"
+ shows "\<exists>p. (p \<bullet> Xs) \<inter> As = {} \<and> (supp p) \<subseteq> (Xs \<union> (p \<bullet> Xs))"
+proof -
+ from b c have "finite Xs" by (rule finite_subset)
+ then show ?thesis using b
+ proof (induct rule: finite_subset_induct)
+ case empty
+ have "0 \<bullet> {} \<inter> As = {}" by simp
+ moreover
+ have "supp (0::perm) \<subseteq> {} \<union> 0 \<bullet> {}" by (simp add: supp_zero_perm)
+ ultimately show ?case by blast
+ next
+ case (insert x Xs)
+ then obtain p where
+ p1: "(p \<bullet> Xs) \<inter> As = {}" and
+ p2: "supp p \<subseteq> (Xs \<union> (p \<bullet> Xs))" by blast
+ from `x \<in> As` p1 have "x \<notin> p \<bullet> Xs" by fast
+ with `x \<notin> Xs` p2 have "x \<notin> supp p" by fast
+ hence px: "p \<bullet> x = x" unfolding supp_perm by simp
+ have "finite (As \<union> p \<bullet> Xs)"
+ using `finite As` `finite Xs`
+ by (simp add: permute_set_eq_image)
+ then obtain y where "y \<notin> (As \<union> p \<bullet> Xs)" "sort_of y = sort_of x"
+ by (rule obtain_atom)
+ hence y: "y \<notin> As" "y \<notin> p \<bullet> Xs" "sort_of y = sort_of x"
+ by simp_all
+ let ?q = "(x \<rightleftharpoons> y) + p"
+ have q: "?q \<bullet> insert x Xs = insert y (p \<bullet> Xs)"
+ unfolding insert_eqvt
+ using `p \<bullet> x = x` `sort_of y = sort_of x`
+ using `x \<notin> p \<bullet> Xs` `y \<notin> p \<bullet> Xs`
+ by (simp add: swap_atom swap_set_fresh)
+ have "?q \<bullet> insert x Xs \<inter> As = {}"
+ using `y \<notin> As` `p \<bullet> Xs \<inter> As = {}`
+ unfolding q by simp
+ moreover
+ have "supp ?q \<subseteq> insert x Xs \<union> ?q \<bullet> insert x Xs"
+ using p2 unfolding q
+ apply (intro subset_trans [OF supp_plus_perm])
+ apply (auto simp add: supp_swap)
+ done
+ ultimately show ?case by blast
+ qed
+qed
+
+lemma at_set_avoiding:
+ assumes a: "finite Xs"
+ and b: "finite (supp c)"
+ obtains p::"perm" where "(p \<bullet> Xs)\<sharp>*c" and "(supp p) \<subseteq> (Xs \<union> (p \<bullet> Xs))"
+ using a b at_set_avoiding_aux [where Xs="Xs" and As="Xs \<union> supp c"]
+ unfolding fresh_star_def fresh_def by blast
+
+
+section {* The freshness lemma according to Andrew Pitts *}
+
+lemma fresh_conv_MOST:
+ shows "a \<sharp> x \<longleftrightarrow> (MOST b. (a \<rightleftharpoons> b) \<bullet> x = x)"
+ unfolding fresh_def supp_def MOST_iff_cofinite by simp
+
+lemma fresh_apply:
+ assumes "a \<sharp> f" and "a \<sharp> x"
+ shows "a \<sharp> f x"
+ using assms unfolding fresh_conv_MOST
+ unfolding permute_fun_app_eq [where f=f]
+ by (elim MOST_rev_mp, simp)
+
+lemma freshness_lemma:
+ fixes h :: "'a::at \<Rightarrow> 'b::pt"
+ assumes a: "\<exists>a. atom a \<sharp> (h, h a)"
+ shows "\<exists>x. \<forall>a. atom a \<sharp> h \<longrightarrow> h a = x"
+proof -
+ from a obtain b where a1: "atom b \<sharp> h" and a2: "atom b \<sharp> h b"
+ by (auto simp add: fresh_Pair)
+ show "\<exists>x. \<forall>a. atom a \<sharp> h \<longrightarrow> h a = x"
+ proof (intro exI allI impI)
+ fix a :: 'a
+ assume a3: "atom a \<sharp> h"
+ show "h a = h b"
+ proof (cases "a = b")
+ assume "a = b"
+ thus "h a = h b" by simp
+ next
+ assume "a \<noteq> b"
+ hence "atom a \<sharp> b" by (simp add: fresh_at)
+ with a3 have "atom a \<sharp> h b" by (rule fresh_apply)
+ with a2 have d1: "(atom b \<rightleftharpoons> atom a) \<bullet> (h b) = (h b)"
+ by (rule swap_fresh_fresh)
+ from a1 a3 have d2: "(atom b \<rightleftharpoons> atom a) \<bullet> h = h"
+ by (rule swap_fresh_fresh)
+ from d1 have "h b = (atom b \<rightleftharpoons> atom a) \<bullet> (h b)" by simp
+ also have "\<dots> = ((atom b \<rightleftharpoons> atom a) \<bullet> h) ((atom b \<rightleftharpoons> atom a) \<bullet> b)"
+ by (rule permute_fun_app_eq)
+ also have "\<dots> = h a"
+ using d2 by simp
+ finally show "h a = h b" by simp
+ qed
+ qed
+qed
+
+lemma freshness_lemma_unique:
+ fixes h :: "'a::at \<Rightarrow> 'b::pt"
+ assumes a: "\<exists>a. atom a \<sharp> (h, h a)"
+ shows "\<exists>!x. \<forall>a. atom a \<sharp> h \<longrightarrow> h a = x"
+proof (rule ex_ex1I)
+ from a show "\<exists>x. \<forall>a. atom a \<sharp> h \<longrightarrow> h a = x"
+ by (rule freshness_lemma)
+next
+ fix x y
+ assume x: "\<forall>a. atom a \<sharp> h \<longrightarrow> h a = x"
+ assume y: "\<forall>a. atom a \<sharp> h \<longrightarrow> h a = y"
+ from a x y show "x = y"
+ by (auto simp add: fresh_Pair)
+qed
+
+text {* packaging the freshness lemma into a function *}
+
+definition
+ fresh_fun :: "('a::at \<Rightarrow> 'b::pt) \<Rightarrow> 'b"
+where
+ "fresh_fun h = (THE x. \<forall>a. atom a \<sharp> h \<longrightarrow> h a = x)"
+
+lemma fresh_fun_app:
+ fixes h :: "'a::at \<Rightarrow> 'b::pt"
+ assumes a: "\<exists>a. atom a \<sharp> (h, h a)"
+ assumes b: "atom a \<sharp> h"
+ shows "fresh_fun h = h a"
+unfolding fresh_fun_def
+proof (rule the_equality)
+ show "\<forall>a'. atom a' \<sharp> h \<longrightarrow> h a' = h a"
+ proof (intro strip)
+ fix a':: 'a
+ assume c: "atom a' \<sharp> h"
+ from a have "\<exists>x. \<forall>a. atom a \<sharp> h \<longrightarrow> h a = x" by (rule freshness_lemma)
+ with b c show "h a' = h a" by auto
+ qed
+next
+ fix fr :: 'b
+ assume "\<forall>a. atom a \<sharp> h \<longrightarrow> h a = fr"
+ with b show "fr = h a" by auto
+qed
+
+lemma fresh_fun_app':
+ fixes h :: "'a::at \<Rightarrow> 'b::pt"
+ assumes a: "atom a \<sharp> h" "atom a \<sharp> h a"
+ shows "fresh_fun h = h a"
+ apply (rule fresh_fun_app)
+ apply (auto simp add: fresh_Pair intro: a)
+ done
+
+lemma fresh_fun_eqvt:
+ fixes h :: "'a::at \<Rightarrow> 'b::pt"
+ assumes a: "\<exists>a. atom a \<sharp> (h, h a)"
+ shows "p \<bullet> (fresh_fun h) = fresh_fun (p \<bullet> h)"
+ using a
+ apply (clarsimp simp add: fresh_Pair)
+ apply (subst fresh_fun_app', assumption+)
+ apply (drule fresh_permute_iff [where p=p, THEN iffD2])
+ apply (drule fresh_permute_iff [where p=p, THEN iffD2])
+ apply (simp add: atom_eqvt permute_fun_app_eq [where f=h])
+ apply (erule (1) fresh_fun_app' [symmetric])
+ done
+
+lemma fresh_fun_supports:
+ fixes h :: "'a::at \<Rightarrow> 'b::pt"
+ assumes a: "\<exists>a. atom a \<sharp> (h, h a)"
+ shows "(supp h) supports (fresh_fun h)"
+ apply (simp add: supports_def fresh_def [symmetric])
+ apply (simp add: fresh_fun_eqvt [OF a] swap_fresh_fresh)
+ done
+
+notation fresh_fun (binder "FRESH " 10)
+
+lemma FRESH_f_iff:
+ fixes P :: "'a::at \<Rightarrow> 'b::pure"
+ fixes f :: "'b \<Rightarrow> 'c::pure"
+ assumes P: "finite (supp P)"
+ shows "(FRESH x. f (P x)) = f (FRESH x. P x)"
+proof -
+ obtain a::'a where "atom a \<notin> supp P"
+ using P by (rule obtain_at_base)
+ hence "atom a \<sharp> P"
+ by (simp add: fresh_def)
+ show "(FRESH x. f (P x)) = f (FRESH x. P x)"
+ apply (subst fresh_fun_app' [where a=a, OF _ pure_fresh])
+ apply (cut_tac `atom a \<sharp> P`)
+ apply (simp add: fresh_conv_MOST)
+ apply (elim MOST_rev_mp, rule MOST_I, clarify)
+ apply (simp add: permute_fun_def permute_pure expand_fun_eq)
+ apply (subst fresh_fun_app' [where a=a, OF `atom a \<sharp> P` pure_fresh])
+ apply (rule refl)
+ done
+qed
+
+lemma FRESH_binop_iff:
+ fixes P :: "'a::at \<Rightarrow> 'b::pure"
+ fixes Q :: "'a::at \<Rightarrow> 'c::pure"
+ fixes binop :: "'b \<Rightarrow> 'c \<Rightarrow> 'd::pure"
+ assumes P: "finite (supp P)"
+ and Q: "finite (supp Q)"
+ shows "(FRESH x. binop (P x) (Q x)) = binop (FRESH x. P x) (FRESH x. Q x)"
+proof -
+ from assms have "finite (supp P \<union> supp Q)" by simp
+ then obtain a::'a where "atom a \<notin> (supp P \<union> supp Q)"
+ by (rule obtain_at_base)
+ hence "atom a \<sharp> P" and "atom a \<sharp> Q"
+ by (simp_all add: fresh_def)
+ show ?thesis
+ apply (subst fresh_fun_app' [where a=a, OF _ pure_fresh])
+ apply (cut_tac `atom a \<sharp> P` `atom a \<sharp> Q`)
+ apply (simp add: fresh_conv_MOST)
+ apply (elim MOST_rev_mp, rule MOST_I, clarify)
+ apply (simp add: permute_fun_def permute_pure expand_fun_eq)
+ apply (subst fresh_fun_app' [where a=a, OF `atom a \<sharp> P` pure_fresh])
+ apply (subst fresh_fun_app' [where a=a, OF `atom a \<sharp> Q` pure_fresh])
+ apply (rule refl)
+ done
+qed
+
+lemma FRESH_conj_iff:
+ fixes P Q :: "'a::at \<Rightarrow> bool"
+ assumes P: "finite (supp P)" and Q: "finite (supp Q)"
+ shows "(FRESH x. P x \<and> Q x) \<longleftrightarrow> (FRESH x. P x) \<and> (FRESH x. Q x)"
+using P Q by (rule FRESH_binop_iff)
+
+lemma FRESH_disj_iff:
+ fixes P Q :: "'a::at \<Rightarrow> bool"
+ assumes P: "finite (supp P)" and Q: "finite (supp Q)"
+ shows "(FRESH x. P x \<or> Q x) \<longleftrightarrow> (FRESH x. P x) \<or> (FRESH x. Q x)"
+using P Q by (rule FRESH_binop_iff)
+
+
+section {* An example of a function without finite support *}
+
+primrec
+ nat_of :: "atom \<Rightarrow> nat"
+where
+ "nat_of (Atom s n) = n"
+
+lemma atom_eq_iff:
+ fixes a b :: atom
+ shows "a = b \<longleftrightarrow> sort_of a = sort_of b \<and> nat_of a = nat_of b"
+ by (induct a, induct b, simp)
+
+lemma not_fresh_nat_of:
+ shows "\<not> a \<sharp> nat_of"
+unfolding fresh_def supp_def
+proof (clarsimp)
+ assume "finite {b. (a \<rightleftharpoons> b) \<bullet> nat_of \<noteq> nat_of}"
+ hence "finite ({a} \<union> {b. (a \<rightleftharpoons> b) \<bullet> nat_of \<noteq> nat_of})"
+ by simp
+ then obtain b where
+ b1: "b \<noteq> a" and
+ b2: "sort_of b = sort_of a" and
+ b3: "(a \<rightleftharpoons> b) \<bullet> nat_of = nat_of"
+ by (rule obtain_atom) auto
+ have "nat_of a = (a \<rightleftharpoons> b) \<bullet> (nat_of a)" by (simp add: permute_nat_def)
+ also have "\<dots> = ((a \<rightleftharpoons> b) \<bullet> nat_of) ((a \<rightleftharpoons> b) \<bullet> a)" by (simp add: permute_fun_app_eq)
+ also have "\<dots> = nat_of ((a \<rightleftharpoons> b) \<bullet> a)" using b3 by simp
+ also have "\<dots> = nat_of b" using b2 by simp
+ finally have "nat_of a = nat_of b" by simp
+ with b2 have "a = b" by (simp add: atom_eq_iff)
+ with b1 show "False" by simp
+qed
+
+lemma supp_nat_of:
+ shows "supp nat_of = UNIV"
+ using not_fresh_nat_of [unfolded fresh_def] by auto
+
+
+(*
+section {* Characterisation of the support of sets of atoms *}
+
+lemma swap_set_ineq:
+ fixes a b::"'a::at"
+ assumes "a \<in> S" "b \<notin> S"
+ shows "(a \<leftrightarrow> b) \<bullet> S \<noteq> S"
+using assms
+unfolding permute_set_eq
+by (auto simp add: permute_flip_at)
+
+lemma supp_finite:
+ fixes S::"'a::at set"
+ assumes asm: "finite S"
+ shows "(supp S) = atom ` S"
+sorry
+
+lemma supp_infinite:
+ fixes S::"atom set"
+ assumes asm: "finite (UNIV - S)"
+ shows "(supp S) = (UNIV - S)"
+apply(rule finite_supp_unique)
+apply(auto simp add: supports_def permute_set_eq swap_atom)[1]
+apply(rule asm)
+apply(auto simp add: permute_set_eq swap_atom)[1]
+done
+
+lemma supp_infinite_coinfinite:
+ fixes S::"atom set"
+ assumes asm1: "infinite S"
+ and asm2: "infinite (UNIV-S)"
+ shows "(supp S) = (UNIV::atom set)"
+*)
+
+
+end
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Quot/Nominal/atom_decl.ML Tue Jan 26 20:07:50 2010 +0100
@@ -0,0 +1,94 @@
+(* Title: atom_decl/ML
+ Authors: Brian Huffman, Christian Urban
+
+ Command for defining concrete atom types.
+
+ At the moment, only single-sorted atom types
+ are supported.
+*)
+
+signature ATOM_DECL =
+sig
+ val add_atom_decl: binding -> theory -> theory
+end;
+
+structure Atom_Decl :> ATOM_DECL =
+struct
+
+val atomT = @{typ atom};
+val permT = @{typ perm};
+
+val sort_of_const = @{term sort_of};
+fun atom_const T = Const (@{const_name atom}, T --> atomT);
+fun permute_const T = Const (@{const_name permute}, permT --> T --> T);
+
+fun mk_sort_of t = sort_of_const $ t;
+fun mk_atom t = atom_const (fastype_of t) $ t;
+fun mk_permute (p, t) = permute_const (fastype_of t) $ p $ t;
+
+fun atom_decl_set (str : string) : term =
+ let
+ val a = Free ("a", atomT);
+ val s = Const (@{const_name "Sort"}, @{typ "string => atom_sort list => atom_sort"})
+ $ HOLogic.mk_string str $ HOLogic.nil_const @{typ "atom_sort"};
+ in
+ HOLogic.mk_Collect ("a", atomT, HOLogic.mk_eq (mk_sort_of a, s))
+ end
+
+fun add_atom_decl (name : binding) (thy : theory) =
+ let
+ val _ = Theory.requires thy "Nominal2_Atoms" "nominal logic";
+ val str = Sign.full_name thy name;
+
+ (* typedef *)
+ val set = atom_decl_set str;
+ val tac = rtac @{thm exists_eq_sort} 1;
+ val ((full_tname, info as {type_definition, Rep_name, Abs_name, ...}), thy) =
+ Typedef.add_typedef false NONE (name, [], NoSyn) set NONE tac thy;
+
+ (* definition of atom and permute *)
+ val newT = #abs_type info;
+ val RepC = Const (Rep_name, newT --> atomT);
+ val AbsC = Const (Abs_name, atomT --> newT);
+ val a = Free ("a", newT);
+ val p = Free ("p", permT);
+ val atom_eqn =
+ HOLogic.mk_Trueprop (HOLogic.mk_eq (mk_atom a, RepC $ a));
+ val permute_eqn =
+ HOLogic.mk_Trueprop (HOLogic.mk_eq
+ (mk_permute (p, a), AbsC $ (mk_permute (p, RepC $ a))));
+ val atom_def_name =
+ Binding.prefix_name "atom_" (Binding.suffix_name "_def" name);
+ val permute_def_name =
+ Binding.prefix_name "permute_" (Binding.suffix_name "_def" name);
+
+ (* at class instance *)
+ val lthy =
+ Theory_Target.instantiation ([full_tname], [], @{sort at}) thy;
+ val ((_, (_, permute_ldef)), lthy) =
+ Specification.definition (NONE, ((permute_def_name, []), permute_eqn)) lthy;
+ val ((_, (_, atom_ldef)), lthy) =
+ Specification.definition (NONE, ((atom_def_name, []), atom_eqn)) lthy;
+ val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy);
+ val permute_def = singleton (ProofContext.export lthy ctxt_thy) permute_ldef;
+ val atom_def = singleton (ProofContext.export lthy ctxt_thy) atom_ldef;
+ val class_thm = @{thm at_class} OF [type_definition, atom_def, permute_def];
+ val thy = lthy
+ |> Class.prove_instantiation_instance (K (Tactic.rtac class_thm 1))
+ |> Local_Theory.exit_global;
+ in
+ thy
+ end;
+
+(** outer syntax **)
+
+local structure P = OuterParse and K = OuterKeyword in
+
+val _ =
+ OuterSyntax.command "atom_decl" "declaration of a concrete atom type" K.thy_decl
+ (P.binding >>
+ (Toplevel.print oo (Toplevel.theory o add_atom_decl)));
+
+end;
+
+end;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Quot/Nominal/nominal_thmdecls.ML Tue Jan 26 20:07:50 2010 +0100
@@ -0,0 +1,171 @@
+(* Title: HOL/Nominal/nominal_thmdecls.ML
+ Author: Julien Narboux, TU Muenchen
+ Author: Christian Urban, TU Muenchen
+
+Infrastructure for the lemma collection "eqvts".
+
+By attaching [eqvt] or [eqvt_force] to a lemma, it will get stored in
+a data-slot in the context. Possible modifiers are [... add] and
+[... del] for adding and deleting, respectively, the lemma from the
+data-slot.
+*)
+
+signature NOMINAL_THMDECLS =
+sig
+ val eqvt_add: attribute
+ val eqvt_del: attribute
+ val eqvt_force_add: attribute
+ val eqvt_force_del: attribute
+ val setup: theory -> theory
+ val get_eqvt_thms: Proof.context -> thm list
+
+end;
+
+structure NominalThmDecls: NOMINAL_THMDECLS =
+struct
+
+structure Data = Generic_Data
+(
+ type T = thm list
+ val empty = []
+ val extend = I
+ val merge = Thm.merge_thms
+)
+
+(* Exception for when a theorem does not conform with form of an equivariance lemma. *)
+(* There are two forms: one is an implication (for relations) and the other is an *)
+(* equality (for functions). In the implication-case, say P ==> Q, Q must be equal *)
+(* to P except that every free variable of Q, say x, is replaced by pi o x. In the *)
+(* equality case, say lhs = rhs, the lhs must be of the form pi o t and the rhs must *)
+(* be equal to t except that every free variable, say x, is replaced by pi o x. In *)
+(* the implicational case it is also checked that the variables and permutation fit *)
+(* together, i.e. are of the right "pt_class", so that a stronger version of the *)
+(* equality-lemma can be derived. *)
+exception EQVT_FORM of string
+
+val perm_boolE =
+ @{lemma "pi \<bullet> P ==> P" by (simp add: permute_bool_def)};
+
+val perm_boolI =
+ @{lemma "P ==> pi \<bullet> P" by (simp add: permute_bool_def)};
+
+fun prove_eqvt_tac ctxt orig_thm pi pi' =
+let
+ val mypi = Thm.cterm_of ctxt pi
+ val T = fastype_of pi'
+ val mypifree = Thm.cterm_of ctxt (Const (@{const_name "uminus"}, T --> T) $ pi')
+ val perm_pi_simp = @{thms permute_minus_cancel}
+in
+ EVERY1 [rtac @{thm iffI},
+ dtac perm_boolE,
+ etac orig_thm,
+ dtac (Drule.cterm_instantiate [(mypi, mypifree)] orig_thm),
+ rtac perm_boolI,
+ full_simp_tac (HOL_basic_ss addsimps perm_pi_simp)]
+end;
+
+fun get_derived_thm ctxt hyp concl orig_thm pi =
+ let
+ val thy = ProofContext.theory_of ctxt;
+ val pi' = Var (pi, @{typ "perm"});
+ val lhs = Const (@{const_name "permute"}, @{typ "perm"} --> HOLogic.boolT --> HOLogic.boolT) $ pi' $ hyp;
+ val ([goal_term, pi''], ctxt') = Variable.import_terms false
+ [HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, concl)), pi'] ctxt
+ in
+ Goal.prove ctxt' [] [] goal_term
+ (fn _ => prove_eqvt_tac thy orig_thm pi' pi'') |>
+ singleton (ProofContext.export ctxt' ctxt)
+ end
+
+(* replaces in t every variable, say x, with pi o x *)
+fun apply_pi trm pi =
+let
+ fun replace n ty =
+ let
+ val c = Const (@{const_name "permute"}, @{typ "perm"} --> ty --> ty)
+ val v1 = Var (pi, @{typ "perm"})
+ val v2 = Var (n, ty)
+ in
+ c $ v1 $ v2
+ end
+in
+ map_aterms (fn Var (n, ty) => replace n ty | t => t) trm
+end
+
+(* returns *the* pi which is in front of all variables, provided there *)
+(* exists such a pi; otherwise raises EQVT_FORM *)
+fun get_pi t thy =
+ let fun get_pi_aux s =
+ (case s of
+ (Const (@{const_name "permute"} ,typrm) $
+ (Var (pi,_)) $
+ (Var (n,ty))) =>
+ if (Sign.of_sort thy (ty, @{sort pt}))
+ then [pi]
+ else raise
+ EQVT_FORM ("Could not find any permutation or an argument is not an instance of pt")
+ | Abs (_,_,t1) => get_pi_aux t1
+ | (t1 $ t2) => get_pi_aux t1 @ get_pi_aux t2
+ | _ => [])
+ in
+ (* collect first all pi's in front of variables in t and then use distinct *)
+ (* to ensure that all pi's must have been the same, i.e. distinct returns *)
+ (* a singleton-list *)
+ (case (distinct (op =) (get_pi_aux t)) of
+ [pi] => pi
+ | [] => raise EQVT_FORM "No permutations found"
+ | _ => raise EQVT_FORM "All permutation should be the same")
+ end;
+
+(* Either adds a theorem (orig_thm) to or deletes one from the equivariance *)
+(* lemma list depending on flag. To be added the lemma has to satisfy a *)
+(* certain form. *)
+
+fun eqvt_add_del_aux flag orig_thm context =
+ let
+ val thy = Context.theory_of context
+ val thms_to_be_added = (case (prop_of orig_thm) of
+ (* case: eqvt-lemma is of the implicational form *)
+ (Const("==>", _) $ (Const ("Trueprop",_) $ hyp) $ (Const ("Trueprop",_) $ concl)) =>
+ let
+ val pi = get_pi concl thy
+ in
+ if (apply_pi hyp pi = concl)
+ then
+ (warning ("equivariance lemma of the relational form");
+ [orig_thm,
+ get_derived_thm (Context.proof_of context) hyp concl orig_thm pi])
+ else raise EQVT_FORM "Type Implication"
+ end
+ (* case: eqvt-lemma is of the equational form *)
+ | (Const (@{const_name "Trueprop"}, _) $ (Const (@{const_name "op ="}, _) $
+ (Const (@{const_name "permute"},typrm) $ Var (pi, _) $ lhs) $ rhs)) =>
+ (if (apply_pi lhs pi) = rhs
+ then [orig_thm]
+ else raise EQVT_FORM "Type Equality")
+ | _ => raise EQVT_FORM "Type unknown")
+ in
+ fold (fn thm => Data.map (flag thm)) thms_to_be_added context
+ end
+ handle EQVT_FORM s =>
+ error (Display.string_of_thm (Context.proof_of context) orig_thm ^
+ " does not comply with the form of an equivariance lemma (" ^ s ^").")
+
+
+val eqvt_add = Thm.declaration_attribute (eqvt_add_del_aux (Thm.add_thm));
+val eqvt_del = Thm.declaration_attribute (eqvt_add_del_aux (Thm.del_thm));
+
+val eqvt_force_add = Thm.declaration_attribute (Data.map o Thm.add_thm);
+val eqvt_force_del = Thm.declaration_attribute (Data.map o Thm.del_thm);
+
+val get_eqvt_thms = Context.Proof #> Data.get;
+
+val setup =
+ Attrib.setup @{binding eqvt} (Attrib.add_del eqvt_add eqvt_del)
+ "equivariance theorem declaration"
+ #> Attrib.setup @{binding eqvt_force} (Attrib.add_del eqvt_force_add eqvt_force_del)
+ "equivariance theorem declaration (without checking the form of the lemma)"
+ #> PureThy.add_thms_dynamic (Binding.name "eqvts", Data.get)
+
+
+end;