diff -r cffc5d78ab7f -r cad5f3851569 Nominal/Test.thy --- a/Nominal/Test.thy Thu Mar 04 15:31:21 2010 +0100 +++ b/Nominal/Test.thy Thu Mar 04 15:31:34 2010 +0100 @@ -1,10 +1,10 @@ theory Test -imports "Parser" +imports "Parser" "../Attic/Prove" begin text {* weirdo example from Peter Sewell's bestiary *} -nominal_datatype weird = +(*nominal_datatype weird = WBind x::"name" y::"name" p1::"weird" p2::"weird" p3::"weird" bind x in p1, bind x in p2, bind y in p2, bind y in p3 | WV "name" @@ -14,6 +14,79 @@ thm alpha_weird_raw.intros[no_vars] thm fv_weird_raw.simps[no_vars] +thm eqvts + +local_setup {* (fn ctxt => snd (Local_Theory.note ((@{binding weird_inj}, []), (build_alpha_inj @{thms alpha_weird_raw.intros} @{thms weird_raw.distinct weird_raw.inject} @{thms alpha_weird_raw.cases} ctxt)) ctxt)) *} +thm weird_inj + +local_setup {* +(fn ctxt => snd (Local_Theory.note ((@{binding alpha_eqvt}, []), +build_alpha_eqvts [@{term alpha_weird_raw}] [@{term "permute :: perm \ weird_raw \ weird_raw"}] @{thms permute_weird_raw.simps weird_inj} @{thm alpha_weird_raw.induct} ctxt) ctxt)) *} + +(*prove {* (snd o snd) (build_alpha_refl_gl [@{term alpha_weird_raw}] ("x","y","z")) *} + +apply (tactic {* transp_tac @{context} @{thm alpha_weird_raw.induct} @{thms weird_inj} @{thms weird_raw.inject} @{thms weird_raw.distinct} @{thms alpha_weird_raw.cases} @{thms alpha_eqvt} 1 *}) +*) +lemma "alpha_weird_raw x y \ (\z. alpha_weird_raw y z \ alpha_weird_raw x z)" +apply (rule impI) +apply (erule alpha_weird_raw.induct) +apply (simp_all add: weird_inj) +defer +apply (rule allI) +apply (rule impI) +apply (erule alpha_weird_raw.cases) +apply (simp_all add: weird_inj) +apply (rule allI) +apply (rule impI) +apply (erule alpha_weird_raw.cases) +apply (simp_all add: weird_inj) +apply (erule conjE)+ +apply (erule exE)+ +apply (erule conjE)+ +apply (erule exE)+ +apply (rule conjI) +apply (rule_tac x="pica + pic" in exI) +apply (erule alpha_gen_compose_trans) +apply assumption +apply (simp add: alpha_eqvt) +apply (rule_tac x="pia + pib" in exI) +apply (rule_tac x="piaa + piba" in exI) +apply (rule conjI) +apply (erule alpha_gen_compose_trans) +apply assumption +apply (simp add: alpha_eqvt) +apply (rule conjI) +defer +apply (rule_tac x="pid + pi" in exI) +apply (erule alpha_gen_compose_trans) +apply assumption +apply (simp add: alpha_eqvt) +sorry + +lemma "alpha_weird_raw x y \ alpha_weird_raw y x" +apply (erule alpha_weird_raw.induct) +apply (simp_all add: weird_inj) +apply (erule conjE)+ +apply (erule exE)+ +apply (erule conjE)+ +apply (erule exE)+ +apply (rule conjI) +apply (rule_tac x="- pic" in exI) +apply (erule alpha_gen_compose_sym) +apply (simp_all add: alpha_eqvt) +apply (rule_tac x="- pia" in exI) +apply (rule_tac x="- pib" in exI) +apply (simp add: minus_add[symmetric]) +apply (rule conjI) +apply (erule alpha_gen_compose_sym) +apply (simp_all add: alpha_eqvt) +apply (rule conjI) +apply (simp add: supp_minus_perm Int_commute) +apply (rule_tac x="- pi" in exI) +apply (erule alpha_gen_compose_sym) +apply (simp_all add: alpha_eqvt) +done + abbreviation "WBind \ WBind_raw" abbreviation "WP \ WP_raw" @@ -45,7 +118,7 @@ apply(simp add: flip_def fresh_def supp_swap) apply(rule alpha_weird_raw.intros) apply(simp add: alpha_weird_raw.intros(2)) -done +done*) text {* example 1 *} @@ -71,9 +144,10 @@ thm permute_lam_raw_permute_bp_raw.simps thm alpha_lam_raw_alpha_bp_raw.intros[no_vars] thm fv_lam_raw_fv_bp_raw.simps[no_vars] -thm eqvts - -print_theorems +thm lam_bp_induct +thm lam_bp_perm +thm lam_bp_fv +thm lam_bp_bn text {* example 2 *} @@ -97,6 +171,10 @@ thm alpha_trm'_raw_alpha_pat'_raw.intros[no_vars] thm fv_trm'_raw_fv_pat'_raw.simps[no_vars] thm f_raw.simps +thm trm'_pat'_induct +thm trm'_pat'_perm +thm trm'_pat'_fv +thm trm'_pat'_bn nominal_datatype trm0 = Var0 "name" @@ -115,6 +193,10 @@ | "f0 (PD0 p1 p2) = (f0 p1) \ (f0 p2)" thm f0_raw.simps +thm trm0_pat0_induct +thm trm0_pat0_perm +thm trm0_pat0_fv +thm trm0_pat0_bn text {* example type schemes *} @@ -214,6 +296,7 @@ (* example 6 from Terms.thy *) +(* BV is not respectful, needs to fail nominal_datatype trm6 = Vr6 "name" | Lm6 x::"name" t::"trm6" bind x in t @@ -223,10 +306,11 @@ where "bv6 (Vr6 n) = {}" | "bv6 (Lm6 n t) = {atom n} \ bv6 t" -| "bv6 (Lt6 l r) = bv6 l \ bv6 r" +| "bv6 (Lt6 l r) = bv6 l \ bv6 r" *) (* example 7 from Terms.thy *) +(* BV is not respectful, needs to fail nominal_datatype trm7 = Vr7 "name" | Lm7 l::"name" r::"trm7" bind l in r @@ -236,7 +320,7 @@ where "bv7 (Vr7 n) = {atom n}" | "bv7 (Lm7 n t) = bv7 t - {atom n}" -| "bv7 (Lt7 l r) = bv7 l \ bv7 r" +| "bv7 (Lt7 l r) = bv7 l \ bv7 r" *) (* example 8 from Terms.thy *) @@ -254,6 +338,7 @@ (* example 9 from Terms.thy *) +(* BV is not respectful, needs to fail nominal_datatype lam9 = Var9 "name" | Lam9 n::"name" l::"lam9" bind n in l @@ -263,13 +348,13 @@ bv9 where "bv9 (Var9 x) = {}" -| "bv9 (Lam9 x b) = {atom x}" +| "bv9 (Lam9 x b) = {atom x}" *) (* example from my PHD *) atom_decl coname -nominal_datatype phd = +(*nominal_datatype phd = Ax "name" "coname" | Cut n::"coname" t1::"phd" c::"coname" t2::"phd" bind n in t1, bind c in t2 | AndR c1::"coname" t1::"phd" c2::"coname" t2::"phd" "coname" bind c1 in t1, bind c2 in t2 @@ -278,10 +363,9 @@ | ImpL c::"coname" t1::"phd" n::"name" t2::"phd" "name" bind c in t1, bind n in t2 | ImpR c::"coname" n::"name" t::"phd" "coname" bind n in t, bind c in t -(* PROBLEM?: why does it create for the Cut AndR ImpL cases -two permutations, but only one is used *) thm alpha_phd_raw.intros[no_vars] thm fv_phd_raw.simps[no_vars] +*) (* example form Leroy 96 about modules; OTT *) @@ -320,9 +404,9 @@ and trmtrm = Tref1 "name" | Tref2 "path" "name" -| Lam v::"name" "tyty" M::"trmtrm" bind v in M -| App "trmtrm" "trmtrm" -| Let "body" "trmtrm" +| Lam' v::"name" "tyty" M::"trmtrm" bind v in M +| App' "trmtrm" "trmtrm" +| Let' "body" "trmtrm" binder cbinders :: "defn \ atom set" and Cbinders :: "spec \ atom set" @@ -337,6 +421,7 @@ | "Cbinders (SVal v T) = {atom v}" (* core haskell *) +print_theorems atom_decl var atom_decl tvar @@ -399,10 +484,10 @@ (* example 3 from Peter Sewell's bestiary *) nominal_datatype exp = - Var "name" -| App "exp" "exp" -| Lam x::"name" e::"exp" bind x in e -| Let x::"name" p::"pat" e1::"exp" e2::"exp" bind x in e2, bind "bp p" in e1 + VarP "name" +| AppP "exp" "exp" +| LamP x::"name" e::"exp" bind x in e +| LetP x::"name" p::"pat" e1::"exp" e2::"exp" bind x in e2, bind "bp p" in e1 and pat = PVar "name" | PUnit @@ -414,24 +499,25 @@ | "bp (PUnit) = {}" | "bp (PPair p1 p2) = bp p1 \ bp p2" +thm quot_respect (* example 6 from Peter Sewell's bestiary *) -nominal_datatype exp6 = +(*nominal_datatype exp6 = EVar name | EPair exp6 exp6 | ELetRec x::name p::pat6 e1::exp6 e2::exp6 bind x in e1, bind x in e2, bind "bp6 p" in e1 and pat6 = - PVar name -| PUnit -| PPair pat6 pat6 + PVar' name +| PUnit' +| PPair' pat6 pat6 binder bp6 :: "pat6 \ atom set" where - "bp6 (PVar x) = {atom x}" -| "bp6 (PUnit) = {}" -| "bp6 (PPair p1 p2) = bp6 p1 \ bp6 p2" + "bp6 (PVar' x) = {atom x}" +| "bp6 (PUnit') = {}" +| "bp6 (PPair' p1 p2) = bp6 p1 \ bp6 p2"*) (* example 7 from Peter Sewell's bestiary *) -nominal_datatype exp7 = +(*nominal_datatype exp7 = EVar name | EUnit | EPair exp7 exp7 @@ -447,10 +533,10 @@ where "b7 (Assign x e) = {atom x}" | "b7s (Single a) = b7 a" -| "b7s (More a as) = (b7 a) \ (b7s as)" +| "b7s (More a as) = (b7 a) \ (b7s as)"*) (* example 8 from Peter Sewell's bestiary *) -nominal_datatype exp8 = +(*nominal_datatype exp8 = EVar name | EUnit | EPair exp8 exp8 @@ -484,7 +570,7 @@ | "b_fnclauses (S fc) = (b_fnclause fc)" | "b_fnclauses (ORs fc fcs) = (b_fnclause fc) \ (b_fnclauses fcs)" | "b_lrb8 (Clause fcs) = (b_fnclauses fcs)" -| "b_fnclause (K x pat exp8) = {atom x}" +| "b_fnclause (K x pat exp8) = {atom x}"*)