theory Nominal2 imports
Nominal2_Base Nominal2_Abs Nominal2_FCB
keywords "nominal_datatype" :: thy_defn and "nominal_function""nominal_inductive""nominal_termination" :: thy_goal_defn and "avoids""binds" begin
ML_file ‹nominal_dt_data.ML›
ML ‹open Nominal_Dt_Data›
ML_file ‹nominal_dt_rawfuns.ML›
ML ‹open Nominal_Dt_RawFuns›
ML_file ‹nominal_dt_alpha.ML›
ML ‹open Nominal_Dt_Alpha›
ML_file ‹nominal_dt_quot.ML›
ML ‹open Nominal_Dt_Quot›
fun rawify_bclause (BC (mode, bnds, bdys)) = BC (mode, rawify_bnds bnds, bdys)
(map o map o map) rawify_bclause bclauses
›
ML ‹
(* definition of the raw datatype *)
fun define_raw_dts dts cnstr_names cnstr_tys bn_funs bn_eqs bclauses lthy = let
val thy = Local_Theory.exit_global lthy
val thy_name = Context.theory_base_name thy
val dt_names = map (fn ((s, _, _), _) => Binding.name_of s) dts
val dt_full_names = map (Long_Name.qualify thy_name) dt_names
val dt_full_names' = add_raws dt_full_names
val dts_env = dt_full_names ~~ dt_full_names'
val cnstr_full_names = map (Long_Name.qualify thy_name) cnstr_names
val cnstr_full_names' = map (fn (x, y) => Long_Name.qualify thy_name
(Long_Name.qualify (add_raw x) (add_raw y))) cnstr_tys
val cnstrs_env = cnstr_full_names ~~ cnstr_full_names'
val bn_fun_strs = get_bn_fun_strs bn_funs
val bn_fun_strs' = add_raws bn_fun_strs
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs'
val bn_fun_full_env = map (apply2 (Long_Name.qualify thy_name))
(bn_fun_strs ~~ bn_fun_strs')
val raw_dts = rawify_dts dts dts_env
val (raw_bn_funs, raw_bn_eqs) = rawify_bn_funs dts_env cnstrs_env bn_fun_env bn_funs bn_eqs
val raw_bclauses = rawify_bclauses dts_env cnstrs_env bn_fun_full_env bclauses
val (raw_full_dt_names', thy1) =
BNF_LFP_Compat.add_datatype [BNF_LFP_Compat.Kill_Type_Args] raw_dts thy
val lthy1 = Named_Target.theory_init thy1
val dtinfos = map (Old_Datatype_Data.the_info (Proof_Context.theory_of lthy1)) raw_full_dt_names'
val raw_fp_sugars = map (the o BNF_FP_Def_Sugar.fp_sugar_of lthy1) raw_full_dt_names'
val {descr, ...} = hd dtinfos
val raw_ty_args = hd (Old_Datatype_Aux.get_rec_types descr)
|> snd o dest_Type
|> map dest_TFree
val raw_schematic_ty_args = (snd o dest_Type o #T o hd) raw_fp_sugars
val typ_subst = raw_schematic_ty_args ~~ map TFree raw_ty_args
val freezeT = Term.typ_subst_atomic typ_subst
val freeze = Term.subst_atomic_types typ_subst
val raw_tys = map (freezeT o #T) raw_fp_sugars
val raw_cns_info = all_dtyp_constrs_types descr
val raw_all_cns = map (map freeze o #ctrs o #ctr_sugar o #fp_ctr_sugar) raw_fp_sugars
val raw_inject_thms = flat (map #inject dtinfos)
val raw_distinct_thms = flat (map #distinct dtinfos)
val raw_induct_thm = (hd o #common_co_inducts o the o #fp_co_induct_sugar o hd) raw_fp_sugars
val raw_induct_thms = map (the_single o #co_inducts o the o #fp_co_induct_sugar) raw_fp_sugars
val raw_exhaust_thms = map #exhaust dtinfos
val raw_size_trms = map HOLogic.size_const raw_tys
val raw_size_thms = these (Option.map (#2 o #2)
(BNF_LFP_Size.size_of lthy1 (hd raw_full_dt_names')))
val raw_size_eqvt = let
val RawDtInfo {raw_size_trms, raw_size_thms, raw_induct_thms, ...} = raw_dt_info in
raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps)
lthy_tmp
|> map (rewrite_rule lthy_tmp
@{thms permute_nat_def[THEN eq_reflection]})
|> map (fn thm => thm RS @{thm sym}) end
val lthy5 = snd (Local_Theory.note ((Binding.empty, @{attributes [eqvt]}), raw_fv_eqvt) lthy_tmp)
val alpha_eqvt = let
val AlphaResult {alpha_trms, alpha_bn_trms, alpha_raw_induct, alpha_intros, ...} = alpha_result in
Nominal_Eqvt.raw_equivariance lthy5 (alpha_trms @ alpha_bn_trms) alpha_raw_induct alpha_intros end
val alpha_eqvt_norm = map (Nominal_ThmDecls.eqvt_transform lthy5) alpha_eqvt
val _ = trace_msg (K "Proving equivalence of alpha...")
val alpha_refl_thms = raw_prove_refl lthy5 alpha_result raw_induct_thm
val alpha_sym_thms = raw_prove_sym lthy5 alpha_result alpha_eqvt_norm
val alpha_trans_thms =
raw_prove_trans lthy5 alpha_result (raw_distinct_thms @ raw_inject_thms) alpha_eqvt_norm
val (alpha_equivp_thms, alpha_bn_equivp_thms) =
raw_prove_equivp lthy5 alpha_result alpha_refl_thms alpha_sym_thms alpha_trans_thms
val _ = trace_msg (K "Proving alpha implies bn...")
val alpha_bn_imp_thms = raw_prove_bn_imp lthy5 alpha_result
val _ = trace_msg (K "Proving respectfulness...")
val raw_funs_rsp_aux =
raw_fv_bn_rsp_aux lthy5 alpha_result raw_fvs raw_bns raw_fv_bns (raw_bn_defs @ raw_fv_defs)
val raw_funs_rsp = map (Drule.eta_contraction_rule o mk_funs_rsp lthy5) raw_funs_rsp_aux
fun match_const cnst th =
(fst o dest_Const o snd o dest_comb o HOLogic.dest_Trueprop o Thm.prop_of) th =
fst (dest_Const cnst); fun find_matching_rsp cnst =
hd (filter (fn th => match_const cnst th) raw_funs_rsp);
val raw_fv_rsp = map find_matching_rsp raw_fvs;
val raw_bn_rsp = map find_matching_rsp raw_bns;
val raw_fv_bn_rsp = map find_matching_rsp raw_fv_bns;
val raw_constrs_rsp =
raw_constrs_rsp lthy5 alpha_result raw_all_cns (alpha_bn_imp_thms @ raw_funs_rsp_aux)
val alpha_permute_rsp = map (mk_alpha_permute_rsp lthy5) alpha_eqvt
val alpha_bn_rsp =
raw_alpha_bn_rsp alpha_result alpha_bn_equivp_thms alpha_bn_imp_thms
val raw_perm_bn_rsp = raw_perm_bn_rsp lthy5 alpha_result raw_perm_bns raw_perm_bn_simps
val _ = trace_msg (K "Defining the quotient types...")
val qty_descr = map (fn ((bind, vs, mx), _) => (map fst vs, bind, mx)) dts
val (qty_infos, lthy7) = let
val AlphaResult {alpha_trms, alpha_tys, ...} = alpha_result in
define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy5 end
val qtys = map #qtyp qty_infos
val qty_full_names = map (fst o dest_Type) qtys
val qty_names = map Long_Name.base_name qty_full_names
val _ = trace_msg (K "Defining the quotient constants...")
val qconstrs_descrs =
(map2 o map2) (fn (b, _, mx) => fn (t, th) => (Variable.check_name b, t, mx, th))
(get_cnstrs dts) (map (op ~~) (raw_all_cns ~~ raw_constrs_rsp))
(* filters the theorems that are of the form "qfv = supp" *)
val qfv_names = map (fst o dest_Const) qfvs fun is_qfv_thm 🍋‹Trueprop for 🍋‹HOL.eq _ for ‹Const (lhs, _)› _›› =
member (op =) qfv_names lhs
| is_qfv_thm _ = false
val qsupp_constrs = qfv_defs
|> map (simplify (put_simpset HOL_basic_ss lthyC
addsimps (filter (is_qfv_thm o Thm.prop_of) qfv_supp_thms)))
val transform_thm = @{lemma"x = y ==> a ∉ x ⟷ a ∉ y"by simp}
val transform_thms =
[ @{lemma"a ∉ (S ∪ T) ⟷ a ∉ S ∧ a ∉ T"by simp},
@{lemma"a ∉ (S - T) ⟷ a ∉ S ∨ a ∈ T"by simp},
@{lemma"(lhs = (a ∉ {})) ⟷ lhs"by simp},
@{thm fresh_def[symmetric]}]
val _ = trace_msg (K "Proving strong induct lemmas...")
val qstrong_induct_thms = prove_strong_induct lthyC qinduct qstrong_exhaust_thms qsize_simps bclauses
(* noting the theorems *)
(* generating the prefix for the theorem names *)
val thms_name =
the_default (Binding.name (space_implode "_" qty_names)) opt_thms_name fun thms_suffix s = Binding.qualify_name true thms_name s
val case_names_attr = Attrib.internal 🍋 (K (Rule_Cases.case_names cnstr_names))
val infos = mk_infos qty_full_names qeq_iffs' qdistincts qstrong_exhaust_thms qstrong_induct_thms
fun mk_constr_trms ((tname, tvs, _), constrs) = let
val ty = Type (Sign.full_name thy tname, map TFree tvs) in
map (fn (c, tys, mx) => (c, (tys ---> ty), mx)) constrs end
val constr_trms = flat (map mk_constr_trms dts')
(* FIXME: local version *) (* val (_, spec_ctxt') = Proof_Context.add_fixes constr_trms spec_ctxt *)
val thy' = Sign.add_consts constr_trms (Proof_Context.theory_of spec_ctxt) in
(dts', thy') end ›
ML ‹
(* parsing the binding function specifications and *) (* declaring the function constants *) fun prepare_bn_funs bn_fun_strs bn_eq_strs thy = let
val lthy = Named_Target.theory_init thy
val ((bn_funs, bn_eqs), lthy') = Specification.read_multi_specs bn_fun_strs bn_eq_strs lthy
fun prep_bn_fun ((bn, T), mx) = (bn, T, mx)
val bn_funs' = map prep_bn_fun bn_funs
in
(Local_Theory.exit_global lthy')
|> Sign.add_consts bn_funs'
|> pair (bn_funs', bn_eqs) end ›
text‹associates every SOME with the index in the list; drops NONEs› ML\<open> funindexifyxs= let funmapp_[]=[] |mappi(NONE::xs)=mapp(i+1)xs |mappi(SOMEx::xs)=(x,i)::mapp(i+1)xs in mapp0xs end
funprep_bclauseenv(mode,binders,bodies)= let valbinders'=map(prep_binderenv)binders valbodies'=map(prep_bodyenv)bodies in BC(mode,binders',bodies') end
funprep_bclauses(annos,bclause_strs)= let
val env = indexify annos (* for every label, associate the index *) in
map (prep_bclause env) bclause_strs end in
((map o map) prep_bclauses annos_bclauses, thy) end ›
ML\<open> funincludedibcs= let funincl(BC(_,bns,bds))= member(op=)(mapsndbns)iorelsemember(op=)bdsi in existsinclbcs end \<close>
ML\<open> funcompletedt_strsbclauses= let valargs= get_cnstrsdt_strs |>(mapomap)(fn(_,antys,_,_)=>lengthantys)
funcompltnbcs= let funaddbcsi=(ifincludedibcsthen[]else[BC(Lst,[],[i])]) in bcs@(flat(map_range(addbcs)n)) end in (map2omap2)compltargsbclauses end \<close>
ML\<open> funnominal_datatype2_cmd(opt_thms_name,dt_strs,bn_fun_strs,bn_eq_strs)lthy= let
(* this theory is used just for parsing *)
val thy = Proof_Context.theory_of lthy
val bclauses' = complete dt_strs bclauses in
nominal_datatype2 opt_thms_name dts bn_funs bn_eqs bclauses' lthy end ›
ML ‹
(* nominal datatype parser *) local fun triple1 ((x, y), z) = (x, y, z) fun triple2 ((x, y), z) = (y, x, z) fun tuple2 (((x, y), z), u) = (x, y, u, z) fun tuple3 ((x, y), (z, u)) = (x, y, z, u) in
val opt_name = Scan.option (Parse.binding --| Args.colon)
val anno_typ = Scan.option (Parse.name --| @{keyword "::"}) -- Parse.typ
val bind_mode = @{keyword "binds"} |--
Scan.optional (Args.parens
(Args.$$$ "list" >> K Lst || (Args.$$$ "set" -- Args.$$$ "+") >> K Res || Args.$$$ "set" >> K Set)) Lst
(* binding function parser *)
val bnfun_parser =
Scan.optional (@{keyword "binder"} |-- Parse_Spec.specification) ([], [])
(* main parser *)
val main_parser =
opt_name -- Parse.and_list1 dt_parser -- bnfun_parser >> tuple3
end
(* Command Keyword *)
val _ = Outer_Syntax.local_theory @{command_keyword nominal_datatype} "declaration of nominal datatypes"
(main_parser >> nominal_datatype2_cmd) ›
end
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.10Bemerkung:
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.