
diff -r 980fdf92a834 -r f7dee6e808eb FSet.thy
--- a/FSet.thy	Wed Nov 25 03:45:44 2009 +0100
+++ b/FSet.thy	Wed Nov 25 03:47:07 2009 +0100
@@ -355,9 +355,15 @@
           (quotient_tac quot);
         val gc = Drule.strip_imp_concl (cprop_of lpi);
         val t = Goal.prove_internal [] gc (fn _ => tac 1)
-        val _ = tracing (Syntax.string_of_term @{context} (prop_of t))
+        val ts = MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] t
+        val te = @{thm eq_reflection} OF [ts]
+        val _ = tracing (Syntax.string_of_term @{context} (term_of ctrm));
+        val _ = tracing (Syntax.string_of_term @{context} (term_of (Thm.lhs_of te)));
+        val insts = matching_prs (ProofContext.theory_of ctxt) (term_of ctrm) (term_of (Thm.lhs_of te));
+        val ti = Drule.instantiate insts te;
+        val _ = tracing (Syntax.string_of_term @{context} (term_of (cprop_of ti)));
       in
-        Conv.rewr_conv (eq_reflection OF [t]) ctrm
+        Conv.rewr_conv (eq_reflection OF [ti]) ctrm
       end
   | _ $ _ => Conv.comb_conv (lambda_prs_conv ctxt quot) ctrm
   | Abs _ => Conv.abs_conv (fn (_, ctxt) => lambda_prs_conv ctxt quot) ctxt ctrm
@@ -365,10 +371,6 @@
 *}
 
 ML {*
-  lambda_prs_conv @{context} quot
-*}
-
-ML {*
 fun lambda_prs_tac ctxt quot = CSUBGOAL (fn (goal, i) =>
   CONVERSION
     (Conv.params_conv ~1 (fn ctxt =>
@@ -376,36 +378,55 @@
           Conv.concl_conv ~1 (lambda_prs_conv ctxt quot))) ctxt) i)
 *}
 
-(*
 ML {*
-lambda_prs_conv @{context} quot 
-@{cterm "((ABS_fset ---> id) ---> id) (\<lambda>x\<Colon>'a list \<Rightarrow> bool. id ((f ((REP_fset ---> id) x) ((REP_fset ---> id) x))))"}
+val ctrm = @{cterm "((ABS_fset ---> id) ---> id) (\<lambda>x. id ((REP_fset ---> id) x))"}
+val pat =  @{cpat  "((ABS_fset ---> id) ---> id) (\<lambda>x. ?f ((REP_fset ---> id) x))"}
 *}
 
+ML {* matching_prs @{theory} (term_of pat) (term_of ctrm); *}
+
 ML {*
-@{cterm "((ABS_fset ---> id) ---> id)
-          (\<lambda>P.
-              All ((REP_fset ---> id)
-                    (\<lambda>list.
+  lambda_prs_conv @{context} quot ctrm
+*}
+
+
+ML {* 
+val t = @{thm LAMBDA_PRS[OF FUN_QUOTIENT[OF QUOTIENT_fset IDENTITY_QUOTIENT] IDENTITY_QUOTIENT]}
+val te = @{thm eq_reflection} OF [t]
+val ts = MetaSimplifier.rewrite_rule [@{thm eq_reflection} OF @{thms id_apply}] te
+val tl = Thm.lhs_of ts
+ *}
+
+ML {* val inst = matching_prs @{theory} (term_of tl) (term_of ctrm); *}
+
+ML {* val trm = @{cterm "(((ABS_fset ---> id) ---> id) (\<lambda>(P\<Colon>('a list \<Rightarrow> bool)).
+              All ((REP_fset ---> id) (\<lambda>(list\<Colon>('a list)).
                         (ABS_fset ---> id) ((REP_fset ---> id) P) (REP_fset (ABS_fset [])) \<longrightarrow>
-                        (\<forall>a. All ((REP_fset ---> id)
-                                      (\<lambda>list.
-                                          (ABS_fset ---> id) ((REP_fset ---> id) P) (REP_fset (ABS_fset list)) \<longrightarrow>
-                                          (ABS_fset ---> id) ((REP_fset ---> id) P)
-                                           (REP_fset (ABS_fset (a # REP_fset (ABS_fset list))))))) \<longrightarrow>
-                        (ABS_fset ---> id) ((REP_fset ---> id) P) (REP_fset (ABS_fset list)))))"}
+               True \<longrightarrow> (ABS_fset ---> id) ((REP_fset ---> id) P) (REP_fset (ABS_fset list))))))"} *}
+
+ML {*
+  lambda_prs_conv @{context} quot trm
+*}
 
-*}
-*)
+
+
+(*ML {* val trm = @{cterm "(((ABS_fset ---> id) ---> id) (\<lambda>(?P\<Colon>('a list \<Rightarrow> bool)). (g (id P)"} *} *)
+
+
 
 lemma "\<lbrakk>P EMPTY; \<And>a x. P x \<Longrightarrow> P (INSERT a x)\<rbrakk> \<Longrightarrow> P l"
 apply(tactic {* procedure_tac @{thm list.induct} @{context} 1 *})
 apply(tactic {* regularize_tac @{context} rel_eqv rel_refl 1 *})
 apply(tactic {* REPEAT_ALL_NEW (r_mk_comb_tac @{context} rty quot rel_refl trans2 rsp_thms) 1 *})
 apply(tactic {* REPEAT_ALL_NEW (allex_prs_tac @{context} quot) 1 *})
-oops
+apply(tactic {* lambda_prs_tac @{context} quot 1 *})
+
 
-(*
+ML_prf {* Subgoal.focus @{context} 1 (#goal (Isar.goal ())) *}
+
+apply (tactic {* lift_tac_fset @{context} @{thm list.induct} 1 *})
+
+
 thm LAMBDA_PRS
 apply(tactic {* EqSubst.eqsubst_tac @{context} [0] @{thms LAMBDA_PRS} 1 *})
 
@@ -416,18 +437,20 @@
 apply(tactic {* clean_tac @{context} quot defs reps_same 1 *})
 apply (tactic {* lift_tac_fset @{context} @{thm list.induct} 1 *})
 ML {* lift_thm_fset @{context} @{thm list.induct} *}
-ML {* lift_thm_g_fset @{context} @{thm list.induct} @{term "\<lbrakk>P EMPTY; \<And>a x. P x \<Longrightarrow> P (INSERT a x)\<rbrakk> \<Longrightarrow> P l"} *}*)
+ML {* lift_thm_g_fset @{context} @{thm list.induct} @{term "\<lbrakk>P EMPTY; \<And>a x. P x \<Longrightarrow> P (INSERT a x)\<rbrakk> \<Longrightarrow> P l"} *}
+
+
 
 
-lemma "\<forall>f x xa. fmap f (FUNION (x::'b fset) (xa::'b fset)) = FUNION (fmap f x) (fmap f xa)"
+thm map_append
+lemma "fmap f (FUNION (x::'b fset) (xa::'b fset)) = FUNION (fmap f x) (fmap f xa)"
 apply(tactic {* procedure_tac @{thm map_append} @{context} 1 *})
-oops
+apply(tactic {* prepare_tac 1 *})
+thm map_append
+apply (tactic {* lift_tac_fset @{context} @{thm map_append} 1 *})
+done
 
 
-lemma "fmap f (FUNION (x::'b fset) (y::'b fset)) = FUNION (fmap f x) (fmap f y)"
-apply(tactic {* procedure_tac @{thm map_append} @{context} 1 *})
-oops
-
 
 lemma "FUNION (FUNION x xa) xb = FUNION x (FUNION xa xb)"
 apply (tactic {* lift_tac_fset @{context} @{thm append_assoc} 1 *})
@@ -438,7 +461,7 @@
     (if rsp_fold f then if IN a x then FOLD f g z x else f (g a) (FOLD f g z x) else z)"} *}*)
 
 
-
+*)
 ML {* lift_thm_g_fset @{context} @{thm map_append} @{term "fmap f (FUNION (x::'b fset) (xa::'b fset)) = FUNION (fmap f x) (fmap f xa)"} *}
 
 
@@ -448,7 +471,7 @@
 ML {* lift_thm_fset @{context} @{thm map_append} *}
 
 
-
+(*
 apply(tactic {* procedure_tac @{thm m1} @{context} 1 *})
 apply(tactic {* regularize_tac @{context} rel_eqv rel_refl 1 *})
 apply(tactic {* REPEAT_ALL_NEW (r_mk_comb_tac @{context} rty quot rel_refl trans2 rsp_thms) 1 *})
@@ -458,7 +481,7 @@
 ML_prf {* val lower = flat (map (add_lower_defs @{context}) defs) *}
 apply(tactic {* REPEAT_ALL_NEW (EqSubst.eqsubst_tac @{context} [0] lower) 1*})
 apply(tactic {* simp_tac (HOL_ss addsimps [reps_same]) 1 *})
-
+*)
 
 
 




