diff -r 55b49de0c2c7 -r 04dad9b0136d Nominal/Abs_res.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Nominal/Abs_res.thy Sat Mar 13 13:49:15 2010 +0100 @@ -0,0 +1,723 @@ +theory Abs_res +imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "../Quotient" "../Quotient_Product" +begin + +fun + alpha_gen +where + alpha_gen[simp del]: + "alpha_gen (bs, x) R f pi (cs, y) \ f x - bs = f y - cs \ (f x - bs) \* pi \ R (pi \ x) y" + +notation + alpha_gen ("_ \gen _ _ _ _" [100, 100, 100, 100, 100] 100) + +lemma [mono]: "R1 \ R2 \ alpha_gen x R1 \ alpha_gen x R2" + by (cases x) (auto simp add: le_fun_def le_bool_def alpha_gen.simps) + +lemma alpha_gen_refl: + assumes a: "R x x" + shows "(bs, x) \gen R f 0 (bs, x)" + using a by (simp add: alpha_gen fresh_star_def fresh_zero_perm) + +lemma alpha_gen_sym: + assumes a: "(bs, x) \gen R f p (cs, y)" + and b: "R (p \ x) y \ R (- p \ y) x" + shows "(cs, y) \gen R f (- p) (bs, x)" + using a b by (simp add: alpha_gen fresh_star_def fresh_def supp_minus_perm) + +lemma alpha_gen_trans: + assumes a: "(bs, x) \gen R f p1 (cs, y)" + and b: "(cs, y) \gen R f p2 (ds, z)" + and c: "\R (p1 \ x) y; R (p2 \ y) z\ \ R ((p2 + p1) \ x) z" + shows "(bs, x) \gen R f (p2 + p1) (ds, z)" + using a b c using supp_plus_perm + apply(simp add: alpha_gen fresh_star_def fresh_def) + apply(blast) + done + +lemma alpha_gen_eqvt: + assumes a: "(bs, x) \gen R f q (cs, y)" + and b: "R (q \ x) y \ R (p \ (q \ x)) (p \ y)" + and c: "p \ (f x) = f (p \ x)" + and d: "p \ (f y) = f (p \ y)" + shows "(p \ bs, p \ x) \gen R f (p \ q) (p \ cs, p \ y)" + using a b + apply(simp add: alpha_gen c[symmetric] d[symmetric] Diff_eqvt[symmetric]) + apply(simp add: permute_eqvt[symmetric]) + apply(simp add: fresh_star_permute_iff) + apply(clarsimp) + done + +lemma alpha_gen_compose_sym: + fixes pi + assumes b: "(aa, t) \gen (\x1 x2. R x1 x2 \ R x2 x1) f pi (ab, s)" + and a: "\pi t s. (R t s \ R (pi \ t) (pi \ s))" + shows "(ab, s) \gen R f (- pi) (aa, t)" + using b apply - + apply(simp add: alpha_gen.simps) + apply(erule conjE)+ + apply(rule conjI) + apply(simp add: fresh_star_def fresh_minus_perm) + apply(subgoal_tac "R (- pi \ s) ((- pi) \ (pi \ t))") + apply simp + apply(rule a) + apply assumption + done + +lemma alpha_gen_compose_trans: + fixes pi pia + assumes b: "(aa, t) \gen (\x1 x2. R x1 x2 \ (\x. R x2 x \ R x1 x)) f pi (ab, ta)" + and c: "(ab, ta) \gen R f pia (ac, sa)" + and a: "\pi t s. (R t s \ R (pi \ t) (pi \ s))" + shows "(aa, t) \gen R f (pia + pi) (ac, sa)" + using b c apply - + apply(simp add: alpha_gen.simps) + apply(erule conjE)+ + apply(simp add: fresh_star_plus) + apply(drule_tac x="- pia \ sa" in spec) + apply(drule mp) + apply(rotate_tac 4) + apply(drule_tac pi="- pia" in a) + apply(simp) + apply(rotate_tac 6) + apply(drule_tac pi="pia" in a) + apply(simp) + done + +lemma alpha_gen_compose_eqvt: + fixes pia + assumes b: "(g d, t) \gen (\x1 x2. R x1 x2 \ R (pi \ x1) (pi \ x2)) f pia (g e, s)" + and c: "\y. pi \ (g y) = g (pi \ y)" + and a: "\x. pi \ (f x) = f (pi \ x)" + shows "(g (pi \ d), pi \ t) \gen R f (pi \ pia) (g (pi \ e), pi \ s)" + using b + apply - + apply(simp add: alpha_gen.simps) + apply(erule conjE)+ + apply(rule conjI) + apply(rule_tac ?p1="- pi" in permute_eq_iff[THEN iffD1]) + apply(simp add: a[symmetric] atom_eqvt Diff_eqvt insert_eqvt set_eqvt empty_eqvt c[symmetric]) + apply(rule conjI) + apply(rule_tac ?p1="- pi" in fresh_star_permute_iff[THEN iffD1]) + apply(simp add: a[symmetric] atom_eqvt Diff_eqvt insert_eqvt set_eqvt empty_eqvt c[symmetric]) + apply(subst permute_eqvt[symmetric]) + apply(simp) + done + +fun + alpha_abs +where + "alpha_abs (bs, x) (cs, y) = (\p. (bs, x) \gen (op=) supp p (cs, y))" + +notation + alpha_abs ("_ \abs _") + +lemma alpha_abs_swap: + assumes a1: "a \ (supp x) - bs" + and a2: "b \ (supp x) - bs" + shows "(bs, x) \abs ((a \ b) \ bs, (a \ b) \ x)" + apply(simp) + apply(rule_tac x="(a \ b)" in exI) + apply(simp add: alpha_gen) + apply(simp add: supp_eqvt[symmetric] Diff_eqvt[symmetric]) + apply(simp add: swap_set_not_in[OF a1 a2]) + apply(subgoal_tac "supp (a \ b) \ {a, b}") + using a1 a2 + apply(simp add: fresh_star_def fresh_def) + apply(blast) + apply(simp add: supp_swap) + done + +lemma alpha_gen_swap_fun: + assumes f_eqvt: "\pi. (pi \ (f x)) = f (pi \ x)" + assumes a1: "a \ (f x) - bs" + and a2: "b \ (f x) - bs" + shows "\pi. (bs, x) \gen (op=) f pi ((a \ b) \ bs, (a \ b) \ x)" + apply(rule_tac x="(a \ b)" in exI) + apply(simp add: alpha_gen) + apply(simp add: f_eqvt[symmetric] Diff_eqvt[symmetric]) + apply(simp add: swap_set_not_in[OF a1 a2]) + apply(subgoal_tac "supp (a \ b) \ {a, b}") + using a1 a2 + apply(simp add: fresh_star_def fresh_def) + apply(blast) + apply(simp add: supp_swap) + done + + +fun + supp_abs_fun +where + "supp_abs_fun (bs, x) = (supp x) - bs" + +lemma supp_abs_fun_lemma: + assumes a: "x \abs y" + shows "supp_abs_fun x = supp_abs_fun y" + using a + apply(induct rule: alpha_abs.induct) + apply(simp add: alpha_gen) + done + +quotient_type 'a abs = "(atom set \ 'a::pt)" / "alpha_abs" + apply(rule equivpI) + unfolding reflp_def symp_def transp_def + apply(simp_all) + (* refl *) + apply(clarify) + apply(rule exI) + apply(rule alpha_gen_refl) + apply(simp) + (* symm *) + apply(clarify) + apply(rule exI) + apply(rule alpha_gen_sym) + apply(assumption) + apply(clarsimp) + (* trans *) + apply(clarify) + apply(rule exI) + apply(rule alpha_gen_trans) + apply(assumption) + apply(assumption) + apply(simp) + done + +quotient_definition + "Abs::atom set \ ('a::pt) \ 'a abs" +is + "Pair::atom set \ ('a::pt) \ (atom set \ 'a)" + +lemma [quot_respect]: + shows "((op =) ===> (op =) ===> alpha_abs) Pair Pair" + apply(clarsimp) + apply(rule exI) + apply(rule alpha_gen_refl) + apply(simp) + done + +lemma [quot_respect]: + shows "((op =) ===> alpha_abs ===> alpha_abs) permute permute" + apply(clarsimp) + apply(rule exI) + apply(rule alpha_gen_eqvt) + apply(assumption) + apply(simp_all add: supp_eqvt) + done + +lemma [quot_respect]: + shows "(alpha_abs ===> (op =)) supp_abs_fun supp_abs_fun" + apply(simp add: supp_abs_fun_lemma) + done + +lemma abs_induct: + "\\as (x::'a::pt). P (Abs as x)\ \ P t" + apply(lifting prod.induct[where 'a="atom set" and 'b="'a"]) + done + +(* TEST case *) +lemmas abs_induct2 = prod.induct[where 'a="atom set" and 'b="'a::pt", quot_lifted] +thm abs_induct abs_induct2 + +instantiation abs :: (pt) pt +begin + +quotient_definition + "permute_abs::perm \ ('a::pt abs) \ 'a abs" +is + "permute:: perm \ (atom set \ 'a::pt) \ (atom set \ 'a::pt)" + +lemma permute_ABS [simp]: + fixes x::"'a::pt" (* ??? has to be 'a \ 'b does not work *) + shows "(p \ (Abs as x)) = Abs (p \ as) (p \ x)" + by (lifting permute_prod.simps(1)[where 'a="atom set" and 'b="'a"]) + +instance + apply(default) + apply(induct_tac [!] x rule: abs_induct) + apply(simp_all) + done + +end + +quotient_definition + "supp_Abs_fun :: ('a::pt) abs \ atom \ bool" +is + "supp_abs_fun" + +lemma supp_Abs_fun_simp: + shows "supp_Abs_fun (Abs bs x) = (supp x) - bs" + by (lifting supp_abs_fun.simps(1)) + +lemma supp_Abs_fun_eqvt [eqvt]: + shows "(p \ supp_Abs_fun x) = supp_Abs_fun (p \ x)" + apply(induct_tac x rule: abs_induct) + apply(simp add: supp_Abs_fun_simp supp_eqvt Diff_eqvt) + done + +lemma supp_Abs_fun_fresh: + shows "a \ Abs bs x \ a \ supp_Abs_fun (Abs bs x)" + apply(rule fresh_fun_eqvt_app) + apply(simp add: eqvts_raw) + apply(simp) + done + +lemma Abs_swap: + assumes a1: "a \ (supp x) - bs" + and a2: "b \ (supp x) - bs" + shows "(Abs bs x) = (Abs ((a \ b) \ bs) ((a \ b) \ x))" + using a1 a2 by (lifting alpha_abs_swap) + +lemma Abs_supports: + shows "((supp x) - as) supports (Abs as x)" + unfolding supports_def + apply(clarify) + apply(simp (no_asm)) + apply(subst Abs_swap[symmetric]) + apply(simp_all) + done + +lemma supp_Abs_subset1: + fixes x::"'a::fs" + shows "(supp x) - as \ supp (Abs as x)" + apply(simp add: supp_conv_fresh) + apply(auto) + apply(drule_tac supp_Abs_fun_fresh) + apply(simp only: supp_Abs_fun_simp) + apply(simp add: fresh_def) + apply(simp add: supp_finite_atom_set finite_supp) + done + +lemma supp_Abs_subset2: + fixes x::"'a::fs" + shows "supp (Abs as x) \ (supp x) - as" + apply(rule supp_is_subset) + apply(rule Abs_supports) + apply(simp add: finite_supp) + done + +lemma supp_Abs: + fixes x::"'a::fs" + shows "supp (Abs as x) = (supp x) - as" + apply(rule_tac subset_antisym) + apply(rule supp_Abs_subset2) + apply(rule supp_Abs_subset1) + done + +instance abs :: (fs) fs + apply(default) + apply(induct_tac x rule: abs_induct) + apply(simp add: supp_Abs) + apply(simp add: finite_supp) + done + +lemma Abs_fresh_iff: + fixes x::"'a::fs" + shows "a \ Abs bs x \ a \ bs \ (a \ bs \ a \ x)" + apply(simp add: fresh_def) + apply(simp add: supp_Abs) + apply(auto) + done + +lemma Abs_eq_iff: + shows "Abs bs x = Abs cs y \ (\p. (bs, x) \gen (op =) supp p (cs, y))" + by (lifting alpha_abs.simps(1)) + + + +(* + below is a construction site for showing that in the + single-binder case, the old and new alpha equivalence + coincide +*) + +fun + alpha1 +where + "alpha1 (a, x) (b, y) \ (a = b \ x = y) \ (a \ b \ x = (a \ b) \ y \ a \ y)" + +notation + alpha1 ("_ \abs1 _") + +fun + alpha2 +where + "alpha2 (a, x) (b, y) \ (\c. c \ (a,b,x,y) \ ((c \ a) \ x) = ((c \ b) \ y))" + +notation + alpha2 ("_ \abs2 _") + +lemma qq: + fixes S::"atom set" + assumes a: "supp p \ S = {}" + shows "p \ S = S" +using a +apply(simp add: supp_perm permute_set_eq) +apply(auto) +apply(simp only: disjoint_iff_not_equal) +apply(simp) +apply (metis permute_atom_def_raw) +apply(rule_tac x="(- p) \ x" in exI) +apply(simp) +apply(simp only: disjoint_iff_not_equal) +apply(simp) +apply(metis permute_minus_cancel) +done + +lemma alpha_old_new: + assumes a: "(a, x) \abs1 (b, y)" "sort_of a = sort_of b" + shows "({a}, x) \abs ({b}, y)" +using a +apply(simp) +apply(erule disjE) +apply(simp) +apply(rule exI) +apply(rule alpha_gen_refl) +apply(simp) +apply(rule_tac x="(a \ b)" in exI) +apply(simp add: alpha_gen) +apply(simp add: fresh_def) +apply(rule conjI) +apply(rule_tac ?p1="(a \ b)" in permute_eq_iff[THEN iffD1]) +apply(rule trans) +apply(simp add: Diff_eqvt supp_eqvt) +apply(subst swap_set_not_in) +back +apply(simp) +apply(simp) +apply(simp add: permute_set_eq) +apply(rule_tac ?p1="(a \ b)" in fresh_star_permute_iff[THEN iffD1]) +apply(simp add: permute_self) +apply(simp add: Diff_eqvt supp_eqvt) +apply(simp add: permute_set_eq) +apply(subgoal_tac "supp (a \ b) \ {a, b}") +apply(simp add: fresh_star_def fresh_def) +apply(blast) +apply(simp add: supp_swap) +done + +lemma perm_zero: + assumes a: "\x::atom. p \ x = x" + shows "p = 0" +using a +by (simp add: expand_perm_eq) + +fun + add_perm +where + "add_perm [] = 0" +| "add_perm ((a, b) # xs) = (a \ b) + add_perm xs" + +fun + elem_perm +where + "elem_perm [] = {}" +| "elem_perm ((a, b) # xs) = {a, b} \ elem_perm xs" + + +lemma add_perm_apend: + shows "add_perm (xs @ ys) = add_perm xs + add_perm ys" +apply(induct xs arbitrary: ys) +apply(auto simp add: add_assoc) +done + +lemma perm_list_exists: + fixes p::perm + shows "\xs. p = add_perm xs \ supp xs \ supp p" +apply(induct p taking: "\p::perm. card (supp p)" rule: measure_induct) +apply(rename_tac p) +apply(case_tac "supp p = {}") +apply(simp) +apply(simp add: supp_perm) +apply(drule perm_zero) +apply(simp) +apply(rule_tac x="[]" in exI) +apply(simp add: supp_Nil) +apply(subgoal_tac "\x. x \ supp p") +defer +apply(auto)[1] +apply(erule exE) +apply(drule_tac x="p + (((- p) \ x) \ x)" in spec) +apply(drule mp) +defer +apply(erule exE) +apply(rule_tac x="xs @ [((- p) \ x, x)]" in exI) +apply(simp add: add_perm_apend) +apply(erule conjE) +apply(drule sym) +apply(simp) +apply(simp add: expand_perm_eq) +apply(simp add: supp_append) +apply(simp add: supp_perm supp_Cons supp_Nil supp_Pair supp_atom) +apply(rule conjI) +prefer 2 +apply(auto)[1] +apply (metis left_minus minus_unique permute_atom_def_raw permute_minus_cancel(2)) +defer +apply(rule psubset_card_mono) +apply(simp add: finite_supp) +apply(rule psubsetI) +defer +apply(subgoal_tac "x \ supp (p + (- p \ x \ x))") +apply(blast) +apply(simp add: supp_perm) +defer +apply(auto simp add: supp_perm)[1] +apply(case_tac "x = xa") +apply(simp) +apply(case_tac "((- p) \ x) = xa") +apply(simp) +apply(case_tac "sort_of xa = sort_of x") +apply(simp) +apply(auto)[1] +apply(simp) +apply(simp) +apply(subgoal_tac "{a. p \ (- p \ x \ x) \ a \ a} \ {a. p \ a \ a}") +apply(blast) +apply(auto simp add: supp_perm)[1] +apply(case_tac "x = xa") +apply(simp) +apply(case_tac "((- p) \ x) = xa") +apply(simp) +apply(case_tac "sort_of xa = sort_of x") +apply(simp) +apply(auto)[1] +apply(simp) +apply(simp) +done + +lemma tt0: + fixes p::perm + shows "(supp x) \* p \ \a \ supp p. a \ x" +apply(auto simp add: fresh_star_def supp_perm fresh_def) +done + +lemma uu0: + shows "(\a \ elem_perm xs. a \ x) \ (add_perm xs \ x) = x" +apply(induct xs rule: add_perm.induct) +apply(simp) +apply(simp add: swap_fresh_fresh) +done + +lemma yy0: + fixes xs::"(atom \ atom) list" + shows "supp xs = elem_perm xs" +apply(induct xs rule: elem_perm.induct) +apply(auto simp add: supp_Nil supp_Cons supp_Pair supp_atom) +done + +lemma tt1: + shows "(supp x) \* p \ p \ x = x" +apply(drule tt0) +apply(subgoal_tac "\xs. p = add_perm xs \ supp xs \ supp p") +prefer 2 +apply(rule perm_list_exists) +apply(erule exE) +apply(simp only: yy0) +apply(rule uu0) +apply(auto) +done + + +lemma perm_induct_test: + fixes P :: "perm => bool" + assumes fin: "finite (supp p)" + assumes zero: "P 0" + assumes swap: "\a b. \sort_of a = sort_of b; a \ b\ \ P (a \ b)" + assumes plus: "\p1 p2. \supp p1 \ supp p2 = {}; P p1; P p2\ \ P (p1 + p2)" + shows "P p" +using fin +apply(induct F\"supp p" arbitrary: p rule: finite_induct) +apply(simp add: supp_perm) +apply(drule perm_zero) +apply(simp add: zero) +apply(rotate_tac 3) +oops +lemma tt: + "(supp x) \* p \ p \ x = x" +oops + +lemma yy: + assumes "S1 - {x} = S2 - {x}" "x \ S1" "x \ S2" + shows "S1 = S2" +using assms +apply (metis insert_Diff_single insert_absorb) +done + +lemma permute_boolI: + fixes P::"bool" + shows "p \ P \ P" +apply(simp add: permute_bool_def) +done + +lemma permute_boolE: + fixes P::"bool" + shows "P \ p \ P" +apply(simp add: permute_bool_def) +done + +lemma kk: + assumes a: "p \ x = y" + shows "\a \ supp x. (p \ a) \ supp y" +using a +apply(auto) +apply(rule_tac p="- p" in permute_boolI) +apply(simp add: mem_eqvt supp_eqvt) +done + +lemma ww: + assumes "a \ supp x" "b \ supp x" "a \ b" "sort_of a = sort_of b" + shows "((a \ b) \ x) \ x" +apply(subgoal_tac "(supp x) supports x") +apply(simp add: supports_def) +using assms +apply - +apply(drule_tac x="a" in spec) +defer +apply(rule supp_supports) +apply(auto) +apply(rotate_tac 1) +apply(drule_tac p="(a \ b)" in permute_boolE) +apply(simp add: mem_eqvt supp_eqvt) +done + +lemma alpha_abs_sym: + assumes a: "({a}, x) \abs ({b}, y)" + shows "({b}, y) \abs ({a}, x)" +using a +apply(simp) +apply(erule exE) +apply(rule_tac x="- p" in exI) +apply(simp add: alpha_gen) +apply(simp add: fresh_star_def fresh_minus_perm) +apply (metis permute_minus_cancel(2)) +done + +lemma alpha_abs_trans: + assumes a: "({a1}, x1) \abs ({a2}, x2)" + assumes b: "({a2}, x2) \abs ({a3}, x3)" + shows "({a1}, x1) \abs ({a3}, x3)" +using a b +apply(simp) +apply(erule exE)+ +apply(rule_tac x="pa + p" in exI) +apply(simp add: alpha_gen) +apply(simp add: fresh_star_def fresh_plus_perm) +done + +lemma alpha_equal: + assumes a: "({a}, x) \abs ({a}, y)" + shows "(a, x) \abs1 (a, y)" +using a +apply(simp) +apply(erule exE) +apply(simp add: alpha_gen) +apply(erule conjE)+ +apply(case_tac "a \ supp x") +apply(simp) +apply(subgoal_tac "supp x \* p") +apply(drule tt1) +apply(simp) +apply(simp) +apply(simp) +apply(case_tac "a \ supp y") +apply(simp) +apply(drule tt1) +apply(clarify) +apply(simp (no_asm_use)) +apply(simp) +apply(simp) +apply(drule yy) +apply(simp) +apply(simp) +apply(simp) +apply(case_tac "a \ p") +apply(subgoal_tac "supp y \* p") +apply(drule tt1) +apply(clarify) +apply(simp (no_asm_use)) +apply(metis) +apply(auto simp add: fresh_star_def)[1] +apply(frule_tac kk) +apply(drule_tac x="a" in bspec) +apply(simp) +apply(simp add: fresh_def) +apply(simp add: supp_perm) +apply(subgoal_tac "((p \ a) \ p)") +apply(simp add: fresh_def supp_perm) +apply(simp add: fresh_star_def) +done + +lemma alpha_unequal: + assumes a: "({a}, x) \abs ({b}, y)" "sort_of a = sort_of b" "a \ b" + shows "(a, x) \abs1 (b, y)" +using a +apply - +apply(subgoal_tac "a \ supp x - {a}") +apply(subgoal_tac "b \ supp x - {a}") +defer +apply(simp add: alpha_gen) +apply(simp) +apply(drule_tac alpha_abs_swap) +apply(assumption) +apply(simp only: insert_eqvt empty_eqvt swap_atom_simps) +apply(drule alpha_abs_sym) +apply(rotate_tac 4) +apply(drule_tac alpha_abs_trans) +apply(assumption) +apply(drule alpha_equal) +apply(simp) +apply(rule_tac p="(a \ b)" in permute_boolI) +apply(simp add: fresh_eqvt) +apply(simp add: fresh_def) +done + +lemma alpha_new_old: + assumes a: "({a}, x) \abs ({b}, y)" "sort_of a = sort_of b" + shows "(a, x) \abs1 (b, y)" +using a +apply(case_tac "a=b") +apply(simp only: alpha_equal) +apply(drule alpha_unequal) +apply(simp) +apply(simp) +apply(simp) +done + +fun + distinct_perms +where + "distinct_perms [] = True" +| "distinct_perms (p # ps) = (supp p \ supp ps = {} \ distinct_perms ps)" + +(* support of concrete atom sets *) + +lemma atom_eqvt_raw: + fixes p::"perm" + shows "(p \ atom) = atom" +by (simp add: expand_fun_eq permute_fun_def atom_eqvt) + +lemma atom_image_cong: + shows "(atom ` X = atom ` Y) = (X = Y)" +apply(rule inj_image_eq_iff) +apply(simp add: inj_on_def) +done + +lemma supp_atom_image: + fixes as::"'a::at_base set" + shows "supp (atom ` as) = supp as" +apply(simp add: supp_def) +apply(simp add: image_eqvt) +apply(simp add: atom_eqvt_raw) +apply(simp add: atom_image_cong) +done + +lemma swap_atom_image_fresh: "\a \ atom ` (fn :: ('a :: at_base set)); b \ atom ` fn\ \ (a \ b) \ fn = fn" + apply (simp add: fresh_def) + apply (simp add: supp_atom_image) + apply (fold fresh_def) + apply (simp add: swap_fresh_fresh) + done + + +end +