src/HOL/Tools/BNF/bnf_def.ML
changeset 56346 42533f8f4729
parent 56016 8875cdcfc85b
child 56376 5a93b8f928a2
equal deleted inserted replaced
56345:228e30cb111d 56346:42533f8f4729
    12   type nonemptiness_witness = {I: int list, wit: term, prop: thm list}
    12   type nonemptiness_witness = {I: int list, wit: term, prop: thm list}
    13 
    13 
    14   val morph_bnf: morphism -> bnf -> bnf
    14   val morph_bnf: morphism -> bnf -> bnf
    15   val morph_bnf_defs: morphism -> bnf -> bnf
    15   val morph_bnf_defs: morphism -> bnf -> bnf
    16   val bnf_of: Proof.context -> string -> bnf option
    16   val bnf_of: Proof.context -> string -> bnf option
    17   val register_bnf: string -> (bnf * local_theory) -> (bnf * local_theory)
    17   val bnf_interpretation: (bnf -> theory -> theory) -> theory -> theory
       
    18   val register_bnf: string -> bnf -> local_theory -> local_theory
    18 
    19 
    19   val name_of_bnf: bnf -> binding
    20   val name_of_bnf: bnf -> binding
    20   val T_of_bnf: bnf -> typ
    21   val T_of_bnf: bnf -> typ
    21   val live_of_bnf: bnf -> int
    22   val live_of_bnf: bnf -> int
    22   val lives_of_bnf: bnf -> typ list
    23   val lives_of_bnf: bnf -> typ list
    23   val dead_of_bnf: bnf -> int
    24   val dead_of_bnf: bnf -> int
    24   val deads_of_bnf: bnf -> typ list
    25   val deads_of_bnf: bnf -> typ list
       
    26   val bd_of_bnf: bnf -> term
    25   val nwits_of_bnf: bnf -> int
    27   val nwits_of_bnf: bnf -> int
    26 
    28 
    27   val mapN: string
    29   val mapN: string
    28   val relN: string
    30   val relN: string
    29   val setN: string
    31   val setN: string
  1305       no_reflexive (bnf_map_def :: bnf_bd_def :: bnf_set_defs @ bnf_wit_defs @ [bnf_rel_def]);
  1307       no_reflexive (bnf_map_def :: bnf_bd_def :: bnf_set_defs @ bnf_wit_defs @ [bnf_rel_def]);
  1306   in
  1308   in
  1307     (key, goals, wit_goalss, after_qed, lthy, one_step_defs)
  1309     (key, goals, wit_goalss, after_qed, lthy, one_step_defs)
  1308   end;
  1310   end;
  1309 
  1311 
  1310 fun register_bnf key (bnf, lthy) =
  1312 structure BNF_Interpretation = Interpretation
  1311   (bnf, Local_Theory.declaration {syntax = false, pervasive = true}
  1313 (
  1312     (fn phi => Data.map (Symtab.update (key, morph_bnf phi bnf))) lthy);
  1314   type T = bnf;
       
  1315   val eq: T * T -> bool = op = o pairself T_of_bnf;
       
  1316 );
       
  1317 
       
  1318 val bnf_interpretation = BNF_Interpretation.interpretation;
       
  1319 
       
  1320 fun register_bnf key bnf =
       
  1321   Local_Theory.declaration {syntax = false, pervasive = true}
       
  1322     (fn phi => Data.map (Symtab.update (key, morph_bnf phi bnf)))
       
  1323   #> Local_Theory.background_theory (BNF_Interpretation.data bnf);
  1313 
  1324 
  1314 fun bnf_def const_policy fact_policy internal qualify tacs wit_tac Ds map_b rel_b set_bs =
  1325 fun bnf_def const_policy fact_policy internal qualify tacs wit_tac Ds map_b rel_b set_bs =
  1315   (fn (_, goals, (triv_tac_opt, wit_goalss), after_qed, lthy, one_step_defs) =>
  1326   (fn (_, goals, (triv_tac_opt, wit_goalss), after_qed, lthy, one_step_defs) =>
  1316   let
  1327   let
  1317     fun mk_wits_tac ctxt set_maps =
  1328     fun mk_wits_tac ctxt set_maps =
  1346       (case triv_tac_opt of
  1357       (case triv_tac_opt of
  1347         NONE => (fn _ => [], map (map (rpair [])) wit_goalss)
  1358         NONE => (fn _ => [], map (map (rpair [])) wit_goalss)
  1348       | SOME tac => (mk_triv_wit_thms tac, []));
  1359       | SOME tac => (mk_triv_wit_thms tac, []));
  1349   in
  1360   in
  1350     Proof.unfolding ([[(defs, [])]])
  1361     Proof.unfolding ([[(defs, [])]])
  1351       (Proof.theorem NONE (snd o register_bnf key oo after_qed mk_wit_thms)
  1362       (Proof.theorem NONE (uncurry (register_bnf key) oo after_qed mk_wit_thms)
  1352         (map (single o rpair []) goals @ nontriv_wit_goals) lthy)
  1363         (map (single o rpair []) goals @ nontriv_wit_goals) lthy)
  1353   end) oo prepare_def Do_Inline (user_policy Note_Some) false I Syntax.read_typ Syntax.read_term
  1364   end) oo prepare_def Do_Inline (user_policy Note_Some) false I Syntax.read_typ Syntax.read_term
  1354     NONE Binding.empty Binding.empty [];
  1365     NONE Binding.empty Binding.empty [];
  1355 
  1366 
  1356 fun print_bnfs ctxt =
  1367 fun print_bnfs ctxt =