src/Pure/more_thm.ML
author wenzelm
Thu Jul 09 22:01:41 2009 +0200 (2009-07-09)
changeset 31971 8c1b845ed105
parent 31947 7daee3bed3af
child 31977 e03059ae2d82
permissions -rw-r--r--
renamed functor TableFun to Table, and GraphFun to Graph;
wenzelm@22362
     1
(*  Title:      Pure/more_thm.ML
wenzelm@22362
     2
    Author:     Makarius
wenzelm@22362
     3
wenzelm@22907
     4
Further operations on type ctyp/cterm/thm, outside the inference kernel.
wenzelm@22362
     5
*)
wenzelm@22362
     6
wenzelm@23169
     7
infix aconvc;
wenzelm@23169
     8
wenzelm@22362
     9
signature THM =
wenzelm@22362
    10
sig
wenzelm@22362
    11
  include THM
wenzelm@24948
    12
  val aconvc: cterm * cterm -> bool
wenzelm@23491
    13
  val add_cterm_frees: cterm -> cterm list -> cterm list
wenzelm@22907
    14
  val mk_binop: cterm -> cterm -> cterm -> cterm
wenzelm@22907
    15
  val dest_binop: cterm -> cterm * cterm
wenzelm@22907
    16
  val dest_implies: cterm -> cterm * cterm
wenzelm@22907
    17
  val dest_equals: cterm -> cterm * cterm
wenzelm@22907
    18
  val dest_equals_lhs: cterm -> cterm
wenzelm@22907
    19
  val dest_equals_rhs: cterm -> cterm
wenzelm@22907
    20
  val lhs_of: thm -> cterm
wenzelm@22907
    21
  val rhs_of: thm -> cterm
wenzelm@22362
    22
  val thm_ord: thm * thm -> order
wenzelm@23599
    23
  val is_reflexive: thm -> bool
wenzelm@22362
    24
  val eq_thm: thm * thm -> bool
wenzelm@22362
    25
  val eq_thms: thm list * thm list -> bool
wenzelm@22362
    26
  val eq_thm_thy: thm * thm -> bool
wenzelm@22362
    27
  val eq_thm_prop: thm * thm -> bool
wenzelm@22362
    28
  val equiv_thm: thm * thm -> bool
wenzelm@31944
    29
  val class_triv: theory -> class -> thm
wenzelm@31944
    30
  val of_sort: ctyp * sort -> thm list
wenzelm@28621
    31
  val check_shyps: sort list -> thm -> thm
wenzelm@24048
    32
  val is_dummy: thm -> bool
wenzelm@22695
    33
  val plain_prop_of: thm -> term
wenzelm@24048
    34
  val add_thm: thm -> thm list -> thm list
wenzelm@24048
    35
  val del_thm: thm -> thm list -> thm list
wenzelm@24048
    36
  val merge_thms: thm list * thm list -> thm list
wenzelm@30560
    37
  val intro_rules: thm Item_Net.T
wenzelm@30560
    38
  val elim_rules: thm Item_Net.T
wenzelm@27866
    39
  val elim_implies: thm -> thm -> thm
wenzelm@27866
    40
  val forall_elim_var: int -> thm -> thm
wenzelm@27866
    41
  val forall_elim_vars: int -> thm -> thm
wenzelm@27866
    42
  val unvarify: thm -> thm
wenzelm@27866
    43
  val close_derivation: thm -> thm
haftmann@29579
    44
  val add_axiom: binding * term -> theory -> thm * theory
haftmann@29579
    45
  val add_def: bool -> bool -> binding * term -> theory -> thm * theory
wenzelm@30210
    46
  type binding = binding * attribute list
wenzelm@30210
    47
  val empty_binding: binding
wenzelm@27866
    48
  val rule_attribute: (Context.generic -> thm -> thm) -> attribute
wenzelm@27866
    49
  val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute
wenzelm@27866
    50
  val theory_attributes: attribute list -> theory * thm -> theory * thm
wenzelm@27866
    51
  val proof_attributes: attribute list -> Proof.context * thm -> Proof.context * thm
wenzelm@27866
    52
  val no_attributes: 'a -> 'a * 'b list
wenzelm@27866
    53
  val simple_fact: 'a -> ('a * 'b list) list
wenzelm@28017
    54
  val tag_rule: Properties.property -> thm -> thm
wenzelm@27866
    55
  val untag_rule: string -> thm -> thm
wenzelm@28017
    56
  val tag: Properties.property -> attribute
wenzelm@27866
    57
  val untag: string -> attribute
wenzelm@27866
    58
  val position_of: thm -> Position.T
wenzelm@27866
    59
  val default_position: Position.T -> thm -> thm
wenzelm@27866
    60
  val default_position_of: thm -> thm -> thm
wenzelm@30342
    61
  val def_name: string -> string
wenzelm@30342
    62
  val def_name_optional: string -> string -> string
wenzelm@30433
    63
  val def_binding_optional: Binding.binding -> Binding.binding -> Binding.binding
wenzelm@27866
    64
  val has_name_hint: thm -> bool
wenzelm@27866
    65
  val get_name_hint: thm -> string
wenzelm@27866
    66
  val put_name_hint: string -> thm -> thm
wenzelm@27866
    67
  val get_group: thm -> string option
wenzelm@27866
    68
  val put_group: string -> thm -> thm
wenzelm@27866
    69
  val group: string -> attribute
wenzelm@22362
    70
  val axiomK: string
wenzelm@22362
    71
  val assumptionK: string
wenzelm@22362
    72
  val definitionK: string
wenzelm@22362
    73
  val theoremK: string
haftmann@31177
    74
  val generatedK : string
wenzelm@22362
    75
  val lemmaK: string
wenzelm@22362
    76
  val corollaryK: string
wenzelm@22362
    77
  val internalK: string
wenzelm@27866
    78
  val has_kind: thm -> bool
wenzelm@27866
    79
  val get_kind: thm -> string
wenzelm@27866
    80
  val kind_rule: string -> thm -> thm
wenzelm@27866
    81
  val kind: string -> attribute
wenzelm@27866
    82
  val kind_internal: attribute
wenzelm@28017
    83
  val has_internal: Properties.property list -> bool
wenzelm@27866
    84
  val is_internal: thm -> bool
wenzelm@22362
    85
end;
wenzelm@22362
    86
wenzelm@22362
    87
structure Thm: THM =
wenzelm@22362
    88
struct
wenzelm@22362
    89
wenzelm@22695
    90
(** basic operations **)
wenzelm@22362
    91
wenzelm@23491
    92
(* collecting cterms *)
wenzelm@23491
    93
wenzelm@23491
    94
val op aconvc = op aconv o pairself Thm.term_of;
wenzelm@23491
    95
wenzelm@23491
    96
fun add_cterm_frees ct =
wenzelm@23491
    97
  let
wenzelm@23491
    98
    val cert = Thm.cterm_of (Thm.theory_of_cterm ct);
wenzelm@23491
    99
    val t = Thm.term_of ct;
wenzelm@23491
   100
  in Term.fold_aterms (fn v as Free _ => insert (op aconvc) (cert v) | _ => I) t end;
wenzelm@23491
   101
wenzelm@23491
   102
wenzelm@22907
   103
(* cterm constructors and destructors *)
wenzelm@22907
   104
wenzelm@22907
   105
fun mk_binop c a b = Thm.capply (Thm.capply c a) b;
wenzelm@22907
   106
fun dest_binop ct = (Thm.dest_arg1 ct, Thm.dest_arg ct);
wenzelm@22907
   107
wenzelm@22907
   108
fun dest_implies ct =
wenzelm@22907
   109
  (case Thm.term_of ct of
wenzelm@22907
   110
    Const ("==>", _) $ _ $ _ => dest_binop ct
wenzelm@22907
   111
  | _ => raise TERM ("dest_implies", [Thm.term_of ct]));
wenzelm@22907
   112
wenzelm@22907
   113
fun dest_equals ct =
wenzelm@22907
   114
  (case Thm.term_of ct of
wenzelm@22907
   115
    Const ("==", _) $ _ $ _ => dest_binop ct
wenzelm@22907
   116
  | _ => raise TERM ("dest_equals", [Thm.term_of ct]));
wenzelm@22907
   117
wenzelm@22907
   118
fun dest_equals_lhs ct =
wenzelm@22907
   119
  (case Thm.term_of ct of
wenzelm@22907
   120
    Const ("==", _) $ _ $ _ => Thm.dest_arg1 ct
wenzelm@22907
   121
  | _ => raise TERM ("dest_equals_lhs", [Thm.term_of ct]));
wenzelm@22907
   122
wenzelm@22907
   123
fun dest_equals_rhs ct =
wenzelm@22907
   124
  (case Thm.term_of ct of
wenzelm@22907
   125
    Const ("==", _) $ _ $ _ => Thm.dest_arg ct
wenzelm@22907
   126
  | _ => raise TERM ("dest_equals_rhs", [Thm.term_of ct]));
wenzelm@22907
   127
wenzelm@22907
   128
val lhs_of = dest_equals_lhs o Thm.cprop_of;
wenzelm@22907
   129
val rhs_of = dest_equals_rhs o Thm.cprop_of;
wenzelm@22907
   130
wenzelm@22907
   131
wenzelm@22907
   132
(* thm order: ignores theory context! *)
wenzelm@22682
   133
wenzelm@22362
   134
fun thm_ord (th1, th2) =
wenzelm@22362
   135
  let
wenzelm@22362
   136
    val {shyps = shyps1, hyps = hyps1, tpairs = tpairs1, prop = prop1, ...} = Thm.rep_thm th1;
wenzelm@22362
   137
    val {shyps = shyps2, hyps = hyps2, tpairs = tpairs2, prop = prop2, ...} = Thm.rep_thm th2;
wenzelm@22362
   138
  in
wenzelm@29269
   139
    (case TermOrd.fast_term_ord (prop1, prop2) of
wenzelm@22362
   140
      EQUAL =>
wenzelm@29269
   141
        (case list_ord (prod_ord TermOrd.fast_term_ord TermOrd.fast_term_ord) (tpairs1, tpairs2) of
wenzelm@22362
   142
          EQUAL =>
wenzelm@29269
   143
            (case list_ord TermOrd.fast_term_ord (hyps1, hyps2) of
wenzelm@29269
   144
              EQUAL => list_ord TermOrd.sort_ord (shyps1, shyps2)
wenzelm@22362
   145
            | ord => ord)
wenzelm@22362
   146
        | ord => ord)
wenzelm@22362
   147
    | ord => ord)
wenzelm@22362
   148
  end;
wenzelm@22362
   149
wenzelm@22682
   150
wenzelm@22682
   151
(* equality *)
wenzelm@22682
   152
wenzelm@23599
   153
fun is_reflexive th = op aconv (Logic.dest_equals (Thm.prop_of th))
wenzelm@23599
   154
  handle TERM _ => false;
wenzelm@23599
   155
wenzelm@22362
   156
fun eq_thm ths =
wenzelm@22362
   157
  Context.joinable (pairself Thm.theory_of_thm ths) andalso
wenzelm@26653
   158
  is_equal (thm_ord ths);
wenzelm@22362
   159
wenzelm@22362
   160
val eq_thms = eq_list eq_thm;
wenzelm@22362
   161
wenzelm@26665
   162
val eq_thm_thy = Theory.eq_thy o pairself Thm.theory_of_thm;
wenzelm@22362
   163
val eq_thm_prop = op aconv o pairself Thm.full_prop_of;
wenzelm@22362
   164
wenzelm@22682
   165
wenzelm@22682
   166
(* pattern equivalence *)
wenzelm@22682
   167
wenzelm@22362
   168
fun equiv_thm ths =
wenzelm@22362
   169
  Pattern.equiv (Theory.merge (pairself Thm.theory_of_thm ths)) (pairself Thm.full_prop_of ths);
wenzelm@22362
   170
wenzelm@22362
   171
wenzelm@31904
   172
(* type classes and sorts *)
wenzelm@31904
   173
wenzelm@31944
   174
fun class_triv thy c =
wenzelm@31944
   175
  Thm.of_class (Thm.ctyp_of thy (TVar ((Name.aT, 0), [c])), c);
wenzelm@31944
   176
wenzelm@31944
   177
fun of_sort (T, S) = map (fn c => Thm.of_class (T, c)) S;
wenzelm@28621
   178
wenzelm@28621
   179
fun check_shyps sorts raw_th =
wenzelm@28621
   180
  let
wenzelm@28621
   181
    val th = Thm.strip_shyps raw_th;
wenzelm@28621
   182
    val prt_sort = Syntax.pretty_sort_global (Thm.theory_of_thm th);
wenzelm@28621
   183
    val pending = Sorts.subtract sorts (Thm.extra_shyps th);
wenzelm@28621
   184
  in
wenzelm@28621
   185
    if null pending then th
wenzelm@28621
   186
    else error (Pretty.string_of (Pretty.block (Pretty.str "Pending sort hypotheses:" ::
wenzelm@28621
   187
      Pretty.brk 1 :: Pretty.commas (map prt_sort pending))))
wenzelm@28621
   188
  end;
wenzelm@28621
   189
wenzelm@28621
   190
wenzelm@22695
   191
(* misc operations *)
wenzelm@22695
   192
wenzelm@24048
   193
fun is_dummy thm =
wenzelm@24048
   194
  (case try Logic.dest_term (Thm.concl_of thm) of
wenzelm@24048
   195
    NONE => false
wenzelm@24048
   196
  | SOME t => Term.is_dummy_pattern t);
wenzelm@24048
   197
wenzelm@22695
   198
fun plain_prop_of raw_thm =
wenzelm@22695
   199
  let
wenzelm@22695
   200
    val thm = Thm.strip_shyps raw_thm;
wenzelm@22695
   201
    fun err msg = raise THM ("plain_prop_of: " ^ msg, 0, [thm]);
wenzelm@22695
   202
    val {hyps, prop, tpairs, ...} = Thm.rep_thm thm;
wenzelm@22695
   203
  in
wenzelm@22695
   204
    if not (null hyps) then
wenzelm@22695
   205
      err "theorem may not contain hypotheses"
wenzelm@22695
   206
    else if not (null (Thm.extra_shyps thm)) then
wenzelm@22695
   207
      err "theorem may not contain sort hypotheses"
wenzelm@22695
   208
    else if not (null tpairs) then
wenzelm@22695
   209
      err "theorem may not contain flex-flex pairs"
wenzelm@22695
   210
    else prop
wenzelm@22695
   211
  end;
wenzelm@22695
   212
wenzelm@22695
   213
wenzelm@30564
   214
(* collections of theorems in canonical order *)
wenzelm@24048
   215
wenzelm@24048
   216
val add_thm = update eq_thm_prop;
wenzelm@24048
   217
val del_thm = remove eq_thm_prop;
wenzelm@24048
   218
val merge_thms = merge eq_thm_prop;
wenzelm@24048
   219
wenzelm@30560
   220
val intro_rules = Item_Net.init eq_thm_prop Thm.concl_of;
wenzelm@30560
   221
val elim_rules = Item_Net.init eq_thm_prop Thm.major_prem_of;
wenzelm@30560
   222
wenzelm@30560
   223
wenzelm@22682
   224
wenzelm@24980
   225
(** basic derived rules **)
wenzelm@24980
   226
wenzelm@24980
   227
(*Elimination of implication
wenzelm@24980
   228
  A    A ==> B
wenzelm@24980
   229
  ------------
wenzelm@24980
   230
        B
wenzelm@24980
   231
*)
wenzelm@24980
   232
fun elim_implies thA thAB = Thm.implies_elim thAB thA;
wenzelm@24980
   233
wenzelm@26653
   234
wenzelm@26653
   235
(* forall_elim_var(s) *)
wenzelm@26653
   236
wenzelm@26653
   237
local
wenzelm@26653
   238
wenzelm@26653
   239
fun forall_elim_vars_aux strip_vars i th =
wenzelm@26653
   240
  let
wenzelm@26653
   241
    val thy = Thm.theory_of_thm th;
wenzelm@26653
   242
    val {tpairs, prop, ...} = Thm.rep_thm th;
wenzelm@26653
   243
    val add_used = Term.fold_aterms
wenzelm@26653
   244
      (fn Var ((x, j), _) => if i = j then insert (op =) x else I | _ => I);
wenzelm@26653
   245
    val used = fold (fn (t, u) => add_used t o add_used u) tpairs (add_used prop []);
wenzelm@26653
   246
    val vars = strip_vars prop;
wenzelm@26653
   247
    val cvars = (Name.variant_list used (map #1 vars), vars)
wenzelm@26653
   248
      |> ListPair.map (fn (x, (_, T)) => Thm.cterm_of thy (Var ((x, i), T)));
wenzelm@26653
   249
  in fold Thm.forall_elim cvars th end;
wenzelm@26653
   250
wenzelm@26653
   251
in
wenzelm@26653
   252
wenzelm@26653
   253
val forall_elim_vars = forall_elim_vars_aux Term.strip_all_vars;
wenzelm@26653
   254
wenzelm@26653
   255
fun forall_elim_var i th = forall_elim_vars_aux
wenzelm@26653
   256
  (fn Const ("all", _) $ Abs (a, T, _) => [(a, T)]
wenzelm@26653
   257
  | _ => raise THM ("forall_elim_vars", i, [th])) i th;
wenzelm@26653
   258
wenzelm@26653
   259
end;
wenzelm@26653
   260
wenzelm@26653
   261
wenzelm@26653
   262
(* unvarify: global schematic variables *)
wenzelm@26653
   263
wenzelm@24980
   264
fun unvarify th =
wenzelm@24980
   265
  let
wenzelm@24980
   266
    val thy = Thm.theory_of_thm th;
wenzelm@24980
   267
    val cert = Thm.cterm_of thy;
wenzelm@24980
   268
    val certT = Thm.ctyp_of thy;
wenzelm@24980
   269
wenzelm@24980
   270
    val prop = Thm.full_prop_of th;
wenzelm@24980
   271
    val _ = map Logic.unvarify (prop :: Thm.hyps_of th)
wenzelm@24980
   272
      handle TERM (msg, _) => raise THM (msg, 0, [th]);
wenzelm@24980
   273
wenzelm@24980
   274
    val instT0 = rev (Term.add_tvars prop []) |> map (fn v as ((a, _), S) => (v, TFree (a, S)));
wenzelm@24980
   275
    val instT = map (fn (v, T) => (certT (TVar v), certT T)) instT0;
wenzelm@24980
   276
    val inst = rev (Term.add_vars prop []) |> map (fn ((a, i), T) =>
wenzelm@24980
   277
      let val T' = TermSubst.instantiateT instT0 T
wenzelm@24980
   278
      in (cert (Var ((a, i), T')), cert (Free ((a, T')))) end);
wenzelm@24980
   279
  in Thm.instantiate (instT, inst) th end;
wenzelm@24980
   280
wenzelm@26653
   281
wenzelm@26653
   282
(* close_derivation *)
wenzelm@26653
   283
wenzelm@26628
   284
fun close_derivation thm =
wenzelm@26628
   285
  if Thm.get_name thm = "" then Thm.put_name "" thm
wenzelm@26628
   286
  else thm;
wenzelm@26628
   287
wenzelm@24980
   288
wenzelm@24980
   289
wenzelm@24980
   290
(** specification primitives **)
wenzelm@24980
   291
wenzelm@30342
   292
(* rules *)
wenzelm@30342
   293
haftmann@29579
   294
fun add_axiom (b, prop) thy =
wenzelm@24980
   295
  let
haftmann@29579
   296
    val b' = if Binding.is_empty b
haftmann@29579
   297
      then Binding.name ("axiom_" ^ serial_string ()) else b;
haftmann@29579
   298
    val thy' = thy |> Theory.add_axioms_i [(b', prop)];
haftmann@29579
   299
    val axm = unvarify (Thm.axiom thy' (Sign.full_name thy' b'));
wenzelm@28116
   300
  in (axm, thy') end;
wenzelm@24980
   301
haftmann@29579
   302
fun add_def unchecked overloaded (b, prop) thy =
wenzelm@24980
   303
  let
wenzelm@24980
   304
    val tfrees = rev (map TFree (Term.add_tfrees prop []));
wenzelm@24980
   305
    val tfrees' = map (fn a => TFree (a, [])) (Name.invents Name.context Name.aT (length tfrees));
wenzelm@24980
   306
    val strip_sorts = tfrees ~~ tfrees';
wenzelm@24980
   307
    val recover_sorts = map (pairself (Thm.ctyp_of thy o Logic.varifyT)) (tfrees' ~~ tfrees);
wenzelm@24980
   308
wenzelm@24980
   309
    val prop' = Term.map_types (Term.map_atyps (perhaps (AList.lookup (op =) strip_sorts))) prop;
haftmann@29579
   310
    val thy' = Theory.add_defs_i unchecked overloaded [(b, prop')] thy;
haftmann@29579
   311
    val axm' = Thm.axiom thy' (Sign.full_name thy' b);
wenzelm@24980
   312
    val thm = unvarify (Thm.instantiate (recover_sorts, []) axm');
wenzelm@24980
   313
  in (thm, thy') end;
wenzelm@24980
   314
wenzelm@27866
   315
wenzelm@27866
   316
wenzelm@27866
   317
(** attributes **)
wenzelm@27866
   318
wenzelm@30210
   319
type binding = binding * attribute list;
wenzelm@30210
   320
val empty_binding: binding = (Binding.empty, []);
wenzelm@30210
   321
wenzelm@27866
   322
fun rule_attribute f (x, th) = (x, f x th);
wenzelm@27866
   323
fun declaration_attribute f (x, th) = (f th x, th);
wenzelm@27866
   324
wenzelm@27866
   325
fun apply_attributes mk dest =
wenzelm@27866
   326
  let
wenzelm@27866
   327
    fun app [] = I
wenzelm@27866
   328
      | app ((f: attribute) :: fs) = fn (x, th) => f (mk x, th) |>> dest |> app fs;
wenzelm@27866
   329
  in app end;
wenzelm@27866
   330
wenzelm@27866
   331
val theory_attributes = apply_attributes Context.Theory Context.the_theory;
wenzelm@27866
   332
val proof_attributes = apply_attributes Context.Proof Context.the_proof;
wenzelm@27866
   333
wenzelm@27866
   334
fun no_attributes x = (x, []);
wenzelm@27866
   335
fun simple_fact x = [(x, [])];
wenzelm@27866
   336
wenzelm@27866
   337
wenzelm@27866
   338
wenzelm@27866
   339
(*** theorem tags ***)
wenzelm@27866
   340
wenzelm@27866
   341
(* add / delete tags *)
wenzelm@27866
   342
wenzelm@27866
   343
fun tag_rule tg = Thm.map_tags (insert (op =) tg);
wenzelm@27866
   344
fun untag_rule s = Thm.map_tags (filter_out (fn (s', _) => s = s'));
wenzelm@27866
   345
wenzelm@27866
   346
fun tag tg x = rule_attribute (K (tag_rule tg)) x;
wenzelm@27866
   347
fun untag s x = rule_attribute (K (untag_rule s)) x;
wenzelm@27866
   348
wenzelm@27866
   349
wenzelm@27866
   350
(* position *)
wenzelm@27866
   351
wenzelm@27866
   352
val position_of = Position.of_properties o Thm.get_tags;
wenzelm@27866
   353
wenzelm@27866
   354
fun default_position pos = Thm.map_tags (Position.default_properties pos);
wenzelm@27866
   355
val default_position_of = default_position o position_of;
wenzelm@27866
   356
wenzelm@27866
   357
wenzelm@30342
   358
(* def_name *)
wenzelm@30342
   359
wenzelm@30342
   360
fun def_name c = c ^ "_def";
wenzelm@30342
   361
wenzelm@30342
   362
fun def_name_optional c "" = def_name c
wenzelm@30342
   363
  | def_name_optional _ name = name;
wenzelm@30342
   364
wenzelm@30433
   365
fun def_binding_optional b name =
wenzelm@30433
   366
  if Binding.is_empty name then Binding.map_name def_name b else name;
wenzelm@30433
   367
wenzelm@30342
   368
wenzelm@27866
   369
(* unofficial theorem names *)
wenzelm@27866
   370
wenzelm@27866
   371
fun the_name_hint thm = the (AList.lookup (op =) (Thm.get_tags thm) Markup.nameN);
wenzelm@27866
   372
wenzelm@27866
   373
val has_name_hint = can the_name_hint;
wenzelm@27866
   374
val get_name_hint = the_default "??.unknown" o try the_name_hint;
wenzelm@27866
   375
wenzelm@27866
   376
fun put_name_hint name = untag_rule Markup.nameN #> tag_rule (Markup.nameN, name);
wenzelm@27866
   377
wenzelm@27866
   378
wenzelm@27866
   379
(* theorem groups *)
wenzelm@27866
   380
wenzelm@28017
   381
fun get_group thm = Properties.get (Thm.get_tags thm) Markup.groupN;
wenzelm@27866
   382
wenzelm@28017
   383
fun put_group name = if name = "" then I else Thm.map_tags (Properties.put (Markup.groupN, name));
wenzelm@27866
   384
wenzelm@27866
   385
fun group name = rule_attribute (K (put_group name));
wenzelm@27866
   386
wenzelm@27866
   387
wenzelm@27866
   388
(* theorem kinds *)
wenzelm@27866
   389
wenzelm@27866
   390
val axiomK = "axiom";
wenzelm@27866
   391
val assumptionK = "assumption";
wenzelm@27866
   392
val definitionK = "definition";
wenzelm@27866
   393
val theoremK = "theorem";
haftmann@31177
   394
val generatedK = "generatedK"
wenzelm@27866
   395
val lemmaK = "lemma";
wenzelm@27866
   396
val corollaryK = "corollary";
wenzelm@27866
   397
val internalK = Markup.internalK;
wenzelm@27866
   398
wenzelm@28017
   399
fun the_kind thm = the (Properties.get (Thm.get_tags thm) Markup.kindN);
wenzelm@27866
   400
wenzelm@27866
   401
val has_kind = can the_kind;
wenzelm@27866
   402
val get_kind = the_default "" o try the_kind;
wenzelm@27866
   403
wenzelm@27866
   404
fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN;
wenzelm@27866
   405
fun kind k x = if k = "" then x else rule_attribute (K (kind_rule k)) x;
wenzelm@27866
   406
fun kind_internal x = kind internalK x;
wenzelm@27866
   407
fun has_internal tags = exists (fn tg => tg = (Markup.kindN, internalK)) tags;
wenzelm@27866
   408
val is_internal = has_internal o Thm.get_tags;
wenzelm@27866
   409
wenzelm@27866
   410
wenzelm@22362
   411
open Thm;
wenzelm@22362
   412
wenzelm@22362
   413
end;
wenzelm@22362
   414
wenzelm@23170
   415
val op aconvc = Thm.aconvc;
wenzelm@23170
   416
wenzelm@31971
   417
structure Thmtab = Table(type key = thm val ord = Thm.thm_ord);