| author | wenzelm | 
| Sat, 15 Feb 2025 14:37:41 +0100 | |
| changeset 82181 | a0d1d772ccab | 
| parent 82142 | 508a673c87ac | 
| permissions | -rw-r--r-- | 
| 70576 | 1 | /* Title: Pure/thm_name.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 4 | Systematic naming of individual theorems, as selections from multi-facts. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 75393 | 10 | object Thm_Name {
 | 
| 11 |   object Ordering extends scala.math.Ordering[Thm_Name] {
 | |
| 70576 | 12 | def compare(thm_name1: Thm_Name, thm_name2: Thm_Name): Int = | 
| 13 |       thm_name1.name compare thm_name2.name match {
 | |
| 14 | case 0 => thm_name1.index compare thm_name2.index | |
| 15 | case ord => ord | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | def graph[A]: Graph[Thm_Name, A] = Graph.empty(Ordering) | |
| 70580 | 20 | |
| 21 | private val Thm_Name_Regex = """^(.)+\((\d+)\)$""".r | |
| 22 | ||
| 80295 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 23 |   val empty: Thm_Name = Thm_Name("", 0)
 | 
| 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 24 | |
| 70580 | 25 | def parse(s: String): Thm_Name = | 
| 26 |     s match {
 | |
| 27 | case Thm_Name_Regex(name, Value.Nat(index)) => Thm_Name(name, index) | |
| 28 | case _ => Thm_Name(s, 0) | |
| 29 | } | |
| 80312 | 30 | |
| 31 | ||
| 32 | /* XML data representation */ | |
| 33 | ||
| 34 |   def encode: XML.Encode.T[Thm_Name] = { (thm_name: Thm_Name) =>
 | |
| 35 | import XML.Encode._ | |
| 36 | pair(string, int)((thm_name.name, thm_name.index)) | |
| 37 | } | |
| 38 | ||
| 39 |   def decode: XML.Decode.T[Thm_Name] = { (body: XML.Body) =>
 | |
| 40 | import XML.Decode._ | |
| 41 | val (name, index) = pair(string, int)(body) | |
| 42 | Thm_Name(name, index) | |
| 43 | } | |
| 70576 | 44 | } | 
| 45 | ||
| 75393 | 46 | sealed case class Thm_Name(name: String, index: Int) {
 | 
| 80295 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 47 | def is_empty: Boolean = name.isEmpty | 
| 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 48 | |
| 70580 | 49 | def print: String = | 
| 70576 | 50 | if (name == "" || index == 0) name | 
| 51 |     else name + "(" + index + ")"
 | |
| 52 | ||
| 79376 | 53 | def short: String = | 
| 70576 | 54 | if (name == "" || index == 0) name | 
| 55 | else name + "_" + index | |
| 56 | } |