src/Pure/more_thm.ML
changeset 45375 7fe19930dfc9
parent 43780 2cb2310d68b6
child 45382 3a9f84ad31e7
equal deleted inserted replaced
45374:e99fd663c4a3 45375:7fe19930dfc9
    10 sig
    10 sig
    11   include BASIC_THM
    11   include BASIC_THM
    12   structure Ctermtab: TABLE
    12   structure Ctermtab: TABLE
    13   structure Thmtab: TABLE
    13   structure Thmtab: TABLE
    14   val aconvc: cterm * cterm -> bool
    14   val aconvc: cterm * cterm -> bool
    15   type attribute = Context.generic * thm -> Context.generic * thm
    15   type attribute = Context.generic * thm -> Context.generic option * thm option
    16 end;
    16 end;
    17 
    17 
    18 signature THM =
    18 signature THM =
    19 sig
    19 sig
    20   include THM
    20   include THM
    65   val close_derivation: thm -> thm
    65   val close_derivation: thm -> thm
    66   val add_axiom: Proof.context -> binding * term -> theory -> (string * thm) * theory
    66   val add_axiom: Proof.context -> binding * term -> theory -> (string * thm) * theory
    67   val add_axiom_global: binding * term -> theory -> (string * thm) * theory
    67   val add_axiom_global: binding * term -> theory -> (string * thm) * theory
    68   val add_def: Proof.context -> bool -> bool -> binding * term -> theory -> (string * thm) * theory
    68   val add_def: Proof.context -> bool -> bool -> binding * term -> theory -> (string * thm) * theory
    69   val add_def_global: bool -> bool -> binding * term -> theory -> (string * thm) * theory
    69   val add_def_global: bool -> bool -> binding * term -> theory -> (string * thm) * theory
    70   type attribute = Context.generic * thm -> Context.generic * thm
    70   type attribute = Context.generic * thm -> Context.generic option * thm option
    71   type binding = binding * attribute list
    71   type binding = binding * attribute list
    72   val empty_binding: binding
    72   val empty_binding: binding
    73   val rule_attribute: (Context.generic -> thm -> thm) -> attribute
    73   val rule_attribute: (Context.generic -> thm -> thm) -> attribute
    74   val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute
    74   val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute
       
    75   val mixed_attribute: (Context.generic * thm -> Context.generic * thm) -> attribute
       
    76   val apply_attribute: attribute -> Context.generic * thm -> Context.generic * thm
       
    77   val attribute_declaration: attribute -> thm -> Context.generic -> Context.generic
    75   val theory_attributes: attribute list -> theory * thm -> theory * thm
    78   val theory_attributes: attribute list -> theory * thm -> theory * thm
    76   val proof_attributes: attribute list -> Proof.context * thm -> Proof.context * thm
    79   val proof_attributes: attribute list -> Proof.context * thm -> Proof.context * thm
    77   val no_attributes: 'a -> 'a * 'b list
    80   val no_attributes: 'a -> 'a * 'b list
    78   val simple_fact: 'a -> ('a * 'b list) list
    81   val simple_fact: 'a -> ('a * 'b list) list
    79   val tag_rule: Properties.entry -> thm -> thm
    82   val tag_rule: Properties.entry -> thm -> thm
   389 
   392 
   390 
   393 
   391 (** attributes **)
   394 (** attributes **)
   392 
   395 
   393 (*attributes subsume any kind of rules or context modifiers*)
   396 (*attributes subsume any kind of rules or context modifiers*)
   394 type attribute = Context.generic * thm -> Context.generic * thm;
   397 type attribute = Context.generic * thm -> Context.generic option * thm option;
   395 
   398 
   396 type binding = binding * attribute list;
   399 type binding = binding * attribute list;
   397 val empty_binding: binding = (Binding.empty, []);
   400 val empty_binding: binding = (Binding.empty, []);
   398 
   401 
   399 fun rule_attribute f (x, th) = (x, f x th);
   402 fun rule_attribute f (x, th) = (NONE, SOME (f x th));
   400 fun declaration_attribute f (x, th) = (f th x, th);
   403 fun declaration_attribute f (x, th) = (SOME (f th x), NONE);
       
   404 fun mixed_attribute f (x, th) = let val (x', th') = f (x, th) in (SOME x', SOME th') end;
       
   405 
       
   406 fun apply_attribute att (x, th) =
       
   407   let val (x', th') = att (x, th)
       
   408   in (the_default x x', the_default th th') end;
       
   409 
       
   410 fun attribute_declaration att th x = #1 (apply_attribute att (x, th));
   401 
   411 
   402 fun apply_attributes mk dest =
   412 fun apply_attributes mk dest =
   403   let
   413   let
   404     fun app [] = I
   414     fun app [] = I
   405       | app ((f: attribute) :: fs) = fn (x, th) => f (mk x, th) |>> dest |> app fs;
   415       | app (att :: atts) = fn (x, th) => apply_attribute att (mk x, th) |>> dest |> app atts;
   406   in app end;
   416   in app end;
   407 
   417 
   408 val theory_attributes = apply_attributes Context.Theory Context.the_theory;
   418 val theory_attributes = apply_attributes Context.Theory Context.the_theory;
   409 val proof_attributes = apply_attributes Context.Proof Context.the_proof;
   419 val proof_attributes = apply_attributes Context.Proof Context.the_proof;
   410 
   420 
   418 (* add / delete tags *)
   428 (* add / delete tags *)
   419 
   429 
   420 fun tag_rule tg = Thm.map_tags (insert (op =) tg);
   430 fun tag_rule tg = Thm.map_tags (insert (op =) tg);
   421 fun untag_rule s = Thm.map_tags (filter_out (fn (s', _) => s = s'));
   431 fun untag_rule s = Thm.map_tags (filter_out (fn (s', _) => s = s'));
   422 
   432 
   423 fun tag tg x = rule_attribute (K (tag_rule tg)) x;
   433 fun tag tg = rule_attribute (K (tag_rule tg));
   424 fun untag s x = rule_attribute (K (untag_rule s)) x;
   434 fun untag s = rule_attribute (K (untag_rule s));
   425 
   435 
   426 
   436 
   427 (* def_name *)
   437 (* def_name *)
   428 
   438 
   429 fun def_name c = c ^ "_def";
   439 fun def_name c = c ^ "_def";
   454 val corollaryK = "corollary";
   464 val corollaryK = "corollary";
   455 
   465 
   456 fun legacy_get_kind thm = the_default "" (Properties.get (Thm.get_tags thm) Markup.kindN);
   466 fun legacy_get_kind thm = the_default "" (Properties.get (Thm.get_tags thm) Markup.kindN);
   457 
   467 
   458 fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN;
   468 fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN;
   459 fun kind k x = if k = "" then x else rule_attribute (K (kind_rule k)) x;
   469 fun kind k = rule_attribute (K (k <> "" ? kind_rule k));
   460 
   470 
   461 
   471 
   462 open Thm;
   472 open Thm;
   463 
   473 
   464 end;
   474 end;