# HG changeset patch # User Christian Urban # Date 1336857685 -3600 # Node ID 89715c48f728706725b73dc267b2675b9c1dd842 # Parent b6873d123f9b647012b8b09ffd008f7818933682 cleaned also examples diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/CPS/CPS1_Plotkin.thy --- a/Nominal/Ex/CPS/CPS1_Plotkin.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,332 +0,0 @@ -header {* CPS conversion *} -theory CPS1_Plotkin -imports Lt -begin - -nominal_primrec - CPS :: "lt \ lt" ("_*" [250] 250) -where - "atom k \ x \ (x~)* = (Lam k ((k~) $ (x~)))" -| "atom k \ (x, M) \ (Lam x M)* = Lam k (k~ $ Lam x (M*))" -| "atom k \ (M, N) \ atom m \ (N, k) \ atom n \ (k, m) \ - (M $ N)* = Lam k (M* $ Lam m (N* $ Lam n (m~ $ n~ $ k~)))" -unfolding eqvt_def CPS_graph_def -apply (rule, perm_simp, rule, rule) -apply (simp_all add: fresh_Pair_elim) -apply (rule_tac y="x" in lt.exhaust) -apply (auto) -apply (rule_tac x="name" and ?'a="name" in obtain_fresh) -apply (simp_all add: fresh_at_base)[3] -apply (rule_tac x="(lt1, lt2)" and ?'a="name" in obtain_fresh) -apply (rule_tac x="(lt2, a)" and ?'a="name" in obtain_fresh) -apply (rule_tac x="(a, aa)" and ?'a="name" in obtain_fresh) -apply (simp add: fresh_Pair_elim fresh_at_base) -apply (rule_tac x="(name, lt)" and ?'a="name" in obtain_fresh) -apply (simp add: fresh_Pair_elim fresh_at_base)[2] -apply (simp add: Abs1_eq_iff lt.fresh fresh_at_base) ---"-" -apply(rule_tac s="[[atom ka]]lst. ka~ $ Lam x (CPS_sumC M)" in trans) -apply (case_tac "k = ka") -apply simp -apply(simp (no_asm) add: Abs1_eq_iff del:eqvts) -apply (simp del: eqvts add: lt.fresh fresh_at_base) -apply (simp only: lt.perm_simps(1) lt.perm_simps(2) flip_def[symmetric] lt.eq_iff) -apply (subst flip_at_base_simps(2)) -apply simp -apply (intro conjI refl) -apply (rule flip_fresh_fresh[symmetric]) -apply (simp_all add: lt.fresh) -apply (metis fresh_eqvt_at lt.fsupp) -apply (case_tac "ka = x") -apply simp_all[2] -apply (metis Abs_fresh_iff(3) atom_eq_iff finite_set fresh_Cons fresh_Nil fresh_atom fresh_eqvt_at fresh_finite_atom_set fresh_set lt.fsupp) -apply (metis Abs_fresh_iff(3) atom_eq_iff finite_set fresh_Cons fresh_Nil fresh_atom fresh_eqvt_at fresh_finite_atom_set fresh_set lt.fsupp) ---"-" -apply (simp add: Abs1_eq(3)) -apply (erule Abs_lst1_fcb2) -apply (simp_all add: Abs_fresh_iff fresh_Nil fresh_star_def eqvt_at_def)[4] ---"-" -apply (rename_tac k' M N m' n') -apply (subgoal_tac "atom k \ CPS_sumC M \ atom k' \ CPS_sumC M \ atom k \ CPS_sumC N \ atom k' \ CPS_sumC N \ - atom m \ CPS_sumC N \ atom m' \ CPS_sumC N") -prefer 2 -apply (intro conjI) -apply (erule fresh_eqvt_at, simp add: finite_supp, assumption)+ -apply clarify -apply (case_tac "k = k'", case_tac [!] "m' = k",case_tac [!]"m = k'",case_tac[!] "m = m'") -apply (simp_all add: Abs1_eq_iff lt.fresh flip_def[symmetric] fresh_at_base flip_fresh_fresh permute_eq_iff) -by (metis flip_at_base_simps(3) flip_at_simps(2) flip_commute permute_flip_at)+ - -termination (eqvt) by lexicographic_order - -lemmas [simp] = fresh_Pair_elim CPS.simps(2,3)[simplified fresh_Pair_elim] - -lemma [simp]: "supp (M*) = supp M" - by (induct rule: CPS.induct, simp_all add: lt.supp supp_at_base fresh_at_base fresh_def supp_Pair) - (simp_all only: atom_eq_iff[symmetric], blast+) - -lemma [simp]: "x \ M* = x \ M" - unfolding fresh_def by simp - -nominal_primrec - convert:: "lt => lt" ("_+" [250] 250) -where - "(Var x)+ = Var x" -| "(Lam x M)+ = Lam x (M*)" -| "(M $ N)+ = M $ N" - unfolding convert_graph_def eqvt_def - apply (rule, perm_simp, rule, rule) - apply (erule lt.exhaust) - apply (simp_all) - apply blast - apply (simp add: Abs1_eq_iff CPS.eqvt) - by blast - -termination (eqvt) - by (relation "measure size") (simp_all) - -lemma convert_supp[simp]: - shows "supp (M+) = supp M" - by (induct M rule: lt.induct, simp_all add: lt.supp) - -lemma convert_fresh[simp]: - shows "x \ (M+) = x \ M" - unfolding fresh_def by simp - -lemma [simp]: - shows "isValue (p \ (M::lt)) = isValue M" - by (nominal_induct M rule: lt.strong_induct) auto - -nominal_primrec - Kapply :: "lt \ lt \ lt" (infixl ";" 100) -where - "Kapply (Lam x M) K = K $ (Lam x M)+" -| "Kapply (Var x) K = K $ Var x" -| "isValue M \ isValue N \ Kapply (M $ N) K = M+ $ N+ $ K" -| "isValue M \ \isValue N \ atom n \ M \ atom n \ K \ - Kapply (M $ N) K = N; (Lam n (M+ $ Var n $ K))" -| "\isValue M \ atom m \ N \ atom m \ K \ atom n \ m \ atom n \ K \ - Kapply (M $ N) K = M; (Lam m (N* $ (Lam n (Var m $ Var n $ K))))" - unfolding Kapply_graph_def eqvt_def - apply (rule, perm_simp, rule, rule) -apply (simp_all) -apply (case_tac x) -apply (rule_tac y="a" in lt.exhaust) -apply (auto) -apply (case_tac "isValue lt1") -apply (case_tac "isValue lt2") -apply (auto)[1] -apply (rule_tac x="(lt1, ba)" and ?'a="name" in obtain_fresh) -apply (simp add: fresh_Pair_elim fresh_at_base) -apply (rule_tac x="(lt2, ba)" and ?'a="name" in obtain_fresh) -apply (rule_tac x="(a, ba)" and ?'a="name" in obtain_fresh) -apply (simp add: fresh_Pair_elim fresh_at_base) -apply (auto simp add: Abs1_eq_iff eqvts)[1] -apply (rename_tac M N u K) -apply (subgoal_tac "Lam n (M+ $ n~ $ K) = Lam u (M+ $ u~ $ K)") -apply (simp only:) -apply (auto simp add: Abs1_eq_iff flip_def[symmetric] lt.fresh fresh_at_base flip_fresh_fresh[symmetric])[1] -apply (subgoal_tac "Lam m (Na* $ Lam n (m~ $ n~ $ Ka)) = Lam ma (Na* $ Lam na (ma~ $ na~ $ Ka))") -apply (simp only:) -apply (simp add: Abs1_eq_iff flip_def[symmetric] lt.fresh fresh_at_base) -apply (subgoal_tac "Ka = (n \ na) \ Ka") -apply (subgoal_tac "Ka = (m \ ma) \ Ka") -apply (subgoal_tac "Ka = (n \ (m \ ma) \ na) \ Ka") -apply (case_tac "m = ma") -apply simp_all -apply rule -apply (auto simp add: flip_fresh_fresh[symmetric]) -apply (metis flip_at_base_simps(3) flip_fresh_fresh permute_flip_at)+ -done - -termination (eqvt) - by (relation "measure (\(t, _). size t)") (simp_all) - -section{* lemma related to Kapply *} - -lemma [simp]: "isValue V \ V; K = K $ (V+)" - by (nominal_induct V rule: lt.strong_induct) auto - -section{* lemma related to CPS conversion *} - -lemma value_CPS: - assumes "isValue V" - and "atom a \ V" - shows "V* = Lam a (a~ $ V+)" - using assms -proof (nominal_induct V avoiding: a rule: lt.strong_induct, simp_all add: lt.fresh) - fix name :: name and lt aa - assume a: "atom name \ aa" "\b. \isValue lt; atom b \ lt\ \ lt* = Lam b (b~ $ lt+)" - "atom aa \ lt \ aa = name" - obtain ab :: name where b: "atom ab \ (name, lt, a)" using obtain_fresh by blast - show "Lam name lt* = Lam aa (aa~ $ Lam name (lt*))" using a b - by (simp add: Abs1_eq_iff fresh_at_base lt.fresh) -qed - -section{* first lemma CPS subst *} - -lemma CPS_subst_fv: - assumes *:"isValue V" - shows "((M[x ::= V])* = (M*)[x ::= V+])" -using * proof (nominal_induct M avoiding: V x rule: lt.strong_induct) - case (Var name) - assume *: "isValue V" - obtain a :: name where a: "atom a \ (x, name, V)" using obtain_fresh by blast - show "((name~)[x ::= V])* = (name~)*[x ::= V+]" using a - by (simp add: fresh_at_base * value_CPS) -next - case (Lam name lt V x) - assume *: "atom name \ V" "atom name \ x" "\b ba. isValue b \ (lt[ba ::= b])* = lt*[ba ::= b+]" - "isValue V" - obtain a :: name where a: "atom a \ (name, lt, lt[x ::= V], x, V)" using obtain_fresh by blast - show "(Lam name lt[x ::= V])* = Lam name lt*[x ::= V+]" using * a - by (simp add: fresh_at_base) -next - case (App lt1 lt2 V x) - assume *: "\b ba. isValue b \ (lt1[ba ::= b])* = lt1*[ba ::= b+]" "\b ba. isValue b \ (lt2[ba ::= b])* = lt2*[ba ::= b+]" - "isValue V" - obtain a :: name where a: "atom a \ (lt1[x ::= V], lt1, lt2[x ::= V], lt2, V, x)" using obtain_fresh by blast - obtain b :: name where b: "atom b \ (lt2[x ::= V], lt2, a, V, x)" using obtain_fresh by blast - obtain c :: name where c: "atom c \ (a, b, V, x)" using obtain_fresh by blast - show "((lt1 $ lt2)[x ::= V])* = (lt1 $ lt2)*[x ::= V+]" using * a b c - by (simp add: fresh_at_base) -qed - -lemma [simp]: "isValue V \ isValue (V+)" - by (nominal_induct V rule: lt.strong_induct, auto) - -lemma CPS_eval_Kapply: - assumes a: "isValue K" - shows "(M* $ K) \\<^isub>\\<^sup>* (M ; K)" - using a -proof (nominal_induct M avoiding: K rule: lt.strong_induct, simp_all) - case (Var name K) - assume *: "isValue K" - obtain a :: name where a: "atom a \ (name, K)" using obtain_fresh by blast - show "(name~)* $ K \\<^isub>\\<^sup>* K $ name~" using * a - by simp (rule evbeta', simp_all add: fresh_at_base) -next - fix name :: name and lt K - assume *: "atom name \ K" "\b. isValue b \ lt* $ b \\<^isub>\\<^sup>* lt ; b" "isValue K" - obtain a :: name where a: "atom a \ (name, K, lt)" using obtain_fresh by blast - then have b: "atom name \ a" using fresh_PairD(1) fresh_at_base atom_eq_iff by metis - show "Lam name lt* $ K \\<^isub>\\<^sup>* K $ Lam name (lt*)" using * a b - by simp (rule evbeta', simp_all) -next - fix lt1 lt2 K - assume *: "\b. isValue b \ lt1* $ b \\<^isub>\\<^sup>* lt1 ; b" "\b. isValue b \ lt2* $ b \\<^isub>\\<^sup>* lt2 ; b" "isValue K" - obtain a :: name where a: "atom a \ (lt1, lt2, K)" using obtain_fresh by blast - obtain b :: name where b: "atom b \ (lt1, lt2, K, a)" using obtain_fresh by blast - obtain c :: name where c: "atom c \ (lt1, lt2, K, a, b)" using obtain_fresh by blast - have d: "atom a \ lt1" "atom a \ lt2" "atom a \ K" "atom b \ lt1" "atom b \ lt2" "atom b \ K" "atom b \ a" - "atom c \ lt1" "atom c \ lt2" "atom c \ K" "atom c \ a" "atom c \ b" using fresh_Pair a b c by simp_all - have "(lt1 $ lt2)* $ K \\<^isub>\\<^sup>* lt1* $ Lam b (lt2* $ Lam c (b~ $ c~ $ K))" using * d - by (simp add: fresh_at_base) (rule evbeta', simp_all add: fresh_at_base) - also have "... \\<^isub>\\<^sup>* lt1 $ lt2 ; K" proof (cases "isValue lt1") - assume e: "isValue lt1" - have "lt1* $ Lam b (lt2* $ Lam c (b~ $ c~ $ K)) \\<^isub>\\<^sup>* Lam b (lt2* $ Lam c (b~ $ c~ $ K)) $ lt1+" - using * d e by simp - also have "... \\<^isub>\\<^sup>* lt2* $ Lam c (lt1+ $ c~ $ K)" - by (rule evbeta', simp_all add: * d e, metis d(12) fresh_at_base) - also have "... \\<^isub>\\<^sup>* lt1 $ lt2 ; K" proof (cases "isValue lt2") - assume f: "isValue lt2" - have "lt2* $ Lam c (lt1+ $ c~ $ K) \\<^isub>\\<^sup>* Lam c (lt1+ $ c~ $ K) $ lt2+" using * d e f by simp - also have "... \\<^isub>\\<^sup>* lt1+ $ lt2+ $ K" - by (rule evbeta', simp_all add: d e f) - finally show ?thesis using * d e f by simp - next - assume f: "\ isValue lt2" - have "lt2* $ Lam c (lt1+ $ c~ $ K) \\<^isub>\\<^sup>* lt2 ; Lam c (lt1+ $ c~ $ K)" using * d e f by simp - also have "... \\<^isub>\\<^sup>* lt2 ; Lam a (lt1+ $ a~ $ K)" using Kapply.simps(4) d e evs1 f by metis - finally show ?thesis using * d e f by simp - qed - finally show ?thesis . - qed (metis Kapply.simps(5) isValue.simps(2) * d) - finally show "(lt1 $ lt2)* $ K \\<^isub>\\<^sup>* lt1 $ lt2 ; K" . -qed - -lemma Kapply_eval: - assumes a: "M \\<^isub>\ N" "isValue K" - shows "(M; K) \\<^isub>\\<^sup>* (N; K)" - using assms -proof (induct arbitrary: K rule: eval.induct) - case (evbeta x V M) - fix K - assume a: "isValue K" "isValue V" "atom x \ V" - have "Lam x (M*) $ V+ $ K \\<^isub>\\<^sup>* (((M*)[x ::= V+]) $ K)" - by (rule evs2,rule ev2,rule Lt.evbeta) (simp_all add: fresh_def a[simplified fresh_def] evs1) - also have "... = ((M[x ::= V])* $ K)" by (simp add: CPS_subst_fv a) - also have "... \\<^isub>\\<^sup>* ((M[x ::= V]) ; K)" by (rule CPS_eval_Kapply, simp_all add: a) - finally show "(Lam x M $ V ; K) \\<^isub>\\<^sup>* ((M[x ::= V]) ; K)" using a by simp -next - case (ev1 V M N) - fix V M N K - assume a: "isValue V" "M \\<^isub>\ N" "\K. isValue K \ M ; K \\<^isub>\\<^sup>* N ; K" "isValue K" - obtain a :: name where b: "atom a \ (V, K, M, N)" using obtain_fresh by blast - show "V $ M ; K \\<^isub>\\<^sup>* V $ N ; K" proof (cases "isValue N") - assume "\ isValue N" - then show "V $ M ; K \\<^isub>\\<^sup>* V $ N ; K" using a b by simp - next - assume n: "isValue N" - have c: "M; Lam a (V+ $ a~ $ K) \\<^isub>\\<^sup>* Lam a (V+ $ a~ $ K) $ N+" using a b by (simp add: n) - also have d: "... \\<^isub>\\<^sup>* V+ $ N+ $ K" by (rule evbeta') (simp_all add: a b n) - finally show "V $ M ; K \\<^isub>\\<^sup>* V $ N ; K" using a b by (simp add: n) - qed -next - case (ev2 M M' N) - assume *: "M \\<^isub>\ M'" "\K. isValue K \ M ; K \\<^isub>\\<^sup>* M' ; K" "isValue K" - obtain a :: name where a: "atom a \ (K, M, N, M')" using obtain_fresh by blast - obtain b :: name where b: "atom b \ (a, K, M, N, M', N+)" using obtain_fresh by blast - have d: "atom a \ K" "atom a \ M" "atom a \ N" "atom a \ M'" "atom b \ a" "atom b \ K" - "atom b \ M" "atom b \ N" "atom b \ M'" using a b fresh_Pair by simp_all - have "M $ N ; K \\<^isub>\\<^sup>* M' ; Lam a (N* $ Lam b (a~ $ b~ $ K))" using * d by simp - also have "... \\<^isub>\\<^sup>* M' $ N ; K" proof (cases "isValue M'") - assume "\ isValue M'" - then show ?thesis using * d by (simp_all add: evs1) - next - assume e: "isValue M'" - then have "M' ; Lam a (N* $ Lam b (a~ $ b~ $ K)) = Lam a (N* $ Lam b (a~ $ b~ $ K)) $ M'+" by simp - also have "... \\<^isub>\\<^sup>* (N* $ Lam b (a~ $ b~ $ K))[a ::= M'+]" - by (rule evbeta') (simp_all add: fresh_at_base e d) - also have "... = N* $ Lam b (M'+ $ b~ $ K)" using * d by (simp add: fresh_at_base) - also have "... \\<^isub>\\<^sup>* M' $ N ; K" proof (cases "isValue N") - assume f: "isValue N" - have "N* $ Lam b (M'+ $ b~ $ K) \\<^isub>\\<^sup>* Lam b (M'+ $ b~ $ K) $ N+" - by (rule eval_trans, rule CPS_eval_Kapply) (simp_all add: d e f * evs1) - also have "... \\<^isub>\\<^sup>* M' $ N ; K" by (rule evbeta') (simp_all add: d e f evs1) - finally show ?thesis . - next - assume "\ isValue N" - then show ?thesis using d e - by (metis CPS_eval_Kapply Kapply.simps(4) isValue.simps(2)) - qed - finally show ?thesis . - qed - finally show ?case . -qed - -lemma Kapply_eval_rtrancl: - assumes H: "M \\<^isub>\\<^sup>* N" and "isValue K" - shows "(M;K) \\<^isub>\\<^sup>* (N;K)" - using H - by (induct) (metis Kapply_eval assms(2) eval_trans evs1)+ - -lemma - assumes "isValue V" "M \\<^isub>\\<^sup>* V" - shows "M* $ (Lam x (x~)) \\<^isub>\\<^sup>* V+" -proof- - obtain y::name where *: "atom y \ V" using obtain_fresh by blast - have e: "Lam x (x~) = Lam y (y~)" - by (simp add: Abs1_eq_iff lt.fresh fresh_at_base) - have "M* $ Lam x (x~) \\<^isub>\\<^sup>* M ; Lam x (x~)" - by(rule CPS_eval_Kapply,simp_all add: assms) - also have "... \\<^isub>\\<^sup>* (V ; Lam x (x~))" by (rule Kapply_eval_rtrancl, simp_all add: assms) - also have "... = V ; Lam y (y~)" using e by (simp only:) - also have "... \\<^isub>\\<^sup>* (V+)" by (simp add: assms, rule evbeta') (simp_all add: assms *) - finally show "M* $ (Lam x (x~)) \\<^isub>\\<^sup>* (V+)" . -qed - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/CPS/CPS2_DanvyNielsen.thy --- a/Nominal/Ex/CPS/CPS2_DanvyNielsen.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -header {* CPS transformation of Danvy and Nielsen *} -theory CPS2_DanvyNielsen -imports Lt -begin - -nominal_datatype cpsctxt = - Hole -| CFun cpsctxt lt -| CArg lt cpsctxt -| CAbs x::name c::cpsctxt binds x in c - -nominal_primrec - fill :: "cpsctxt \ lt \ lt" ("_<_>" [200, 200] 100) -where - fill_hole : "Hole = M" -| fill_fun : "(CFun C N) = (C) $ N" -| fill_arg : "(CArg N C) = N $ (C)" -| fill_abs : "atom x \ M \ (CAbs x C) = Lam x (C)" - unfolding eqvt_def fill_graph_def - apply perm_simp - apply auto - apply (rule_tac y="a" and c="b" in cpsctxt.strong_exhaust) - apply (auto simp add: fresh_star_def) - apply (erule Abs_lst1_fcb) - apply (simp_all add: Abs_fresh_iff) - apply (erule fresh_eqvt_at) - apply (simp add: finite_supp) - apply (simp add: fresh_Pair) - apply (simp add: eqvt_at_def swap_fresh_fresh) - done - -termination (eqvt) by lexicographic_order - -nominal_primrec - ccomp :: "cpsctxt => cpsctxt => cpsctxt" -where - "ccomp Hole C = C" -| "atom x \ C' \ ccomp (CAbs x C) C' = CAbs x (ccomp C C')" -| "ccomp (CArg N C) C' = CArg N (ccomp C C')" -| "ccomp (CFun C N) C' = CFun (ccomp C C') N" - unfolding eqvt_def ccomp_graph_def - apply perm_simp - apply auto - apply (rule_tac y="a" and c="b" in cpsctxt.strong_exhaust) - apply (auto simp add: fresh_star_def) - apply blast+ - apply (erule Abs_lst1_fcb) - apply (simp_all add: Abs_fresh_iff) - apply (erule fresh_eqvt_at) - apply (simp add: finite_supp) - apply (simp add: fresh_Pair) - apply (simp add: eqvt_at_def swap_fresh_fresh) - done - -termination (eqvt) by lexicographic_order - -nominal_primrec - CPSv :: "lt => lt" -and CPS :: "lt => cpsctxt" where - "CPSv (Var x) = x~" -| "CPS (Var x) = CFun Hole (x~)" -| "atom b \ M \ CPSv (Lam y M) = Lam y (Lam b ((CPS M)))" -| "atom b \ M \ CPS (Lam y M) = CFun Hole (Lam y (Lam b ((CPS M))))" -| "CPSv (M $ N) = Lam x (Var x)" -| "isValue M \ isValue N \ CPS (M $ N) = CArg (CPSv M $ CPSv N) Hole" -| "isValue M \ ~isValue N \ atom a \ M \ CPS (M $ N) = - ccomp (CPS N) (CAbs a (CArg (CPSv M $ Var a) Hole))" -| "~isValue M \ isValue N \ atom a \ N \ CPS (M $ N) = - ccomp (CPS M) (CAbs a (CArg (Var a $ (CPSv N)) Hole))" -| "~isValue M \ ~isValue N \ atom a \ (N, b) \ CPS (M $ N) = - ccomp (CPS M) (CAbs a (ccomp (CPS N) (CAbs b (CArg (Var a $ Var b) Hole))))" - apply auto - defer - apply (case_tac x) - apply (rule_tac y="a" in lt.exhaust) - apply auto - apply blast - apply (rule_tac x="lt" and ?'a="name" in obtain_fresh) - apply (simp add: Abs1_eq_iff) - apply blast+ - apply (rule_tac y="b" in lt.exhaust) - apply auto - apply (rule_tac ?'a="name" in obtain_fresh) - apply (rule_tac x="(lt1, lt2, a)" and ?'a="name" in obtain_fresh) - apply (simp add: fresh_Pair_elim) - apply (case_tac "isValue lt1", case_tac [!] "isValue lt2")[1] - apply (simp_all add: fresh_Pair)[4] - apply (rule_tac x="lt" and ?'a="name" in obtain_fresh) - apply (simp add: Abs1_eq_iff) - apply blast ---"" - apply (rule_tac x="(y, ya, b, ba, M, Ma)" and ?'a="name" in obtain_fresh) - apply (subgoal_tac "Lam b (Sum_Type.Projr (CPSv_CPS_sumC (Inr M))<(b~)>) = Lam a (Sum_Type.Projr (CPSv_CPS_sumC (Inr M))<(a~)>)") - apply (subgoal_tac "Lam ba (Sum_Type.Projr (CPSv_CPS_sumC (Inr Ma))<(ba~)>) = Lam a (Sum_Type.Projr (CPSv_CPS_sumC (Inr Ma))<(a~)>)") - apply (simp only:) - apply (erule Abs_lst1_fcb) - apply (simp add: Abs_fresh_iff) - apply (simp_all add: Abs_fresh_iff lt.fresh fresh_Pair_elim fresh_at_base swap_fresh_fresh)[2] - (* need an invariant to get eqvt_at (Proj) *) - defer defer - apply simp - apply (simp_all add: Abs1_eq_iff fresh_Pair_elim fresh_at_base)[2] - defer defer - defer - apply (simp add: Abs1_eq_iff fresh_at_base lt.fresh) - apply (rule arg_cong) back - defer - apply (rule arg_cong) back - defer - apply (rule arg_cong) back - defer - oops --"The goals seem reasonable" - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/CPS/CPS3_DanvyFilinski.thy --- a/Nominal/Ex/CPS/CPS3_DanvyFilinski.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,252 +0,0 @@ -header {* CPS transformation of Danvy and Filinski *} -theory CPS3_DanvyFilinski imports Lt begin - -nominal_primrec - CPS1 :: "lt \ (lt \ lt) \ lt" ("_*_" [100,100] 100) -and - CPS2 :: "lt \ lt \ lt" ("_^_" [100,100] 100) -where - "eqvt k \ (x~)*k = k (x~)" -| "eqvt k \ (M$N)*k = M*(%m. (N*(%n.((m $ n) $ (Lam c (k (c~)))))))" -| "eqvt k \ atom c \ (x, M) \ (Lam x M)*k = k (Lam x (Lam c (M^(c~))))" -| "\eqvt k \ (CPS1 t k) = t" -| "(x~)^l = l $ (x~)" -| "(M$N)^l = M*(%m. (N*(%n.((m $ n) $ l))))" -| "atom c \ (x, M) \ (Lam x M)^l = l $ (Lam x (Lam c (M^(c~))))" - apply (simp only: eqvt_def CPS1_CPS2_graph_def) - apply (rule, perm_simp, rule) - apply auto - apply (case_tac x) - apply (case_tac a) - apply (case_tac "eqvt b") - apply (rule_tac y="aa" in lt.strong_exhaust) - apply auto[4] - apply (rule_tac x="(name, lt)" and ?'a="name" in obtain_fresh) - apply (simp add: fresh_at_base Abs1_eq_iff) - apply (case_tac b) - apply (rule_tac y="a" in lt.strong_exhaust) - apply auto[3] - apply blast+ - apply (rule_tac x="(name, lt)" and ?'a="name" in obtain_fresh) - apply (simp add: fresh_at_base Abs1_eq_iff) ---"-" - apply (subgoal_tac "Lam c (ka (c~)) = Lam ca (ka (ca~))") - apply (simp only:) - apply (simp add: Abs1_eq_iff) - apply (case_tac "c=ca") - apply simp_all[2] - apply rule - apply (perm_simp) - apply (simp add: eqvt_def) - apply (simp add: fresh_def) - apply (rule contra_subsetD[OF supp_fun_app]) - back - apply (simp add: supp_fun_eqvt lt.supp supp_at_base) ---"-" - apply (rule arg_cong) - back - apply simp - apply (thin_tac "eqvt ka") - apply (rule_tac x="(c, ca, x, xa, M, Ma)" and ?'a="name" in obtain_fresh) - apply (subgoal_tac "Lam c (CPS1_CPS2_sumC (Inr (M, c~))) = Lam a (CPS1_CPS2_sumC (Inr (M, a~)))") - prefer 2 - apply (simp add: Abs1_eq_iff') - apply (case_tac "c = a") - apply simp_all[2] - apply rule - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh fresh_Pair_elim) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (subgoal_tac "Lam ca (CPS1_CPS2_sumC (Inr (Ma, ca~))) = Lam a (CPS1_CPS2_sumC (Inr (Ma, a~)))") - prefer 2 - apply (simp add: Abs1_eq_iff') - apply (case_tac "ca = a") - apply simp_all[2] - apply rule - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh fresh_Pair_elim) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (simp only: ) - apply (erule Abs_lst1_fcb) - apply (simp add: Abs_fresh_iff) - apply (drule sym) - apply (simp only:) - apply (simp add: Abs_fresh_iff lt.fresh) - apply clarify - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (drule sym) - apply (drule sym) - apply (drule sym) - apply (simp only:) - apply (thin_tac "Lam a (CPS1_CPS2_sumC (Inr (M, a~))) = Lam c (CPS1_CPS2_sumC (Inr (M, c~)))") - apply (thin_tac "Lam a (CPS1_CPS2_sumC (Inr (Ma, a~))) = Lam ca (CPS1_CPS2_sumC (Inr (Ma, ca~)))") - apply (thin_tac "atom a \ (c, ca, x, xa, M, Ma)") - apply (simp add: fresh_Pair_elim) - apply (subst iffD1[OF meta_eq_to_obj_eq[OF eqvt_at_def]]) - back - back - back - apply assumption - apply (simp add: Abs1_eq_iff' fresh_Pair_elim fresh_at_base swap_fresh_fresh lt.fresh) - apply (case_tac "(atom x \ atom xa) \ c = ca") - apply simp_all[3] - apply rule - apply (case_tac "c = xa") - apply simp_all[2] - apply (rotate_tac 1) - apply (drule_tac q="(atom ca \ atom x)" in eqvt_at_perm) - apply (simp add: swap_fresh_fresh) - apply (simp add: eqvt_at_def swap_fresh_fresh) - apply (thin_tac "eqvt_at CPS1_CPS2_sumC (Inr (M, c~))") - apply (simp add: eqvt_at_def) - apply (drule_tac x="(atom ca \ atom c)" in spec) - apply simp - apply (metis (no_types) atom_eq_iff fresh_permute_iff permute_swap_cancel swap_atom_simps(3) swap_fresh_fresh) - apply (case_tac "c = xa") - apply simp - apply (subgoal_tac "((ca \ x) \ (atom x)) \ (ca \ x) \ CPS1_CPS2_sumC (Inr (Ma, ca~))") - apply (simp add: atom_eqvt eqvt_at_def) - apply (simp add: flip_fresh_fresh) - apply (subst fresh_permute_iff) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr lt.fresh fresh_at_base fresh_Pair) - apply simp - apply clarify - apply (subgoal_tac "atom ca \ (atom x \ atom xa) \ CPS1_CPS2_sumC (Inr (M, c~))") - apply (simp add: eqvt_at_def) - apply (subgoal_tac "(atom x \ atom xa) \ atom ca \ CPS1_CPS2_sumC (Inr (M, c~))") - apply (metis Nominal2_Base.swap_commute fresh_permute_iff permute_swap_cancel2) - apply (erule fresh_eqvt_at) - apply (simp add: finite_supp supp_Inr) - apply (simp add: fresh_Inr fresh_Pair lt.fresh) - apply rule - apply (metis Nominal2_Base.swap_commute fresh_permute_iff permute_swap_cancel2) - apply (simp add: fresh_def supp_at_base) - apply (metis atom_eq_iff permute_swap_cancel2 swap_atom_simps(3)) ---"-" - apply (rule_tac x="(c, ca, x, xa, M, Ma)" and ?'a="name" in obtain_fresh) - apply (subgoal_tac "Lam c (CPS1_CPS2_sumC (Inr (M, c~))) = Lam a (CPS1_CPS2_sumC (Inr (M, a~)))") - prefer 2 - apply (simp add: Abs1_eq_iff') - apply (case_tac "c = a") - apply simp_all[2] - apply rule - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh fresh_Pair_elim) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (subgoal_tac "Lam ca (CPS1_CPS2_sumC (Inr (Ma, ca~))) = Lam a (CPS1_CPS2_sumC (Inr (Ma, a~)))") - prefer 2 - apply (simp add: Abs1_eq_iff') - apply (case_tac "ca = a") - apply simp_all[2] - apply rule - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh fresh_Pair_elim) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (simp only: ) - apply (erule Abs_lst1_fcb) - apply (simp add: Abs_fresh_iff) - apply (drule sym) - apply (simp only:) - apply (simp add: Abs_fresh_iff lt.fresh) - apply clarify - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) (* TODO put sum of fs into fs typeclass *) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (drule sym) - apply (drule sym) - apply (drule sym) - apply (simp only:) - apply (thin_tac "Lam a (CPS1_CPS2_sumC (Inr (M, a~))) = Lam c (CPS1_CPS2_sumC (Inr (M, c~)))") - apply (thin_tac "Lam a (CPS1_CPS2_sumC (Inr (Ma, a~))) = Lam ca (CPS1_CPS2_sumC (Inr (Ma, ca~)))") - apply (thin_tac "atom a \ (c, ca, x, xa, M, Ma)") - apply (simp add: fresh_Pair_elim) - apply (subst iffD1[OF meta_eq_to_obj_eq[OF eqvt_at_def]]) - back - back - back - apply assumption - apply (simp add: Abs1_eq_iff' fresh_Pair_elim fresh_at_base swap_fresh_fresh lt.fresh) - apply (case_tac "(atom x \ atom xa) \ c = ca") - apply simp_all[3] - apply rule - apply (case_tac "c = xa") - apply simp_all[2] - apply (rotate_tac 1) - apply (drule_tac q="(atom ca \ atom x)" in eqvt_at_perm) - apply (simp add: swap_fresh_fresh) - apply (simp add: eqvt_at_def swap_fresh_fresh) - apply (thin_tac "eqvt_at CPS1_CPS2_sumC (Inr (M, c~))") - apply (simp add: eqvt_at_def) - apply (drule_tac x="(atom ca \ atom c)" in spec) - apply simp - apply (metis (no_types) atom_eq_iff fresh_permute_iff permute_swap_cancel swap_atom_simps(3) swap_fresh_fresh) - apply (case_tac "c = xa") - apply simp - apply (subgoal_tac "((ca \ x) \ (atom x)) \ (ca \ x) \ CPS1_CPS2_sumC (Inr (Ma, ca~))") - apply (simp add: atom_eqvt eqvt_at_def) - apply (simp add: flip_fresh_fresh) - apply (subst fresh_permute_iff) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr lt.fresh fresh_at_base fresh_Pair) - apply simp - apply clarify - apply (subgoal_tac "atom ca \ (atom x \ atom xa) \ CPS1_CPS2_sumC (Inr (M, c~))") - apply (simp add: eqvt_at_def) - apply (subgoal_tac "(atom x \ atom xa) \ atom ca \ CPS1_CPS2_sumC (Inr (M, c~))") - apply (metis Nominal2_Base.swap_commute fresh_permute_iff permute_swap_cancel2) - apply (erule fresh_eqvt_at) - apply (simp add: finite_supp supp_Inr) - apply (simp add: fresh_Inr fresh_Pair lt.fresh) - apply rule - apply (metis Nominal2_Base.swap_commute fresh_permute_iff permute_swap_cancel2) - apply (simp add: fresh_def supp_at_base) - apply (metis atom_eq_iff permute_swap_cancel2 swap_atom_simps(3)) - done - -termination (eqvt) - by lexicographic_order - -definition psi:: "lt => lt" - where [simp]: "psi V == V*(\x. x)" - -section {* Simple consequence of CPS *} - -lemma [simp]: "eqvt (\x\lt. x)" - by (simp add: eqvt_def eqvt_bound eqvt_lambda) - -lemma value_eq1 : "isValue V \ eqvt k \ V*k = k (psi V)" - apply (cases V rule: lt.exhaust) - apply simp_all - apply (rule_tac x="(name, lt)" and ?'a="name" in obtain_fresh) - apply simp - done - -lemma value_eq2 : "isValue V \ V^K = K $ (psi V)" - apply (cases V rule: lt.exhaust) - apply simp_all - apply (rule_tac x="(name, lt)" and ?'a="name" in obtain_fresh) - apply simp - done - -lemma value_eq3' : "~isValue M \ eqvt k \ M*k = (M^(Lam n (k (Var n))))" - by (cases M rule: lt.exhaust) auto - - - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/CPS/CPS3_DanvyFilinski_FCB2.thy --- a/Nominal/Ex/CPS/CPS3_DanvyFilinski_FCB2.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -header {* CPS transformation of Danvy and Filinski *} -theory CPS3_DanvyFilinski imports Lt begin - -nominal_primrec - CPS1 :: "lt \ (lt \ lt) \ lt" ("_*_" [100,100] 100) -and - CPS2 :: "lt \ lt \ lt" ("_^_" [100,100] 100) -where - "eqvt k \ (x~)*k = k (x~)" -| "eqvt k \ (M$N)*k = M*(%m. (N*(%n.((m $ n) $ (Lam c (k (c~)))))))" -| "eqvt k \ atom c \ (x, M) \ (Lam x M)*k = k (Lam x (Lam c (M^(c~))))" -| "\eqvt k \ (CPS1 t k) = t" -| "(x~)^l = l $ (x~)" -| "(M$N)^l = M*(%m. (N*(%n.((m $ n) $ l))))" -| "atom c \ (x, M) \ (Lam x M)^l = l $ (Lam x (Lam c (M^(c~))))" - apply (simp only: eqvt_def CPS1_CPS2_graph_def) - apply (rule, perm_simp, rule) - apply auto - apply (case_tac x) - apply (case_tac a) - apply (case_tac "eqvt b") - apply (rule_tac y="aa" in lt.strong_exhaust) - apply auto[4] - apply (rule_tac x="(name, lt)" and ?'a="name" in obtain_fresh) - apply (simp add: fresh_at_base Abs1_eq_iff) - apply (case_tac b) - apply (rule_tac y="a" in lt.strong_exhaust) - apply auto[3] - apply blast - apply (rule_tac x="(name, lt)" and ?'a="name" in obtain_fresh) - apply (simp add: fresh_at_base Abs1_eq_iff) - apply blast ---"-" - apply (subgoal_tac "Lam c (ka (c~)) = Lam ca (ka (ca~))") - apply (simp only:) - apply (simp add: Abs1_eq_iff) - apply (case_tac "c=ca") - apply simp_all[2] - apply rule - apply (perm_simp) - apply (simp add: eqvt_def) - apply (simp add: fresh_def) - apply (rule contra_subsetD[OF supp_fun_app]) - back - apply (simp add: supp_fun_eqvt lt.supp supp_at_base) ---"-" - apply (rule arg_cong) - back - apply (thin_tac "eqvt ka") - apply (rule_tac x="(c, ca, x, xa, M, Ma)" and ?'a="name" in obtain_fresh) - apply (subgoal_tac "Lam c (CPS1_CPS2_sumC (Inr (M, c~))) = Lam a (CPS1_CPS2_sumC (Inr (M, a~)))") - prefer 2 - apply (simp add: Abs1_eq_iff') - apply (case_tac "c = a") - apply simp_all[2] - apply rule - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh fresh_Pair_elim) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (subgoal_tac "Lam ca (CPS1_CPS2_sumC (Inr (Ma, ca~))) = Lam a (CPS1_CPS2_sumC (Inr (Ma, a~)))") - prefer 2 - apply (simp add: Abs1_eq_iff') - apply (case_tac "ca = a") - apply simp_all[2] - apply rule - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh fresh_Pair_elim) - apply (erule fresh_eqvt_at) - apply (simp add: supp_Inr finite_supp) - apply (simp add: fresh_Inr fresh_Pair lt.fresh fresh_at_base) - apply (simp only:) - apply (simp (no_asm)) - apply (erule_tac c="a" in Abs_lst1_fcb2') - apply (simp add: Abs_fresh_iff lt.fresh) - apply (simp add: fresh_star_def fresh_Pair_elim lt.fresh fresh_at_base) - oops - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/CPS/Lt.thy --- a/Nominal/Ex/CPS/Lt.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -header {* The Call-by-Value Lambda Calculus *} -theory Lt -imports "../../Nominal2" -begin - -atom_decl name - -nominal_datatype lt = - Var name ("_~" [150] 149) - | App lt lt (infixl "$" 100) - | Lam x::"name" t::"lt" binds x in t - -nominal_primrec - subst :: "lt \ name \ lt \ lt" ("_ [_ ::= _]" [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 simp add: lt.distinct lt.eq_iff) - apply(rule_tac y="a" and c="(aa, b)" in lt.strong_exhaust) - apply blast - apply(simp_all add: fresh_star_def fresh_Pair_elim) - apply blast - 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)+ -done - -termination (eqvt) by lexicographic_order - -lemma forget[simp]: - shows "atom x \ M \ M[x ::= s] = M" - by (nominal_induct M avoiding: x s rule: lt.strong_induct) - (auto simp add: lt.fresh fresh_at_base) - -lemma [simp]: "supp (M[x ::= V]) <= (supp(M) - {atom x}) Un (supp V)" - by (nominal_induct M avoiding: x V rule: lt.strong_induct) - (auto simp add: lt.supp supp_at_base, blast, blast) - -nominal_primrec - isValue:: "lt => bool" -where - "isValue (Var x) = True" -| "isValue (Lam y N) = True" -| "isValue (A $ B) = False" - unfolding eqvt_def isValue_graph_def - by (perm_simp, auto) - (erule lt.exhaust, auto) - -termination (eqvt) - by (relation "measure size") (simp_all) - -inductive - eval :: "[lt, lt] \ bool" (" _ \\<^isub>\ _" [80,80] 80) - where - evbeta: "\atom x\V; isValue V\ \ ((Lam x M) $ V) \\<^isub>\ (M[x ::= V])" -| ev1: "\isValue V; M \\<^isub>\ M' \ \ (V $ M) \\<^isub>\ (V $ M')" -| ev2: "M \\<^isub>\ M' \ (M $ N) \\<^isub>\ (M' $ N)" - -equivariance eval - -nominal_inductive eval -done - -(*lemmas [simp] = lt.supp(2)*) - -lemma closedev1: assumes "s \\<^isub>\ t" - shows "supp t <= supp s" - using assms - by (induct, auto simp add: lt.supp) - - -lemma [simp]: "~ ((Lam x M) \\<^isub>\ N)" -by (rule, erule eval.cases, simp_all) - -lemma [simp]: assumes "M \\<^isub>\ N" shows "~ isValue M" -using assms -by (cases, auto) - - -inductive - eval_star :: "[lt, lt] \ bool" (" _ \\<^isub>\\<^sup>* _" [80,80] 80) - where - evs1: "M \\<^isub>\\<^sup>* M" -| evs2: "\M \\<^isub>\ M'; M' \\<^isub>\\<^sup>* M'' \ \ M \\<^isub>\\<^sup>* M''" - -lemma eval_evs: assumes *: "M \\<^isub>\ M'" shows "M \\<^isub>\\<^sup>* M'" -by (rule evs2, rule *, rule evs1) - -lemma eval_trans[trans]: - assumes "M1 \\<^isub>\\<^sup>* M2" - and "M2 \\<^isub>\\<^sup>* M3" - shows "M1 \\<^isub>\\<^sup>* M3" - using assms - by (induct, auto intro: evs2) - -lemma evs3[rule_format]: assumes "M1 \\<^isub>\\<^sup>* M2" - shows "M2 \\<^isub>\ M3 \ M1 \\<^isub>\\<^sup>* M3" - using assms - by (induct, auto intro: eval_evs evs2) - -equivariance eval_star - -lemma evbeta': - fixes x :: name - assumes "isValue V" and "atom x\V" and "N = (M[x ::= V])" - shows "((Lam x M) $ V) \\<^isub>\\<^sup>* N" - using assms by simp (rule evs2, rule evbeta, simp_all add: evs1) - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/FiniteType.thy --- a/Nominal/Ex/FiniteType.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -theory FiniteType -imports "../Nominal2" -begin - -typedef ('a::pt, 'b::fs) ffun = "{f::'a => 'b. finite (supp f)}" -apply(rule_tac x="\_. undefined::'b::fs" in exI) -apply(auto) -apply(rule_tac S="supp (undefined::'b::fs)" in supports_finite) -apply(simp add: supports_def) -apply(perm_simp) -apply(simp add: fresh_def[symmetric]) -apply(simp add: swap_fresh_fresh) -apply(simp add: finite_supp) -done - - - - -end \ No newline at end of file diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/Finite_Alpha.thy --- a/Nominal/Ex/Finite_Alpha.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -theory Finite_Alpha -imports "../Nominal2" -begin - -lemma - assumes "(supp x - as) \* p" - and "p \ x = y" - and "p \ as = bs" - shows "(as, x) \set (op =) supp p (bs, y)" - using assms unfolding alphas - apply(simp) - apply(clarify) - apply(simp only: Diff_eqvt[symmetric] supp_eqvt[symmetric]) - apply(simp only: atom_set_perm_eq) - done - - -lemma - assumes "(supp x - set as) \* p" - and "p \ x = y" - and "p \ as = bs" - shows "(as, x) \lst (op =) supp p (bs, y)" - using assms unfolding alphas - apply(simp) - apply(clarify) - apply(simp only: set_eqvt[symmetric] Diff_eqvt[symmetric] supp_eqvt[symmetric]) - apply(simp only: atom_set_perm_eq) - done - -lemma - assumes "(supp x - as) \* p" - and "p \ x = y" - and "p \ (as \ supp x) = bs \ supp y" - and "finite (supp x)" - shows "(as, x) \res (op =) supp p (bs, y)" - using assms - unfolding alpha_res_alpha_set - unfolding alphas - apply simp - apply rule - apply (rule trans) - apply (rule supp_perm_eq[symmetric, of _ p]) - apply (simp add: supp_finite_atom_set fresh_star_def) - apply(auto)[1] - apply(simp only: Diff_eqvt inter_eqvt supp_eqvt) - apply (simp add: fresh_star_def) - apply blast - done - -lemma - assumes "(as, x) \res (op =) supp p (bs, y)" - shows "(supp x - as) \* p" - and "p \ (as \ supp x) = bs \ supp y" - and "p \ x = y" - using assms - apply - - prefer 3 - apply (auto simp add: alphas)[2] - unfolding alpha_res_alpha_set - unfolding alphas - by blast - -(* On the raw level *) - -atom_decl name - -nominal_datatype lam = - Var "name" -| App "lam" "lam" -| Lam x::"name" l::"lam" binds x in l ("Lam [_]. _" [100, 100] 100) - -thm alpha_lam_raw.intros(3)[unfolded alphas, simplified] - -lemma alpha_fv: "alpha_lam_raw l r \ fv_lam_raw l = fv_lam_raw r" - by (induct rule: alpha_lam_raw.induct) (simp_all add: alphas) - -lemma finite_fv_raw: "finite (fv_lam_raw l)" - by (induct rule: lam_raw.induct) (simp_all add: supp_at_base) - -lemma "(fv_lam_raw l - {atom n}) \* p \ alpha_lam_raw (p \ l) r \ - fv_lam_raw l - {atom n} = fv_lam_raw r - {atom (p \ n)}" - apply (rule trans) - apply (rule supp_perm_eq[symmetric]) - apply (subst supp_finite_atom_set) - apply (rule finite_Diff) - apply (rule finite_fv_raw) - apply assumption - apply (simp add: eqvts) - apply (subst alpha_fv) - apply assumption - apply (rule) - done - -(* For the res binding *) - -nominal_datatype ty2 = - Var2 "name" -| Fun2 "ty2" "ty2" - -nominal_datatype tys2 = - All2 xs::"name fset" ty::"ty2" binds (set+) xs in ty - -lemma alpha_fv': "alpha_tys2_raw l r \ fv_tys2_raw l = fv_tys2_raw r" - by (induct rule: alpha_tys2_raw.induct) (simp_all add: alphas) - -lemma finite_fv_raw': "finite (fv_tys2_raw l)" - by (induct rule: tys2_raw.induct) (simp_all add: supp_at_base finite_supp) - -thm alpha_tys2_raw.intros[unfolded alphas, simplified] - -lemma "(supp x - atom ` (fset as)) \* p \ p \ (x :: tys2) = y \ - p \ (atom ` (fset as) \ supp x) = atom ` (fset bs) \ supp y \ - supp x - atom ` (fset as) = supp y - atom ` (fset bs)" - apply (rule trans) - apply (rule supp_perm_eq[symmetric]) - apply (subst supp_finite_atom_set) - apply (rule finite_Diff) - apply (rule finite_supp) - apply assumption - apply (simp add: eqvts) - apply blast - done - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/LamTest.thy --- a/Nominal/Ex/LamTest.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1894 +0,0 @@ -theory LamTest -imports "../Nominal2" -begin - -atom_decl name - -nominal_datatype lam = - Var "name" -| App "lam" "lam" -| Lam x::"name" l::"lam" bind x in l - - -ML {* - -val trace = Unsynchronized.ref false -fun trace_msg msg = if ! trace then tracing (msg ()) else () - -val boolT = HOLogic.boolT -val mk_eq = HOLogic.mk_eq - -open Function_Lib -open Function_Common - -datatype globals = Globals of - {fvar: term, - domT: typ, - ranT: typ, - h: term, - y: term, - x: term, - z: term, - a: term, - P: term, - D: term, - Pbool:term} - -datatype rec_call_info = RCInfo of - {RIvs: (string * typ) list, (* Call context: fixes and assumes *) - CCas: thm list, - rcarg: term, (* The recursive argument *) - llRI: thm, - h_assum: term} - - -datatype clause_context = ClauseContext of - {ctxt : Proof.context, - qs : term list, - gs : term list, - lhs: term, - rhs: term, - cqs: cterm list, - ags: thm list, - case_hyp : thm} - - -fun transfer_clause_ctx thy (ClauseContext { ctxt, qs, gs, lhs, rhs, cqs, ags, case_hyp }) = - ClauseContext { ctxt = ProofContext.transfer thy ctxt, - qs = qs, gs = gs, lhs = lhs, rhs = rhs, cqs = cqs, ags = ags, case_hyp = case_hyp } - - -datatype clause_info = ClauseInfo of - {no: int, - qglr : ((string * typ) list * term list * term * term), - cdata : clause_context, - tree: Function_Ctx_Tree.ctx_tree, - lGI: thm, - RCs: rec_call_info list} -*} - -thm accp_induct_rule - -ML {* -(* Theory dependencies. *) -val acc_induct_rule = @{thm accp_induct_rule} - -val ex1_implies_ex = @{thm FunDef.fundef_ex1_existence} -val ex1_implies_un = @{thm FunDef.fundef_ex1_uniqueness} -val ex1_implies_iff = @{thm FunDef.fundef_ex1_iff} - -val acc_downward = @{thm accp_downward} -val accI = @{thm accp.accI} -val case_split = @{thm HOL.case_split} -val fundef_default_value = @{thm FunDef.fundef_default_value} -val not_acc_down = @{thm not_accp_down} -*} - - -ML {* -fun find_calls tree = - let - fun add_Ri (fixes,assumes) (_ $ arg) _ (_, xs) = - ([], (fixes, assumes, arg) :: xs) - | add_Ri _ _ _ _ = raise Match - in - rev (Function_Ctx_Tree.traverse_tree add_Ri tree []) - end -*} - -ML {* -fun mk_eqvt_at (f_trm, arg_trm) = - let - val f_ty = fastype_of f_trm - val arg_ty = domain_type f_ty - in - Const (@{const_name eqvt_at}, [f_ty, arg_ty] ---> @{typ bool}) $ f_trm $ arg_trm - |> HOLogic.mk_Trueprop - end -*} - -ML {* -fun find_calls2 f t = - let - fun aux (g $ arg) = aux g #> aux arg #> (if f = g then cons ((g, arg)) else I) - | aux (Abs (_, _, t)) = aux t - | aux _ = I - in - aux t [] - end -*} - - -ML {* -(** building proof obligations *) - -fun mk_compat_proof_obligations domT ranT fvar f glrs = - let - fun mk_impl ((qs, gs, lhs, rhs), (qs', gs', lhs', rhs')) = - let - val shift = incr_boundvars (length qs') - - val RCs_rhs = find_calls2 fvar rhs - val RCs_rhs' = find_calls2 fvar rhs' - in - Logic.mk_implies - (HOLogic.mk_Trueprop (HOLogic.eq_const domT $ shift lhs $ lhs'), - HOLogic.mk_Trueprop (HOLogic.eq_const ranT $ shift rhs $ rhs')) - |> fold_rev (curry Logic.mk_implies) (map shift gs @ gs') - |> fold_rev (curry Logic.mk_implies) (map (shift o mk_eqvt_at) RCs_rhs) (* HERE *) - (*|> fold_rev (curry Logic.mk_implies) (map mk_eqvt_at RCs_rhs')*) (* HERE *) - |> fold_rev (fn (n,T) => fn b => Term.all T $ Abs(n,T,b)) (qs @ qs') - |> curry abstract_over fvar - |> curry subst_bound f - end - in - map mk_impl (unordered_pairs glrs) - end -*} - -ML {* -fun mk_completeness (Globals {x, Pbool, ...}) clauses qglrs = - let - fun mk_case (ClauseContext {qs, gs, lhs, ...}, (oqs, _, _, _)) = - HOLogic.mk_Trueprop Pbool - |> curry Logic.mk_implies (HOLogic.mk_Trueprop (mk_eq (x, lhs))) - |> fold_rev (curry Logic.mk_implies) gs - |> fold_rev mk_forall_rename (map fst oqs ~~ qs) - in - HOLogic.mk_Trueprop Pbool - |> fold_rev (curry Logic.mk_implies o mk_case) (clauses ~~ qglrs) - |> mk_forall_rename ("x", x) - |> mk_forall_rename ("P", Pbool) - end -*} - -(** making a context with it's own local bindings **) -ML {* - -fun mk_clause_context x ctxt (pre_qs,pre_gs,pre_lhs,pre_rhs) = - let - val (qs, ctxt') = Variable.variant_fixes (map fst pre_qs) ctxt - |>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs - - val thy = ProofContext.theory_of ctxt' - - fun inst t = subst_bounds (rev qs, t) - val gs = map inst pre_gs - val lhs = inst pre_lhs - val rhs = inst pre_rhs - - val cqs = map (cterm_of thy) qs - val ags = map (Thm.assume o cterm_of thy) gs - - val case_hyp = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (x, lhs)))) - in - ClauseContext { ctxt = ctxt', qs = qs, gs = gs, lhs = lhs, rhs = rhs, - cqs = cqs, ags = ags, case_hyp = case_hyp } - end -*} - -ML {* -(* lowlevel term function. FIXME: remove *) -fun abstract_over_list vs body = - let - fun abs lev v tm = - if v aconv tm then Bound lev - else - (case tm of - Abs (a, T, t) => Abs (a, T, abs (lev + 1) v t) - | t $ u => abs lev v t $ abs lev v u - | t => t) - in - fold_index (fn (i, v) => fn t => abs i v t) vs body - end - - - -fun mk_clause_info globals G f no cdata qglr tree RCs GIntro_thm RIntro_thms = - let - val Globals {h, ...} = globals - - val ClauseContext { ctxt, qs, cqs, ags, ... } = cdata - val cert = Thm.cterm_of (ProofContext.theory_of ctxt) - - (* Instantiate the GIntro thm with "f" and import into the clause context. *) - val lGI = GIntro_thm - |> Thm.forall_elim (cert f) - |> fold Thm.forall_elim cqs - |> fold Thm.elim_implies ags - - fun mk_call_info (rcfix, rcassm, rcarg) RI = - let - val llRI = RI - |> fold Thm.forall_elim cqs - |> fold (Thm.forall_elim o cert o Free) rcfix - |> fold Thm.elim_implies ags - |> fold Thm.elim_implies rcassm - - val h_assum = - HOLogic.mk_Trueprop (G $ rcarg $ (h $ rcarg)) - |> fold_rev (curry Logic.mk_implies o prop_of) rcassm - |> fold_rev (Logic.all o Free) rcfix - |> Pattern.rewrite_term (ProofContext.theory_of ctxt) [(f, h)] [] - |> abstract_over_list (rev qs) - in - RCInfo {RIvs=rcfix, rcarg=rcarg, CCas=rcassm, llRI=llRI, h_assum=h_assum} - end - - val RC_infos = map2 mk_call_info RCs RIntro_thms - in - ClauseInfo {no=no, cdata=cdata, qglr=qglr, lGI=lGI, RCs=RC_infos, - tree=tree} - end -*} - -ML {* -fun store_compat_thms 0 thms = [] - | store_compat_thms n thms = - let - val (thms1, thms2) = chop n thms - in - (thms1 :: store_compat_thms (n - 1) thms2) - end -*} - -ML {* -(* expects i <= j *) -fun lookup_compat_thm i j cts = - nth (nth cts (i - 1)) (j - i) - -(* Returns "Gsi, Gsj, lhs_i = lhs_j |-- rhs_j_f = rhs_i_f" *) -(* if j < i, then turn around *) -fun get_compat_thm thy cts eqvtsi eqvtsj i j ctxi ctxj = - let - val ClauseContext {cqs=cqsi,ags=agsi,lhs=lhsi,...} = ctxi - val ClauseContext {cqs=cqsj,ags=agsj,lhs=lhsj,...} = ctxj - - val lhsi_eq_lhsj = cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj))) - in if j < i then - let - val compat = lookup_compat_thm j i cts - in - compat (* "!!qj qi. Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *) - |> fold Thm.forall_elim (cqsj @ cqsi) (* "Gsj => Gsi => lhsj = lhsi ==> rhsj = rhsi" *) - |> fold Thm.elim_implies (rev eqvtsj) (* HERE *) - |> fold Thm.elim_implies agsj - |> fold Thm.elim_implies agsi - |> Thm.elim_implies ((Thm.assume lhsi_eq_lhsj) RS sym) (* "Gsj, Gsi, lhsi = lhsj |-- rhsj = rhsi" *) - end - else - let - val compat = lookup_compat_thm i j cts - in - compat (* "!!qi qj. Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *) - |> fold Thm.forall_elim (cqsi @ cqsj) (* "Gsi => Gsj => lhsi = lhsj ==> rhsi = rhsj" *) - |> fold Thm.elim_implies (rev eqvtsi) (* HERE *) - |> fold Thm.elim_implies agsi - |> fold Thm.elim_implies agsj - |> Thm.elim_implies (Thm.assume lhsi_eq_lhsj) - |> (fn thm => thm RS sym) (* "Gsi, Gsj, lhsi = lhsj |-- rhsj = rhsi" *) - end - end -*} - - -ML {* -(* Generates the replacement lemma in fully quantified form. *) -fun mk_replacement_lemma thy h ih_elim clause = - let - val ClauseInfo {cdata=ClauseContext {qs, cqs, ags, case_hyp, ...}, - RCs, tree, ...} = clause - local open Conv in - val ih_conv = arg1_conv o arg_conv o arg_conv - end - - val ih_elim_case = - Conv.fconv_rule (ih_conv (K (case_hyp RS eq_reflection))) ih_elim - - val Ris = map (fn RCInfo {llRI, ...} => llRI) RCs - val h_assums = map (fn RCInfo {h_assum, ...} => - Thm.assume (cterm_of thy (subst_bounds (rev qs, h_assum)))) RCs - - val (eql, _) = - Function_Ctx_Tree.rewrite_by_tree thy h ih_elim_case (Ris ~~ h_assums) tree - - val replace_lemma = (eql RS meta_eq_to_obj_eq) - |> Thm.implies_intr (cprop_of case_hyp) - |> fold_rev (Thm.implies_intr o cprop_of) h_assums - |> fold_rev (Thm.implies_intr o cprop_of) ags - |> fold_rev Thm.forall_intr cqs - |> Thm.close_derivation - in - replace_lemma - end -*} - -ML {* -fun mk_eqvt_lemma thy ih_eqvt clause = - let - val ClauseInfo {cdata=ClauseContext {cqs, ags, case_hyp, ...}, RCs, ...} = clause - - local open Conv in - val ih_conv = arg1_conv o arg_conv o arg_conv - end - - val ih_eqvt_case = - Conv.fconv_rule (ih_conv (K (case_hyp RS eq_reflection))) ih_eqvt - - fun prep_eqvt (RCInfo {llRI, RIvs, CCas, ...}) = - (llRI RS ih_eqvt_case) - |> fold_rev (Thm.implies_intr o cprop_of) CCas - |> fold_rev (Thm.forall_intr o cterm_of thy o Free) RIvs - in - map prep_eqvt RCs - |> map (fold_rev (Thm.implies_intr o cprop_of) ags) - |> map (Thm.implies_intr (cprop_of case_hyp)) - |> map (fold_rev Thm.forall_intr cqs) - |> map (Thm.close_derivation) - end -*} - -ML {* -fun mk_uniqueness_clause thy globals compat_store eqvts clausei clausej RLj = - let - val Globals {h, y, x, fvar, ...} = globals - val ClauseInfo {no=i, cdata=cctxi as ClauseContext {ctxt=ctxti, lhs=lhsi, case_hyp, cqs = cqsi, - ags = agsi, ...}, ...} = clausei - val ClauseInfo {no=j, qglr=cdescj, RCs=RCsj, ...} = clausej - - val cctxj as ClauseContext {ags = agsj', lhs = lhsj', rhs = rhsj', qs = qsj', cqs = cqsj', ...} = - mk_clause_context x ctxti cdescj - - val rhsj'h = Pattern.rewrite_term thy [(fvar,h)] [] rhsj' - - val Ghsj' = map - (fn RCInfo {h_assum, ...} => Thm.assume (cterm_of thy (subst_bounds (rev qsj', h_assum)))) RCsj - - val y_eq_rhsj'h = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (y, rhsj'h)))) - val lhsi_eq_lhsj' = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (mk_eq (lhsi, lhsj')))) - (* lhs_i = lhs_j' |-- lhs_i = lhs_j' *) - - val case_hypj' = trans OF [case_hyp, lhsi_eq_lhsj'] - - val RLj_import = RLj - |> fold Thm.forall_elim cqsj' - |> fold Thm.elim_implies agsj' - |> fold Thm.elim_implies Ghsj' - - val eqvtsi = nth eqvts (i - 1) - |> map (fold Thm.forall_elim cqsi) - |> map (fold Thm.elim_implies [case_hyp]) - |> map (fold Thm.elim_implies agsi) - - val eqvtsj = nth eqvts (j - 1) - |> map (fold Thm.forall_elim cqsj') - |> map (fold Thm.elim_implies [case_hypj']) - |> map (fold Thm.elim_implies agsj') - - val compat = get_compat_thm thy compat_store eqvtsi eqvtsj i j cctxi cctxj - - in - (trans OF [case_hyp, lhsi_eq_lhsj']) (* lhs_i = lhs_j' |-- x = lhs_j' *) - |> Thm.implies_elim RLj_import - (* Rj1' ... Rjk', lhs_i = lhs_j' |-- rhs_j'_h = rhs_j'_f *) - |> (fn it => trans OF [it, compat]) - (* lhs_i = lhs_j', Gj', Rj1' ... Rjk' |-- rhs_j'_h = rhs_i_f *) - |> (fn it => trans OF [y_eq_rhsj'h, it]) - (* lhs_i = lhs_j', Gj', Rj1' ... Rjk', y = rhs_j_h' |-- y = rhs_i_f *) - |> fold_rev (Thm.implies_intr o cprop_of) Ghsj' - |> fold_rev (Thm.implies_intr o cprop_of) agsj' - (* lhs_i = lhs_j' , y = rhs_j_h' |-- Gj', Rj1'...Rjk' ==> y = rhs_i_f *) - |> Thm.implies_intr (cprop_of y_eq_rhsj'h) - |> Thm.implies_intr (cprop_of lhsi_eq_lhsj') - |> fold_rev Thm.forall_intr (cterm_of thy h :: cqsj') - end -*} - - -ML {* -fun mk_uniqueness_case thy globals G f ihyp ih_intro G_cases compat_store clauses replems eqvtlems clausei = - let - val Globals {x, y, ranT, fvar, ...} = globals - val ClauseInfo {cdata = ClauseContext {lhs, rhs, cqs, ags, case_hyp, ...}, lGI, RCs, ...} = clausei - val rhsC = Pattern.rewrite_term thy [(fvar, f)] [] rhs - - val ih_intro_case = full_simplify (HOL_basic_ss addsimps [case_hyp]) ih_intro - - fun prep_RC (RCInfo {llRI, RIvs, CCas, ...}) = - (llRI RS ih_intro_case) - |> fold_rev (Thm.implies_intr o cprop_of) CCas - |> fold_rev (Thm.forall_intr o cterm_of thy o Free) RIvs - - val existence = fold (curry op COMP o prep_RC) RCs lGI - - val P = cterm_of thy (mk_eq (y, rhsC)) - val G_lhs_y = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (G $ lhs $ y))) - - val unique_clauses = - map2 (mk_uniqueness_clause thy globals compat_store eqvtlems clausei) clauses replems - - fun elim_implies_eta A AB = - Thm.compose_no_flatten true (A, 0) 1 AB |> Seq.list_of |> the_single - - val uniqueness = G_cases - |> Thm.forall_elim (cterm_of thy lhs) - |> Thm.forall_elim (cterm_of thy y) - |> Thm.forall_elim P - |> Thm.elim_implies G_lhs_y - |> fold elim_implies_eta unique_clauses - |> Thm.implies_intr (cprop_of G_lhs_y) - |> Thm.forall_intr (cterm_of thy y) - - val P2 = cterm_of thy (lambda y (G $ lhs $ y)) (* P2 y := (lhs, y): G *) - - val exactly_one = - ex1I |> instantiate' [SOME (ctyp_of thy ranT)] [SOME P2, SOME (cterm_of thy rhsC)] - |> curry (op COMP) existence - |> curry (op COMP) uniqueness - |> simplify (HOL_basic_ss addsimps [case_hyp RS sym]) - |> Thm.implies_intr (cprop_of case_hyp) - |> fold_rev (Thm.implies_intr o cprop_of) ags - |> fold_rev Thm.forall_intr cqs - - val function_value = - existence - |> Thm.implies_intr ihyp - |> Thm.implies_intr (cprop_of case_hyp) - |> Thm.forall_intr (cterm_of thy x) - |> Thm.forall_elim (cterm_of thy lhs) - |> curry (op RS) refl - in - (exactly_one, function_value) - end -*} - - -ML {* -fun prove_stuff ctxt globals G f R clauses complete compat compat_store G_elim G_eqvt f_def = - let - val Globals {h, domT, ranT, x, ...} = globals - val thy = ProofContext.theory_of ctxt - - (* Inductive Hypothesis: !!z. (z,x):R ==> EX!y. (z,y):G *) - val ihyp = Term.all domT $ Abs ("z", domT, - Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x), - HOLogic.mk_Trueprop (Const (@{const_name Ex1}, (ranT --> boolT) --> boolT) $ - Abs ("y", ranT, G $ Bound 1 $ Bound 0)))) - |> cterm_of thy - - val ihyp_thm = Thm.assume ihyp |> Thm.forall_elim_vars 0 - val ih_intro = ihyp_thm RS (f_def RS ex1_implies_ex) - val ih_elim = ihyp_thm RS (f_def RS ex1_implies_un) - |> instantiate' [] [NONE, SOME (cterm_of thy h)] - val ih_eqvt = ihyp_thm RS (G_eqvt RS (f_def RS @{thm fundef_ex1_eqvt_at})) - - val _ = trace_msg (K "Proving Replacement lemmas...") - val repLemmas = map (mk_replacement_lemma thy h ih_elim) clauses - - val _ = trace_msg (K "Proving Equivariance lemmas...") - val eqvtLemmas = map (mk_eqvt_lemma thy ih_eqvt) clauses - - val _ = trace_msg (K "Proving cases for unique existence...") - val (ex1s, values) = - split_list (map (mk_uniqueness_case thy globals G f - ihyp ih_intro G_elim compat_store clauses repLemmas eqvtLemmas) clauses) - - val _ = trace_msg (K "Proving: Graph is a function") - val graph_is_function = complete - |> Thm.forall_elim_vars 0 - |> fold (curry op COMP) ex1s - |> Thm.implies_intr (ihyp) - |> Thm.implies_intr (cterm_of thy (HOLogic.mk_Trueprop (mk_acc domT R $ x))) - |> Thm.forall_intr (cterm_of thy x) - |> (fn it => Drule.compose_single (it, 2, acc_induct_rule)) (* "EX! y. (?x,y):G" *) - |> (fn it => fold (Thm.forall_intr o cterm_of thy o Var) (Term.add_vars (prop_of it) []) it) - - val goalstate = Conjunction.intr graph_is_function complete - |> Thm.close_derivation - |> Goal.protect - |> fold_rev (Thm.implies_intr o cprop_of) compat - |> Thm.implies_intr (cprop_of complete) - in - (goalstate, values) - end -*} - - -ML {* -(* wrapper -- restores quantifiers in rule specifications *) -fun inductive_def eqvt_flag (binding as ((R, T), _)) intrs lthy = - let - val ({intrs = intrs_gen, elims = [elim_gen], preds = [ Rdef ], induct, raw_induct, ...}, lthy) = - lthy - |> Local_Theory.conceal - |> Inductive.add_inductive_i - {quiet_mode = true, - verbose = ! trace, - alt_name = Binding.empty, - coind = false, - no_elim = false, - no_ind = false, - skip_mono = true, - fork_mono = false} - [binding] (* relation *) - [] (* no parameters *) - (map (fn t => (Attrib.empty_binding, t)) intrs) (* intro rules *) - [] (* no special monos *) - ||> Local_Theory.restore_naming lthy - - val eqvt_thm' = - if eqvt_flag = false then NONE - else - let - val ([eqvt_thm], lthy) = Nominal_Eqvt.raw_equivariance false [Rdef] raw_induct intrs_gen lthy - in - SOME ((Nominal_ThmDecls.eqvt_transform lthy eqvt_thm) RS @{thm eqvtI}) - end - - val cert = cterm_of (ProofContext.theory_of lthy) - fun requantify orig_intro thm = - let - val (qs, t) = dest_all_all orig_intro - val frees = frees_in_term lthy t |> remove (op =) (Binding.name_of R, T) - val vars = Term.add_vars (prop_of thm) [] |> rev - val varmap = AList.lookup (op =) (frees ~~ map fst vars) - #> the_default ("",0) - in - fold_rev (fn Free (n, T) => - forall_intr_rename (n, cert (Var (varmap (n, T), T)))) qs thm - end - in - ((Rdef, map2 requantify intrs intrs_gen, forall_intr_vars elim_gen, induct, eqvt_thm'), lthy) - end -*} - -ML {* -fun define_graph Gname fvar domT ranT clauses RCss lthy = - let - val GT = domT --> ranT --> boolT - val (Gvar as (n, T)) = singleton (Variable.variant_frees lthy []) (Gname, GT) - - fun mk_GIntro (ClauseContext {qs, gs, lhs, rhs, ...}) RCs = - let - fun mk_h_assm (rcfix, rcassm, rcarg) = - HOLogic.mk_Trueprop (Free Gvar $ rcarg $ (fvar $ rcarg)) - |> fold_rev (curry Logic.mk_implies o prop_of) rcassm - |> fold_rev (Logic.all o Free) rcfix - in - HOLogic.mk_Trueprop (Free Gvar $ lhs $ rhs) - |> fold_rev (curry Logic.mk_implies o mk_h_assm) RCs - |> fold_rev (curry Logic.mk_implies) gs - |> fold_rev Logic.all (fvar :: qs) - end - - val G_intros = map2 mk_GIntro clauses RCss - in - inductive_def true ((Binding.name n, T), NoSyn) G_intros lthy - end -*} - -ML {* -fun define_function fdefname (fname, mixfix) domT ranT G default lthy = - let - val f_def = - Abs ("x", domT, Const (@{const_name FunDef.THE_default}, ranT --> (ranT --> boolT) --> ranT) - $ (default $ Bound 0) $ Abs ("y", ranT, G $ Bound 1 $ Bound 0)) - |> Syntax.check_term lthy - in - Local_Theory.define - ((Binding.name (function_name fname), mixfix), - ((Binding.conceal (Binding.name fdefname), []), f_def)) lthy - end - -fun define_recursion_relation Rname domT qglrs clauses RCss lthy = - let - val RT = domT --> domT --> boolT - val (Rvar as (n, T)) = singleton (Variable.variant_frees lthy []) (Rname, RT) - - fun mk_RIntro (ClauseContext {qs, gs, lhs, ...}, (oqs, _, _, _)) (rcfix, rcassm, rcarg) = - HOLogic.mk_Trueprop (Free Rvar $ rcarg $ lhs) - |> fold_rev (curry Logic.mk_implies o prop_of) rcassm - |> fold_rev (curry Logic.mk_implies) gs - |> fold_rev (Logic.all o Free) rcfix - |> fold_rev mk_forall_rename (map fst oqs ~~ qs) - (* "!!qs xs. CS ==> G => (r, lhs) : R" *) - - val R_intross = map2 (map o mk_RIntro) (clauses ~~ qglrs) RCss - - val ((R, RIntro_thms, R_elim, _, _), lthy) = - inductive_def false ((Binding.name n, T), NoSyn) (flat R_intross) lthy - in - ((R, Library.unflat R_intross RIntro_thms, R_elim), lthy) - end - - -fun fix_globals domT ranT fvar ctxt = - let - val ([h, y, x, z, a, D, P, Pbool],ctxt') = Variable.variant_fixes - ["h_fd", "y_fd", "x_fd", "z_fd", "a_fd", "D_fd", "P_fd", "Pb_fd"] ctxt - in - (Globals {h = Free (h, domT --> ranT), - y = Free (y, ranT), - x = Free (x, domT), - z = Free (z, domT), - a = Free (a, domT), - D = Free (D, domT --> boolT), - P = Free (P, domT --> boolT), - Pbool = Free (Pbool, boolT), - fvar = fvar, - domT = domT, - ranT = ranT}, - ctxt') - end - -fun inst_RC thy fvar f (rcfix, rcassm, rcarg) = - let - fun inst_term t = subst_bound(f, abstract_over (fvar, t)) - in - (rcfix, map (Thm.assume o cterm_of thy o inst_term o prop_of) rcassm, inst_term rcarg) - end - - - -(********************************************************** - * PROVING THE RULES - **********************************************************) - -fun mk_psimps thy globals R clauses valthms f_iff graph_is_function = - let - val Globals {domT, z, ...} = globals - - fun mk_psimp (ClauseInfo {qglr = (oqs, _, _, _), cdata = ClauseContext {cqs, lhs, ags, ...}, ...}) valthm = - let - val lhs_acc = cterm_of thy (HOLogic.mk_Trueprop (mk_acc domT R $ lhs)) (* "acc R lhs" *) - val z_smaller = cterm_of thy (HOLogic.mk_Trueprop (R $ z $ lhs)) (* "R z lhs" *) - in - ((Thm.assume z_smaller) RS ((Thm.assume lhs_acc) RS acc_downward)) - |> (fn it => it COMP graph_is_function) - |> Thm.implies_intr z_smaller - |> Thm.forall_intr (cterm_of thy z) - |> (fn it => it COMP valthm) - |> Thm.implies_intr lhs_acc - |> asm_simplify (HOL_basic_ss addsimps [f_iff]) - |> fold_rev (Thm.implies_intr o cprop_of) ags - |> fold_rev forall_intr_rename (map fst oqs ~~ cqs) - end - in - map2 mk_psimp clauses valthms - end - - -(** Induction rule **) - - -val acc_subset_induct = @{thm predicate1I} RS @{thm accp_subset_induct} - - -fun mk_partial_induct_rule thy globals R complete_thm clauses = - let - val Globals {domT, x, z, a, P, D, ...} = globals - val acc_R = mk_acc domT R - - val x_D = Thm.assume (cterm_of thy (HOLogic.mk_Trueprop (D $ x))) - val a_D = cterm_of thy (HOLogic.mk_Trueprop (D $ a)) - - val D_subset = cterm_of thy (Logic.all x - (Logic.mk_implies (HOLogic.mk_Trueprop (D $ x), HOLogic.mk_Trueprop (acc_R $ x)))) - - val D_dcl = (* "!!x z. [| x: D; (z,x):R |] ==> z:D" *) - Logic.all x (Logic.all z (Logic.mk_implies (HOLogic.mk_Trueprop (D $ x), - Logic.mk_implies (HOLogic.mk_Trueprop (R $ z $ x), - HOLogic.mk_Trueprop (D $ z))))) - |> cterm_of thy - - (* Inductive Hypothesis: !!z. (z,x):R ==> P z *) - val ihyp = Term.all domT $ Abs ("z", domT, - Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x), - HOLogic.mk_Trueprop (P $ Bound 0))) - |> cterm_of thy - - val aihyp = Thm.assume ihyp - - fun prove_case clause = - let - val ClauseInfo {cdata = ClauseContext {ctxt, qs, cqs, ags, gs, lhs, case_hyp, ...}, - RCs, qglr = (oqs, _, _, _), ...} = clause - - val case_hyp_conv = K (case_hyp RS eq_reflection) - local open Conv in - val lhs_D = fconv_rule (arg_conv (arg_conv (case_hyp_conv))) x_D - val sih = - fconv_rule (Conv.binder_conv - (K (arg1_conv (arg_conv (arg_conv case_hyp_conv)))) ctxt) aihyp - end - - fun mk_Prec (RCInfo {llRI, RIvs, CCas, rcarg, ...}) = sih - |> Thm.forall_elim (cterm_of thy rcarg) - |> Thm.elim_implies llRI - |> fold_rev (Thm.implies_intr o cprop_of) CCas - |> fold_rev (Thm.forall_intr o cterm_of thy o Free) RIvs - - val P_recs = map mk_Prec RCs (* [P rec1, P rec2, ... ] *) - - val step = HOLogic.mk_Trueprop (P $ lhs) - |> fold_rev (curry Logic.mk_implies o prop_of) P_recs - |> fold_rev (curry Logic.mk_implies) gs - |> curry Logic.mk_implies (HOLogic.mk_Trueprop (D $ lhs)) - |> fold_rev mk_forall_rename (map fst oqs ~~ qs) - |> cterm_of thy - - val P_lhs = Thm.assume step - |> fold Thm.forall_elim cqs - |> Thm.elim_implies lhs_D - |> fold Thm.elim_implies ags - |> fold Thm.elim_implies P_recs - - val res = cterm_of thy (HOLogic.mk_Trueprop (P $ x)) - |> Conv.arg_conv (Conv.arg_conv case_hyp_conv) - |> Thm.symmetric (* P lhs == P x *) - |> (fn eql => Thm.equal_elim eql P_lhs) (* "P x" *) - |> Thm.implies_intr (cprop_of case_hyp) - |> fold_rev (Thm.implies_intr o cprop_of) ags - |> fold_rev Thm.forall_intr cqs - in - (res, step) - end - - val (cases, steps) = split_list (map prove_case clauses) - - val istep = complete_thm - |> Thm.forall_elim_vars 0 - |> fold (curry op COMP) cases (* P x *) - |> Thm.implies_intr ihyp - |> Thm.implies_intr (cprop_of x_D) - |> Thm.forall_intr (cterm_of thy x) - - val subset_induct_rule = - acc_subset_induct - |> (curry op COMP) (Thm.assume D_subset) - |> (curry op COMP) (Thm.assume D_dcl) - |> (curry op COMP) (Thm.assume a_D) - |> (curry op COMP) istep - |> fold_rev Thm.implies_intr steps - |> Thm.implies_intr a_D - |> Thm.implies_intr D_dcl - |> Thm.implies_intr D_subset - - val simple_induct_rule = - subset_induct_rule - |> Thm.forall_intr (cterm_of thy D) - |> Thm.forall_elim (cterm_of thy acc_R) - |> assume_tac 1 |> Seq.hd - |> (curry op COMP) (acc_downward - |> (instantiate' [SOME (ctyp_of thy domT)] - (map (SOME o cterm_of thy) [R, x, z])) - |> Thm.forall_intr (cterm_of thy z) - |> Thm.forall_intr (cterm_of thy x)) - |> Thm.forall_intr (cterm_of thy a) - |> Thm.forall_intr (cterm_of thy P) - in - simple_induct_rule - end - - -(* FIXME: broken by design *) -fun mk_domain_intro ctxt (Globals {domT, ...}) R R_cases clause = - let - val thy = ProofContext.theory_of ctxt - val ClauseInfo {cdata = ClauseContext {gs, lhs, cqs, ...}, - qglr = (oqs, _, _, _), ...} = clause - val goal = HOLogic.mk_Trueprop (mk_acc domT R $ lhs) - |> fold_rev (curry Logic.mk_implies) gs - |> cterm_of thy - in - Goal.init goal - |> (SINGLE (resolve_tac [accI] 1)) |> the - |> (SINGLE (eresolve_tac [Thm.forall_elim_vars 0 R_cases] 1)) |> the - |> (SINGLE (auto_tac (clasimpset_of ctxt))) |> the - |> Goal.conclude - |> fold_rev forall_intr_rename (map fst oqs ~~ cqs) - end - - - -(** Termination rule **) - -val wf_induct_rule = @{thm Wellfounded.wfP_induct_rule} -val wf_in_rel = @{thm FunDef.wf_in_rel} -val in_rel_def = @{thm FunDef.in_rel_def} - -fun mk_nest_term_case thy globals R' ihyp clause = - let - val Globals {z, ...} = globals - val ClauseInfo {cdata = ClauseContext {qs, cqs, ags, lhs, case_hyp, ...}, tree, - qglr=(oqs, _, _, _), ...} = clause - - val ih_case = full_simplify (HOL_basic_ss addsimps [case_hyp]) ihyp - - fun step (fixes, assumes) (_ $ arg) u (sub,(hyps,thms)) = - let - val used = (u @ sub) - |> map (fn (ctx,thm) => Function_Ctx_Tree.export_thm thy ctx thm) - - val hyp = HOLogic.mk_Trueprop (R' $ arg $ lhs) - |> fold_rev (curry Logic.mk_implies o prop_of) used (* additional hyps *) - |> Function_Ctx_Tree.export_term (fixes, assumes) - |> fold_rev (curry Logic.mk_implies o prop_of) ags - |> fold_rev mk_forall_rename (map fst oqs ~~ qs) - |> cterm_of thy - - val thm = Thm.assume hyp - |> fold Thm.forall_elim cqs - |> fold Thm.elim_implies ags - |> Function_Ctx_Tree.import_thm thy (fixes, assumes) - |> fold Thm.elim_implies used (* "(arg, lhs) : R'" *) - - val z_eq_arg = HOLogic.mk_Trueprop (mk_eq (z, arg)) - |> cterm_of thy |> Thm.assume - - val acc = thm COMP ih_case - val z_acc_local = acc - |> Conv.fconv_rule - (Conv.arg_conv (Conv.arg_conv (K (Thm.symmetric (z_eq_arg RS eq_reflection))))) - - val ethm = z_acc_local - |> Function_Ctx_Tree.export_thm thy (fixes, - z_eq_arg :: case_hyp :: ags @ assumes) - |> fold_rev forall_intr_rename (map fst oqs ~~ cqs) - - val sub' = sub @ [(([],[]), acc)] - in - (sub', (hyp :: hyps, ethm :: thms)) - end - | step _ _ _ _ = raise Match - in - Function_Ctx_Tree.traverse_tree step tree - end - - -fun mk_nest_term_rule thy globals R R_cases clauses = - let - val Globals { domT, x, z, ... } = globals - val acc_R = mk_acc domT R - - val R' = Free ("R", fastype_of R) - - val Rrel = Free ("R", HOLogic.mk_setT (HOLogic.mk_prodT (domT, domT))) - val inrel_R = Const (@{const_name FunDef.in_rel}, - HOLogic.mk_setT (HOLogic.mk_prodT (domT, domT)) --> fastype_of R) $ Rrel - - val wfR' = HOLogic.mk_Trueprop (Const (@{const_name Wellfounded.wfP}, - (domT --> domT --> boolT) --> boolT) $ R') - |> cterm_of thy (* "wf R'" *) - - (* Inductive Hypothesis: !!z. (z,x):R' ==> z : acc R *) - val ihyp = Term.all domT $ Abs ("z", domT, - Logic.mk_implies (HOLogic.mk_Trueprop (R' $ Bound 0 $ x), - HOLogic.mk_Trueprop (acc_R $ Bound 0))) - |> cterm_of thy - - val ihyp_a = Thm.assume ihyp |> Thm.forall_elim_vars 0 - - val R_z_x = cterm_of thy (HOLogic.mk_Trueprop (R $ z $ x)) - - val (hyps, cases) = fold (mk_nest_term_case thy globals R' ihyp_a) clauses ([], []) - in - R_cases - |> Thm.forall_elim (cterm_of thy z) - |> Thm.forall_elim (cterm_of thy x) - |> Thm.forall_elim (cterm_of thy (acc_R $ z)) - |> curry op COMP (Thm.assume R_z_x) - |> fold_rev (curry op COMP) cases - |> Thm.implies_intr R_z_x - |> Thm.forall_intr (cterm_of thy z) - |> (fn it => it COMP accI) - |> Thm.implies_intr ihyp - |> Thm.forall_intr (cterm_of thy x) - |> (fn it => Drule.compose_single(it,2,wf_induct_rule)) - |> curry op RS (Thm.assume wfR') - |> forall_intr_vars - |> (fn it => it COMP allI) - |> fold Thm.implies_intr hyps - |> Thm.implies_intr wfR' - |> Thm.forall_intr (cterm_of thy R') - |> Thm.forall_elim (cterm_of thy (inrel_R)) - |> curry op RS wf_in_rel - |> full_simplify (HOL_basic_ss addsimps [in_rel_def]) - |> Thm.forall_intr (cterm_of thy Rrel) - end - - - -(* Tail recursion (probably very fragile) - * - * FIXME: - * - Need to do forall_elim_vars on psimps: Unneccesary, if psimps would be taken from the same context. - * - Must we really replace the fvar by f here? - * - Splitting is not configured automatically: Problems with case? - *) -fun mk_trsimps octxt globals f G R f_def R_cases G_induct clauses psimps = - let - val Globals {domT, ranT, fvar, ...} = globals - - val R_cases = Thm.forall_elim_vars 0 R_cases (* FIXME: Should be already in standard form. *) - - val graph_implies_dom = (* "G ?x ?y ==> dom ?x" *) - Goal.prove octxt ["x", "y"] [HOLogic.mk_Trueprop (G $ Free ("x", domT) $ Free ("y", ranT))] - (HOLogic.mk_Trueprop (mk_acc domT R $ Free ("x", domT))) - (fn {prems=[a], ...} => - ((rtac (G_induct OF [a])) - THEN_ALL_NEW rtac accI - THEN_ALL_NEW etac R_cases - THEN_ALL_NEW asm_full_simp_tac (simpset_of octxt)) 1) - - val default_thm = - forall_intr_vars graph_implies_dom COMP (f_def COMP fundef_default_value) - - fun mk_trsimp clause psimp = - let - val ClauseInfo {qglr = (oqs, _, _, _), cdata = - ClauseContext {ctxt, cqs, gs, lhs, rhs, ...}, ...} = clause - val thy = ProofContext.theory_of ctxt - val rhs_f = Pattern.rewrite_term thy [(fvar, f)] [] rhs - - val trsimp = Logic.list_implies(gs, - HOLogic.mk_Trueprop (HOLogic.mk_eq(f $ lhs, rhs_f))) (* "f lhs = rhs" *) - val lhs_acc = (mk_acc domT R $ lhs) (* "acc R lhs" *) - fun simp_default_tac ss = - asm_full_simp_tac (ss addsimps [default_thm, Let_def]) - in - Goal.prove ctxt [] [] trsimp (fn _ => - rtac (instantiate' [] [SOME (cterm_of thy lhs_acc)] case_split) 1 - THEN (rtac (Thm.forall_elim_vars 0 psimp) THEN_ALL_NEW assume_tac) 1 - THEN (simp_default_tac (simpset_of ctxt) 1) - THEN TRY ((etac not_acc_down 1) - THEN ((etac R_cases) - THEN_ALL_NEW (simp_default_tac (simpset_of ctxt))) 1)) - |> fold_rev forall_intr_rename (map fst oqs ~~ cqs) - end - in - map2 mk_trsimp clauses psimps - end -*} - -ML {* -fun prepare_function config defname [((fname, fT), mixfix)] abstract_qglrs lthy = - let - val FunctionConfig {domintros, tailrec, default=default_opt, ...} = config - - val default_str = the_default "%x. undefined" default_opt (*FIXME dynamic scoping*) - val fvar = Free (fname, fT) - val domT = domain_type fT - val ranT = range_type fT - - val default = Syntax.parse_term lthy default_str - |> Type.constraint fT |> Syntax.check_term lthy - - val (globals, ctxt') = fix_globals domT ranT fvar lthy - - val Globals { x, h, ... } = globals - - val clauses = map (mk_clause_context x ctxt') abstract_qglrs - - val n = length abstract_qglrs - - fun build_tree (ClauseContext { ctxt, rhs, ...}) = - Function_Ctx_Tree.mk_tree (fname, fT) h ctxt rhs - - val trees = map build_tree clauses - val RCss = map find_calls trees - - val ((G, GIntro_thms, G_elim, G_induct, SOME G_eqvt), lthy) = - PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy - - val ((f, (_, f_defthm)), lthy) = - PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy - - val RCss = map (map (inst_RC (ProofContext.theory_of lthy) fvar f)) RCss - val trees = map (Function_Ctx_Tree.inst_tree (ProofContext.theory_of lthy) fvar f) trees - - val ((R, RIntro_thmss, R_elim), lthy) = - PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy - - val (_, lthy) = - Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy - - val newthy = ProofContext.theory_of lthy - val clauses = map (transfer_clause_ctx newthy) clauses - - val cert = cterm_of (ProofContext.theory_of lthy) - - val xclauses = PROFILE "xclauses" - (map7 (mk_clause_info globals G f) (1 upto n) clauses abstract_qglrs trees - RCss GIntro_thms) RIntro_thmss - - val complete = - mk_completeness globals clauses abstract_qglrs |> cert |> Thm.assume - - val compat = - mk_compat_proof_obligations domT ranT fvar f abstract_qglrs - |> map (cert #> Thm.assume) - - val compat_store = store_compat_thms n compat - - val (goalstate, values) = PROFILE "prove_stuff" - (prove_stuff lthy globals G f R xclauses complete compat - compat_store G_elim G_eqvt) f_defthm - - val mk_trsimps = - mk_trsimps lthy globals f G R f_defthm R_elim G_induct xclauses - - fun mk_partial_rules provedgoal = - let - val newthy = theory_of_thm provedgoal (*FIXME*) - - val (graph_is_function, complete_thm) = - provedgoal - |> Conjunction.elim - |> apfst (Thm.forall_elim_vars 0) - - val f_iff = graph_is_function RS (f_defthm RS ex1_implies_iff) - - val psimps = PROFILE "Proving simplification rules" - (mk_psimps newthy globals R xclauses values f_iff) graph_is_function - - val simple_pinduct = PROFILE "Proving partial induction rule" - (mk_partial_induct_rule newthy globals R complete_thm) xclauses - - val total_intro = PROFILE "Proving nested termination rule" - (mk_nest_term_rule newthy globals R R_elim) xclauses - - val dom_intros = - if domintros then SOME (PROFILE "Proving domain introduction rules" - (map (mk_domain_intro lthy globals R R_elim)) xclauses) - else NONE - val trsimps = if tailrec then SOME (mk_trsimps psimps) else NONE - - in - FunctionResult {fs=[f], G=G, R=R, cases=complete_thm, - psimps=psimps, simple_pinducts=[simple_pinduct], - termination=total_intro, trsimps=trsimps, - domintros=dom_intros} - end - in - ((f, goalstate, mk_partial_rules), lthy) - end -*} - -ML {* -open Function_Lib -open Function_Common - -type qgar = string * (string * typ) list * term list * term list * term - -datatype mutual_part = MutualPart of - {i : int, - i' : int, - fvar : string * typ, - cargTs: typ list, - f_def: term, - - f: term option, - f_defthm : thm option} - -datatype mutual_info = Mutual of - {n : int, - n' : int, - fsum_var : string * typ, - - ST: typ, - RST: typ, - - parts: mutual_part list, - fqgars: qgar list, - qglrs: ((string * typ) list * term list * term * term) list, - - fsum : term option} - -fun mutual_induct_Pnames n = - if n < 5 then fst (chop n ["P","Q","R","S"]) - else map (fn i => "P" ^ string_of_int i) (1 upto n) - -fun get_part fname = - the o find_first (fn (MutualPart {fvar=(n,_), ...}) => n = fname) - -(* FIXME *) -fun mk_prod_abs e (t1, t2) = - let - val bTs = rev (map snd e) - val T1 = fastype_of1 (bTs, t1) - val T2 = fastype_of1 (bTs, t2) - in - HOLogic.pair_const T1 T2 $ t1 $ t2 - end - -fun analyze_eqs ctxt defname fs eqs = - let - val num = length fs - val fqgars = map (split_def ctxt (K true)) eqs - val arity_of = map (fn (fname,_,_,args,_) => (fname, length args)) fqgars - |> AList.lookup (op =) #> the - - fun curried_types (fname, fT) = - let - val (caTs, uaTs) = chop (arity_of fname) (binder_types fT) - in - (caTs, uaTs ---> body_type fT) - end - - val (caTss, resultTs) = split_list (map curried_types fs) - val argTs = map (foldr1 HOLogic.mk_prodT) caTss - - val dresultTs = distinct (op =) resultTs - val n' = length dresultTs - - val RST = Balanced_Tree.make (uncurry SumTree.mk_sumT) dresultTs - val ST = Balanced_Tree.make (uncurry SumTree.mk_sumT) argTs - - val fsum_type = ST --> RST - - val ([fsum_var_name], _) = Variable.add_fixes [ defname ^ "_sum" ] ctxt - val fsum_var = (fsum_var_name, fsum_type) - - fun define (fvar as (n, _)) caTs resultT i = - let - val vars = map_index (fn (j,T) => Free ("x" ^ string_of_int j, T)) caTs (* FIXME: Bind xs properly *) - val i' = find_index (fn Ta => Ta = resultT) dresultTs + 1 - - val f_exp = SumTree.mk_proj RST n' i' - (Free fsum_var $ SumTree.mk_inj ST num i (foldr1 HOLogic.mk_prod vars)) - - val def = Term.abstract_over (Free fsum_var, fold_rev lambda vars f_exp) - - val rew = (n, fold_rev lambda vars f_exp) - in - (MutualPart {i=i, i'=i', fvar=fvar,cargTs=caTs,f_def=def,f=NONE,f_defthm=NONE}, rew) - end - - val (parts, rews) = split_list (map4 define fs caTss resultTs (1 upto num)) - - fun convert_eqs (f, qs, gs, args, rhs) = - let - val MutualPart {i, i', ...} = get_part f parts - in - (qs, gs, SumTree.mk_inj ST num i (foldr1 (mk_prod_abs qs) args), - SumTree.mk_inj RST n' i' (replace_frees rews rhs) - |> Envir.beta_norm) - end - - val qglrs = map convert_eqs fqgars - in - Mutual {n=num, n'=n', fsum_var=fsum_var, ST=ST, RST=RST, - parts=parts, fqgars=fqgars, qglrs=qglrs, fsum=NONE} - end -*} - -ML {* -fun define_projections fixes mutual fsum lthy = - let - fun def ((MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs, f_def, ...}), (_, mixfix)) lthy = - let - val ((f, (_, f_defthm)), lthy') = - Local_Theory.define - ((Binding.name fname, mixfix), - ((Binding.conceal (Binding.name (fname ^ "_def")), []), - Term.subst_bound (fsum, f_def))) lthy - in - (MutualPart {i=i, i'=i', fvar=(fname, fT), cargTs=cargTs, f_def=f_def, - f=SOME f, f_defthm=SOME f_defthm }, - lthy') - end - - val Mutual { n, n', fsum_var, ST, RST, parts, fqgars, qglrs, ... } = mutual - val (parts', lthy') = fold_map def (parts ~~ fixes) lthy - in - (Mutual { n=n, n'=n', fsum_var=fsum_var, ST=ST, RST=RST, parts=parts', - fqgars=fqgars, qglrs=qglrs, fsum=SOME fsum }, - lthy') - end - -fun in_context ctxt (f, pre_qs, pre_gs, pre_args, pre_rhs) F = - let - val thy = ProofContext.theory_of ctxt - - val oqnames = map fst pre_qs - val (qs, _) = Variable.variant_fixes oqnames ctxt - |>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs - - fun inst t = subst_bounds (rev qs, t) - val gs = map inst pre_gs - val args = map inst pre_args - val rhs = inst pre_rhs - - val cqs = map (cterm_of thy) qs - val ags = map (Thm.assume o cterm_of thy) gs - - val import = fold Thm.forall_elim cqs - #> fold Thm.elim_implies ags - - val export = fold_rev (Thm.implies_intr o cprop_of) ags - #> fold_rev forall_intr_rename (oqnames ~~ cqs) - in - F ctxt (f, qs, gs, args, rhs) import export - end - -fun recover_mutual_psimp all_orig_fdefs parts ctxt (fname, _, _, args, rhs) - import (export : thm -> thm) sum_psimp_eq = - let - val (MutualPart {f=SOME f, ...}) = get_part fname parts - - val psimp = import sum_psimp_eq - val (simp, restore_cond) = - case cprems_of psimp of - [] => (psimp, I) - | [cond] => (Thm.implies_elim psimp (Thm.assume cond), Thm.implies_intr cond) - | _ => raise General.Fail "Too many conditions" - - in - Goal.prove ctxt [] [] - (HOLogic.Trueprop $ HOLogic.mk_eq (list_comb (f, args), rhs)) - (fn _ => (Local_Defs.unfold_tac ctxt all_orig_fdefs) - THEN EqSubst.eqsubst_tac ctxt [0] [simp] 1 - THEN (simp_tac (simpset_of ctxt)) 1) (* FIXME: global simpset?!! *) - |> restore_cond - |> export - end - -fun mk_applied_form ctxt caTs thm = - let - val thy = ProofContext.theory_of ctxt - val xs = map_index (fn (i,T) => cterm_of thy (Free ("x" ^ string_of_int i, T))) caTs (* FIXME: Bind xs properly *) - in - fold (fn x => fn thm => Thm.combination thm (Thm.reflexive x)) xs thm - |> Conv.fconv_rule (Thm.beta_conversion true) - |> fold_rev Thm.forall_intr xs - |> Thm.forall_elim_vars 0 - end - -fun mutual_induct_rules lthy induct all_f_defs (Mutual {n, ST, parts, ...}) = - let - val cert = cterm_of (ProofContext.theory_of lthy) - val newPs = - map2 (fn Pname => fn MutualPart {cargTs, ...} => - Free (Pname, cargTs ---> HOLogic.boolT)) - (mutual_induct_Pnames (length parts)) parts - - fun mk_P (MutualPart {cargTs, ...}) P = - let - val avars = map_index (fn (i,T) => Var (("a", i), T)) cargTs - val atup = foldr1 HOLogic.mk_prod avars - in - HOLogic.tupled_lambda atup (list_comb (P, avars)) - end - - val Ps = map2 mk_P parts newPs - val case_exp = SumTree.mk_sumcases HOLogic.boolT Ps - - val induct_inst = - Thm.forall_elim (cert case_exp) induct - |> full_simplify SumTree.sumcase_split_ss - |> full_simplify (HOL_basic_ss addsimps all_f_defs) - - fun project rule (MutualPart {cargTs, i, ...}) k = - let - val afs = map_index (fn (j,T) => Free ("a" ^ string_of_int (j + k), T)) cargTs (* FIXME! *) - val inj = SumTree.mk_inj ST n i (foldr1 HOLogic.mk_prod afs) - in - (rule - |> Thm.forall_elim (cert inj) - |> full_simplify SumTree.sumcase_split_ss - |> fold_rev (Thm.forall_intr o cert) (afs @ newPs), - k + length cargTs) - end - in - fst (fold_map (project induct_inst) parts 0) - end - -fun mk_partial_rules_mutual lthy inner_cont (m as Mutual {parts, fqgars, ...}) proof = - let - val result = inner_cont proof - val FunctionResult {G, R, cases, psimps, trsimps, simple_pinducts=[simple_pinduct], - termination, domintros, ...} = result - - val (all_f_defs, fs) = - map (fn MutualPart {f_defthm = SOME f_def, f = SOME f, cargTs, ...} => - (mk_applied_form lthy cargTs (Thm.symmetric f_def), f)) - parts - |> split_list - - val all_orig_fdefs = - map (fn MutualPart {f_defthm = SOME f_def, ...} => f_def) parts - - fun mk_mpsimp fqgar sum_psimp = - in_context lthy fqgar (recover_mutual_psimp all_orig_fdefs parts) sum_psimp - - val rew_ss = HOL_basic_ss addsimps all_f_defs - val mpsimps = map2 mk_mpsimp fqgars psimps - val mtrsimps = Option.map (map2 mk_mpsimp fqgars) trsimps - val minducts = mutual_induct_rules lthy simple_pinduct all_f_defs m - val mtermination = full_simplify rew_ss termination - val mdomintros = Option.map (map (full_simplify rew_ss)) domintros - in - FunctionResult { fs=fs, G=G, R=R, - psimps=mpsimps, simple_pinducts=minducts, - cases=cases, termination=mtermination, - domintros=mdomintros, trsimps=mtrsimps} - end - -fun prepare_function_mutual config defname fixes eqss lthy = - let - val mutual as Mutual {fsum_var=(n, T), qglrs, ...} = - analyze_eqs lthy defname (map fst fixes) (map Envir.beta_eta_contract eqss) - - val ((fsum, goalstate, cont), lthy') = - prepare_function config defname [((n, T), NoSyn)] qglrs lthy - - val (mutual', lthy'') = define_projections fixes mutual fsum lthy' - - val mutual_cont = mk_partial_rules_mutual lthy'' cont mutual' - in - ((goalstate, mutual_cont), lthy'') - end - -*} - - -ML {* - -open Function_Lib -open Function_Common - -val simp_attribs = map (Attrib.internal o K) - [Simplifier.simp_add, - Code.add_default_eqn_attribute, - Nitpick_Simps.add] - -val psimp_attribs = map (Attrib.internal o K) - [Nitpick_Psimps.add] - -fun mk_defname fixes = fixes |> map (fst o fst) |> space_implode "_" - -fun add_simps fnames post sort extra_qualify label mod_binding moreatts - simps lthy = - let - val spec = post simps - |> map (apfst (apsnd (fn ats => moreatts @ ats))) - |> map (apfst (apfst extra_qualify)) - - val (saved_spec_simps, lthy) = - fold_map Local_Theory.note spec lthy - - val saved_simps = maps snd saved_spec_simps - val simps_by_f = sort saved_simps - - fun add_for_f fname simps = - Local_Theory.note - ((mod_binding (Binding.qualify true fname (Binding.name label)), []), simps) - #> snd - in - (saved_simps, fold2 add_for_f fnames simps_by_f lthy) - end - -fun prepare_function is_external prep default_constraint fixspec eqns config lthy = - let - val constrn_fxs = map (fn (b, T, mx) => (b, SOME (the_default default_constraint T), mx)) - val ((fixes0, spec0), ctxt') = prep (constrn_fxs fixspec) eqns lthy - val fixes = map (apfst (apfst Binding.name_of)) fixes0; - val spec = map (fn (bnd, prop) => (bnd, [prop])) spec0; - val (eqs, post, sort_cont, cnames) = get_preproc lthy config ctxt' fixes spec - - val defname = mk_defname fixes - val FunctionConfig {partials, tailrec, default, ...} = config - val _ = - if tailrec then Output.legacy_feature - "'function (tailrec)' command. Use 'partial_function (tailrec)'." - else () - val _ = - if is_some default then Output.legacy_feature - "'function (default)'. Use 'partial_function'." - else () - - val ((goal_state, cont), lthy') = - prepare_function_mutual config defname fixes eqs lthy - - fun afterqed [[proof]] lthy = - let - val FunctionResult {fs, R, psimps, trsimps, simple_pinducts, - termination, domintros, cases, ...} = - cont (Thm.close_derivation proof) - - val fnames = map (fst o fst) fixes - fun qualify n = Binding.name n - |> Binding.qualify true defname - val conceal_partial = if partials then I else Binding.conceal - - val addsmps = add_simps fnames post sort_cont - - val (((psimps', pinducts'), (_, [termination'])), lthy) = - lthy - |> addsmps (conceal_partial o Binding.qualify false "partial") - "psimps" conceal_partial psimp_attribs psimps - ||> (case trsimps of NONE => I | SOME thms => - addsmps I "simps" I simp_attribs thms #> snd - #> Spec_Rules.add Spec_Rules.Equational (fs, thms)) - ||>> Local_Theory.note ((conceal_partial (qualify "pinduct"), - [Attrib.internal (K (Rule_Cases.case_names cnames)), - Attrib.internal (K (Rule_Cases.consumes 1)), - Attrib.internal (K (Induct.induct_pred ""))]), simple_pinducts) - ||>> Local_Theory.note ((Binding.conceal (qualify "termination"), []), [termination]) - ||> (snd o Local_Theory.note ((qualify "cases", - [Attrib.internal (K (Rule_Cases.case_names cnames))]), [cases])) - ||> (case domintros of NONE => I | SOME thms => - Local_Theory.note ((qualify "domintros", []), thms) #> snd) - - val info = { add_simps=addsmps, case_names=cnames, psimps=psimps', - pinducts=snd pinducts', simps=NONE, inducts=NONE, termination=termination', - fs=fs, R=R, defname=defname, is_partial=true } - - val _ = - if not is_external then () - else Specification.print_consts lthy (K false) (map fst fixes) - in - (info, - lthy |> Local_Theory.declaration false (add_function_data o morph_function_data info)) - end - in - ((goal_state, afterqed), lthy') - end - -*} - -ML {* -fun gen_function is_external prep default_constraint fixspec eqns config lthy = - let - val ((goal_state, afterqed), lthy') = - prepare_function is_external prep default_constraint fixspec eqns config lthy - in - lthy' - |> Proof.theorem NONE (snd oo afterqed) [[(Logic.unprotect (concl_of goal_state), [])]] - |> Proof.refine (Method.primitive_text (K goal_state)) - |> Seq.hd - end -*} - - -ML {* -val function = gen_function false Specification.check_spec (Type_Infer.anyT HOLogic.typeS) -val function_cmd = gen_function true Specification.read_spec "_::type" - -fun add_case_cong n thy = - let - val cong = #case_cong (Datatype.the_info thy n) - |> safe_mk_meta_eq - in - Context.theory_map - (Function_Ctx_Tree.map_function_congs (Thm.add_thm cong)) thy - end - -val setup_case_cong = Datatype.interpretation (K (fold add_case_cong)) - - -(* setup *) - -val setup = - Attrib.setup @{binding fundef_cong} - (Attrib.add_del Function_Ctx_Tree.cong_add Function_Ctx_Tree.cong_del) - "declaration of congruence rule for function definitions" - #> setup_case_cong - #> Function_Relation.setup - #> Function_Common.Termination_Simps.setup - -val get_congs = Function_Ctx_Tree.get_function_congs - -fun get_info ctxt t = Item_Net.retrieve (get_function ctxt) t - |> the_single |> snd - - -(* outer syntax *) - -val _ = - Outer_Syntax.local_theory_to_proof "nominal_primrec" "define recursive functions for nominal types" - Keyword.thy_goal - (function_parser default_config - >> (fn ((config, fixes), statements) => function_cmd fixes statements config)) -*} - -ML {* trace := true *} - -lemma test: - assumes a: "[[x]]lst. t = [[x]]lst. t'" - shows "t = t'" -using a -apply(simp add: Abs_eq_iff) -apply(erule exE) -apply(simp only: alphas) -apply(erule conjE)+ -apply(rule sym) -apply(clarify) -apply(rule supp_perm_eq) -apply(subgoal_tac "set [x] \* p") -apply(auto simp add: fresh_star_def)[1] -apply(simp) -apply(simp add: fresh_star_def) -apply(simp add: fresh_perm) -done - -lemma test2: - assumes "a \ x" "c \ x" "b \ y" "c \ y" - and "(a \ c) \ x = (b \ c) \ y" - shows "x = y" -using assms by (simp add: swap_fresh_fresh) - -lemma test3: - assumes "x = y" - and "a \ x" "c \ x" "b \ y" "c \ y" - shows "(a \ c) \ x = (b \ c) \ y" -using assms by (simp add: swap_fresh_fresh) - -nominal_primrec - depth :: "lam \ nat" -where - "depth (Var x) = 1" -| "depth (App t1 t2) = (max (depth t1) (depth t2)) + 1" -| "depth (Lam x t) = (depth t) + 1" -apply(rule_tac y="x" in lam.exhaust) -apply(simp_all)[3] -apply(simp_all only: lam.distinct) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(subst (asm) Abs_eq_iff) -apply(erule exE) -apply(simp add: alphas) -apply(clarify) -oops - -lemma removeAll_eqvt[eqvt]: - shows "p \ (removeAll x xs) = removeAll (p \ x) (p \ xs)" -by (induct xs) (auto) - -nominal_primrec - frees_lst :: "lam \ atom list" -where - "frees_lst (Var x) = [atom x]" -| "frees_lst (App t1 t2) = (frees_lst t1) @ (frees_lst t2)" -| "frees_lst (Lam x t) = removeAll (atom x) (frees_lst t)" -apply(rule_tac y="x" in lam.exhaust) -apply(simp_all)[3] -apply(simp_all only: lam.distinct) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: Abs_eq_iff) -apply(erule exE) -apply(simp add: alphas) -apply(simp add: atom_eqvt) -apply(clarify) -oops - -nominal_primrec - subst :: "lam \ name \ lam \ lam" ("_ [_ ::= _]" [100,100,100] 100) -where - "(Var x)[y ::= s] = (if x=y then s else (Var x))" -| "(App t\<^isub>1 t\<^isub>2)[y ::= s] = App (t\<^isub>1[y ::= s]) (t\<^isub>2[y ::= s])" -| "atom x \ (y, s) \ (Lam x t)[y ::= s] = Lam x (t[y ::= s])" -apply(case_tac x) -apply(simp) -apply(rule_tac y="a" and c="(b, c)" in lam.strong_exhaust) -apply(simp add: lam.eq_iff lam.distinct) -apply(auto)[1] -apply(simp add: lam.eq_iff lam.distinct) -apply(auto)[1] -apply(simp add: fresh_star_def lam.eq_iff lam.distinct) -apply(simp_all add: lam.distinct)[5] -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(erule conjE)+ -oops - - - -nominal_primrec - depth :: "lam \ nat" -where - "depth (Var x) = 1" -| "depth (App t1 t2) = (max (depth t1) (depth t2)) + 1" -| "depth (Lam x t) = (depth t) + 1" -apply(rule_tac y="x" in lam.exhaust) -apply(simp_all)[3] -apply(simp_all only: lam.distinct) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -(* -apply(subst (asm) Abs_eq_iff) -apply(erule exE) -apply(simp add: alphas) -apply(clarify) -*) -apply(subgoal_tac "finite (supp (x, xa, t, ta, depth_sumC t, depth_sumC ta))") -apply(erule_tac ?'a="name" in obtain_at_base) -unfolding fresh_def[symmetric] -apply(drule_tac a="atom x" and b="atom xa" and c="atom a" in test3) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(rule_tac a="atom x" and b="atom xa" and c="atom a" in test2) -apply(simp add: pure_fresh) -apply(simp add: pure_fresh) -apply(simp add: pure_fresh) -apply(simp add: pure_fresh) -apply(simp add: eqvt_at_def) -apply(drule test) -apply(simp) -apply(simp add: finite_supp) -done - -termination depth - apply(relation "measure size") - apply(auto simp add: lam.size) - done - -thm depth.psimps -thm depth.simps - - -lemma swap_set_not_in_at: - fixes a b::"'a::at" - and S::"'a::at set" - assumes a: "a \ S" "b \ S" - shows "(a \ b) \ S = S" - unfolding permute_set_def - using a by (auto simp add: permute_flip_at) - -lemma removeAll_eqvt[eqvt]: - shows "p \ (removeAll x xs) = removeAll (p \ x) (p \ xs)" -by (induct xs) (auto) - -nominal_primrec - frees_lst :: "lam \ atom list" -where - "frees_lst (Var x) = [atom x]" -| "frees_lst (App t1 t2) = (frees_lst t1) @ (frees_lst t2)" -| "frees_lst (Lam x t) = removeAll (atom x) (frees_lst t)" -apply(rule_tac y="x" in lam.exhaust) -apply(simp_all)[3] -apply(simp_all only: lam.distinct) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: Abs_eq_iff) -apply(erule exE) -apply(simp add: alphas) -apply(simp add: atom_eqvt) -apply(clarify) -apply(rule trans) -apply(rule sym) -apply(rule_tac p="p" in supp_perm_eq) -oops - -nominal_primrec - frees :: "lam \ name set" -where - "frees (Var x) = {x}" -| "frees (App t1 t2) = (frees t1) \ (frees t2)" -| "frees (Lam x t) = (frees t) - {x}" -apply(rule_tac y="x" in lam.exhaust) -apply(simp_all)[3] -apply(simp_all only: lam.distinct) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(subgoal_tac "finite (supp (x, xa, t, ta, frees_sumC t, frees_sumC ta))") -apply(erule_tac ?'a="name" in obtain_at_base) -unfolding fresh_def[symmetric] -apply(drule_tac a="atom x" and b="atom xa" and c="atom a" in test3) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp) -apply(drule test) -apply(rule_tac t="frees_sumC t - {x}" and s="(x \ a) \ (frees_sumC t - {x})" in subst) -oops - -thm Abs_eq_iff[simplified alphas] - -lemma Abs_set_eq_iff2: - fixes x y::"'a::fs" - shows "[bs]set. x = [cs]set. y \ - (\p. supp ([bs]set. x) = supp ([cs]set. y) \ - supp ([bs]set. x) \* p \ - p \ x = y \ p \ bs = cs)" -unfolding Abs_eq_iff -unfolding alphas -unfolding supp_Abs -by simp - -lemma Abs_set_eq_iff3: - fixes x y::"'a::fs" - assumes a: "finite bs" "finite cs" - shows "[bs]set. x = [cs]set. y \ - (\p. supp ([bs]set. x) = supp ([cs]set. y) \ - supp ([bs]set. x) \* p \ - p \ x = y \ p \ bs = cs \ - supp p \ bs \ cs)" -unfolding Abs_eq_iff -unfolding alphas -unfolding supp_Abs -apply(auto) -using set_renaming_perm -sorry - -lemma Abs_eq_iff2: - fixes x y::"'a::fs" - shows "[bs]lst. x = [cs]lst. y \ - (\p. supp ([bs]lst. x) = supp ([cs]lst. y) \ - supp ([bs]lst. x) \* p \ - p \ x = y \ p \ bs = cs)" -unfolding Abs_eq_iff -unfolding alphas -unfolding supp_Abs -by simp - -lemma Abs_eq_iff3: - fixes x y::"'a::fs" - shows "[bs]lst. x = [cs]lst. y \ - (\p. supp ([bs]lst. x) = supp ([cs]lst. y) \ - supp ([bs]lst. x) \* p \ - p \ x = y \ p \ bs = cs \ - supp p \ set bs \ set cs)" -unfolding Abs_eq_iff -unfolding alphas -unfolding supp_Abs -apply(auto) -using list_renaming_perm -apply - -apply(drule_tac x="bs" in meta_spec) -apply(drule_tac x="p" in meta_spec) -apply(erule exE) -apply(rule_tac x="q" in exI) -apply(simp add: set_eqvt) -sorry - -nominal_primrec - subst :: "lam \ name \ lam \ lam" ("_ [_ ::= _]" [100,100,100] 100) -where - "(Var x)[y ::= s] = (if x=y then s else (Var x))" -| "(App t\<^isub>1 t\<^isub>2)[y ::= s] = App (t\<^isub>1[y ::= s]) (t\<^isub>2[y ::= s])" -| "atom x \ (y, s) \ (Lam x t)[y ::= s] = Lam x (t[y ::= s])" -apply(case_tac x) -apply(simp) -apply(rule_tac y="a" and c="(b, c)" in lam.strong_exhaust) -apply(simp add: lam.eq_iff lam.distinct) -apply(auto)[1] -apply(simp add: lam.eq_iff lam.distinct) -apply(auto)[1] -apply(simp add: fresh_star_def lam.eq_iff lam.distinct) -apply(simp_all add: lam.distinct)[5] -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(erule conjE)+ -apply(subst (asm) Abs_eq_iff3) -apply(erule exE) -apply(erule conjE)+ -apply(clarify) -apply(perm_simp) -apply(simp) -apply(rule trans) -apply(rule sym) -apply(rule_tac p="p" in supp_perm_eq) -apply(rule fresh_star_supp_conv) -apply(drule fresh_star_supp_conv) -apply(simp add: Abs_fresh_star_iff) -thm fresh_eqvt_at -apply(rule_tac f="subst_sumC" in fresh_eqvt_at) -apply(assumption) -apply(simp add: finite_supp) -prefer 2 -apply(simp) -apply(simp add: eqvt_at_def) -apply(perm_simp) -apply(subgoal_tac "p \ ya = ya") -apply(subgoal_tac "p \ sa = sa") -apply(simp) -apply(rule supp_perm_eq) -apply(rule fresh_star_supp_conv) -apply(auto simp add: fresh_star_def fresh_Pair)[1] -apply(rule supp_perm_eq) -apply(rule fresh_star_supp_conv) -apply(auto simp add: fresh_star_def fresh_Pair)[1] - - - -nominal_primrec - subst :: "lam \ name \ lam \ lam" ("_ [_ ::= _]" [100,100,100] 100) -where - "(Var x)[y ::= s] = (if x=y then s else (Var x))" -| "(App t\<^isub>1 t\<^isub>2)[y ::= s] = App (t\<^isub>1[y ::= s]) (t\<^isub>2[y ::= s])" -| "atom x \ (y, s) \ (Lam x t)[y ::= s] = Lam x (t[y ::= s])" -apply(case_tac x) -apply(simp) -apply(rule_tac y="a" and c="(b, c)" in lam.strong_exhaust) -apply(simp add: lam.eq_iff lam.distinct) -apply(auto)[1] -apply(simp add: lam.eq_iff lam.distinct) -apply(auto)[1] -apply(simp add: fresh_star_def lam.eq_iff lam.distinct) -apply(simp_all add: lam.distinct)[5] -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(subgoal_tac "finite (supp (ya, sa, x, xa, t, ta, subst_sumC (t, ya, sa), subst_sumC (ta, ya, sa)))") -apply(erule_tac ?'a="name" in obtain_at_base) -unfolding fresh_def[symmetric] -apply(rule_tac a="atom x" and b="atom xa" and c="atom a" in test2) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(erule conjE)+ -apply(drule_tac a="atom x" and b="atom xa" and c="atom a" in test3) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff) -apply(simp add: eqvt_at_def) -apply(drule test) -apply(simp) -apply(subst (2) swap_fresh_fresh) -apply(simp) -apply(simp) -apply(subst (2) swap_fresh_fresh) -apply(simp) -apply(simp) -apply(subst (3) swap_fresh_fresh) -apply(simp) -apply(simp) -apply(subst (3) swap_fresh_fresh) -apply(simp) -apply(simp) -apply(simp) -apply(simp add: finite_supp) -done - -(* this should not work *) -nominal_primrec - bnds :: "lam \ name set" -where - "bnds (Var x) = {}" -| "bnds (App t1 t2) = (bnds t1) \ (bnds t2)" -| "bnds (Lam x t) = (bnds t) \ {x}" -apply(rule_tac y="x" in lam.exhaust) -apply(simp_all)[3] -apply(simp_all only: lam.distinct) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -apply(simp add: lam.eq_iff) -sorry - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/Lambda_F_T.thy --- a/Nominal/Ex/Lambda_F_T.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -theory Lambda -imports "../Nominal2" -begin - -atom_decl name - -nominal_datatype lam = - Var "name" -| App "lam" "lam" -| Lam x::"name" l::"lam" binds x in l ("Lam [_]. _" [100, 100] 100) - -lemma fresh_fun_eqvt_app3: - assumes a: "eqvt f" - and b: "a \ x" "a \ y" "a \ z" - shows "a \ f x y z" - using fresh_fun_eqvt_app[OF a b(1)] a b - by (metis fresh_fun_app) - -lemma fresh_fun_eqvt_app4: - assumes a: "eqvt f" - and b: "a \ x" "a \ y" "a \ z" "a \ w" - shows "a \ f x y z w" - using fresh_fun_eqvt_app[OF a b(1)] a b - by (metis fresh_fun_app) - -lemma the_default_pty: - assumes f_def: "f == (\x::'a. THE_default d (G x))" - and unique: "\!y. G x y" - and pty: "\x y. G x y \ P x y" - shows "P x (f x)" - apply(subst f_def) - apply (rule ex1E[OF unique]) - apply (subst THE_default1_equality[OF unique]) - apply assumption - apply (rule pty) - apply assumption - done - -locale test = - fixes f1::"name \ name list \ ('a::pt)" - and f2::"lam \ lam \ 'a \ 'a \ name list \ ('a::pt)" - and f3::"name \ lam \ 'a \ name list \ ('a::pt)" - assumes fs: "finite (supp (f1, f2, f3))" - and eq: "eqvt f1" "eqvt f2" "eqvt f3" - and fcb1: "\l n. atom ` set l \* f1 n l" - and fcb2: "\l t1 t2 r1 r2. atom ` set l \* (r1, r2) \ atom ` set l \* f2 t1 t2 r1 r2 l" - and fcb3: "\t l r. atom ` set (x # l) \* r \ atom ` set (x # l) \* f3 x t r l" -begin - -nominal_primrec (invariant "\(x, l) y. atom ` set l \* y") - f -where - "f (Var x) l = f1 x l" -| "f (App t1 t2) l = f2 t1 t2 (f t1 l) (f t2 l) l" -| "atom x \ l \ (f (Lam [x].t) l) = f3 x t (f t (x # l)) l" - apply (simp add: eqvt_def f_graph_def) - apply (rule, perm_simp) - apply (simp only: eq[unfolded eqvt_def]) - apply (erule f_graph.induct) - apply (simp add: fcb1) - apply (simp add: fcb2 fresh_star_Pair) - apply simp - apply (subgoal_tac "atom ` set (xa # l) \* f3 xa t (f_sum (t, xa # l)) l") - apply (simp add: fresh_star_def) - apply (rule fcb3) - apply (simp add: fresh_star_def fresh_def) - apply simp_all - apply(case_tac x) - apply(rule_tac y="a" and c="b" in lam.strong_exhaust) - apply(auto simp add: fresh_star_def) - apply(erule Abs_lst1_fcb) - apply (subgoal_tac "atom ` set (x # la) \* f3 x t (f_sumC (t, x # la)) la") - apply (simp add: fresh_star_def) - apply (rule fcb3) - apply (simp add: fresh_star_def) - apply (rule fresh_fun_eqvt_app4[OF eq(3)]) - apply (simp add: fresh_at_base) - apply assumption - apply (erule fresh_eqvt_at) - apply (simp add: finite_supp) - apply (simp add: fresh_Pair fresh_Cons fresh_at_base) - apply assumption - apply (subgoal_tac "\p y r l. p \ (f3 x y r l) = f3 (p \ x) (p \ y) (p \ r) (p \ l)") - apply (subgoal_tac "(atom x \ atom xa) \ la = la") - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh) - apply (simp add: permute_fun_app_eq eq[unfolded eqvt_def]) - apply simp - done - -termination - by (relation "measure (\(x,_). size x)") (auto simp add: lam.size) - -end - -section {* Locally Nameless Terms *} - -nominal_datatype ln = - LNBnd nat -| LNVar name -| LNApp ln ln -| LNLam ln - -fun - lookup :: "name list \ nat \ name \ ln" -where - "lookup [] n x = LNVar x" -| "lookup (y # ys) n x = (if x = y then LNBnd n else (lookup ys (n + 1) x))" - -lemma lookup_eqvt[eqvt]: - shows "(p \ lookup xs n x) = lookup (p \ xs) (p \ n) (p \ x)" - by (induct xs arbitrary: n) (simp_all add: permute_pure) - -lemma fresh_at_list: "atom x \ xs \ x \ set xs" - unfolding fresh_def supp_set[symmetric] - apply (induct xs) - apply (simp add: supp_set_empty) - apply simp - apply auto - apply (simp_all add: insert_absorb UnI2 finite_set supp_of_finite_insert supp_at_base) - done - -interpretation trans: test - "%x l. lookup l 0 x" - "%t1 t2 r1 r2 l. LNApp r1 r2" - "%n t r l. LNLam r" - apply default - apply (auto simp add: pure_fresh supp_Pair) - apply (simp_all add: fresh_def supp_def permute_fun_def permute_pure lookup_eqvt)[3] - apply (simp_all add: eqvt_def permute_fun_def permute_pure lookup_eqvt) - apply (simp add: fresh_star_def) - apply (rule_tac x="0 :: nat" in spec) - apply (induct_tac l) - apply (simp add: ln.fresh pure_fresh) - apply (auto simp add: ln.fresh pure_fresh)[1] - apply (case_tac "a \ set list") - apply simp - apply (rule_tac f="lookup" in fresh_fun_eqvt_app3) - unfolding eqvt_def - apply rule - using eqvts_raw(35) - apply auto[1] - apply (simp add: fresh_at_list) - apply (simp add: pure_fresh) - apply (simp add: fresh_at_base) - apply (simp add: fresh_star_Pair fresh_star_def ln.fresh) - apply (simp add: fresh_star_def ln.fresh) - done - -thm trans.f.simps - -lemma lam_strong_exhaust2: - "\\name. y = Var name \ P; - \lam1 lam2. y = App lam1 lam2 \ P; - \name lam. \{atom name} \* c; y = Lam [name]. lam\ \ P; - finite (supp c)\ - \ P" -sorry - -nominal_primrec - g -where - "(~finite (supp (g1, g2, g3))) \ g g1 g2 g3 t = t" -| "finite (supp (g1, g2, g3)) \ g g1 g2 g3 (Var x) = g1 x" -| "finite (supp (g1, g2, g3)) \ g g1 g2 g3 (App t1 t2) = g2 t1 t2 (g g1 g2 g3 t1) (g g1 g2 g3 t2)" -| "finite (supp (g1, g2, g3)) \ atom x \ (g1,g2,g3) \ (g g1 g2 g3 (Lam [x].t)) = g3 x t (g g1 g2 g3 t)" - apply (simp add: eqvt_def g_graph_def) - apply (rule, perm_simp, rule) - apply simp_all - apply (case_tac x) - apply (case_tac "finite (supp (a, b, c))") - prefer 2 - apply simp - apply(rule_tac y="d" and c="(a,b,c)" in lam_strong_exhaust2) - apply auto - apply blast - apply (simp add: Abs1_eq_iff fresh_star_def) - sorry - -termination - by (relation "measure (\(_,_,_,t). size t)") (simp_all add: lam.size) - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/Lambda_F_T_FCB2.thy --- a/Nominal/Ex/Lambda_F_T_FCB2.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,270 +0,0 @@ -theory Lambda -imports "../Nominal2" -begin - -atom_decl name - -nominal_datatype lam = - Var "name" -| App "lam" "lam" -| Lam x::"name" l::"lam" bind x in l ("Lam [_]. _" [100, 100] 100) - -lemma fresh_fun_eqvt_app3: - assumes a: "eqvt f" - and b: "a \ x" "a \ y" "a \ z" - shows "a \ f x y z" - using fresh_fun_eqvt_app[OF a b(1)] a b - by (metis fresh_fun_app) - -lemma fresh_fun_eqvt_app4: - assumes a: "eqvt f" - and b: "a \ x" "a \ y" "a \ z" "a \ w" - shows "a \ f x y z w" - using fresh_fun_eqvt_app[OF a b(1)] a b - by (metis fresh_fun_app) - -lemma the_default_pty: - assumes f_def: "f == (\x::'a. THE_default d (G x))" - and unique: "\!y. G x y" - and pty: "\x y. G x y \ P x y" - shows "P x (f x)" - apply(subst f_def) - apply (rule ex1E[OF unique]) - apply (subst THE_default1_equality[OF unique]) - apply assumption - apply (rule pty) - apply assumption - done - -lemma Abs_lst1_fcb2: - fixes a b :: "'a :: at" - and S T :: "'b :: fs" - and c::"'c::fs" - assumes e: "(Abs_lst [atom a] T) = (Abs_lst [atom b] S)" - and fcb: "\a T. atom a \ f a T c" - and fresh: "{atom a, atom b} \* c" - and perm1: "\p. supp p \* c \ p \ (f a T c) = f (p \ a) (p \ T) c" - and perm2: "\p. supp p \* c \ p \ (f b S c) = f (p \ b) (p \ S) c" - shows "f a T c = f b S c" -proof - - have fin1: "finite (supp (f a T c))" - apply(rule_tac S="supp (a, T, c)" in supports_finite) - apply(simp add: supports_def) - apply(simp add: fresh_def[symmetric]) - apply(clarify) - apply(subst perm1) - apply(simp add: supp_swap fresh_star_def) - apply(simp add: swap_fresh_fresh fresh_Pair) - apply(simp add: finite_supp) - done - have fin2: "finite (supp (f b S c))" - apply(rule_tac S="supp (b, S, c)" in supports_finite) - apply(simp add: supports_def) - apply(simp add: fresh_def[symmetric]) - apply(clarify) - apply(subst perm2) - apply(simp add: supp_swap fresh_star_def) - apply(simp add: swap_fresh_fresh fresh_Pair) - apply(simp add: finite_supp) - done - obtain d::"'a::at" where fr: "atom d \ (a, b, S, T, c, f a T c, f b S c)" - using obtain_fresh'[where x="(a, b, S, T, c, f a T c, f b S c)"] - apply(auto simp add: finite_supp supp_Pair fin1 fin2) - done - have "(a \ d) \ (Abs_lst [atom a] T) = (b \ d) \ (Abs_lst [atom b] S)" - apply(simp (no_asm_use) only: flip_def) - apply(subst swap_fresh_fresh) - apply(simp add: Abs_fresh_iff) - using fr - apply(simp add: Abs_fresh_iff) - apply(subst swap_fresh_fresh) - apply(simp add: Abs_fresh_iff) - using fr - apply(simp add: Abs_fresh_iff) - apply(rule e) - done - then have "Abs_lst [atom d] ((a \ d) \ T) = Abs_lst [atom d] ((b \ d) \ S)" - apply (simp add: swap_atom flip_def) - done - then have eq: "(a \ d) \ T = (b \ d) \ S" - by (simp add: Abs1_eq_iff) - have "f a T c = (a \ d) \ f a T c" - unfolding flip_def - apply(rule sym) - apply(rule swap_fresh_fresh) - using fcb[where a="a"] - apply(simp) - using fr - apply(simp add: fresh_Pair) - done - also have "... = f d ((a \ d) \ T) c" - unfolding flip_def - apply(subst perm1) - using fresh fr - apply(simp add: supp_swap fresh_star_def fresh_Pair) - apply(simp) - done - also have "... = f d ((b \ d) \ S) c" using eq by simp - also have "... = (b \ d) \ f b S c" - unfolding flip_def - apply(subst perm2) - using fresh fr - apply(simp add: supp_swap fresh_star_def fresh_Pair) - apply(simp) - done - also have "... = f b S c" - apply(rule flip_fresh_fresh) - using fcb[where a="b"] - apply(simp) - using fr - apply(simp add: fresh_Pair) - done - finally show ?thesis by simp -qed - -locale test = - fixes f1::"name \ name list \ ('a::pt)" - and f2::"lam \ lam \ 'a \ 'a \ name list \ ('a::pt)" - and f3::"name \ lam \ 'a \ name list \ ('a::pt)" - assumes fs: "finite (supp (f1, f2, f3))" - and eq: "eqvt f1" "eqvt f2" "eqvt f3" - and fcb1: "\l n. atom ` set l \* f1 n l" - and fcb2: "\l t1 t2 r1 r2. atom ` set l \* (r1, r2) \ atom ` set l \* f2 t1 t2 r1 r2 l" - and fcb3: "\t l r. atom ` set (x # l) \* r \ atom ` set (x # l) \* f3 x t r l" -begin - -nominal_primrec (invariant "\(x, l) y. atom ` set l \* y") - f -where - "f (Var x) l = f1 x l" -| "f (App t1 t2) l = f2 t1 t2 (f t1 l) (f t2 l) l" -| "atom x \ l \ (f (Lam [x].t) l) = f3 x t (f t (x # l)) l" - apply (simp add: eqvt_def f_graph_def) - apply (rule, perm_simp) - apply (simp only: eq[unfolded eqvt_def]) - apply (erule f_graph.induct) - apply (simp add: fcb1) - apply (simp add: fcb2 fresh_star_Pair) - apply simp - apply (subgoal_tac "atom ` set (xa # l) \* f3 xa t (f_sum (t, xa # l)) l") - apply (simp add: fresh_star_def) - apply (rule fcb3) - apply (simp add: fresh_star_def fresh_def) - apply simp_all - apply(case_tac x) - apply(rule_tac y="a" and c="b" in lam.strong_exhaust) - apply(auto simp add: fresh_star_def) - apply(erule_tac Abs_lst1_fcb2) ---"?" - apply (subgoal_tac "atom ` set (a # la) \* f3 a T (f_sumC (T, a # la)) la") - apply (simp add: fresh_star_def) - apply (rule fcb3) - apply (simp add: fresh_star_def) - apply (rule fresh_fun_eqvt_app4[OF eq(3)]) - apply (simp add: fresh_at_base) - apply assumption - apply (erule fresh_eqvt_at) - apply (simp add: finite_supp) - apply (simp add: fresh_Pair fresh_Cons fresh_at_base) - apply assumption - apply (subgoal_tac "\p y r l. p \ (f3 x y r l) = f3 (p \ x) (p \ y) (p \ r) (p \ l)") - apply (subgoal_tac "(atom x \ atom xa) \ la = la") - apply (simp add: eqvt_at_def) - apply (simp add: swap_fresh_fresh) - apply (simp add: permute_fun_app_eq eq[unfolded eqvt_def]) - apply simp - done - -termination - by (relation "measure (\(x,_). size x)") (auto simp add: lam.size) - -end - -section {* Locally Nameless Terms *} - -nominal_datatype ln = - LNBnd nat -| LNVar name -| LNApp ln ln -| LNLam ln - -fun - lookup :: "name list \ nat \ name \ ln" -where - "lookup [] n x = LNVar x" -| "lookup (y # ys) n x = (if x = y then LNBnd n else (lookup ys (n + 1) x))" - -lemma lookup_eqvt[eqvt]: - shows "(p \ lookup xs n x) = lookup (p \ xs) (p \ n) (p \ x)" - by (induct xs arbitrary: n) (simp_all add: permute_pure) - -lemma fresh_at_list: "atom x \ xs \ x \ set xs" - unfolding fresh_def supp_set[symmetric] - apply (induct xs) - apply (simp add: supp_set_empty) - apply simp - apply auto - apply (simp_all add: insert_absorb UnI2 finite_set supp_of_finite_insert supp_at_base) - done - -interpretation trans: test - "%x l. lookup l 0 x" - "%t1 t2 r1 r2 l. LNApp r1 r2" - "%n t r l. LNLam r" - apply default - apply (auto simp add: pure_fresh supp_Pair) - apply (simp_all add: fresh_def supp_def permute_fun_def permute_pure lookup_eqvt)[3] - apply (simp_all add: eqvt_def permute_fun_def permute_pure lookup_eqvt) - apply (simp add: fresh_star_def) - apply (rule_tac x="0 :: nat" in spec) - apply (induct_tac l) - apply (simp add: ln.fresh pure_fresh) - apply (auto simp add: ln.fresh pure_fresh)[1] - apply (case_tac "a \ set list") - apply simp - apply (rule_tac f="lookup" in fresh_fun_eqvt_app3) - unfolding eqvt_def - apply rule - using eqvts_raw(35) - apply auto[1] - apply (simp add: fresh_at_list) - apply (simp add: pure_fresh) - apply (simp add: fresh_at_base) - apply (simp add: fresh_star_Pair fresh_star_def ln.fresh) - apply (simp add: fresh_star_def ln.fresh) - done - -thm trans.f.simps - -lemma lam_strong_exhaust2: - "\\name. y = Var name \ P; - \lam1 lam2. y = App lam1 lam2 \ P; - \name lam. \{atom name} \* c; y = Lam [name]. lam\ \ P; - finite (supp c)\ - \ P" -sorry - -nominal_primrec - g -where - "(~finite (supp (g1, g2, g3))) \ g g1 g2 g3 t = t" -| "finite (supp (g1, g2, g3)) \ g g1 g2 g3 (Var x) = g1 x" -| "finite (supp (g1, g2, g3)) \ g g1 g2 g3 (App t1 t2) = g2 t1 t2 (g g1 g2 g3 t1) (g g1 g2 g3 t2)" -| "finite (supp (g1, g2, g3)) \ atom x \ (g1,g2,g3) \ (g g1 g2 g3 (Lam [x].t)) = g3 x t (g g1 g2 g3 t)" - apply (simp add: eqvt_def g_graph_def) - apply (rule, perm_simp, rule) - apply simp_all - apply (case_tac x) - apply (case_tac "finite (supp (a, b, c))") - prefer 2 - apply simp - apply(rule_tac y="d" and c="(a,b,c)" in lam_strong_exhaust2) - apply auto - apply blast - apply (simp add: Abs1_eq_iff fresh_star_def) - sorry - -termination - by (relation "measure (\(_,_,_,t). size t)") (simp_all add: lam.size) - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/LetRecFunNo.thy --- a/Nominal/Ex/LetRecFunNo.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,299 +0,0 @@ -theory Let -imports "../Nominal2" -begin - -atom_decl name - -nominal_datatype trm = - Var "name" -| App "trm" "trm" -| Let as::"assn" t::"trm" binds "bn as" in as t -and assn = - ANil -| ACons "name" "trm" "assn" -binder - bn -where - "bn ANil = []" -| "bn (ACons x t as) = (atom x) # (bn as)" - -nominal_primrec substrec where - "substrec fa fl fd y z (Var x) = (if (y = x) then z else (Var x))" -| "substrec fa fl fd y z (App l r) = fa l r" -| "(set (bn as) \* (Let as t, y, z) \ (\bs s. set (bn bs) \* (Let bs s, y, z) \ Let as t = Let bs s \ fl as t = fl bs s)) \ - substrec fa fl fd y z (Let as t) = fl as t" -| "(set (bn as) \* (Let as t, y, z) \ \(\bs s. set (bn bs) \* (Let bs s, y, z) \ Let as t = Let bs s \ fl as t = fl bs s)) \ - substrec fa fl fd y z (Let as t) = fd" - unfolding eqvt_def substrec_graph_def - apply (rule, perm_simp, rule, rule) - apply (case_tac x) - apply (rule_tac y="f" and c="(f, d, e)" in trm_assn.strong_exhaust(1)) - apply metis - apply metis - apply (thin_tac "\fa fl fd y z xa. x = (fa, fl, fd, y, z, Var xa) \ P") - apply (thin_tac "\fa fl fd y z l r. x = (fa, fl, fd, y, z, App l r) \ P") - apply (drule_tac x="assn" in meta_spec)+ - apply (drule_tac x="trm" in meta_spec)+ - apply (drule_tac x="d" in meta_spec)+ - apply (drule_tac x="e" in meta_spec)+ - apply (drule_tac x="b" in meta_spec)+ - apply (drule_tac x="a" in meta_spec)+ - apply (drule_tac x="c" in meta_spec)+ - apply (case_tac "(\bs s. - set (bn bs) \* (Let bs s, d, e) \ - Let.Let assn trm = Let.Let bs s \ b assn trm = b bs s)") - apply simp - apply (thin_tac "set (bn assn) \* (Let assn trm, d, e) \ - (\bs s. - set (bn bs) \* (Let bs s, d, e) \ - Let.Let assn trm = Let.Let bs s \ b assn trm = b bs s) \ - x = (a, b, c, d, e, Let.Let assn trm) \ P") - apply simp - apply simp_all - apply clarify - apply metis - done -termination (eqvt) by lexicographic_order - -nominal_primrec substarec :: "(name \ trm \ assn \ assn) \ assn \ assn" where - "substarec fac ANil = ANil" -| "substarec fac (ACons x t as) = fac x t as" - unfolding eqvt_def substarec_graph_def - apply (rule, perm_simp, rule, rule) - apply (case_tac x) - apply (rule_tac y="b" in trm_assn.exhaust(2)) - apply auto - done -termination (eqvt) by lexicographic_order - -lemma [fundef_cong]: - "(\t1 t2. t = App t1 t2 \ fa t1 t2 = fa' t1 t2) \ - (\as s. t = Let as s \ fl as s = fl' as s) \ - substrec fa fl fd y z t = substrec fa' fl' fd y z t" - apply (rule_tac y="t" and c="(t, y, z)" in trm_assn.strong_exhaust(1)) - apply auto - apply (case_tac "(\bs s. set (bn bs) \* (Let bs s, y, z) \ Let assn trm = Let bs s \ fl assn trm = fl bs s)") - apply (subst substrec.simps(3)) apply simp - apply (subst substrec.simps(3)) apply simp - apply metis - apply (subst substrec.simps(4)) apply simp - apply (subst substrec.simps(4)) apply simp_all - done - -lemma [fundef_cong]: - "(\x s as. t = ACons x s as \ fac x s as = fac' x s as) \ - substarec fac t = substarec fac' t" - by (rule_tac y="t" in trm_assn.exhaust(2)) simp_all - -function - subst :: "name \ trm \ trm \ trm" -and substa :: "name \ trm \ assn \ assn" -where - [simp del]: "subst y z t = substrec - (\l r. App (subst y z l) (subst y z r)) - (\as t. Let (substa y z as) (subst y z t)) - (Let (ACons y (Var y) ANil) (Var y)) y z t" -| [simp del]: "substa y z t = substarec - (\x t as. ACons x (subst y z t) (substa y z as)) t" - by pat_completeness auto - -termination by lexicographic_order - -lemma testl: - assumes a: "\y. f x = Inl y" - shows "(p \ (Sum_Type.Projl (f x))) = Sum_Type.Projl ((p \ f) (p \ x))" -using a -apply clarify -apply(frule_tac p="p" in permute_boolI) -apply(simp (no_asm_use) only: eqvts) -apply(subst (asm) permute_fun_app_eq) -back -apply(simp) -done - -lemma testr: - assumes a: "\y. f x = Inr y" - shows "(p \ (Sum_Type.Projr (f x))) = Sum_Type.Projr ((p \ f) (p \ x))" -using a -apply clarify -apply(frule_tac p="p" in permute_boolI) -apply(simp (no_asm_use) only: eqvts) -apply(subst (asm) permute_fun_app_eq) -back -apply(simp) -done - -lemma permute_move: "p \ x = y \ x = -p \ y" - by (metis eqvt_bound unpermute_def) - -lemma "subst_substa_graph x t \ subst_substa_graph (p \ x) (p \ t)" -proof (induct arbitrary: p rule: subst_substa_graph.induct) -fix f y z t p -assume a: "\t1 t2 p. t = App t1 t2 \ subst_substa_graph (p \ Inl (y, z, t1)) (p \ f (Inl (y, z, t1)))" - and b: "\t1 t2 p. t = App t1 t2 \ subst_substa_graph (p \ Inl (y, z, t2)) (p \ f (Inl (y, z, t2)))" - and c: "\as s p. t = Let.Let as s \ subst_substa_graph (p \ Inr (y, z, as)) (p \ f (Inr (y, z, as)))" - and d: "\as s p. t = Let.Let as s \ subst_substa_graph (p \ Inl (y, z, s)) (p \ f (Inl (y, z, s)))" - then show "subst_substa_graph (p \ Inl (y, z, t)) - (p \ Inl (substrec - (\l r. App (Sum_Type.Projl (f (Inl (y, z, l)))) - (Sum_Type.Projl (f (Inl (y, z, r))))) - (\as t. Let.Let (Sum_Type.Projr (f (Inr (y, z, as)))) - (Sum_Type.Projl (f (Inl (y, z, t))))) - (Let.Let (ACons y (Var y) ANil) (Var y)) y z t))" - proof (rule_tac y="t" and c="(t, y, z)" in trm_assn.strong_exhaust(1)) - fix name - assume "t = Var name" - then show ?thesis - apply (simp add: eqvts split del: if_splits) - apply (simp only: trm_assn.perm_simps) - apply (rule subst_substa_graph.intros(1)[of "Var (p \ name)" "p \ y" "p \ z", simplified]) - by simp_all - next - fix trm1 trm2 - assume e: "t = App trm1 trm2" - then show ?thesis - apply (simp add: eqvts) - apply (subst testl) back - apply (rule subst_substa_graph.cases[OF a[OF e, of 0, simplified]]) - apply metis apply simp - apply (subst testl) back - apply (rule subst_substa_graph.cases[OF b[OF e, of 0, simplified]]) - apply metis apply (simp add: eqvts) - apply (simp only: Inl_eqvt) apply simp - apply (rule subst_substa_graph.intros(1)[of "App (p \ trm1) (p \ trm2)" "p \ y" "p \ z", simplified]) - apply simp_all apply clarify - using a[OF e, simplified Inl_eqvt, simplified] - apply (metis (lifting) Inl_eqvt permute_fun_app_eq permute_prod.simps) - apply clarify - using b[OF e, simplified Inl_eqvt, simplified] - by (metis (lifting) Inl_eqvt permute_fun_app_eq permute_prod.simps) - next - fix assn trm - assume e: "t = Let.Let assn trm" and f: "set (bn assn) \* (t, y, z)" - then show ?thesis - apply (simp add: eqvts) - apply (simp only: permute_fun_def) - apply (simp only: eqvts permute_minus_cancel) - apply (case_tac "(\bs s. set (bn bs) \* (Let.Let bs s, p \ y, p \ z) \ - Let.Let (p \ assn) (p \ trm) = Let.Let bs s \ - Let.Let (p \ Sum_Type.Projr (f (Inr (y, z, - p \ p \ assn)))) - (p \ Sum_Type.Projl (f (Inl (y, z, - p \ p \ trm)))) = - Let.Let (p \ Sum_Type.Projr (f (Inr (y, z, - p \ bs)))) - (p \ Sum_Type.Projl (f (Inl (y, z, - p \ s)))))") - prefer 2 - apply (subst substrec.simps(4)) - apply rule - apply (simp add: fresh_star_Pair) - apply (intro conjI) - apply (metis fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4) trm_assn.perm_simps(3)) - apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4)) - apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4)) - apply assumption - prefer 2 - apply (subst substrec.simps(3)) - apply rule - apply (simp add: fresh_star_Pair) - apply (intro conjI) - apply (metis fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4) trm_assn.perm_simps(3)) - apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4)) - apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4)) - apply assumption -(* The following subgoal is motivated by: - thm subst_substa_graph.intros(1)[of "Let (p \ assn) (p \ trm)" "p \ y" "p \ z" "(p \ f)", simplified]*) - apply (subgoal_tac "subst_substa_graph (Inl (p \ y, p \ z, Let.Let (p \ assn) (p \ trm))) - (Inl (substrec - (\l r. App (Sum_Type.Projl ((p \ f) (Inl (p \ y, p \ z, l)))) - (Sum_Type.Projl ((p \ f) (Inl (p \ y, p \ z, r))))) - (\as t. Let.Let (Sum_Type.Projr ((p \ f) (Inr (p \ y, p \ z, as)))) - (Sum_Type.Projl ((p \ f) (Inl (p \ y, p \ z, t))))) - (Let.Let (ACons (p \ y) (Var (p \ y)) ANil) (Var (p \ y))) (p \ y) (p \ z) - (Let.Let (p \ assn) (p \ trm))))") - apply (subst (asm) substrec.simps(3)) - apply rule - apply (simp add: fresh_star_Pair) - apply (intro conjI) - apply (metis fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4) trm_assn.perm_simps(3)) - apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4)) - apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4)) - (* We don't have equivariance of Projl/Projr at the arbitrary 'bs' point *) - defer - apply (subst testr) back - apply (rule subst_substa_graph.cases[OF c[OF e, of 0, simplified]]) - apply simp apply simp - apply (subst testl) back - apply (rule subst_substa_graph.cases[OF d[OF e, of 0, simplified]]) - apply simp apply simp apply simp - apply (rule subst_substa_graph.intros(1)[of "Let (p \ assn) (p \ trm)" "p \ y" "p \ z" "(p \ f)", simplified]) - apply simp apply simp (* These two should follow by d for arbitrary 'as' point *) - defer defer - sorry - qed - next - fix f y z t p - show "subst_substa_graph (p \ Inr (y, z, t)) (p \ Inr (substarec (\x t as. ACons - x (Sum_Type.Projl (f (Inl (y, z, t)))) (Sum_Type.Projr (f (Inr (y, z, as))))) t))" - sorry - qed - -(* Will follow from above and accp *) -lemma [eqvt]: - "p \ (subst y z t) = subst (p \ y) (p \ z) (p \ t)" - "p \ (substa y z t2) = substa (p \ y) (p \ z) (p \ t2)" - sorry - -lemma substa_simps[simp]: - "substa y z ANil = ANil" - "substa y z (ACons x t as) = ACons x (subst y z t) (substa y z as)" - apply (subst substa.simps) apply (subst substarec.simps) apply rule - apply (subst substa.simps) apply (subst substarec.simps) apply rule - done - -lemma bn_substa: "bn (substa y z t) = bn t" - by (induct t rule: trm_assn.inducts(2)) (simp_all add: trm_assn.bn_defs) - -lemma fresh_fun_eqvt_app3: - assumes e: "eqvt f" - 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 - "subst y z (Var x) = (if (y = x) then z else (Var x))" - "subst y z (App l r) = App (subst y z l) (subst y z r)" - "set (bn as) \* (Let as t, y, z) \ subst y z (Let as t) = Let (substa y z as) (subst y z t)" - apply (subst subst.simps) apply (subst substrec.simps) apply rule - apply (subst subst.simps) apply (subst substrec.simps) apply rule - apply (subst subst.simps) apply (subst substrec.simps) apply auto - apply (subst (asm) Abs_eq_iff2) - apply clarify - apply (simp add: alphas bn_substa) - apply (rule_tac s="p \ ([bn as]lst. (substa y z as, subst y z t))" in trans) - apply (rule sym) - defer - apply (simp add: eqvts) - apply (subgoal_tac "supp p \* y") - apply (subgoal_tac "supp p \* z") - apply (simp add: perm_supp_eq) - apply (simp add: fresh_Pair fresh_star_def) - apply blast - apply (simp add: fresh_Pair fresh_star_def) - apply blast - apply (rule perm_supp_eq) - apply (simp add: fresh_star_Pair) - apply (simp add: fresh_star_def Abs_fresh_iff) - apply (auto) - apply (simp add: bn_substa fresh_Pair) - apply (rule) - apply (rule fresh_fun_eqvt_app3[of substa]) - apply (simp add: eqvt_def eqvts_raw) - apply (metis (lifting) Diff_partition Un_iff) - apply (metis (lifting) Diff_partition Un_iff) - apply (simp add: fresh_def trm_assn.supp) - apply (metis (lifting) DiffI UnI1 supp_Pair) - apply (rule fresh_fun_eqvt_app3[of subst]) - apply (simp add: eqvt_def eqvts_raw) - apply (metis (lifting) Diff_partition Un_iff) - apply (metis (lifting) Diff_partition Un_iff) - apply (simp add: fresh_def trm_assn.supp) - by (metis Diff_iff Un_iff supp_Pair) - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/Let_ExhaustIssue.thy --- a/Nominal/Ex/Let_ExhaustIssue.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -theory Let -imports "../Nominal2" -begin - - -atom_decl name - -nominal_datatype trm = - Var "name" -| App "trm" "trm" -| Lam x::"name" t::"trm" binds x in t -| Let as::"assn" t::"trm" binds "bn as" in t -and assn = - ANil -| ACons "name" "trm" "assn" -binder - bn -where - "bn ANil = []" -| "bn (ACons x t as) = (atom x) # (bn as)" - -lemma alpha_bn_inducts_raw: - "\alpha_bn_raw a b; P3 ANil_raw ANil_raw; - \trm_raw trm_rawa assn_raw assn_rawa name namea. - \alpha_trm_raw trm_raw trm_rawa; alpha_bn_raw assn_raw assn_rawa; - P3 assn_raw assn_rawa\ - \ P3 (ACons_raw name trm_raw assn_raw) - (ACons_raw namea trm_rawa assn_rawa)\ \ P3 a b" - by (erule alpha_trm_raw_alpha_assn_raw_alpha_bn_raw.inducts(3)[of _ _ "\x y. True" _ "\x y. True", simplified]) auto - -lemmas alpha_bn_inducts = alpha_bn_inducts_raw[quot_lifted] - -lemma alpha_bn_refl: "alpha_bn x x" - by (induct x rule: trm_assn.inducts(2)) - (rule TrueI, auto simp add: trm_assn.eq_iff) - -lemma max_eqvt[eqvt]: "p \ (max (a :: _ :: pure) b) = max (p \ a) (p \ b)" - by (simp add: permute_pure) - -lemma what_we_would_like: - assumes a: "alpha_bn as asa" - shows "\p. set (bn as) \* fv_bn as \ set (bn asa) \* fv_bn asa \ - p \ bn as = bn asa \ supp p \ set (bn as) \ set (bn asa) \ p \ as = asa" - apply (rule alpha_bn_inducts[OF a]) - apply - (simp_all add: trm_assn.bn_defs trm_assn.perm_bn_simps trm_assn.supp) - apply clarify - apply simp - apply (simp add: atom_eqvt) - apply (case_tac "name = namea") - sorry - -lemma Abs_lst_fcb2: - fixes as bs :: "'a :: fs" - and x y :: "'b :: fs" - and c::"'c::fs" - assumes eq: "[ba as]lst. x = [ba bs]lst. y" - and fcb1: "set (ba as) \* f as x c" - and fresh1: "set (ba as) \* c" - and fresh2: "set (ba bs) \* c" - and perm1: "\p. supp p \* c \ p \ (f as x c) = f (p \ as) (p \ x) c" - and perm2: "\p. supp p \* c \ p \ (f bs y c) = f (p \ bs) (p \ y) c" - and ba_inj: "\q r. q \ ba as = r \ ba bs \ q \ as = r \ bs" - shows "f as x c = f bs y c" -sorry - -nominal_primrec - height_trm :: "trm \ nat" -and height_assn :: "assn \ nat" -where - "height_trm (Var x) = 1" -| "height_trm (App l r) = max (height_trm l) (height_trm r)" -| "height_trm (Lam v b) = 1 + (height_trm b)" -| "set (bn as) \* fv_bn as \ height_trm (Let as b) = max (height_assn as) (height_trm b)" -| "height_assn ANil = 0" -| "height_assn (ACons v t as) = max (height_trm t) (height_assn as)" - apply (simp only: eqvt_def height_trm_height_assn_graph_def) - apply (rule, perm_simp, rule, rule TrueI) - apply (case_tac x) - apply (rule_tac y="a" in trm_assn.strong_exhaust(1)) - apply (auto)[4] - apply (drule_tac x="assn" in meta_spec) - apply (drule_tac x="trm" in meta_spec) - apply (simp add: alpha_bn_refl) ---"HERE" - defer - apply (case_tac b rule: trm_assn.exhaust(2)) - apply (auto)[2] - apply(simp_all) - apply (erule_tac c="()" in Abs_lst_fcb2) - apply (simp_all add: pure_fresh fresh_star_def)[3] - apply (simp add: eqvt_at_def) - apply (simp add: eqvt_at_def) - apply assumption - apply(erule conjE) - apply (simp add: meta_eq_to_obj_eq[OF height_trm_def, symmetric, unfolded fun_eq_iff]) - apply (simp add: meta_eq_to_obj_eq[OF height_assn_def, symmetric, unfolded fun_eq_iff]) - apply (subgoal_tac "eqvt_at height_assn as") - apply (subgoal_tac "eqvt_at height_assn asa") - apply (subgoal_tac "eqvt_at height_trm b") - apply (subgoal_tac "eqvt_at height_trm ba") - apply (thin_tac "eqvt_at height_trm_height_assn_sumC (Inr as)") - apply (thin_tac "eqvt_at height_trm_height_assn_sumC (Inr asa)") - apply (thin_tac "eqvt_at height_trm_height_assn_sumC (Inl b)") - apply (thin_tac "eqvt_at height_trm_height_assn_sumC (Inl ba)") - defer - apply (simp add: eqvt_at_def height_trm_def) - apply (simp add: eqvt_at_def height_trm_def) - apply (simp add: eqvt_at_def height_assn_def) - apply (simp add: eqvt_at_def height_assn_def) - defer - apply (subgoal_tac "height_assn as = height_assn asa") - apply (subgoal_tac "height_trm b = height_trm ba") - apply simp - apply (erule_tac c="()" in Abs_lst_fcb2) - apply (simp_all add: pure_fresh fresh_star_def)[3] - apply (simp_all add: eqvt_at_def)[2] - apply assumption - apply (erule_tac Abs_lst_fcb) - apply (simp_all add: pure_fresh fresh_star_def)[2] - apply (drule what_we_would_like) - apply (drule_tac x="p" in spec) - apply simp - apply (simp add: eqvt_at_def) - oops - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/NBE.thy --- a/Nominal/Ex/NBE.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,546 +0,0 @@ -theory Lambda -imports - "../Nominal2" -begin - - -atom_decl name - -nominal_datatype lam = - Var "name" -| App "lam" "lam" -| Lam x::"name" l::"lam" binds x in l ("Lam [_]. _" [100, 100] 100) - -nominal_datatype sem = - L e::"env" x::"name" l::"lam" binds x "bn e" in l -| N "neu" -and neu = - V "name" -| A "neu" "sem" -and env = - ENil -| ECons "env" "name" "sem" -binder - bn -where - "bn ENil = []" -| "bn (ECons env x v) = (atom x) # (bn env)" - -thm sem_neu_env.supp - -lemma [simp]: - shows "finite (fv_bn env)" -apply(induct env rule: sem_neu_env.inducts(3)) -apply(rule TrueI)+ -apply(auto simp add: sem_neu_env.supp finite_supp) -done - -lemma test1: - shows "supp p \* (fv_bn env) \ (p \ env) = permute_bn p env" -apply(induct env rule: sem_neu_env.inducts(3)) -apply(rule TrueI)+ -apply(auto simp add: sem_neu_env.perm_bn_simps sem_neu_env.supp) -apply(drule meta_mp) -apply(drule fresh_star_supp_conv) -apply(subst (asm) supp_finite_atom_set) -apply(simp add: finite_supp) -apply(simp add: fresh_star_Un) -apply(rule fresh_star_supp_conv) -apply(subst supp_finite_atom_set) -apply(simp) -apply(simp) -apply(simp) -apply(rule perm_supp_eq) -apply(drule fresh_star_supp_conv) -apply(subst (asm) supp_finite_atom_set) -apply(simp add: finite_supp) -apply(simp add: fresh_star_Un) -apply(rule fresh_star_supp_conv) -apply(simp) -done - -thm alpha_sem_raw_alpha_neu_raw_alpha_env_raw_alpha_bn_raw.inducts(4)[no_vars] - -lemma alpha_bn_inducts_raw[consumes 1]: - "\alpha_bn_raw x7 x8; - P4 ENil_raw ENil_raw; - \env_raw env_rawa sem_raw sem_rawa name namea. - \alpha_bn_raw env_raw env_rawa; P4 env_raw env_rawa; alpha_sem_raw sem_raw sem_rawa\ - \ P4 (ECons_raw env_raw name sem_raw) (ECons_raw env_rawa namea sem_rawa)\ -\ P4 x7 x8" -apply(induct rule: alpha_sem_raw_alpha_neu_raw_alpha_env_raw_alpha_bn_raw.inducts(4)) -apply(rule TrueI)+ -apply(auto) -done - -lemmas alpha_bn_inducts[consumes 1] = alpha_bn_inducts_raw[quot_lifted] - -lemma test2: - shows "alpha_bn env1 env2 \ p \ (bn env1) = q \ (bn env2) \ permute_bn p env1 = permute_bn q env2" -apply(induct rule: alpha_bn_inducts) -apply(auto simp add: sem_neu_env.perm_bn_simps sem_neu_env.bn_defs) -apply(simp add: atom_eqvt) -done - -lemma fresh_star_Union: - assumes "as \ bs" "bs \* x" - shows "as \* x" -using assms by (auto simp add: fresh_star_def) - - -nominal_primrec (invariant "\x y. case x of Inl (x1, y1) \ - supp y \ (supp y1 - set (bn x1)) \ (fv_bn x1) | Inr (x2, y2) \ supp y \ supp x2 \ supp y2") - evals :: "env \ lam \ sem" and - evals_aux :: "sem \ sem \ sem" -where - "evals ENil (Var x) = N (V x)" -| "evals (ECons tail y v) (Var x) = (if x = y then v else evals tail (Var x))" -| "atom x \ env \ evals env (Lam [x]. t) = L env x t" -| "evals env (App t1 t2) = evals_aux (evals env t1) (evals env t2)" -| "set (atom x # bn env) \* (fv_bn env, t') \ evals_aux (L env x t) t' = evals (ECons env x t') t" -| "evals_aux (N n) t' = N (A n t')" -apply(simp add: eqvt_def evals_evals_aux_graph_def) -apply(perm_simp) -apply(simp) -apply(erule evals_evals_aux_graph.induct) -apply(simp add: sem_neu_env.supp lam.supp sem_neu_env.bn_defs) -apply(simp add: sem_neu_env.supp lam.supp sem_neu_env.bn_defs) -apply(rule conjI) -apply(rule impI) -apply(blast) -apply(rule impI) -apply(simp add: supp_at_base) -apply(blast) -apply(simp add: sem_neu_env.supp lam.supp sem_neu_env.bn_defs) -apply(blast) -apply(simp add: sem_neu_env.supp lam.supp sem_neu_env.bn_defs) -apply(blast) -apply(simp add: sem_neu_env.supp lam.supp sem_neu_env.bn_defs) -apply(blast) -apply(simp add: sem_neu_env.supp lam.supp sem_neu_env.bn_defs) ---"completeness" -apply(case_tac x) -apply(simp) -apply(case_tac a) -apply(simp) -apply(case_tac aa rule: sem_neu_env.exhaust(3)) -apply(simp add: sem_neu_env.fresh) -apply(case_tac b rule: lam.exhaust) -apply(metis)+ -apply(case_tac aa rule: sem_neu_env.exhaust(3)) -apply(rule_tac y="b" and c="env" in lam.strong_exhaust) -apply(metis)+ -apply(simp add: fresh_star_def) -apply(simp) -apply(rule_tac y="b" and c="ECons env name sem" in lam.strong_exhaust) -apply(metis)+ -apply(simp add: fresh_star_def) -apply(simp) -apply(case_tac b) -apply(simp) -apply(rule_tac y="a" and c="(a, ba)" in sem_neu_env.strong_exhaust(1)) -apply(simp) -apply(rotate_tac 4) -apply(drule_tac x="name" in meta_spec) -apply(drule_tac x="env" in meta_spec) -apply(drule_tac x="ba" in meta_spec) -apply(drule_tac x="lam" in meta_spec) -apply(simp add: sem_neu_env.alpha_refl) -apply(rotate_tac 9) -apply(drule_tac meta_mp) -apply(simp (no_asm_use) add: fresh_star_def sem_neu_env.fresh fresh_Pair) -apply(simp) -apply(subst fresh_finite_atom_set) -defer -apply(simp) -apply(subst fresh_finite_atom_set) -defer -apply(simp) -apply(metis)+ ---"compatibility" -apply(all_trivials) -apply(simp) -apply(simp) -defer -apply(simp) -apply(simp) -apply (simp add: meta_eq_to_obj_eq[OF evals_def, symmetric, unfolded fun_eq_iff]) -apply (subgoal_tac "eqvt_at (\(a, b). evals a b) (ECons env x t'a, t)") -apply (subgoal_tac "eqvt_at (\(a, b). evals a b) (ECons enva xa t'a, ta)") -apply (thin_tac "eqvt_at evals_evals_aux_sumC (Inl (ECons env x t'a, t))") -apply (thin_tac "eqvt_at evals_evals_aux_sumC (Inl (ECons enva xa t'a, ta))") -apply(erule conjE)+ -defer -apply (simp_all add: eqvt_at_def evals_def)[3] -defer -defer -apply(simp add: sem_neu_env.alpha_refl) -apply(erule conjE)+ -apply(erule_tac c="(env, enva)" in Abs_lst1_fcb2) -apply(simp add: Abs_fresh_iff) -apply(simp add: fresh_star_def) -apply(perm_simp) -apply(simp add: fresh_star_Pair perm_supp_eq) -apply(perm_simp) -apply(simp add: fresh_star_Pair perm_supp_eq) -apply(simp add: sem_neu_env.bn_defs sem_neu_env.supp) -using at_set_avoiding3 -apply - -apply(drule_tac x="set (atom x # bn env)" in meta_spec) -apply(drule_tac x="(fv_bn env, fv_bn enva, env, enva, x, xa, t, ta, t'a)" in meta_spec) -apply(drule_tac x="[atom x # bn env]lst. t" in meta_spec) -apply(simp (no_asm_use) add: finite_supp Abs_fresh_star_iff) -apply(drule meta_mp) -apply(simp add: supp_Pair finite_supp supp_finite_atom_set) -apply(drule meta_mp) -apply(simp add: fresh_star_def) -apply(erule exE) -apply(erule conjE)+ -apply(rule trans) -apply(rule sym) -apply(rule_tac p="p" in perm_supp_eq) -apply(simp) -apply(perm_simp) -apply(simp add: fresh_star_Un fresh_star_insert) -apply(rule conjI) -apply(simp (no_asm_use) add: fresh_star_def fresh_Pair) -apply(simp add: fresh_def) -apply(simp add: supp_finite_atom_set) -apply(blast) -apply(rule conjI) -apply(simp (no_asm_use) add: fresh_star_def fresh_Pair) -apply(simp add: fresh_def) -apply(simp add: supp_finite_atom_set) -apply(blast) -apply(rule conjI) -apply(simp (no_asm_use) add: fresh_star_def fresh_Pair) -apply(simp add: fresh_def) -apply(simp add: supp_finite_atom_set) -apply(blast) -apply(simp (no_asm_use) add: fresh_star_def fresh_Pair) -apply(simp add: fresh_def) -apply(simp add: supp_finite_atom_set) -apply(blast) -apply(simp add: eqvt_at_def perm_supp_eq) -apply(subst (3) perm_supp_eq) -apply(simp) -apply(simp add: fresh_star_def fresh_Pair) -apply(auto)[1] -apply(rotate_tac 6) -apply(drule sym) -apply(simp) -apply(rotate_tac 11) -apply(drule trans) -apply(rule sym) -apply(rule_tac p="p" in supp_perm_eq) -apply(assumption) -apply(rotate_tac 11) -apply(rule sym) -apply(simp add: atom_eqvt) -apply(simp (no_asm_use) add: Abs_eq_iff2 alphas) -apply(erule conjE | erule exE)+ -apply(rule trans) -apply(rule sym) -apply(rule_tac p="pa" in perm_supp_eq) -apply(erule fresh_star_Union) -apply(simp (no_asm_use) add: fresh_star_insert fresh_star_Un) -apply(rule conjI) -apply(perm_simp) -apply(simp add: fresh_star_insert fresh_star_Un) -apply(simp add: fresh_Pair) -apply(simp add: fresh_def) -apply(simp add: supp_finite_atom_set) -apply(blast) -apply(rule conjI) -apply(perm_simp) -apply(simp add: fresh_star_insert fresh_star_Un) -apply(simp add: fresh_Pair) -apply(simp add: fresh_def) -apply(simp add: supp_finite_atom_set) -apply(blast) -apply(rule conjI) -apply(perm_simp) -defer -apply(perm_simp) -apply(simp add: fresh_star_insert fresh_star_Un) -apply(simp add: fresh_star_Pair) -apply(simp add: fresh_star_def fresh_def) -apply(simp add: supp_finite_atom_set) -apply(blast) -apply(simp) -apply(perm_simp) -apply(subst (3) perm_supp_eq) -apply(erule fresh_star_Union) -apply(simp add: fresh_star_insert fresh_star_Un) -apply(simp add: fresh_star_def fresh_Pair) -apply(subgoal_tac "pa \ enva = p \ env") -apply(simp) -defer -apply(simp (no_asm_use) add: fresh_star_insert fresh_star_Un) -apply(simp (no_asm_use) add: fresh_star_def) -apply(rule ballI) -apply(subgoal_tac "a \ supp ta - insert (atom xa) (set (bn enva)) \ (fv_bn enva \ supp t'a)") -apply(simp only: fresh_def) -apply(blast) -apply(simp (no_asm_use)) -apply(rule conjI) -apply(blast) -apply(simp add: fresh_Pair) -apply(simp add: fresh_star_def fresh_def) -apply(simp add: supp_finite_atom_set) -apply(subst test1) -apply(erule fresh_star_Union) -apply(simp add: fresh_star_insert fresh_star_Un) -apply(simp add: fresh_star_def fresh_Pair) -apply(subst test1) -apply(simp) -apply(simp add: fresh_star_insert fresh_star_Un) -apply(simp add: fresh_star_def fresh_Pair) -apply(rule sym) -apply(erule test2) -apply(perm_simp) -apply(simp) -done - - - - -text {* can probably not proved by a trivial size argument *} -termination (* apply(lexicographic_order) *) -sorry - -lemma [eqvt]: - shows "(p \ evals env t) = evals (p \ env) (p \ t)" - and "(p \ evals_aux v s) = evals_aux (p \ v) (p \ s)" -sorry - -(* fixme: should be a provided lemma *) -lemma fv_bn_finite: - shows "finite (fv_bn env)" -apply(induct env rule: sem_neu_env.inducts(3)) -apply(auto simp add: sem_neu_env.supp finite_supp) -done - -lemma test: - fixes env::"env" - shows "supp (evals env t) \ (supp t - set (bn env)) \ (fv_bn env)" - and "supp (evals_aux s v) \ (supp s) \ (supp v)" -apply(induct env t and s v rule: evals_evals_aux.induct) -apply(simp add: sem_neu_env.supp lam.supp supp_Nil sem_neu_env.bn_defs) -apply(simp add: sem_neu_env.supp lam.supp supp_Nil supp_Cons sem_neu_env.bn_defs) -apply(rule conjI) -apply(auto)[1] -apply(rule impI) -apply(simp) -apply(simp add: supp_at_base) -apply(blast) -apply(simp) -apply(subst sem_neu_env.supp) -apply(simp add: sem_neu_env.supp lam.supp) -apply(auto)[1] -apply(simp add: lam.supp sem_neu_env.supp) -apply(blast) -apply(simp add: sem_neu_env.supp sem_neu_env.bn_defs) -apply(blast) -apply(simp add: sem_neu_env.supp) -done - - -nominal_primrec - reify :: "sem \ lam" and - reifyn :: "neu \ lam" -where - "atom x \ (env, y, t) \ reify (L env y t) = Lam [x]. (reify (evals (ECons env y (N (V x))) t))" -| "reify (N n) = reifyn n" -| "reifyn (V x) = Var x" -| "reifyn (A n d) = App (reifyn n) (reify d)" -apply(subgoal_tac "\p x y. reify_reifyn_graph x y \ reify_reifyn_graph (p \ x) (p \ y)") -apply(simp add: eqvt_def) -apply(simp add: permute_fun_def) -apply(rule allI) -apply(rule ext) -apply(rule ext) -apply(rule iffI) -apply(drule_tac x="p" in meta_spec) -apply(drule_tac x="- p \ x" in meta_spec) -apply(drule_tac x="- p \ xa" in meta_spec) -apply(simp add: permute_bool_def) -apply(simp add: permute_bool_def) -apply(erule reify_reifyn_graph.induct) -apply(perm_simp) -apply(rule reify_reifyn_graph.intros) -apply(rule_tac p="-p" in permute_boolE) -apply(perm_simp add: permute_minus_cancel) -apply(simp) -apply(simp) -apply(perm_simp) -apply(rule reify_reifyn_graph.intros) -apply(simp) -apply(perm_simp) -apply(rule reify_reifyn_graph.intros) -apply(perm_simp) -apply(rule reify_reifyn_graph.intros) -apply(simp) -apply(simp) -apply(rule TrueI) ---"completeness" -apply(case_tac x) -apply(simp) -apply(case_tac a rule: sem_neu_env.exhaust(1)) -apply(subgoal_tac "\x::name. atom x \ (env, name, lam)") -apply(metis) -apply(rule obtain_fresh) -apply(blast) -apply(blast) -apply(case_tac b rule: sem_neu_env.exhaust(2)) -apply(simp) -apply(simp) -apply(metis) ---"compatibility" -apply(all_trivials) -defer -apply(simp) -apply(simp) -apply(simp) -apply(erule conjE) -apply (simp add: meta_eq_to_obj_eq[OF reify_def, symmetric, unfolded fun_eq_iff]) -apply (subgoal_tac "eqvt_at (\t. reify t) (evals (ECons env y (N (V x))) t)") -apply (subgoal_tac "eqvt_at (\t. reify t) (evals (ECons enva ya (N (V xa))) ta)") -apply (thin_tac "eqvt_at reify_reifyn_sumC (Inl (evals (ECons env y (N (V x))) t))") -apply (thin_tac "eqvt_at reify_reifyn_sumC (Inl (evals (ECons enva ya (N (V xa))) ta))") -defer -apply (simp_all add: eqvt_at_def reify_def)[2] -apply(subgoal_tac "\c::name. atom c \ (x, xa, env, enva, y, ya, t, ta)") -prefer 2 -apply(rule obtain_fresh) -apply(blast) -apply(erule exE) -apply(rule trans) -apply(rule sym) -apply(rule_tac a="x" and b="c" in flip_fresh_fresh) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff fresh_Pair) -apply(auto)[1] -apply(rule fresh_eqvt_at) -back -apply(assumption) -apply(simp add: finite_supp) -apply(rule_tac S="supp (env, y, x, t)" in supports_fresh) -apply(simp add: supports_def fresh_def[symmetric]) -apply(perm_simp) -apply(simp add: swap_fresh_fresh fresh_Pair) -apply(simp add: finite_supp) -apply(simp add: fresh_def[symmetric]) -apply(simp add: eqvt_at_def) -apply(simp add: eqvt_at_def[symmetric]) -apply(perm_simp) -apply(simp add: flip_fresh_fresh) -apply(rule sym) -apply(rule trans) -apply(rule sym) -apply(rule_tac a="xa" and b="c" in flip_fresh_fresh) -apply(simp add: Abs_fresh_iff) -apply(simp add: Abs_fresh_iff fresh_Pair) -apply(auto)[1] -apply(rule fresh_eqvt_at) -back -apply(assumption) -apply(simp add: finite_supp) -apply(rule_tac S="supp (enva, ya, xa, ta)" in supports_fresh) -apply(simp add: supports_def fresh_def[symmetric]) -apply(perm_simp) -apply(simp add: swap_fresh_fresh fresh_Pair) -apply(simp add: finite_supp) -apply(simp add: fresh_def[symmetric]) -apply(simp add: eqvt_at_def) -apply(simp add: eqvt_at_def[symmetric]) -apply(perm_simp) -apply(simp add: flip_fresh_fresh) -apply(simp (no_asm) add: Abs1_eq_iff) -(* HERE *) -thm at_set_avoiding3 -using at_set_avoiding3 -apply - -apply(drule_tac x="set (atom y # bn env)" in meta_spec) -apply(drule_tac x="(env, enva)" in meta_spec) -apply(drule_tac x="[atom y # bn env]lst. t" in meta_spec) -apply(simp (no_asm_use) add: finite_supp) -apply(drule meta_mp) -apply(rule Abs_fresh_star) -apply(auto)[1] -apply(erule exE) -apply(erule conjE)+ -apply(drule_tac q="(x \ c)" in eqvt_at_perm) -apply(perm_simp) -apply(simp add: flip_fresh_fresh fresh_Pair) -apply(drule_tac q="(xa \ c)" in eqvt_at_perm) -apply(perm_simp) -apply(simp add: flip_fresh_fresh fresh_Pair) -apply(drule sym) -(* HERE *) -apply(rotate_tac 9) -apply(drule sym) -apply(rotate_tac 9) -apply(drule trans) -apply(rule sym) -apply(rule_tac p="p" in supp_perm_eq) -apply(assumption) -apply(simp) -apply(perm_simp) -apply(simp (no_asm_use) add: Abs_eq_iff2 alphas) -apply(erule conjE | erule exE)+ -apply(clarify) -apply(rule trans) -apply(rule sym) -apply(rule_tac p="pa" in perm_supp_eq) -defer -apply(rule sym) -apply(rule trans) -apply(rule sym) -apply(rule_tac p="p" in perm_supp_eq) -defer -apply(simp add: atom_eqvt) -apply(drule_tac q="(x \ c)" in eqvt_at_perm) -apply(perm_simp) -apply(simp add: flip_fresh_fresh fresh_Pair) - -apply(rule sym) -apply(erule_tac Abs_lst1_fcb2') -apply(rule fresh_eqvt_at) -back -apply(drule_tac q="(c \ x)" in eqvt_at_perm) -apply(perm_simp) -apply(simp add: flip_fresh_fresh) -apply(simp add: finite_supp) -apply(rule supports_fresh) -apply(rule_tac S="supp (enva, ya, xa, ta)" in supports_fresh) -apply(simp add: supports_def fresh_def[symmetric]) -apply(perm_simp) -apply(simp add: swap_fresh_fresh fresh_Pair) -apply(simp add: finite_supp) -apply(simp add: fresh_def[symmetric]) -apply(simp add: eqvt_at_def) -apply(simp add: eqvt_at_def[symmetric]) -apply(perm_simp) -apply(rule fresh_eqvt_at) -back -apply(drule_tac q="(c \ x)" in eqvt_at_perm) -apply(perm_simp) -apply(simp add: flip_fresh_fresh) -apply(assumption) -apply(simp add: finite_supp) -sorry - -termination sorry - -definition - eval :: "lam \ sem" -where - "eval t = evals ENil t" - -definition - normalize :: "lam \ lam" -where - "normalize t = reify (eval t)" - -end \ No newline at end of file diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/PaperTest.thy --- a/Nominal/Ex/PaperTest.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,303 +0,0 @@ -theory PaperTest -imports "../Nominal2" -begin - -atom_decl name - -datatype trm = - Const "string" -| Var "name" -| App "trm" "trm" -| Lam "name" "trm" ("Lam [_]. _" [100, 100] 100) - -fun - subst :: "trm \ name \ name \ trm" ("_[_::=_]" [100,100,100] 100) -where - "(Var x)[y::=p] = (if x=y then (App (App (Const ''unpermute'') (Var p)) (Var x)) else (Var x))" -| "(App t\<^isub>1 t\<^isub>2)[y::=p] = App (t\<^isub>1[y::=p]) (t\<^isub>2[y::=p])" -| "(Lam [x].t)[y::=p] = (if x=y then (Lam [x].t) else Lam [x].(t[y::=p]))" -| "(Const n)[y::=p] = Const n" - -datatype utrm = - UConst "string" -| UnPermute "name" "name" -| UVar "name" -| UApp "utrm" "utrm" -| ULam "name" "utrm" ("ULam [_]. _" [100, 100] 100) - -fun - usubst :: "utrm \ name \ name \ utrm" ("_[_:::=_]" [100,100,100] 100) -where - "(UVar x)[y:::=p] = (if x=y then UnPermute p x else (UVar x))" -| "(UApp t\<^isub>1 t\<^isub>2)[y:::=p] = UApp (t\<^isub>1[y:::=p]) (t\<^isub>2[y:::=p])" -| "(ULam [x].t)[y:::=p] = (if x=y then (ULam [x].t) else ULam [x].(t[y:::=p]))" -| "(UConst n)[y:::=p] = UConst n" -| "(UnPermute x q)[y:::=p] = UnPermute x q" - -function - ss :: "trm \ nat" -where - "ss (Var x) = 1" -| "ss (Const s) = 1" -| "ss (Lam [x].t) = 1 + ss t" -| "ss (App (App (Const ''unpermute'') (Var p)) (Var x)) = 1" -| "\(\p x. t1 = App (Const ''unpermute'') (Var p) \ t2 = (Var x)) \ ss (App t1 t2) = 1 + ss t1 + ss t2" -defer -apply(simp_all) -apply(auto)[1] -apply(case_tac x) -apply(simp_all) -apply(auto) -apply(blast) -done - -termination - apply(relation "measure (\t. size t)") - apply(simp_all) - done - -fun - uss :: "utrm \ nat" -where - "uss (UVar x) = 1" -| "uss (UConst s) = 1" -| "uss (ULam [x].t) = 1 + uss t" -| "uss (UnPermute x y) = 1" -| "uss (UApp t1 t2) = 1 + uss t1 + uss t2" - -lemma trm_uss: - shows "uss (t[x:::=p]) = uss t" -apply(induct rule: uss.induct) -apply(simp_all) -done - -inductive - ufree :: "utrm \ bool" -where - "ufree (UVar x)" -| "s \ ''unpermute'' \ ufree (UConst s)" -| "ufree t \ ufree (ULam [x].t)" -| "ufree (UnPermute x y)" -| "\ufree t1; ufree t2\ \ ufree (UApp t1 t2)" - -fun - trans :: "utrm \ trm" ("\_\" [100] 100) -where - "\(UVar x)\ = Var x" -| "\(UConst x)\ = Const x" -| "\(UnPermute p x)\ = (App (App (Const ''unpermute'') (Var p)) (Var x))" -| "\(ULam [x].t)\ = Lam [x].(\t\)" -| "\(UApp t1 t2)\ = App (\t1\) (\t2\)" - -function - utrans :: "trm \ utrm" ("\_\" [90] 100) -where - "\Var x\ = UVar x" -| "\Const x\ = UConst x" -| "\Lam [x].t\ = ULam [x].\t\" -| "\App (App (Const ''unpermute'') (Var p)) (Var x)\ = UnPermute p x" -| "\(\p x. t1 = App (Const ''unpermute'') (Var p) \ t2 = (Var x)) \ \App t1 t2\ = UApp (\t1\) (\t2\)" -defer -apply(simp_all) -apply(auto)[1] -apply(case_tac x) -apply(simp_all) -apply(auto) -apply(blast) -done - -termination - apply(relation "measure (\t. size t)") - apply(simp_all) - done - - -lemma elim1: - "ufree t \ \t\ \(Const ''unpermute'')" -apply(erule ufree.induct) -apply(auto) -done - -lemma elim2: - "ufree t \ \(\p. \t\ = App (Const ''unpermute'') (Var p))" -apply(erule ufree.induct) -apply(auto dest: elim1) -done - -lemma ss1: - "ufree t \ uss t = ss (\t\)" -apply(erule ufree.induct) -apply(simp_all) -apply(subst ss.simps) -apply(auto) -apply(drule elim2) -apply(auto) -done - -lemma trans1: - shows "\\t\\ = t" -apply(induct t) -apply(simp) -apply(simp) -prefer 2 -apply(simp) -apply(case_tac "(\p x. t1 = App (Const ''unpermute'') (Var p) \ t2 = (Var x))") -apply(erule exE)+ -apply(simp) -apply(simp) -done - -lemma trans_subst: - shows "\t[x ::= p]\ = \t\[x :::= p]" -apply(induct rule: subst.induct) -apply(simp) -defer -apply(simp) -apply(simp) -apply(simp) -apply(case_tac "(t1 = App (Const ''unpermute'') (Var p) \ t2 = (Var x))") -apply(erule exE)+ -apply(simp only:) -apply(subst utrans.simps) -apply(subst usubst.simps) -apply(case_tac "xa = x") -apply(subst (asm) subst.simps) -apply(simp only:) -apply(subst (asm) utrans.simps) -apply(simp only: usubst.simps) -apply(simp) -apply(auto)[1] -apply(case_tac "pa = x") -apply(simp) -prefer 2 -apply(simp) -apply(simp) -done - -lemma - "ss (t[x ::= p]) = ss t" -apply(subst (2) trans1[symmetric]) -apply(subst ss1[symmetric]) - - -fun - fr :: "trm \ name set" -where - "fr (Var x) = {x}" -| "fr (Const s) = {}" -| "fr (Lam [x].t) = fr t - {x}" -| "fr (App t1 t2) = fr t1 \ fr t2" - -function - sfr :: "trm \ name set" -where - "sfr (Var x) = {}" -| "sfr (Const s) = {}" -| "sfr (Lam [x].t) = sfr t - {x}" -| "sfr (App (App (Const ''unpermute'') (Var p)) (Var x)) = {p, x}" -| "\(\p x. t1 = App (Const ''unpermute'') (Var p) \ t2 = (Var x)) \ sfr (App t1 t2) = sfr t1 \ sfr t2" -defer -apply(simp_all) -apply(auto)[1] -apply(case_tac x) -apply(simp_all) -apply(auto) -apply(blast) -done - -termination - apply(relation "measure (\t. size t)") - apply(simp_all) - done - -function - ss :: "trm \ nat" -where - "ss (Var x) = 1" -| "ss (Const s) = 1" -| "ss (Lam [x].t) = 1 + ss t" -| "ss (App (App (Const ''unpermute'') (Var p)) (Var x)) = 1" -| "\(\p x. t1 = App (Const ''unpermute'') (Var p) \ t2 = (Var x)) \ ss (App t1 t2) = 1 + ss t1 + ss t2" -defer -apply(simp_all) -apply(auto)[1] -apply(case_tac x) -apply(simp_all) -apply(auto) -apply(blast) -done - -termination - apply(relation "measure (\t. size t)") - apply(simp_all) - done - -inductive - improper :: "trm \ bool" -where - "improper (App (App (Const ''unpermute'') (Var p)) (Var x))" -| "improper p x t \ improper p x (Lam [y].t)" -| "\improper p x t1; improper p x t2\ \ improper p x (App t1 t2)" - -lemma trm_ss: - shows "\improper p x t \ ss (t[x::= p]) = ss t" -apply(induct rule: ss.induct) -apply(simp) -apply(simp) -apply(simp) -apply(auto)[1] -apply(case_tac "improper p x t") -apply(drule improper.intros(2)) -apply(blast) -apply(simp) -using improper.intros(1) -apply(blast) -apply(erule contrapos_pn) -thm contrapos_np -apply(simp) -apply(auto)[1] -apply(simp) -apply(erule disjE) -apply(erule conjE)+ -apply(subst ss.simps) -apply(simp) -apply(rule disjI1) -apply(rule allI) -apply(rule notI) - -apply(simp del: ss.simps) -apply(erule disjE) -apply(subst ss.simps) -apply(simp) -apply(simp only: subst.simps) -apply(subst ss.simps) -apply(simp del: ss.simps) -apply(rule conjI) -apply(rule impI) -apply(erule conjE) -apply(erule exE)+ -apply(subst ss.simps) -apply(simp) -apply(auto)[1] -apply(simp add: if_splits) -apply() - -function - simp :: "name \ trm \ trm" -where - "simp p (Const c) = (Const c)" -| "simp p (Var x) = App (App (Const ''permute'') (Var p)) (Var x)" -| "simp p (App t1 t2) = (if ((\x. t1 = App (Const ''unpermute'') (Var p) \ t2 = (Var x))) - then t2 - else App (simp p t1) (simp p t2))" -| "simp p (Lam [x].t) = Lam [x]. (simp p (t[x ::= p]))" -apply(pat_completeness) -apply(simp_all) -apply(auto) -done - -termination -apply(relation "measure (\(_, t). size t)") -apply(simp_all) - -end \ No newline at end of file diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/QuotientSet.thy --- a/Nominal/Ex/QuotientSet.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -theory QuotientSet -imports - "../Nominal2" -begin - -lemma supp_quot: - "(supp (R, x)) supports (R `` {x})" -unfolding supports_def -unfolding fresh_def[symmetric] -apply(perm_simp) -apply(simp add: swap_fresh_fresh) -done - -lemma - assumes "equiv UNIV R" - and "(x, y) \ R" - shows "R `` {x} = R `` {y}" -using assms -by (rule equiv_class_eq) - -lemma s1: - assumes "equiv UNIV R" - and "(x, y) \ R" - shows "a \ (R `` {x}) \ a \ (R `` {y})" -using assms -apply(subst equiv_class_eq) -apply(auto) -done - -lemma s2: - fixes x::"'a::fs" - assumes "equiv UNIV R" - and "supp R = {}" - shows "\{supp y | y. (x, y) \ R} supports (R `` {x})" -unfolding supports_def -apply(rule allI)+ -apply(rule impI) -apply(rule swap_fresh_fresh) -apply(drule conjunct1) -apply(auto)[1] -apply(subst s1) -apply(rule assms) -apply(assumption) -apply(rule supports_fresh) -apply(rule supp_quot) -apply(simp add: supp_Pair finite_supp assms) -apply(simp add: supp_Pair assms) -apply(drule conjunct2) -apply(auto)[1] -apply(subst s1) -apply(rule assms) -apply(assumption) -apply(rule supports_fresh) -apply(rule supp_quot) -apply(simp add: supp_Pair finite_supp assms) -apply(simp add: supp_Pair assms) -done - -lemma s3: - fixes S::"'a::fs set" - assumes "finite S" - and "S \ {}" - and "a \ S" - shows "\x \ S. a \ x" -using assms -apply(auto simp add: fresh_def) -apply(subst (asm) supp_of_finite_sets) -apply(auto) -done - -(* -lemma supp_inter: - fixes x::"'a::fs" - assumes "equiv UNIV R" - and "supp R = {}" - shows "supp (R `` {x}) = \{supp y | y. (x, y) \ R}" -apply(rule finite_supp_unique) -apply(rule s2) -apply(rule assms) -apply(rule assms) -apply(metis (lam_lifting, no_types) at_base_infinite finite_UNIV) -*) - - - - - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/SFT/Consts.thy --- a/Nominal/Ex/SFT/Consts.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,294 +0,0 @@ -header {* Constant definitions *} - -theory Consts imports Utils begin - -fun Umn :: "nat \ nat \ lam" -where - [simp del]: "Umn 0 n = \(cn 0). Var (cn n)" -| [simp del]: "Umn (Suc m) n = \(cn (Suc m)). Umn m n" - -lemma [simp]: "2 = Suc 1" - by auto - -lemma split_lemma: - "(a = b \ X) \ (a \ b \ Y) \ (a = b \ X) \ (a \ b \ Y)" - by blast - -lemma Lam_U: - assumes "x \ y" "y \ z" "x \ z" - shows "Umn 2 0 = \x. \y. \z. Var z" - "Umn 2 1 = \x. \y. \z. Var y" - "Umn 2 2 = \x. \y. \z. Var x" - apply (simp_all add: Umn.simps Abs1_eq_iff lam.fresh fresh_at_base flip_def[symmetric] Umn.simps cnd permute_flip_at assms assms[symmetric] split_lemma) - apply (intro impI conjI) - apply (metis assms)+ - done - -lemma supp_U1: "n \ m \ atom (cn n) \ supp (Umn m n)" - by (induct m) - (auto simp add: lam.supp supp_at_base Umn.simps le_Suc_eq) - -lemma supp_U2: "supp (Umn m n) \ {atom (cn n)}" - by (induct m) (auto simp add: lam.supp supp_at_base Umn.simps) - -lemma supp_U[simp]: "n \ m \ supp (Umn m n) = {}" - using supp_U1 supp_U2 - by blast - -lemma U_eqvt: - "n \ m \ p \ (Umn m n) = Umn m n" - by (rule_tac [!] perm_supp_eq) (simp_all add: fresh_star_def fresh_def) - -definition VAR where "VAR \ \cx. \cy. (Var cy \ (Umn 2 2) \ Var cx \ Var cy)" -definition "APP \ \cx. \cy. \cz. (Var cz \ Umn 2 1 \ Var cx \ Var cy \ Var cz)" -definition "Abs \ \cx. \cy. (Var cy \ Umn 2 0 \ Var cx \ Var cy)" - -lemma VAR_APP_Abs: - "x \ e \ VAR = \x. \e. (Var e \ Umn 2 2 \ Var x \ Var e)" - "e \ x \ e \ y \ x \ y \ APP = \x. \y. \e. (Var e \ Umn 2 1 \ Var x \ Var y \ Var e)" - "x \ e \ Abs = \x. \e. (Var e \ Umn 2 0 \ Var x \ Var e)" - unfolding VAR_def APP_def Abs_def - by (simp_all add: Abs1_eq_iff lam.fresh flip_def[symmetric] U_eqvt fresh_def lam.supp supp_at_base split_lemma permute_flip_at) - (auto simp only: cx_cy_cz cx_cy_cz[symmetric]) - -lemma VAR_app: - "VAR \ x \ e \ e \ Umn 2 2 \ x \ e" - by (rule lam2_fast_app[OF VAR_APP_Abs(1)]) simp_all - -lemma APP_app: - "APP \ x \ y \ e \ e \ Umn 2 1 \ x \ y \ e" - by (rule lam3_fast_app[OF VAR_APP_Abs(2)]) (simp_all) - -lemma Abs_app: - "Abs \ x \ e \ e \ Umn 2 0 \ x \ e" - by (rule lam2_fast_app[OF VAR_APP_Abs(3)]) simp_all - -lemma supp_VAR_APP_Abs[simp]: - "supp VAR = {}" "supp APP = {}" "supp Abs = {}" - by (simp_all add: VAR_def APP_def Abs_def lam.supp supp_at_base) blast+ - -lemma VAR_APP_Abs_eqvt[eqvt]: - "p \ VAR = VAR" "p \ APP = APP" "p \ Abs = Abs" - by (rule_tac [!] perm_supp_eq) (simp_all add: fresh_star_def fresh_def) - -nominal_primrec - Numeral :: "lam \ lam" ("\_\" 1000) -where - "\Var x\ = VAR \ (Var x)" -| Ap: "\M \ N\ = APP \ \M\ \ \N\" -| "\\x. M\ = Abs \ (\x. \M\)" -proof auto - fix x :: lam and P - assume "\xa. x = Var xa \ P" "\M N. x = M \ N \ P" "\xa M. x = \ xa. M \ P" - then show "P" - by (rule_tac y="x" and c="0 :: perm" in lam.strong_exhaust) - (auto simp add: Abs1_eq_iff fresh_star_def)[3] -next - fix x :: name and M and xa :: name and Ma - assume "[[atom x]]lst. M = [[atom xa]]lst. Ma" - "eqvt_at Numeral_sumC M" - then show "[[atom x]]lst. Numeral_sumC M = [[atom xa]]lst. Numeral_sumC Ma" - apply - - apply (erule Abs_lst1_fcb) - apply (simp_all add: Abs_fresh_iff) - apply (erule fresh_eqvt_at) - apply (simp_all add: finite_supp Abs1_eq_iff eqvt_at_def) - done -next - show "eqvt Numeral_graph" unfolding eqvt_def Numeral_graph_def - by (rule, perm_simp, rule) -qed - -termination (eqvt) by lexicographic_order - -lemma supp_numeral[simp]: - "supp \x\ = supp x" - by (induct x rule: lam.induct) - (simp_all add: lam.supp) - -lemma fresh_numeral[simp]: - "x \ \y\ = x \ y" - unfolding fresh_def by simp - -fun app_lst :: "name \ lam list \ lam" where - "app_lst n [] = Var n" -| "app_lst n (h # t) = (app_lst n t) \ h" - -lemma app_lst_eqvt[eqvt]: "p \ (app_lst t ts) = app_lst (p \ t) (p \ ts)" - by (induct ts arbitrary: t p) (simp_all add: eqvts) - -lemma supp_app_lst: "supp (app_lst x l) = {atom x} \ supp l" - apply (induct l) - apply (simp_all add: supp_Nil lam.supp supp_at_base supp_Cons) - by blast - -lemma app_lst_eq_iff: "app_lst n M = app_lst n N \ M = N" - by (induct M N rule: list_induct2') simp_all - -lemma app_lst_rev_eq_iff: "app_lst n (rev M) = app_lst n (rev N) \ M = N" - by (drule app_lst_eq_iff) simp - -nominal_primrec - Ltgt :: "lam list \ lam" ("\_\" 1000) -where - [simp del]: "atom x \ l \ \l\ = \x. (app_lst x (rev l))" - unfolding eqvt_def Ltgt_graph_def - apply (rule, perm_simp, rule, rule) - apply (rule_tac x="x" and ?'a="name" in obtain_fresh) - apply (simp_all add: Abs1_eq_iff lam.fresh swap_fresh_fresh fresh_at_base) - apply (simp add: eqvts swap_fresh_fresh) - apply (case_tac "x = xa") - apply simp_all - apply (subgoal_tac "eqvt app_lst") - apply (erule fresh_fun_eqvt_app2) - apply (simp_all add: fresh_at_base lam.fresh eqvt_def eqvts_raw fresh_rev) - done - -termination (eqvt) by lexicographic_order - -lemma ltgt_eq_iff[simp]: - "\M\ = \N\ \ M = N" -proof auto - obtain x :: name where "atom x \ (M, N)" using obtain_fresh by auto - then have *: "atom x \ M" "atom x \ N" using fresh_Pair by simp_all - then show "(\M\ = \N\) \ (M = N)" by (simp add: Abs1_eq_iff app_lst_rev_eq_iff Ltgt.simps) -qed - -lemma Ltgt1_app: "\[M]\ \ N \ N \ M" -proof - - obtain x :: name where "atom x \ (M, N)" using obtain_fresh by auto - then have "atom x \ M" "atom x \ N" using fresh_Pair by simp_all - then show ?thesis - apply (subst Ltgt.simps) - apply (simp add: fresh_Cons fresh_Nil) - apply (rule b3, rule bI, simp add: b1) - done -qed - -lemma Ltgt3_app: "\[M,N,P]\ \ R \ R \ M \ N \ P" -proof - - obtain x :: name where "atom x \ (M, N, P, R)" using obtain_fresh by auto - then have *: "atom x \ (M,N,P)" "atom x \ R" using fresh_Pair by simp_all - then have s: "Var x \ M \ N \ P [x ::= R] \ R \ M \ N \ P" using b1 by simp - show ?thesis using * - apply (subst Ltgt.simps) - apply (simp add: fresh_Cons fresh_Nil fresh_Pair_elim) - apply auto[1] - apply (rule b3, rule bI, simp add: b1) - done -qed - -lemma supp_ltgt[simp]: - "supp \t\ = supp t" -proof - - obtain x :: name where *:"atom x \ t" using obtain_fresh by auto - show ?thesis using * - by (simp_all add: Ltgt.simps lam.supp supp_at_base supp_Nil supp_app_lst supp_rev fresh_def) -qed - -lemma fresh_ltgt[simp]: - "x \ \[y]\ = x \ y" - "x \ \[t,r,s]\ = x \ (t,r,s)" - by (simp_all add: fresh_def supp_Cons supp_Nil supp_Pair) - -lemma Ltgt1_subst[simp]: - "\[M]\ [y ::= A] = \[M [y ::= A]]\" -proof - - obtain x :: name where a: "atom x \ (M, A, y, M [y ::= A])" using obtain_fresh by blast - have "x \ y" using a[simplified fresh_Pair fresh_at_base] by simp - then show ?thesis - apply (subst Ltgt.simps) - using a apply (simp add: fresh_Nil fresh_Cons fresh_Pair_elim) - apply (subst Ltgt.simps) - using a apply (simp add: fresh_Pair_elim fresh_Nil fresh_Cons) - apply (simp add: a) - done -qed - -lemma U_app: - "\[A,B,C]\ \ Umn 2 2 \ A" "\[A,B,C]\ \ Umn 2 1 \ B" "\[A,B,C]\ \ Umn 2 0 \ C" - by (rule b3, rule Ltgt3_app, rule lam3_fast_app, rule Lam_U, simp_all) - (rule b3, rule Ltgt3_app, rule lam3_fast_app, rule Lam_U[simplified], simp_all)+ - -definition "F1 \ \cx. (APP \ \VAR\ \ (VAR \ Var cx))" -definition "F2 \ \cx. \cy. \cz. ((APP \ (APP \ \APP\ \ (Var cz \ Var cx))) \ (Var cz \ Var cy))" -definition "F3 \ \cx. \cy. (APP \ \Abs\ \ (Abs \ (\cz. (Var cy \ (Var cx \ Var cz)))))" - - -lemma Lam_F: - "F1 = \x. (APP \ \VAR\ \ (VAR \ Var x))" - "a \ b \ a \ c \ c \ b \ F2 = \a. \b. \c. ((APP \ (APP \ \APP\ \ (Var c \ Var a))) \ (Var c \ Var b))" - "a \ b \ a \ x \ x \ b \ F3 = \a. \b. (APP \ \Abs\ \ (Abs \ (\x. (Var b \ (Var a \ Var x)))))" - by (simp_all add: F1_def F2_def F3_def Abs1_eq_iff lam.fresh supp_at_base VAR_APP_Abs_eqvt Numeral.eqvt flip_def[symmetric] fresh_at_base split_lemma permute_flip_at) - (auto simp add: cx_cy_cz cx_cy_cz[symmetric]) - -lemma supp_F[simp]: - "supp F1 = {}" "supp F2 = {}" "supp F3 = {}" - by (simp_all add: F1_def F2_def F3_def lam.supp supp_at_base) - blast+ - -lemma F_eqvt[eqvt]: - "p \ F1 = F1" "p \ F2 = F2" "p \ F3 = F3" - by (rule_tac [!] perm_supp_eq) - (simp_all add: fresh_star_def fresh_def) - -lemma F_app: - "F1 \ A \ APP \ \VAR\ \ (VAR \ A)" - "F2 \ A \ B \ C \ (APP \ (APP \ \APP\ \ (C \ A))) \ (C \ B)" - by (rule lam1_fast_app, rule Lam_F, simp_all) - (rule lam3_fast_app, rule Lam_F, simp_all) - -lemma F3_app: - assumes f: "atom x \ A" "atom x \ B" (* or A and B have empty support *) - shows "F3 \ A \ B \ APP \ \Abs\ \ (Abs \ (\x. (B \ (A \ Var x))))" -proof - - obtain y :: name where b: "atom y \ (x, A, B)" using obtain_fresh by blast - obtain z :: name where c: "atom z \ (x, y, A, B)" using obtain_fresh by blast - have *: "x \ z" "x \ y" "y \ z" - using b c by (simp_all add: fresh_Pair fresh_at_base) blast+ - have **: - "atom y \ z" "atom x \ z" "atom y \ x" - "atom z \ y" "atom z \ x" "atom x \ y" - "atom x \ A" "atom y \ A" "atom z \ A" - "atom x \ B" "atom y \ B" "atom z \ B" - using b c f by (simp_all add: fresh_Pair fresh_at_base) blast+ - show ?thesis - apply (simp add: Lam_F(3)[of y z x] * *[symmetric]) - apply (rule b3) apply (rule b5) apply (rule bI) - apply (simp add: ** fresh_Pair * *[symmetric]) - apply (rule b3) apply (rule bI) - apply (simp add: ** fresh_Pair * *[symmetric]) - apply (rule b1) - done -qed - -definition Lam_A1_pre : "A1 \ \cx. \cy. (F1 \ Var cx)" -definition Lam_A2_pre : "A2 \ \cx. \cy. \cz. (F2 \ Var cx \ Var cy \ \[Var cz]\)" -definition Lam_A3_pre : "A3 \ \cx. \cy. (F3 \ Var cx \ \[Var cy]\)" -lemma Lam_A: - "x \ y \ A1 = \x. \y. (F1 \ Var x)" - "a \ b \ a \ c \ c \ b \ A2 = \a. \b. \c. (F2 \ Var a \ Var b \ \[Var c]\)" - "a \ b \ A3 = \a. \b. (F3 \ Var a \ \[Var b]\)" - by (simp_all add: Lam_A1_pre Lam_A2_pre Lam_A3_pre Abs1_eq_iff lam.fresh supp_at_base VAR_APP_Abs_eqvt Numeral.eqvt flip_def[symmetric] fresh_at_base F_eqvt Ltgt.eqvt split_lemma permute_flip_at cx_cy_cz cx_cy_cz[symmetric]) - auto - -lemma supp_A[simp]: - "supp A1 = {}" "supp A2 = {}" "supp A3 = {}" - by (auto simp add: Lam_A1_pre Lam_A2_pre Lam_A3_pre lam.supp supp_at_base supp_Cons supp_Nil) - -lemma A_app: - "A1 \ A \ B \ F1 \ A" - "A2 \ A \ B \ C \ F2 \ A \ B \ \[C]\" - "A3 \ A \ B \ F3 \ A \ \[B]\" - apply (rule lam2_fast_app, rule Lam_A, simp_all) - apply (rule lam3_fast_app, rule Lam_A, simp_all) - apply (rule lam2_fast_app, rule Lam_A, simp_all) - done - -definition "Num \ \[\[A1,A2,A3]\]\" - -lemma supp_Num[simp]: - "supp Num = {}" - by (auto simp only: Num_def supp_ltgt supp_Pair supp_A supp_Cons supp_Nil) - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/SFT/LambdaTerms.thy --- a/Nominal/Ex/SFT/LambdaTerms.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -header {* Definition of Lambda terms and convertibility *} - -theory LambdaTerms imports "../../Nominal2" begin - -lemma [simp]: "supp x = {} \ y \ x" - unfolding fresh_def by blast - -atom_decl name - -nominal_datatype lam = - Var "name" -| App "lam" "lam" -| Lam x::"name" l::"lam" binds x in l ("Lam [_]. _" [100, 100] 100) - -notation - App (infixl "\" 98) and - Lam ("\ _. _" [97, 97] 99) - -nominal_primrec - subst :: "lam \ name \ lam \ lam" ("_ [_ ::= _]" [90, 90, 90] 90) -where - "(Var x)[y ::= s] = (if x = y then s else (Var x))" -| "(t1 \ t2)[y ::= s] = (t1[y ::= s]) \ (t2[y ::= s])" -| "atom x \ (y, s) \ (\x. t)[y ::= s] = \x.(t[y ::= s])" -proof auto - fix a b :: lam and aa :: name and P - assume "\x y s. a = Var x \ aa = y \ b = s \ P" - "\t1 t2 y s. a = t1 \ t2 \ aa = y \ b = s \ P" - "\x y s t. \atom x \ (y, s); a = \ x. t \ aa = y \ b = s\ \ P" - then show "P" - by (rule_tac y="a" and c="(aa, b)" in lam.strong_exhaust) - (blast, blast, simp add: fresh_star_def) -next - fix x :: name and t and xa :: name and ya sa ta - assume *: "eqvt_at subst_sumC (t, ya, sa)" - "atom x \ (ya, sa)" "atom xa \ (ya, sa)" - "[[atom x]]lst. t = [[atom xa]]lst. ta" - then show "[[atom x]]lst. subst_sumC (t, ya, sa) = [[atom xa]]lst. subst_sumC (ta, ya, sa)" - apply - - apply (erule Abs_lst1_fcb) - apply(simp (no_asm) add: Abs_fresh_iff) - apply(drule_tac a="atom xa" in fresh_eqvt_at) - apply(simp add: finite_supp) - apply(simp_all add: fresh_Pair_elim Abs_fresh_iff Abs1_eq_iff) - apply(subgoal_tac "(atom x \ atom xa) \ ya = ya") - apply(subgoal_tac "(atom x \ atom xa) \ sa = sa") - apply(simp add: atom_eqvt eqvt_at_def) - apply(rule perm_supp_eq, simp add: supp_swap fresh_star_def fresh_Pair)+ - done -next - show "eqvt subst_graph" unfolding eqvt_def subst_graph_def - by (rule, perm_simp, rule) -qed - -termination (eqvt) by lexicographic_order - -lemma forget[simp]: - shows "atom x \ t \ t[x ::= s] = t" - by (nominal_induct t avoiding: x s rule: lam.strong_induct) - (auto simp add: lam.fresh fresh_at_base) - -lemma forget_closed[simp]: "supp t = {} \ t[x ::= s] = t" - by (simp add: fresh_def) - -lemma subst_id[simp]: "M [x ::= Var x] = M" - by (rule_tac lam="M" and c="x" in lam.strong_induct) - (simp_all add: fresh_star_def lam.fresh fresh_Pair) - -inductive - beta :: "lam \ lam \ bool" (infix "\" 80) -where - bI: "(\x. M) \ N \ M[x ::= N]" -| b1: "M \ M" -| b2: "M \ N \ N \ M" -| b3: "M \ N \ N \ L \ M \ L" -| b4: "M \ N \ Z \ M \ Z \ N" -| b5: "M \ N \ M \ Z \ N \ Z" -| b6: "M \ N \ \x. M \ \x. N" - -lemmas [trans] = b3 -equivariance beta - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/SFT/Theorem.thy --- a/Nominal/Ex/SFT/Theorem.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -header {* The main lemma about Num and the Second Fixed Point Theorem *} - -theory Theorem imports Consts begin - -lemmas [simp] = b3[OF bI] b1 b4 b5 supp_Num[unfolded Num_def supp_ltgt] Num_def lam.fresh[unfolded fresh_def] fresh_def b6 -lemmas app = Ltgt1_app - -lemma Num: - shows "Num \ \M\ \ \\M\\" -proof (induct M rule: lam.induct) - case (Var n) - have "Num \ \Var n\ = Num \ (VAR \ Var n)" by simp - also have "... = \[\[A1,A2,A3]\]\ \ (VAR \ Var n)" by simp - also have "... \ VAR \ Var n \ \[A1,A2,A3]\" using app . - also have "... \ \[A1,A2,A3]\ \ Umn 2 2 \ Var n \ \[A1,A2,A3]\" using VAR_app . - also have "... \ A1 \ Var n \ \[A1,A2,A3]\" using U_app by simp - also have "... \ F1 \ Var n" using A_app(1) . - also have "... \ APP \ \VAR\ \ (VAR \ Var n)" using F_app(1) . - also have "... = \\Var n\\" by simp - finally show "Num \ \Var n\ \ \\Var n\\". -next - case (App M N) - assume IH: "Num \ \M\ \ \\M\\" "Num \ \N\ \ \\N\\" - have "Num \ \M \ N\ = Num \ (APP \ \M\ \ \N\)" by simp - also have "... = \[\[A1,A2,A3]\]\ \ (APP \ \M\ \ \N\)" by simp - also have "... \ APP \ \M\ \ \N\ \ \[A1,A2,A3]\" using app . - also have "... \ \[A1,A2,A3]\ \ Umn 2 1 \ \M\ \ \N\ \ \[A1,A2,A3]\" using APP_app . - also have "... \ A2 \ \M\ \ \N\ \ \[A1,A2,A3]\" using U_app by simp - also have "... \ F2 \ \M\ \ \N\ \ Num" using A_app(2) by simp - also have "... \ APP \ (APP \ \APP\ \ (Num \ \M\)) \ (Num \ \N\)" using F_app(2) . - also have "... \ APP \ (APP \ \APP\ \ (\\M\\)) \ (Num \ \N\)" using IH by simp - also have "... \ \\M \ N\\" using IH by simp - finally show "Num \ \M \ N\ \ \\M \ N\\". -next - case (Lam x P) - assume IH: "Num \ \P\ \ \\P\\" - have "Num \ \\ x. P\ = Num \ (Abs \ \ x. \P\)" by simp - also have "... = \[\[A1,A2,A3]\]\ \ (Abs \ \ x. \P\)" by simp - also have "... \ Abs \ (\ x. \P\) \ \[A1,A2,A3]\" using app . - also have "... \ \[A1,A2,A3]\ \ Umn 2 0 \ (\ x. \P\) \ \[A1,A2,A3]\" using Abs_app . - also have "... \ A3 \ (\ x. \P\) \ \[A1,A2,A3]\" using U_app by simp - also have "... \ F3 \ (\ x. \P\) \ \[\[A1,A2,A3]\]\" using A_app(3) . - also have "... = F3 \ (\ x. \P\) \ Num" by simp - also have "... \ APP \ \Abs\ \ (Abs \ \ x. (Num \ ((\ x. \P\) \ Var x)))" by (rule F3_app) simp_all - also have "... \ APP \ \Abs\ \ (Abs \ \ x. (Num \ \P\))" using beta_app by simp - also have "... \ APP \ \Abs\ \ (Abs \ \ x. \\P\\)" using IH by simp - also have "... = \\\ x. P\\" by simp - finally show "Num \ \\ x. P\ \ \\\ x. P\\" . -qed - -lemmas [simp] = Ap Num -lemmas [simp del] = fresh_def Num_def - -theorem SFP: - fixes F :: lam - shows "\X. X \ F \ \X\" -proof - - obtain x :: name where [simp]:"atom x \ F" using obtain_fresh by blast - def W \ "\x. (F \ (APP \ Var x \ (Num \ Var x)))" - def X \ "W \ \W\" - have a: "X = W \ \W\" unfolding X_def .. - also have "... = (\x. (F \ (APP \ Var x \ (Num \ Var x)))) \ \W\" unfolding W_def .. - also have "... \ F \ (APP \ \W\ \ (Num \ \W\))" by simp - also have "... \ F \ (APP \ \W\ \ \\W\\)" by simp - also have "... \ F \ \W \ \W\\" by simp - also have "... = F \ \X\" unfolding X_def .. - finally show ?thesis by blast -qed - -end diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/SFT/Utils.thy --- a/Nominal/Ex/SFT/Utils.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -header {* Utilities for defining constants and functions *} - -theory Utils imports LambdaTerms begin - -lemma beta_app: - "(\ x. M) \ Var x \ M" - by (rule b3, rule bI) - (simp add: b1) - -lemma lam1_fast_app: - assumes leq: "\a. (L = \ a. (F (V a)))" - and su: "\x. atom x \ A \ F (V x) [x ::= A] = F A" - shows "L \ A \ F A" -proof - - obtain x :: name where a: "atom x \ A" using obtain_fresh by blast - show ?thesis - by (simp add: leq[of x], rule b3, rule bI, simp add: su b1 a) -qed - -lemma lam2_fast_app: - assumes leq: "\a b. a \ b \ L = \ a. \ b. (F (V a) (V b))" - and su: "\x y. atom x \ A \ atom y \ A \ atom x \ B \ atom y \ B \ - x \ y \ F (V x) (V y) [x ::= A] [y ::= B] = F A B" - shows "L \ A \ B \ F A B" -proof - - obtain x :: name where a: "atom x \ (A, B)" using obtain_fresh by blast - obtain y :: name where b: "atom y \ (x, A, B)" using obtain_fresh by blast - obtain z :: name where c: "atom z \ (x, y, A, B)" using obtain_fresh by blast - have *: "x \ y" "x \ z" "y \ z" - using a b c by (simp_all add: fresh_Pair fresh_at_base) blast+ - have ** : "atom y \ z" "atom x \ z" "atom y \ x" - "atom z \ y" "atom z \ x" "atom x \ y" - "atom x \ A" "atom y \ A" "atom z \ A" - "atom x \ B" "atom y \ B" "atom z \ B" - using a b c by (simp_all add: fresh_Pair fresh_at_base) blast+ - show ?thesis - apply (simp add: leq[OF *(1)]) - apply (rule b3) apply (rule b5) apply (rule bI) - apply (simp add: ** fresh_Pair) - apply (rule b3) apply (rule bI) apply (simp add: su b1 ** *) - done - qed - -lemma lam3_fast_app: - assumes leq: "\a b c. a \ b \ b \ c \ c \ a \ - L = \ a. \ b. \ c. (F (V a) (V b) (V c))" - and su: "\x y z. atom x \ A \ atom y \ A \ atom z \ A \ - atom x \ B \ atom y \ B \ atom z \ B \ - atom y \ B \ atom y \ B \ atom z \ B \ - x \ y \ y \ z \ z \ x \ - ((F (V x) (V y) (V z))[x ::= A] [y ::= B] [z ::= C] = F A B C)" - shows "L \ A \ B \ C \ F A B C" -proof - - obtain x :: name where a: "atom x \ (A, B, C)" using obtain_fresh by blast - obtain y :: name where b: "atom y \ (x, A, B, C)" using obtain_fresh by blast - obtain z :: name where c: "atom z \ (x, y, A, B, C)" using obtain_fresh by blast - have *: "x \ y" "y \ z" "z \ x" - using a b c by (simp_all add: fresh_Pair fresh_at_base) blast+ - have ** : "atom y \ z" "atom x \ z" "atom y \ x" - "atom z \ y" "atom z \ x" "atom x \ y" - "atom x \ A" "atom y \ A" "atom z \ A" - "atom x \ B" "atom y \ B" "atom z \ B" - "atom x \ C" "atom y \ C" "atom z \ C" - using a b c by (simp_all add: fresh_Pair fresh_at_base) blast+ - show ?thesis - apply (simp add: leq[OF *(1) *(2) *(3)]) - apply (rule b3) apply (rule b5) apply (rule b5) apply (rule bI) - apply (simp add: ** fresh_Pair) - apply (rule b3) apply (rule b5) apply (rule bI) - apply (simp add: ** fresh_Pair) - apply (rule b3) apply (rule bI) apply (simp add: su b1 ** *) - done - qed - -definition cn :: "nat \ name" where "cn n \ Abs_name (Atom (Sort ''LambdaTerms.name'' []) n)" - -lemma cnd[simp]: "m \ n \ cn m \ cn n" - unfolding cn_def using Abs_name_inject by simp - -definition cx :: name where "cx \ cn 0" -definition cy :: name where "cy \ cn 1" -definition cz :: name where "cz \ cn 2" - -lemma cx_cy_cz[simp]: - "cx \ cy" "cx \ cz" "cz \ cy" - unfolding cx_def cy_def cz_def - by simp_all - -lemma noteq_fresh: "atom x \ y = (x \ y)" - by (simp add: fresh_at_base(2)) - -lemma fresh_fun_eqvt_app2: - assumes a: "eqvt f" - and b: "a \ x" "a \ y" - shows "a \ f x y" - using fresh_fun_eqvt_app[OF a b(1)] a b - by (metis fresh_fun_app) - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/SubstNoFcb.thy --- a/Nominal/Ex/SubstNoFcb.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -theory Lambda imports "../Nominal2" begin - -atom_decl name - -nominal_datatype lam = - Var "name" -| App "lam" "lam" -| Lam x::"name" l::"lam" binds x in l ("Lam [_]. _" [100, 100] 100) - -nominal_primrec lam_rec :: - "(name \ 'a :: pt) \ (lam \ lam \ 'a) \ (name \ lam \ 'a) \ 'a \ 'b :: fs \ lam \ 'a" -where - "lam_rec fv fa fl fd P (Var n) = fv n" -| "lam_rec fv fa fl fd P (App l r) = fa l r" -| "(atom x \ P \ (\y s. atom y \ P \ Lam [x]. t = Lam [y]. s \ fl x t = fl y s)) \ - lam_rec fv fa fl fd P (Lam [x]. t) = fl x t" -| "(atom x \ P \ \(\y s. atom y \ P \ Lam [x]. t = Lam [y]. s \ fl x t = fl y s)) \ - lam_rec fv fa fl fd P (Lam [x]. t) = fd" - apply (simp add: eqvt_def lam_rec_graph_def) - apply (rule, perm_simp, rule, rule) - apply (case_tac x) - apply (rule_tac y="f" and c="e" in lam.strong_exhaust) - apply metis - apply metis - unfolding fresh_star_def - apply simp - apply metis - apply simp_all[2] - apply (metis (no_types) Pair_inject lam.distinct)+ - apply simp - apply (metis (no_types) Pair_inject lam.distinct)+ - done - -termination (eqvt) by lexicographic_order - -lemma lam_rec_cong[fundef_cong]: - " (\v. l = Var v \ fv v = fv' v) \ - (\t1 t2. l = App t1 t2 \ fa t1 t2 = fa' t1 t2) \ - (\n t. l = Lam [n]. t \ fl n t = fl' n t) \ - lam_rec fv fa fl fd P l = lam_rec fv' fa' fl' fd P l" - apply (rule_tac y="l" and c="P" in lam.strong_exhaust) - apply auto - apply (case_tac "(\y s. atom y \ P \ Lam [name]. lam = Lam [y]. s \ fl name lam = fl y s)") - apply (subst lam_rec.simps) apply (simp add: fresh_star_def) - apply (subst lam_rec.simps) apply (simp add: fresh_star_def) - using Abs1_eq_iff lam.eq_iff apply metis - apply (subst lam_rec.simps(4)) apply (simp add: fresh_star_def) - apply (subst lam_rec.simps(4)) apply (simp add: fresh_star_def) - using Abs1_eq_iff lam.eq_iff apply metis - done - -nominal_primrec substr where -[simp del]: "substr l y s = lam_rec - (%x. if x = y then s else (Var x)) - (%t1 t2. App (substr t1 y s) (substr t2 y s)) - (%x t. Lam [x]. (substr t y s)) (Lam [y]. Var y) (y, s) l" -unfolding eqvt_def substr_graph_def -apply (rule, perm_simp, rule, rule) -by pat_completeness auto - -termination (eqvt) by lexicographic_order - -lemma fresh_fun_eqvt_app3: - assumes e: "eqvt f" - 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 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)" - apply (subst substr.simps) apply (simp only: lam_rec.simps) - apply (subst substr.simps) apply (simp only: lam_rec.simps) - apply (subst substr.simps) apply (subst lam_rec.simps) - apply (auto simp add: Abs1_eq_iff substr.eqvt swap_fresh_fresh) - apply (rule fresh_fun_eqvt_app3[of substr]) - apply (simp add: eqvt_def eqvts_raw) - apply (simp_all add: fresh_Pair) - done - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/Ex/TypeVarsTest.thy --- a/Nominal/Ex/TypeVarsTest.thy Sat May 12 21:39:09 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -theory TypeVarsTest -imports "../Nominal2" -begin - -(* a nominal datatype with type variables and sorts *) - - -(* the sort constraints need to be attached to the *) -(* first occurence of the type variables on the *) -(* right-hand side *) - -atom_decl name - -class s1 -class s2 - -instance nat :: s1 .. -instance int :: s2 .. - -nominal_datatype ('a::s1, 'b::s2, 'c::at) lam = - Var "name" -| App "('a, 'b, 'c) lam" "('a, 'b, 'c) lam" -| Lam x::"name" l::"('a, 'b, 'c) lam" binds x in l -| Foo "'a" "'b" -| Bar x::"'c" l::"('a, 'b, 'c) lam" binds x in l (* Bar binds a polymorphic atom *) - -term Foo -term Bar - -thm lam.distinct -thm lam.induct -thm lam.exhaust -thm lam.strong_exhaust -thm lam.fv_defs -thm lam.bn_defs -thm lam.perm_simps -thm lam.eq_iff -thm lam.fv_bn_eqvt -thm lam.size_eqvt - - -nominal_datatype ('alpha, 'beta, 'gamma) psi = - PsiNil -| Output "'alpha" "'alpha" "('alpha, 'beta, 'gamma) psi" - - -nominal_datatype 'a foo = - Node x::"name" f::"'a foo" binds x in f -| Leaf "'a" - -term "Leaf" - - - - -end - - - diff -r b6873d123f9b -r 89715c48f728 Nominal/ROOT.ML --- a/Nominal/ROOT.ML Sat May 12 21:39:09 2012 +0100 +++ b/Nominal/ROOT.ML Sat May 12 22:21:25 2012 +0100 @@ -18,12 +18,12 @@ "Ex/LetRec2", "Ex/LetFun", "Ex/Modules", + "Ex/SingleLet", "Ex/Shallow", "Ex/SystemFOmega", "Ex/TypeSchemes1", "Ex/TypeSchemes2", - "Ex/TypeVarsTest", "Ex/Foo1", "Ex/Foo2", "Ex/CoreHaskell",