src/Pure/thm_name.ML
author wenzelm
Tue, 01 Sep 2020 18:03:17 +0200
changeset 72235 a5bf0b69c22a
parent 70586 57df8a85317a
child 79329 992c494bda25
permissions -rw-r--r--
discontinue export_document --- always enabled (reverting f0f83ce0badd);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
70574
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/thm_name.ML
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     3
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     4
Systematic naming of individual theorems, as selections from multi-facts.
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     5
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     6
  (NAME, 0): the single entry of a singleton fact NAME
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     7
  (NAME, i): entry i of a non-singleton fact (1 <= i <= length)
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     8
*)
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
     9
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    10
signature THM_NAME =
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    11
sig
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    12
  type T = string * int
70586
57df8a85317a clarified signature;
wenzelm
parents: 70575
diff changeset
    13
  val ord: T ord
70574
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    14
  val print: T -> string
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    15
  val flatten: T -> string
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    16
  val make_list: string -> thm list -> (T * thm) list
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    17
end;
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    18
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    19
structure Thm_Name: THM_NAME =
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    20
struct
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    21
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    22
type T = string * int;
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    23
val ord = prod_ord string_ord int_ord;
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    24
70575
wenzelm
parents: 70574
diff changeset
    25
fun print (name, index) =
wenzelm
parents: 70574
diff changeset
    26
  if name = "" orelse index = 0 then name
wenzelm
parents: 70574
diff changeset
    27
  else name ^ enclose "(" ")" (string_of_int index);
70574
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    28
70575
wenzelm
parents: 70574
diff changeset
    29
fun flatten (name, index) =
wenzelm
parents: 70574
diff changeset
    30
  if name = "" orelse index = 0 then name
wenzelm
parents: 70574
diff changeset
    31
  else name ^ "_" ^ string_of_int index;
70574
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    32
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    33
fun make_list name [thm: thm] = [((name, 0), thm)]
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    34
  | make_list name thms = map_index (fn (i, thm) => ((name, i + 1), thm)) thms;
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    35
503ca64329cc clarified modules;
wenzelm
parents:
diff changeset
    36
end;