src/HOL/Tools/BNF/bnf_def.ML
changeset 58659 6c9821c32dd5
parent 58634 9f10d82e8188
child 58660 8d4aebb9e327
equal deleted inserted replaced
58658:9002fe021e2f 58659:6c9821c32dd5
    15   val morph_bnf: morphism -> bnf -> bnf
    15   val morph_bnf: morphism -> bnf -> bnf
    16   val morph_bnf_defs: morphism -> bnf -> bnf
    16   val morph_bnf_defs: morphism -> bnf -> bnf
    17   val transfer_bnf: theory -> bnf -> bnf
    17   val transfer_bnf: theory -> bnf -> bnf
    18   val bnf_of: Proof.context -> string -> bnf option
    18   val bnf_of: Proof.context -> string -> bnf option
    19   val bnf_of_global: theory -> string -> bnf option
    19   val bnf_of_global: theory -> string -> bnf option
    20   val bnf_interpretation: string -> (bnf -> theory -> theory) ->
    20   val bnf_interpretation: string -> (bnf -> local_theory -> local_theory) -> theory -> theory
    21     (bnf -> local_theory -> local_theory) -> theory -> theory
       
    22   val interpret_bnf: (string -> bool) -> bnf -> local_theory -> local_theory
    21   val interpret_bnf: (string -> bool) -> bnf -> local_theory -> local_theory
    23   val register_bnf_raw: string -> bnf -> local_theory -> local_theory
    22   val register_bnf_raw: string -> bnf -> local_theory -> local_theory
    24   val register_bnf: (string -> bool) -> string -> bnf -> local_theory -> local_theory
    23   val register_bnf: (string -> bool) -> string -> bnf -> local_theory -> local_theory
    25 
    24 
    26   val name_of_bnf: bnf -> binding
    25   val name_of_bnf: bnf -> binding
  1512       no_reflexive (bnf_map_def :: bnf_bd_def :: bnf_set_defs @ bnf_wit_defs @ [bnf_rel_def]);
  1511       no_reflexive (bnf_map_def :: bnf_bd_def :: bnf_set_defs @ bnf_wit_defs @ [bnf_rel_def]);
  1513   in
  1512   in
  1514     (key, goals, wit_goalss, after_qed, lthy, one_step_defs)
  1513     (key, goals, wit_goalss, after_qed, lthy, one_step_defs)
  1515   end;
  1514   end;
  1516 
  1515 
  1517 structure BNF_Interpretation = Local_Interpretation
  1516 structure BNF_Plugin = Plugin(type T = bnf);
  1518 (
  1517 
  1519   type T = bnf;
  1518 fun bnf_interpretation name f =
  1520   val eq: T * T -> bool = op = o pairself T_of_bnf;
  1519   BNF_Plugin.interpretation name
  1521 );
  1520     (fn bnf => fn lthy => f (transfer_bnf (Proof_Context.theory_of lthy) bnf) lthy);
  1522 
  1521 
  1523 fun with_transfer_bnf g bnf thy = g (transfer_bnf thy bnf) thy;
  1522 val interpret_bnf = BNF_Plugin.data;
  1524 
       
  1525 fun bnf_interpretation name =
       
  1526   BNF_Interpretation.interpretation name o with_transfer_bnf;
       
  1527 
       
  1528 val interpret_bnf = BNF_Interpretation.data;
       
  1529 
  1523 
  1530 fun register_bnf_raw key bnf =
  1524 fun register_bnf_raw key bnf =
  1531   Local_Theory.declaration {syntax = false, pervasive = true}
  1525   Local_Theory.declaration {syntax = false, pervasive = true}
  1532     (fn phi => Data.map (Symtab.update (key, morph_bnf phi bnf)));
  1526     (fn phi => Data.map (Symtab.update (key, morph_bnf phi bnf)));
  1533 
  1527 
  1555         unfold_thms_tac ctxt one_step_defs THEN tac ctxt) tacs)
  1549         unfold_thms_tac ctxt one_step_defs THEN tac ctxt) tacs)
  1556     |> (fn thms => after_qed mk_wit_thms (map single thms) lthy)
  1550     |> (fn thms => after_qed mk_wit_thms (map single thms) lthy)
  1557   end) o prepare_def const_policy fact_policy internal qualify (K I) (K I) Ds map_b rel_b set_bs
  1551   end) o prepare_def const_policy fact_policy internal qualify (K I) (K I) Ds map_b rel_b set_bs
  1558     raw_csts;
  1552     raw_csts;
  1559 
  1553 
  1560 fun bnf_cmd (raw_csts, plugins) =
  1554 fun bnf_cmd (raw_csts, raw_plugins) =
  1561   (fn (key, goals, (triv_tac_opt, wit_goalss), after_qed, lthy, defs) =>
  1555   (fn (key, goals, (triv_tac_opt, wit_goalss), after_qed, lthy, defs) =>
  1562   let
  1556   let
       
  1557     val plugins = raw_plugins lthy;
  1563     val wit_goals = map Logic.mk_conjunction_balanced wit_goalss;
  1558     val wit_goals = map Logic.mk_conjunction_balanced wit_goalss;
  1564     fun mk_triv_wit_thms tac set_maps =
  1559     fun mk_triv_wit_thms tac set_maps =
  1565       Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced wit_goals)
  1560       Goal.prove_sorry lthy [] [] (Logic.mk_conjunction_balanced wit_goals)
  1566         (fn {context = ctxt, prems = _} => TRYALL Goal.conjunction_tac THEN tac ctxt set_maps)
  1561         (fn {context = ctxt, prems = _} => TRYALL Goal.conjunction_tac THEN tac ctxt set_maps)
  1567         |> Conjunction.elim_balanced (length wit_goals)
  1562         |> Conjunction.elim_balanced (length wit_goals)
  1617        (Parse.reserved "bd" -- @{keyword ":"}) -- Parse.term --
  1612        (Parse.reserved "bd" -- @{keyword ":"}) -- Parse.term --
  1618        Scan.optional ((Parse.reserved "wits" -- @{keyword ":"}) |--
  1613        Scan.optional ((Parse.reserved "wits" -- @{keyword ":"}) |--
  1619          Scan.repeat1 (Scan.unless (Parse.reserved "rel" ||
  1614          Scan.repeat1 (Scan.unless (Parse.reserved "rel" ||
  1620            Parse.reserved "plugins") Parse.term)) [] --
  1615            Parse.reserved "plugins") Parse.term)) [] --
  1621        Scan.option ((Parse.reserved "rel" -- @{keyword ":"}) |-- Parse.term) --
  1616        Scan.option ((Parse.reserved "rel" -- @{keyword ":"}) |-- Parse.term) --
  1622        Scan.optional parse_plugins (K true)
  1617        Scan.optional Plugin_Name.parse_filter (K (K true))
  1623        >> bnf_cmd);
  1618        >> bnf_cmd);
  1624 
  1619 
  1625 val _ = Context.>> (Context.map_theory BNF_Interpretation.init);
       
  1626 
       
  1627 end;
  1620 end;