src/HOL/Tools/Lifting/lifting_setup.ML
changeset 59630 c9aa1c90796f
parent 59621 291934bac95e
child 59936 b8ffc3dc9e24
equal deleted inserted replaced
59629:0d77c51b5040 59630:c9aa1c90796f
   104       
   104       
   105       fun make_inst var ctxt = 
   105       fun make_inst var ctxt = 
   106         let 
   106         let 
   107           val typ = (snd o relation_types o snd o dest_Var) var
   107           val typ = (snd o relation_types o snd o dest_Var) var
   108           val sort = Type.sort_of_atyp typ
   108           val sort = Type.sort_of_atyp typ
   109           val (fresh_var, ctxt) = yield_singleton Variable.invent_types sort ctxt
   109           val (fresh_var, ctxt') = yield_singleton Variable.invent_types sort ctxt
   110           val thy = Proof_Context.theory_of ctxt
       
   111         in
   110         in
   112           ((Thm.global_cterm_of thy var, Thm.global_cterm_of thy (HOLogic.eq_const (TFree fresh_var))), ctxt)
   111           (apply2 (Thm.cterm_of ctxt') (var, HOLogic.eq_const (TFree fresh_var)), ctxt')
   113         end
   112         end
   114       
   113       
   115       val orig_lthy = lthy
   114       val orig_lthy = lthy
   116       val (args_inst, lthy) = fold_map make_inst args lthy
   115       val (args_inst, lthy) = fold_map make_inst args lthy
   117       val pcr_cr_eq = 
   116       val pcr_cr_eq = 
   285     let val (inst, ctxt') = import_inst_exclude exclude ts ctxt
   284     let val (inst, ctxt') = import_inst_exclude exclude ts ctxt
   286     in (map (Term_Subst.instantiate inst) ts, ctxt') end
   285     in (map (Term_Subst.instantiate inst) ts, ctxt') end
   287 in
   286 in
   288   fun reduce_goal not_fix goal tac ctxt =
   287   fun reduce_goal not_fix goal tac ctxt =
   289     let
   288     let
   290       val thy = Proof_Context.theory_of ctxt
   289       val (fixed_goal, ctxt') = yield_singleton (import_terms_exclude not_fix) goal ctxt
   291       val orig_ctxt = ctxt
   290       val init_goal = Goal.init (Thm.cterm_of ctxt' fixed_goal)
   292       val (fixed_goal, ctxt) = yield_singleton (import_terms_exclude not_fix) goal ctxt
       
   293       val init_goal = Goal.init (Thm.global_cterm_of thy fixed_goal)
       
   294     in
   291     in
   295       (singleton (Variable.export ctxt orig_ctxt) o Goal.conclude) (the (SINGLE tac init_goal))
   292       (singleton (Variable.export ctxt' ctxt) o Goal.conclude) (the (SINGLE tac init_goal))
   296     end
   293     end
   297 end
   294 end
   298 
   295 
   299 local 
   296 local 
   300   val OO_rules = @{thms left_total_OO left_unique_OO right_total_OO right_unique_OO bi_total_OO
   297   val OO_rules = @{thms left_total_OO left_unique_OO right_total_OO right_unique_OO bi_total_OO
   302 in
   299 in
   303   fun parametrize_class_constraint ctxt pcr_def constraint =
   300   fun parametrize_class_constraint ctxt pcr_def constraint =
   304     let
   301     let
   305       fun generate_transfer_rule pcr_def constraint goal ctxt =
   302       fun generate_transfer_rule pcr_def constraint goal ctxt =
   306         let
   303         let
   307           val thy = Proof_Context.theory_of ctxt
   304           val (fixed_goal, ctxt') = yield_singleton (Variable.import_terms true) goal ctxt
   308           val orig_ctxt = ctxt
   305           val init_goal = Goal.init (Thm.cterm_of ctxt' fixed_goal)
   309           val (fixed_goal, ctxt) = yield_singleton (Variable.import_terms true) goal ctxt
   306           val rules = Transfer.get_transfer_raw ctxt'
   310           val init_goal = Goal.init (Thm.global_cterm_of thy fixed_goal)
       
   311           val rules = Transfer.get_transfer_raw ctxt
       
   312           val rules = constraint :: OO_rules @ rules
   307           val rules = constraint :: OO_rules @ rules
   313           val tac =
   308           val tac =
   314             K (Local_Defs.unfold_tac ctxt [pcr_def]) THEN' REPEAT_ALL_NEW (resolve_tac ctxt rules)
   309             K (Local_Defs.unfold_tac ctxt' [pcr_def]) THEN' REPEAT_ALL_NEW (resolve_tac ctxt' rules)
   315         in
   310         in
   316           (singleton (Variable.export ctxt orig_ctxt) o Goal.conclude) (the (SINGLE (tac 1) init_goal))
   311           (singleton (Variable.export ctxt' ctxt) o Goal.conclude) (the (SINGLE (tac 1) init_goal))
   317         end
   312         end
   318       
   313       
   319       fun make_goal pcr_def constr =
   314       fun make_goal pcr_def constr =
   320         let 
   315         let 
   321           val pred_name =
   316           val pred_name =
   369 local
   364 local
   370   val id_unfold = (Conv.rewr_conv (mk_meta_eq @{thm id_def}))
   365   val id_unfold = (Conv.rewr_conv (mk_meta_eq @{thm id_def}))
   371 in
   366 in
   372   fun generate_parametric_id lthy rty id_transfer_rule =
   367   fun generate_parametric_id lthy rty id_transfer_rule =
   373     let
   368     let
   374       val orig_lthy = lthy
       
   375       (* it doesn't raise an exception because it would have already raised it in define_pcrel *)
   369       (* it doesn't raise an exception because it would have already raised it in define_pcrel *)
   376       val (quot_thm, _, lthy) = Lifting_Term.prove_param_quot_thm lthy rty
   370       val (quot_thm, _, ctxt') = Lifting_Term.prove_param_quot_thm lthy rty
   377       val parametrized_relator = singleton (Variable.export_terms lthy orig_lthy) (quot_thm_crel quot_thm)
   371       val parametrized_relator =
   378       val lthy = orig_lthy
   372         singleton (Variable.export_terms ctxt' lthy) (quot_thm_crel quot_thm)
   379       val id_transfer = 
   373       val id_transfer = 
   380          @{thm id_transfer}
   374          @{thm id_transfer}
   381         |> Thm.incr_indexes (Term.maxidx_of_term parametrized_relator + 1)
   375         |> Thm.incr_indexes (Term.maxidx_of_term parametrized_relator + 1)
   382         |> Conv.fconv_rule(HOLogic.Trueprop_conv (Conv.arg_conv id_unfold then_conv Conv.arg1_conv id_unfold))
   376         |> Conv.fconv_rule(HOLogic.Trueprop_conv (Conv.arg_conv id_unfold then_conv Conv.arg1_conv id_unfold))
   383       val var = Var (hd (Term.add_vars (Thm.prop_of id_transfer) []))
   377       val var = Var (hd (Term.add_vars (Thm.prop_of id_transfer) []))
   384       val thy = Proof_Context.theory_of lthy
   378       val inst = [(Thm.cterm_of lthy var, Thm.cterm_of lthy parametrized_relator)]
   385       val inst = [(Thm.global_cterm_of thy var, Thm.global_cterm_of thy parametrized_relator)]
       
   386       val id_par_thm = Drule.cterm_instantiate inst id_transfer
   379       val id_par_thm = Drule.cterm_instantiate inst id_transfer
   387     in
   380     in
   388       Lifting_Def.generate_parametric_transfer_rule lthy id_transfer_rule id_par_thm
   381       Lifting_Def.generate_parametric_transfer_rule lthy id_transfer_rule id_par_thm
   389     end
   382     end
   390     handle Lifting_Term.MERGE_TRANSFER_REL msg => 
   383     handle Lifting_Term.MERGE_TRANSFER_REL msg =>