
diff -r 029f8aabed12 -r a1d27083e688 Nominal/Ex/Lambda.thy
--- a/Nominal/Ex/Lambda.thy	Tue May 18 14:40:05 2010 +0100
+++ b/Nominal/Ex/Lambda.thy	Tue May 18 15:58:52 2010 +0200
@@ -472,6 +472,60 @@
 nominal_inductive typing
 *)
 
+(* Substitution *)
+fun
+  subst_raw :: "lam_raw \<Rightarrow> name \<Rightarrow> lam_raw \<Rightarrow> lam_raw"
+where
+  "subst_raw (Var_raw x) y s = (if x=y then s else (Var_raw x))"
+| "subst_raw (App_raw l r) y s = App_raw (subst_raw l y s) (subst_raw r y s)"
+| "subst_raw (Lam_raw x t) y s =
+     (if x = y then t else
+       (if atom x \<notin> (fv_lam_raw s) then (Lam_raw x (subst_raw t y s)) else undefined))"
+
+quotient_definition
+  subst ("_ [ _ ::= _ ]" [100,100,100] 100)
+where
+  "subst :: lam \<Rightarrow> name \<Rightarrow> lam \<Rightarrow> lam" is "subst_raw"
+
+lemmas fv_rsp = quot_respect(10)[simplified,rulify]
+
+lemma subst_rsp_pre1:
+  assumes a: "alpha_lam_raw a b"
+  shows "alpha_lam_raw (subst_raw a y c) (subst_raw b y c)"
+  using a
+  apply (induct a b arbitrary: c y rule: alpha_lam_raw.induct)
+  apply (simp add: equivp_reflp[OF lam_equivp])
+  apply (simp add: alpha_lam_raw.intros)
+  apply (simp only: alphas)
+  apply clarify
+  apply (simp only: subst_raw.simps)
+  sorry
+
+lemma subst_rsp_pre2:
+  assumes a: "alpha_lam_raw a b"
+  shows "alpha_lam_raw (subst_raw c y a) (subst_raw c y b)"
+  sorry
+
+(* The below is definitely not true... *)
+lemma [quot_respect]:
+  "(alpha_lam_raw ===> op = ===> alpha_lam_raw ===> alpha_lam_raw) subst_raw subst_raw"
+  proof (intro fun_relI, simp)
+    fix a b c d :: lam_raw
+    fix y :: name
+    assume a: "alpha_lam_raw a b"
+    assume b: "alpha_lam_raw c d"
+    have c: "alpha_lam_raw (subst_raw a y c) (subst_raw b y c)" using subst_rsp_pre1 a by simp
+    then have d: "alpha_lam_raw (subst_raw b y c) (subst_raw b y d)" using subst_rsp_pre2 b by simp
+    show "alpha_lam_raw (subst_raw a y c) (subst_raw b y d)"
+      using c d equivp_transp[OF lam_equivp] by blast
+  qed
+
+lemma simp3:
+  "x \<noteq> y \<Longrightarrow> atom x \<notin> fv_lam_raw s \<Longrightarrow> Lam_raw x (subst_raw t y s) = Lam_raw x (subst_raw t y s)"
+  by simp
+
+lemmas subst_simps = subst_raw.simps(1-2)[quot_lifted,no_vars]
+  simp3[quot_lifted,simplified lam.supp,simplified fresh_def[symmetric], no_vars]
 
 end
 




