merged
authorChristian Urban <urbanc@in.tum.de>
Fri, 05 Feb 2010 09:06:49 +0100
changeset 1067 8d4d52f51e0d
parent 1066 96651cddeba9 (current diff)
parent 1065 3664eafcad09 (diff)
child 1069 ffae51f14367
merged
--- a/Quot/quotient_info.ML	Fri Feb 05 09:06:27 2010 +0100
+++ b/Quot/quotient_info.ML	Fri Feb 05 09:06:49 2010 +0100
@@ -23,6 +23,7 @@
   val quotdata_lookup: theory -> string -> quotdata_info     (* raises NotFound *)
   val quotdata_update_thy: string -> quotdata_info -> theory -> theory
   val quotdata_update_gen: string -> quotdata_info -> Context.generic -> Context.generic
+  val quotdata_dest: Proof.context -> quotdata_info list
   val print_quotinfo: Proof.context -> unit
 
   type qconsts_info = {qconst: term, rconst: term, def: thm}
@@ -166,6 +167,9 @@
 fun quotdata_update_thy str qinfo = QuotData.map (Symtab.update (str, qinfo))
 fun quotdata_update_gen str qinfo = Context.mapping (quotdata_update_thy str qinfo) I
 
+fun quotdata_dest lthy =
+  map snd (Symtab.dest (QuotData.get (ProofContext.theory_of lthy)))
+
 fun print_quotinfo ctxt =
 let
   fun prt_quot {qtyp, rtyp, equiv_rel, equiv_thm} = 
--- a/Quot/quotient_term.ML	Fri Feb 05 09:06:27 2010 +0100
+++ b/Quot/quotient_term.ML	Fri Feb 05 09:06:49 2010 +0100
@@ -25,6 +25,8 @@
 
   val inj_repabs_trm: Proof.context -> term * term -> term
   val inj_repabs_trm_chk: Proof.context -> term * term -> term
+
+  val quotient_lift_all: Proof.context -> term -> term
 end;
 
 structure Quotient_Term: QUOTIENT_TERM =
@@ -681,6 +683,48 @@
   inj_repabs_trm ctxt (rtrm, qtrm) 
   |> Syntax.check_term ctxt
 
+(* Finds subterms of a term that are lifted to constants and replaces
+   those as well as occurrences of the equivalence relation and replaces
+   those by equality.
+   Currently types are not checked so because of the dummyTs it may
+   not be complete *)
+fun quotient_lift_all ctxt t =
+let
+  val thy = ProofContext.theory_of ctxt
+  val const_infos = Quotient_Info.qconsts_dest ctxt
+  val rel_infos = Quotient_Info.quotdata_dest ctxt
+  fun treat_const_info t qc_info s =
+    if s <> NONE then s else
+      case try (Pattern.match thy (t, #rconst qc_info)) (Vartab.empty, Vartab.empty) of
+        SOME inst => SOME (Envir.subst_term inst (#qconst qc_info))
+      | NONE => NONE;
+  fun treat_const t = fold (treat_const_info t) const_infos NONE
+  fun treat_rel_info t rel_info s =
+    if s <> NONE then s else
+    if Pattern.matches thy (t, #equiv_rel rel_info) then SOME (Const ("op =", dummyT))
+    else NONE
+  fun treat_rel t = fold (treat_rel_info t) rel_infos NONE
+  fun lift_aux t =
+    case treat_const t of
+      SOME x => x
+    | NONE =>
+      (case treat_rel t of
+        SOME x => x
+      | NONE =>
+        (case t of
+          a $ b => lift_aux a $ lift_aux b
+        | Abs(a, T, s) =>
+            let val (y, s') = Term.dest_abs (a, T, s) in
+            Abs(y, dummyT, abstract_over (Free (y, dummyT), (lift_aux s')))
+            end
+        | Free(n, _) => Free(n, dummyT)
+        | Var(n, _) => Var(n, dummyT)
+        | Bound i => Bound i
+        | Const(s, _) => Const(s, dummyT)))
+in
+  lift_aux t
+end
+
 end; (* structure *)