# HG changeset patch # User Cezary Kaliszyk # Date 1333084524 -7200 # Node ID 1da802bd2ab189f7085dd4145c77e79005484bef # Parent 4d01d1056e2262605883b2121e396d41ad8ff7c9 Correct Aux and proof sketch that it's same as alpha-equality, following Dan Synek's proof. diff -r 4d01d1056e22 -r 1da802bd2ab1 Nominal/Ex/AuxNoFCB.thy --- a/Nominal/Ex/AuxNoFCB.thy Thu Mar 29 10:37:41 2012 +0200 +++ b/Nominal/Ex/AuxNoFCB.thy Fri Mar 30 07:15:24 2012 +0200 @@ -7,8 +7,18 @@ | App "lam" "lam" | Lam x::"name" l::"lam" binds x in l ("Lam [_]. _" [100, 100] 100) +nominal_primrec lookup where + "lookup (n :: name) m [] \ (n = m)" +| "lookup n m ((hn, hm) # t) \ + (n, m) = (hn, hm) \ (n \ hn \ m \ hm \ lookup n m t)" + apply (simp add: eqvt_def lookup_graph_def) + apply (rule, perm_simp, rule, rule) + by pat_completeness auto + +termination (eqvt) by lexicographic_order + nominal_primrec lam2_rec where - "lam2_rec faa fll xs (Var n) (Var m) = (n = m \ (n, m) \ set xs)" + "lam2_rec faa fll xs (Var n) (Var m) = lookup n m xs" | "lam2_rec faa fll xs (Var n) (App l r) = False" | "lam2_rec faa fll xs (Var n) (Lam [x]. t) = False" | "lam2_rec faa fll xs (App l r) (Var n) = False" @@ -118,7 +128,7 @@ by (relation "measure (\(l, r, xs). size l + size r)") simp_all lemma aux_simps[simp]: - "aux (Var x) (Var y) xs = (x = y \ (x, y) \ set xs)" + "aux (Var x) (Var y) xs = lookup x y xs" "aux (App t1 t2) (App s1 s2) xs = (aux t1 s1 xs \ aux t2 s2 xs)" "aux (Var x) (App t1 t2) xs = False" "aux (Var x) (Lam [y].t) xs = False" @@ -212,6 +222,211 @@ apply lexicographic_order done +lemma foldr_eqvt[eqvt]: + "p \ foldr a b c = foldr (p \ a) (p \ b) (p \ c)" + apply (induct b) + apply simp_all + apply (perm_simp) + apply simp + done + +nominal_primrec + subst :: "lam \ name \ lam \ lam" ("_ [_ ::= _]" [90, 90, 90] 90) +where + "(Var x)[y ::= s] = (if x = y then s else (Var x))" +| "(App t1 t2)[y ::= s] = App (t1[y ::= s]) (t2[y ::= s])" +| "atom x \ (y, s) \ (Lam [x]. t)[y ::= s] = Lam [x].(t[y ::= s])" + unfolding eqvt_def subst_graph_def + apply (rule, perm_simp, rule) + apply(rule TrueI) + apply(auto) + apply(rule_tac y="a" and c="(aa, b)" in lam.strong_exhaust) + apply(blast)+ + apply(simp_all add: fresh_star_def fresh_Pair_elim) + apply (erule_tac c="(ya,sa)" in Abs_lst1_fcb2) + apply(simp_all add: Abs_fresh_iff) + apply(simp add: fresh_star_def fresh_Pair) + apply(simp add: eqvt_at_def atom_eqvt fresh_star_Pair perm_supp_eq) + apply(simp add: eqvt_at_def atom_eqvt fresh_star_Pair perm_supp_eq) +done + +termination (eqvt) by lexicographic_order + +nominal_primrec swapequal :: "lam \ lam \ (name \ name) list \ bool" where + "swapequal l r [] \ l = r" +| "atom x \ (l, r, hl, hr, t) \ + swapequal l r ((hl, hr) # t) \ swapequal ((hl \ x) \ l) ((hr \ x) \ r) t" + unfolding eqvt_def swapequal_graph_def + apply (rule, perm_simp, rule) + apply(rule TrueI) + apply (case_tac x) + apply (case_tac c) + apply metis + apply (case_tac aa) + apply (rename_tac l r lst h t hl hr) + apply (rule_tac x="(l, r, hl, hr, t)" and ?'a="name" in obtain_fresh) + apply simp + apply simp + apply simp + sorry + +termination (eqvt) by lexicographic_order + +lemma lookup_swapequal: "lookup n m xs = swapequal (Var n) (Var m) xs" + apply (induct xs arbitrary: m n) + apply simp + apply (case_tac a) + apply simp + apply (rule_tac x="(n, m, aa, b, xs)" and ?'a="name" in obtain_fresh) + apply (subst swapequal.simps) + apply (simp add: fresh_Pair lam.fresh fresh_Nil) + apply (case_tac "n = aa \ m = b") + apply simp + defer + apply (case_tac "n = aa") + apply (simp add: fresh_Pair_elim fresh_at_base) + defer + apply (simp add: fresh_Pair_elim fresh_at_base flip_def) + apply (case_tac "m = b") + apply simp + defer + apply simp + sorry + +(* +lemma lookup_property: + assumes "distinct (map fst xs @ map snd xs)" + shows "aux (Var n) (Var m) xs = swapequal (Var n) (Var m) xs" + using assms + apply (induct xs arbitrary: n m) + apply simp + apply simp + apply (case_tac a) + apply simp + apply (rule_tac x="(n, m, aa, b, xs)" and ?'a="name" in obtain_fresh) + apply (subst swapequal.simps) + apply (simp add: fresh_Pair lam.fresh fresh_Cons) + apply auto[1] + + apply (case_tac "n = aa \ m = b") + apply simp +proof - + have "lookup n m xs = (fold (\(x, y) t. if n = t then y else t) xs n = m)" + using assms + proof (induct xs, simp) + fix a b xs + assume d: "distinct (map fst xs @ map snd xs) \ + lookup n m xs = (fold (\(x\name, y\name) t\name. if n = t then y else t) xs n = m)" + assume "distinct (map fst (a # xs) @ map snd (a # xs))" + then have "lookup n m xs = (fold (\(x\name, y\name) t\name. if n = t then y else t) xs n = m)" + using d by simp + then show "lookup n m (a # xs) = + (fold (\(x\name, y\name) t\name. if n = t then y else t) (a # xs) n = m)" + proof (cases a) + case (Pair b c) + assume "lookup n m xs = (fold (\(x\name, y\name) t\name. if n = t then y else t) xs n = m)" "a = (b, c)" + then show "lookup n m (a # xs) = (fold (\(x\name, y\name) t\name. if n = t then y else t) (a # xs) n = m)" + apply simp + apply auto + sledgehammer + + apply - + apply (case_tac a) + apply auto + + + apply simp + apply (case_tac a) + apply simp + apply metis + also have "... = (Var (foldr (\(x, y) t. if n = t then y else t) xs n) = Var m)" by simp + also have "... = (foldr (\(x, y) t. subst t x (Var y)) xs (Var n) = Var m)" + apply (rule arg_cong) back + apply (induct xs) + apply simp + apply (case_tac a) + apply simp + apply auto + find_theorems "fold _ _ _ = fold _ _ _" + apply (induct xs) apply simp + apply simp + apply (case_tac a) + apply simp + apply (simp only: lookup.simps) + apply simp + apply clarify + apply (case_tac "n = aa") + apply (case_tac "m = ba") + apply simp + apply (induct_tac xs) + apply simp + apply simp + sorry*) + +lemma reord: " + a \ x \ a \ y \ b \ x \ b \ y \ + swapequal t s ((x, y) # (a, b) # xs) = swapequal t s ((a, b) # (x, y) # xs)" + sorry + +lemma need: + assumes "distinct xs \ atom x \ xs \ atom y \ xs" + shows "swapequal (Lam [x]. t) (Lam [y]. s) xs = swapequal t s ((x, y) # xs)" + using assms + apply (induct xs arbitrary: t s x y) + apply (rule_tac x="(x, y, t, s)" and ?'a="name" in obtain_fresh) + apply (simp add: fresh_Pair_elim fresh_Nil) + apply (subst swapequal.simps) + apply (simp add: fresh_Pair fresh_Nil) + apply auto[1] + apply simp + apply (subgoal_tac "[[atom x]]lst. t = [[atom a]]lst. ((x \ a) \ t)") + apply (subgoal_tac "[[atom y]]lst. s = [[atom a]]lst. ((y \ a) \ s)") + apply simp + apply (simp add: Abs1_eq_iff) + apply (auto simp add: Abs1_eq_iff flip_def fresh_at_base)[1] + apply (smt atom_eqvt eq_eqvt flip_at_simps(2) flip_def fresh_eqvt) + apply (simp add: Abs1_eq_iff) + apply (auto simp add: Abs1_eq_iff flip_def fresh_at_base)[1] + apply (smt atom_eqvt eq_eqvt flip_at_simps(2) flip_def fresh_eqvt) + apply clarify + apply (simp add: fresh_Cons fresh_Pair fresh_at_base) + apply clarify + apply (subst reord) + apply auto[4] + apply (rule_tac x="(x, y, t, s, a, b, xs)" and ?'a="name" in obtain_fresh) + apply (rename_tac f) + apply (subst (2) swapequal.simps) + apply (simp add: lam.fresh fresh_Pair fresh_at_base fresh_Cons) + apply auto[1] + apply (subst swapequal.simps) + apply (simp add: lam.fresh fresh_Pair fresh_at_base fresh_Cons) + apply auto[1] + apply simp + apply (simp add: flip_def) + apply (simp add: fresh_Pair_elim fresh_at_base) + done + +lemma aux_alphaish: + assumes "distinct (map fst xs @ map snd xs)" + shows "aux x y xs \ swapequal x y xs" + using assms + apply (induct xs x y rule: aux_induct) + apply (simp add: lookup_swapequal) + prefer 8 + apply (simp add: fresh_Pair_elim lam.fresh fresh_at_base) + apply (elim conjE) + apply (simp add: fresh_Pair_elim lam.fresh fresh_at_base) + apply (subgoal_tac "x \ fst ` set xs \ + x \ snd ` set xs \ y \ snd ` set xs \ y \ fst ` set xs") + apply (simp) + apply (subst need) + apply auto[1] + sorry + +lemma + "aux x y [] \ (x = y)" + by (simp_all add: supp_Nil aux_alphaish) + end diff -r 4d01d1056e22 -r 1da802bd2ab1 Nominal/Ex/SubstNoFcb.thy --- a/Nominal/Ex/SubstNoFcb.thy Thu Mar 29 10:37:41 2012 +0200 +++ b/Nominal/Ex/SubstNoFcb.thy Fri Mar 30 07:15:24 2012 +0200 @@ -65,7 +65,7 @@ shows "\a \ x; a \ y; a \ z\ \ a \ f x y z" using fresh_fun_eqvt_app[OF e] fresh_fun_app by (metis (lifting, full_types)) -lemma +lemma substr_simps: "substr (Var x) y s = (if x = y then s else (Var x))" "substr (App t1 t2) y s = App (substr t1 y s) (substr t2 y s)" "atom x \ (y, s) \ substr (Lam [x]. t) y s = Lam [x]. (substr t y s)"