Nominal/Fv.thy
changeset 1376 56efa1e854bf
parent 1375 aa787c9b6955
child 1377 34317cb033f2
equal deleted inserted replaced
1375:aa787c9b6955 1376:56efa1e854bf
   191 in
   191 in
   192   ((bn, fvbn), (fvbn_name, eqs))
   192   ((bn, fvbn), (fvbn_name, eqs))
   193 end
   193 end
   194 *}
   194 *}
   195 
   195 
       
   196 ML {* fn x => split_list(flat x) *}
       
   197 ML {* fn x => apsnd flat (split_list (map split_list x)) *}
   196 (* TODO: Notice datatypes without bindings and replace alpha with equality *)
   198 (* TODO: Notice datatypes without bindings and replace alpha with equality *)
   197 ML {*
   199 ML {*
   198 fun define_fv_alpha (dt_info : Datatype_Aux.info) bindsall bns lthy =
   200 fun define_fv_alpha (dt_info : Datatype_Aux.info) bindsall bns lthy =
   199 let
   201 let
   200   val thy = ProofContext.theory_of lthy;
   202   val thy = ProofContext.theory_of lthy;
   300       val alpha_eq = Logic.mk_implies (HOLogic.mk_Trueprop alpha_lhss_ex, alpha_rhs)
   302       val alpha_eq = Logic.mk_implies (HOLogic.mk_Trueprop alpha_lhss_ex, alpha_rhs)
   301     in
   303     in
   302       (fv_eq, alpha_eq)
   304       (fv_eq, alpha_eq)
   303     end;
   305     end;
   304   fun fv_alpha_eq (i, (_, _, constrs)) binds = map2i (fv_alpha_constr i) constrs binds;
   306   fun fv_alpha_eq (i, (_, _, constrs)) binds = map2i (fv_alpha_constr i) constrs binds;
   305   val (fv_eqs, alpha_eqs) = split_list (flat (map2i fv_alpha_eq descr (gather_binds bindsall)))
   307   val fveqs_alphaeqs = map2i fv_alpha_eq descr (gather_binds bindsall)
   306   val fv_eqs_all = fv_eqs @ (flat fv_bn_eqs);
   308   val (fv_eqs_perfv, alpha_eqs) = apsnd flat (split_list (map split_list fveqs_alphaeqs))
   307   val fv_names_all = fv_names @ fv_bn_names;
   309   val rel_bns_nos = map (fn (_, i, _) => i) rel_bns;
       
   310   fun filter_fun (a, b) = b mem rel_bns_nos;
       
   311   val all_fvs = (fv_names ~~ fv_eqs_perfv) ~~ (0 upto (length fv_names - 1))
       
   312   val (fv_names_fst, fv_eqs_fst) = apsnd flat (split_list (map fst (filter_out filter_fun all_fvs)))
       
   313   val (fv_names_snd, fv_eqs_snd) = apsnd flat (split_list (map fst (filter filter_fun all_fvs)))
       
   314   val fv_eqs_all = fv_eqs_fst @ (flat fv_bn_eqs);
       
   315   val fv_names_all = fv_names_fst @ fv_bn_names;
   308   val add_binds = map (fn x => (Attrib.empty_binding, x))
   316   val add_binds = map (fn x => (Attrib.empty_binding, x))
   309 (* Function_Fun.add_fun Function_Common.default_config ... true *)
   317 (* Function_Fun.add_fun Function_Common.default_config ... true *)
       
   318   val _ = map tracing (map (Syntax.string_of_term @{context}) fv_eqs_all)
   310   val (fvs, lthy') = (Primrec.add_primrec
   319   val (fvs, lthy') = (Primrec.add_primrec
   311     (map (fn s => (Binding.name s, NONE, NoSyn)) fv_names_all) (add_binds fv_eqs_all) lthy)
   320     (map (fn s => (Binding.name s, NONE, NoSyn)) fv_names_all) (add_binds fv_eqs_all) lthy)
   312   val (alphas, lthy'') = (Inductive.add_inductive_i
   321   val (fvs2, lthy'') =
       
   322     if fv_eqs_snd = [] then (([], []), lthy') else
       
   323    (Primrec.add_primrec
       
   324     (map (fn s => (Binding.name s, NONE, NoSyn)) fv_names_snd) (add_binds fv_eqs_snd) lthy')
       
   325   val (alphas, lthy''') = (Inductive.add_inductive_i
   313      {quiet_mode = true, verbose = false, alt_name = Binding.empty,
   326      {quiet_mode = true, verbose = false, alt_name = Binding.empty,
   314       coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
   327       coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
   315      (map2 (fn x => fn y => ((Binding.name x, y), NoSyn)) alpha_names alpha_types) []
   328      (map2 (fn x => fn y => ((Binding.name x, y), NoSyn)) alpha_names alpha_types) []
   316      (add_binds alpha_eqs) [] lthy')
   329      (add_binds alpha_eqs) [] lthy'')
   317 in
   330 in
   318   ((fvs, alphas), lthy'')
   331   ((fvs, alphas), lthy'')
   319 end
   332 end
   320 *}
   333 *}
   321 
   334 
   337 setup {* snd o define_raw_perms (Datatype.the_info @{theory} "Fv.lam") 2 *}
   350 setup {* snd o define_raw_perms (Datatype.the_info @{theory} "Fv.lam") 2 *}
   338 
   351 
   339 
   352 
   340 local_setup {*
   353 local_setup {*
   341   snd o define_fv_alpha (Datatype.the_info @{theory} "Fv.lam")
   354   snd o define_fv_alpha (Datatype.the_info @{theory} "Fv.lam")
   342   [[[], [], [(SOME (@{term bi}, true), 0, 1)]], [[]]] [(@{term bi}, 1, [0])] *}
   355   [[[], [], [(SOME (@{term bi}, false), 0, 1)]], [[]]] [(@{term bi}, 1, [0])] *}
   343 print_theorems
   356 print_theorems
   344 *)
   357 *)
   345 
   358 
   346 (*
   359 (*
   347 datatype rtrm1 =
   360 datatype rtrm1 =