QuotMain.thy
changeset 453 c22ab554a32d
parent 452 7ba2c16fe0c8
child 455 9cb45d022524
equal deleted inserted replaced
452:7ba2c16fe0c8 453:c22ab554a32d
   134   then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
   134   then show "R (REP a) (REP b) \<equiv> (a = b)" by simp
   135 qed
   135 qed
   136 
   136 
   137 end
   137 end
   138 
   138 
   139 lemma tst: "EQUIV bla"
       
   140 sorry
       
   141 
       
   142 lemma equiv_trans2:
   139 lemma equiv_trans2:
   143   assumes e: "EQUIV R"
   140   assumes e: "EQUIV R"
   144   and     ac: "R a c"
   141   and     ac: "R a c"
   145   and     bd: "R b d"
   142   and     bd: "R b d"
   146   shows "R a b = R c d"
   143   shows "R a b = R c d"
   233   MetaSimplifier.rewrite_rule @{thms id_simps} thm
   230   MetaSimplifier.rewrite_rule @{thms id_simps} thm
   234 *}
   231 *}
   235 
   232 
   236 section {* Debugging infrastructure for testing tactics *}
   233 section {* Debugging infrastructure for testing tactics *}
   237 
   234 
   238 
       
   239 
       
   240 ML {*
   235 ML {*
   241 fun my_print_tac ctxt s i thm =
   236 fun my_print_tac ctxt s i thm =
   242 let
   237 let
   243   val prem_str = nth (prems_of thm) (i - 1)
   238   val prem_str = nth (prems_of thm) (i - 1)
   244                  |> Syntax.string_of_term ctxt
   239                  |> Syntax.string_of_term ctxt
   261 end
   256 end
   262 
   257 
   263 fun NDT ctxt s tac thm = tac thm  
   258 fun NDT ctxt s tac thm = tac thm  
   264 *}
   259 *}
   265 
   260 
       
   261 
   266 section {*  Infrastructure about definitions *}
   262 section {*  Infrastructure about definitions *}
   267 
   263 
   268 (* Does the same as 'subst' in a given theorem *)
   264 (* Does the same as 'subst' in a given theorem *)
   269 ML {*
   265 ML {*
   270 fun eqsubst_thm ctxt thms thm =
   266 fun eqsubst_thm ctxt thms thm =
   343     fun dest_term (a $ b) = (a, b);
   339     fun dest_term (a $ b) = (a, b);
   344     val def_terms = map (snd o Logic.dest_equals o concl_of) defs;
   340     val def_terms = map (snd o Logic.dest_equals o concl_of) defs;
   345   in
   341   in
   346     map (fst o dest_Const o snd o dest_term) def_terms
   342     map (fst o dest_Const o snd o dest_term) def_terms
   347   end
   343   end
       
   344 *}
       
   345 
       
   346 section {* Infrastructure for special quotient identity *}
       
   347 
       
   348 definition
       
   349   "qid TYPE('a) TYPE('b) x \<equiv> x"
       
   350 
       
   351 ML {*
       
   352 fun get_typ1 (Type ("itself", [T])) = T 
       
   353 fun get_typ2 (Const ("TYPE", T)) = get_typ1 T
       
   354 fun get_tys (Const (@{const_name "qid"},_) $ ty1 $ ty2) =
       
   355   (get_typ2 ty1, get_typ2 ty2)
       
   356 
       
   357 fun is_qid (Const (@{const_name "qid"},_) $ _ $ _) = true
       
   358   | is_qid _ = false
       
   359 
       
   360 
       
   361 fun mk_itself ty = Type ("itself", [ty])
       
   362 fun mk_TYPE ty = Const ("TYPE", mk_itself ty)
       
   363 fun mk_qid (rty, qty, trm) = 
       
   364   Const (@{const_name "qid"}, [mk_itself rty, mk_itself qty, dummyT] ---> dummyT) 
       
   365     $ mk_TYPE rty $ mk_TYPE qty $ trm
       
   366 *}
       
   367 
       
   368 ML {*
       
   369 fun insertion_aux rtrm qtrm =
       
   370   case (rtrm, qtrm) of
       
   371     (Abs (x, ty, t), Abs (x', ty', t')) =>
       
   372        let
       
   373          val (y, s) = Term.dest_abs (x, ty, t)
       
   374          val (_, s') = Term.dest_abs (x', ty', t')
       
   375          val yvar = Free (y, ty)
       
   376          val result = Term.lambda_name (y, yvar) (insertion_aux s s')
       
   377        in     
       
   378          if ty = ty'
       
   379          then result
       
   380          else mk_qid (ty, ty', result)
       
   381        end
       
   382   | (t1 $ t2, t1' $ t2') =>
       
   383        let 
       
   384          val rty = fastype_of rtrm
       
   385          val qty = fastype_of qtrm 
       
   386          val subtrm1 = insertion_aux t1 t1' 
       
   387          val subtrm2 = insertion_aux t2 t2'
       
   388        in
       
   389          if rty = qty
       
   390          then subtrm1 $ subtrm2
       
   391          else mk_qid (rty, qty, subtrm1 $ subtrm2)
       
   392        end
       
   393   | (Free (_, ty), Free (_, ty')) =>
       
   394        if ty = ty'
       
   395        then rtrm 
       
   396        else mk_qid (ty, ty', rtrm)
       
   397   | (Const (s, ty), Const (s', ty')) =>
       
   398        if s = s' andalso ty = ty'
       
   399        then rtrm
       
   400        else mk_qid (ty, ty', rtrm) 
       
   401   | (_, _) => raise (LIFT_MATCH "insertion")
   348 *}
   402 *}
   349 
   403 
   350 section {* Regularization *} 
   404 section {* Regularization *} 
   351 
   405 
   352 (*
   406 (*
   468          then Const (@{const_name "op ="}, ty) $ subtrm
   522          then Const (@{const_name "op ="}, ty) $ subtrm
   469          else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm
   523          else mk_resp_arg lthy (domain_type ty, domain_type ty') $ subtrm
   470        end 
   524        end 
   471   | (t1 $ t2, t1' $ t2') =>
   525   | (t1 $ t2, t1' $ t2') =>
   472        (regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2')
   526        (regularize_trm lthy t1 t1') $ (regularize_trm lthy t2 t2')
   473   | (Free (x, ty), Free (x', ty')) =>
   527   | (Free (x, ty), Free (x', ty')) => 
   474        if x = x' 
   528        (* this case cannot arrise as we start with two fully atomized terms *)
   475        then rtrm     (* FIXME: check whether types corresponds *)
   529        raise (LIFT_MATCH "regularize (frees)")
   476        else raise (LIFT_MATCH "regularize (frees)")
       
   477   | (Bound i, Bound i') =>
   530   | (Bound i, Bound i') =>
   478        if i = i' 
   531        if i = i' 
   479        then rtrm 
   532        then rtrm 
   480        else raise (LIFT_MATCH "regularize (bounds)")
   533        else raise (LIFT_MATCH "regularize (bounds)")
   481   | (Const (s, ty), Const (s', ty')) =>
   534   | (Const (s, ty), Const (s', ty')) =>
   732   | (Abs (x, T, t), Abs (x', T', t')) =>
   785   | (Abs (x, T, t), Abs (x', T', t')) =>
   733       let
   786       let
   734         val (y, s) = Term.dest_abs (x, T, t)
   787         val (y, s) = Term.dest_abs (x, T, t)
   735         val (_, s') = Term.dest_abs (x', T', t')
   788         val (_, s') = Term.dest_abs (x', T', t')
   736         val yvar = Free (y, T)
   789         val yvar = Free (y, T)
   737         val result = lambda yvar (inj_repabs_trm lthy (s, s'))
   790         val result = Term.lambda_name (y, yvar) (inj_repabs_trm lthy (s, s'))
   738       in
   791       in
   739         if rty = qty 
   792         if rty = qty 
   740         then result
   793         then result
   741         else mk_repabs lthy (rty, qty) result
   794         else mk_repabs lthy (rty, qty) result
   742       end
   795       end
   788     rtac (Drule.instantiate insts thm) 1
   841     rtac (Drule.instantiate insts thm) 1
   789   end
   842   end
   790   handle _ => no_tac)
   843   handle _ => no_tac)
   791 *}
   844 *}
   792 
   845 
   793 
       
   794 ML {*
   846 ML {*
   795 fun quotient_tac quot_thms =
   847 fun quotient_tac quot_thms =
   796   REPEAT_ALL_NEW (FIRST' 
   848   REPEAT_ALL_NEW (FIRST' 
   797     [rtac @{thm FUN_QUOTIENT},
   849     [rtac @{thm FUN_QUOTIENT},
   798      resolve_tac quot_thms,
   850      resolve_tac quot_thms,