| author | wenzelm | 
| Sun, 03 Nov 2019 19:43:59 +0100 | |
| changeset 71016 | b05d78bfc67c | 
| parent 71015 | bb49abc2ecbb | 
| child 71202 | 785610ad6bfa | 
| permissions | -rw-r--r-- | 
| 68171 | 1  | 
/* Title: Pure/Thy/export_theory.scala  | 
2  | 
Author: Makarius  | 
|
3  | 
||
4  | 
Export foundational theory content.  | 
|
5  | 
*/  | 
|
6  | 
||
7  | 
package isabelle  | 
|
8  | 
||
9  | 
||
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
10  | 
import scala.collection.immutable.SortedMap  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
11  | 
|
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
12  | 
|
| 68171 | 13  | 
object Export_Theory  | 
14  | 
{
 | 
|
| 68206 | 15  | 
/** session content **/  | 
16  | 
||
| 70789 | 17  | 
sealed case class Session(name: String, theory_graph: Graph[String, Option[Theory]])  | 
| 68206 | 18  | 
  {
 | 
19  | 
override def toString: String = name  | 
|
20  | 
||
| 70789 | 21  | 
def theory(theory_name: String): Option[Theory] =  | 
| 68206 | 22  | 
if (theory_graph.defined(theory_name)) theory_graph.get_node(theory_name)  | 
| 70789 | 23  | 
else None  | 
| 68206 | 24  | 
|
25  | 
def theories: List[Theory] =  | 
|
| 70789 | 26  | 
theory_graph.topological_order.flatMap(theory(_))  | 
| 68206 | 27  | 
}  | 
28  | 
||
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
29  | 
def read_session(  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
30  | 
store: Sessions.Store,  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
31  | 
sessions_structure: Sessions.Structure,  | 
| 68209 | 32  | 
session_name: String,  | 
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
33  | 
progress: Progress = No_Progress,  | 
| 68206 | 34  | 
types: Boolean = true,  | 
| 68264 | 35  | 
consts: Boolean = true,  | 
36  | 
axioms: Boolean = true,  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
37  | 
thms: Boolean = true,  | 
| 68264 | 38  | 
classes: Boolean = true,  | 
| 68862 | 39  | 
locales: Boolean = true,  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
40  | 
locale_dependencies: Boolean = true,  | 
| 68295 | 41  | 
classrel: Boolean = true,  | 
42  | 
arities: Boolean = true,  | 
|
| 70920 | 43  | 
constdefs: Boolean = true,  | 
| 68862 | 44  | 
typedefs: Boolean = true,  | 
| 68267 | 45  | 
cache: Term.Cache = Term.make_cache()): Session =  | 
| 68206 | 46  | 
  {
 | 
47  | 
val thys =  | 
|
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
48  | 
sessions_structure.build_requirements(List(session_name)).flatMap(session =>  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
49  | 
using(store.open_database(session))(db =>  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
50  | 
        {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
51  | 
          db.transaction {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
52  | 
for (theory <- Export.read_theory_names(db, session))  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
53  | 
            yield {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
54  | 
              progress.echo("Reading theory " + theory)
 | 
| 70891 | 55  | 
read_theory(Export.Provider.database(db, session, theory),  | 
56  | 
session, theory, types = types, consts = consts,  | 
|
57  | 
axioms = axioms, thms = thms, classes = classes, locales = locales,  | 
|
58  | 
locale_dependencies = locale_dependencies, classrel = classrel, arities = arities,  | 
|
| 70920 | 59  | 
constdefs = constdefs, typedefs = typedefs, cache = Some(cache))  | 
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
60  | 
}  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
61  | 
}  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
62  | 
}))  | 
| 68206 | 63  | 
|
64  | 
val graph0 =  | 
|
| 70890 | 65  | 
      (Graph.string[Option[Theory]] /: thys) {
 | 
66  | 
case (g, thy) => g.default_node(thy.name, Some(thy)) }  | 
|
| 68206 | 67  | 
val graph1 =  | 
68  | 
      (graph0 /: thys) { case (g0, thy) =>
 | 
|
69  | 
        (g0 /: thy.parents) { case (g1, parent) =>
 | 
|
| 70789 | 70  | 
g1.default_node(parent, None).add_edge_acyclic(parent, thy.name) } }  | 
| 68206 | 71  | 
|
72  | 
Session(session_name, graph1)  | 
|
73  | 
}  | 
|
74  | 
||
75  | 
||
76  | 
||
| 68203 | 77  | 
/** theory content **/  | 
78  | 
||
| 68346 | 79  | 
val export_prefix: String = "theory/"  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
80  | 
val export_prefix_proofs: String = "proofs/"  | 
| 68346 | 81  | 
|
| 68208 | 82  | 
sealed case class Theory(name: String, parents: List[String],  | 
83  | 
types: List[Type],  | 
|
84  | 
consts: List[Const],  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
85  | 
axioms: List[Axiom],  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
86  | 
thms: List[Thm],  | 
| 68264 | 87  | 
classes: List[Class],  | 
| 68862 | 88  | 
locales: List[Locale],  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
89  | 
locale_dependencies: List[Locale_Dependency],  | 
| 68295 | 90  | 
classrel: List[Classrel],  | 
| 68862 | 91  | 
arities: List[Arity],  | 
| 70920 | 92  | 
constdefs: List[Constdef],  | 
| 68862 | 93  | 
typedefs: List[Typedef])  | 
| 68206 | 94  | 
  {
 | 
95  | 
override def toString: String = name  | 
|
| 68267 | 96  | 
|
| 70789 | 97  | 
def entity_iterator: Iterator[Entity] =  | 
98  | 
types.iterator.map(_.entity) ++  | 
|
99  | 
consts.iterator.map(_.entity) ++  | 
|
100  | 
axioms.iterator.map(_.entity) ++  | 
|
101  | 
thms.iterator.map(_.entity) ++  | 
|
102  | 
classes.iterator.map(_.entity) ++  | 
|
103  | 
locales.iterator.map(_.entity) ++  | 
|
104  | 
locale_dependencies.iterator.map(_.entity)  | 
|
| 68711 | 105  | 
|
| 68267 | 106  | 
def cache(cache: Term.Cache): Theory =  | 
107  | 
Theory(cache.string(name),  | 
|
108  | 
parents.map(cache.string(_)),  | 
|
109  | 
types.map(_.cache(cache)),  | 
|
110  | 
consts.map(_.cache(cache)),  | 
|
111  | 
axioms.map(_.cache(cache)),  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
112  | 
thms.map(_.cache(cache)),  | 
| 68267 | 113  | 
classes.map(_.cache(cache)),  | 
| 68862 | 114  | 
locales.map(_.cache(cache)),  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
115  | 
locale_dependencies.map(_.cache(cache)),  | 
| 68295 | 116  | 
classrel.map(_.cache(cache)),  | 
| 68862 | 117  | 
arities.map(_.cache(cache)),  | 
| 70920 | 118  | 
constdefs.map(_.cache(cache)),  | 
| 68862 | 119  | 
typedefs.map(_.cache(cache)))  | 
| 68206 | 120  | 
}  | 
121  | 
||
| 68418 | 122  | 
def read_theory(provider: Export.Provider, session_name: String, theory_name: String,  | 
| 68203 | 123  | 
types: Boolean = true,  | 
| 68208 | 124  | 
consts: Boolean = true,  | 
| 68232 | 125  | 
axioms: Boolean = true,  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
126  | 
thms: Boolean = true,  | 
| 68264 | 127  | 
classes: Boolean = true,  | 
| 68862 | 128  | 
locales: Boolean = true,  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
129  | 
locale_dependencies: Boolean = true,  | 
| 68295 | 130  | 
classrel: Boolean = true,  | 
131  | 
arities: Boolean = true,  | 
|
| 70920 | 132  | 
constdefs: Boolean = true,  | 
| 68862 | 133  | 
typedefs: Boolean = true,  | 
| 68267 | 134  | 
cache: Option[Term.Cache] = None): Theory =  | 
| 68203 | 135  | 
  {
 | 
| 68206 | 136  | 
val parents =  | 
| 70891 | 137  | 
if (theory_name == Thy_Header.PURE) Nil  | 
138  | 
      else {
 | 
|
139  | 
        provider(export_prefix + "parents") match {
 | 
|
140  | 
case Some(entry) => split_lines(entry.uncompressed().text)  | 
|
141  | 
case None =>  | 
|
142  | 
            error("Missing theory export in session " + quote(session_name) + ": " +
 | 
|
143  | 
quote(theory_name))  | 
|
144  | 
}  | 
|
| 68206 | 145  | 
}  | 
| 68267 | 146  | 
val theory =  | 
147  | 
Theory(theory_name, parents,  | 
|
| 68418 | 148  | 
if (types) read_types(provider) else Nil,  | 
149  | 
if (consts) read_consts(provider) else Nil,  | 
|
150  | 
if (axioms) read_axioms(provider) else Nil,  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
151  | 
if (thms) read_thms(provider) else Nil,  | 
| 68418 | 152  | 
if (classes) read_classes(provider) else Nil,  | 
| 68862 | 153  | 
if (locales) read_locales(provider) else Nil,  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
154  | 
if (locale_dependencies) read_locale_dependencies(provider) else Nil,  | 
| 68418 | 155  | 
if (classrel) read_classrel(provider) else Nil,  | 
| 68862 | 156  | 
if (arities) read_arities(provider) else Nil,  | 
| 70920 | 157  | 
if (constdefs) read_constdefs(provider) else Nil,  | 
| 68862 | 158  | 
if (typedefs) read_typedefs(provider) else Nil)  | 
| 68267 | 159  | 
if (cache.isDefined) theory.cache(cache.get) else theory  | 
| 68203 | 160  | 
}  | 
161  | 
||
| 70883 | 162  | 
def read_pure[A](store: Sessions.Store, read: (Export.Provider, String, String) => A): A =  | 
| 68710 | 163  | 
  {
 | 
164  | 
val session_name = Thy_Header.PURE  | 
|
165  | 
val theory_name = Thy_Header.PURE  | 
|
166  | 
||
167  | 
using(store.open_database(session_name))(db =>  | 
|
168  | 
    {
 | 
|
169  | 
      db.transaction {
 | 
|
| 70883 | 170  | 
read(Export.Provider.database(db, session_name, theory_name), session_name, theory_name)  | 
| 68710 | 171  | 
}  | 
172  | 
})  | 
|
173  | 
}  | 
|
174  | 
||
| 70883 | 175  | 
def read_pure_theory(store: Sessions.Store, cache: Option[Term.Cache] = None): Theory =  | 
176  | 
read_pure(store, read_theory(_, _, _, cache = cache))  | 
|
177  | 
||
| 
70899
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
178  | 
def read_pure_proof(  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
179  | 
store: Sessions.Store, id: Thm_Id, cache: Option[Term.Cache] = None): Option[Proof] =  | 
| 70884 | 180  | 
read_pure(store, (provider, _, _) => read_proof(provider, id, cache = cache))  | 
| 70883 | 181  | 
|
| 68203 | 182  | 
|
| 68171 | 183  | 
/* entities */  | 
184  | 
||
| 68714 | 185  | 
object Kind extends Enumeration  | 
| 68171 | 186  | 
  {
 | 
| 68714 | 187  | 
    val TYPE = Value("type")
 | 
188  | 
    val CONST = Value("const")
 | 
|
189  | 
    val AXIOM = Value("axiom")
 | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
190  | 
    val THM = Value("thm")
 | 
| 70882 | 191  | 
    val PROOF = Value("proof")
 | 
| 68714 | 192  | 
    val CLASS = Value("class")
 | 
| 68862 | 193  | 
    val LOCALE = Value("locale")
 | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
194  | 
    val LOCALE_DEPENDENCY = Value("locale_dependency")
 | 
| 70913 | 195  | 
    val DOCUMENT_HEADING = Value("document_heading")
 | 
196  | 
    val DOCUMENT_TEXT = Value("document_text")
 | 
|
197  | 
    val PROOF_TEXT = Value("proof_text")
 | 
|
| 68714 | 198  | 
}  | 
199  | 
||
| 68835 | 200  | 
sealed case class Entity(  | 
| 68997 | 201  | 
kind: Kind.Value, name: String, xname: String, pos: Position.T, id: Option[Long], serial: Long)  | 
| 68714 | 202  | 
  {
 | 
| 68718 | 203  | 
override def toString: String = kind.toString + " " + quote(name)  | 
| 68267 | 204  | 
|
205  | 
def cache(cache: Term.Cache): Entity =  | 
|
| 68997 | 206  | 
Entity(kind, cache.string(name), cache.string(xname), cache.position(pos), id, serial)  | 
| 68171 | 207  | 
}  | 
208  | 
||
| 68714 | 209  | 
def decode_entity(kind: Kind.Value, tree: XML.Tree): (Entity, XML.Body) =  | 
| 68171 | 210  | 
  {
 | 
211  | 
def err(): Nothing = throw new XML.XML_Body(List(tree))  | 
|
212  | 
||
213  | 
    tree match {
 | 
|
214  | 
case XML.Elem(Markup(Markup.ENTITY, props), body) =>  | 
|
215  | 
val name = Markup.Name.unapply(props) getOrElse err()  | 
|
| 68997 | 216  | 
val xname = Markup.XName.unapply(props) getOrElse err()  | 
| 
68830
 
44ec6fdaacf8
retain original id, which is command_id/exec_id for PIDE;
 
wenzelm 
parents: 
68726 
diff
changeset
 | 
217  | 
        val pos = props.filter({ case (a, _) => Markup.POSITION_PROPERTIES(a) && a != Markup.ID })
 | 
| 68835 | 218  | 
val id = Position.Id.unapply(props)  | 
| 68171 | 219  | 
val serial = Markup.Serial.unapply(props) getOrElse err()  | 
| 68997 | 220  | 
(Entity(kind, name, xname, pos, id, serial), body)  | 
| 68171 | 221  | 
case _ => err()  | 
222  | 
}  | 
|
223  | 
}  | 
|
224  | 
||
225  | 
||
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
226  | 
/* approximative syntax */  | 
| 69003 | 227  | 
|
228  | 
object Assoc extends Enumeration  | 
|
229  | 
  {
 | 
|
230  | 
val NO_ASSOC, LEFT_ASSOC, RIGHT_ASSOC = Value  | 
|
231  | 
}  | 
|
232  | 
||
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
233  | 
sealed abstract class Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
234  | 
case object No_Syntax extends Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
235  | 
case class Prefix(delim: String) extends Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
236  | 
case class Infix(assoc: Assoc.Value, delim: String, pri: Int) extends Syntax  | 
| 69003 | 237  | 
|
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
238  | 
def decode_syntax: XML.Decode.T[Syntax] =  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
239  | 
XML.Decode.variant(List(  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
240  | 
      { case (Nil, Nil) => No_Syntax },
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
241  | 
      { case (List(delim), Nil) => Prefix(delim) },
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
242  | 
      { case (Nil, body) =>
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
243  | 
import XML.Decode._  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
244  | 
val (ass, delim, pri) = triple(int, string, int)(body)  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
245  | 
Infix(Assoc(ass), delim, pri) }))  | 
| 69003 | 246  | 
|
247  | 
||
| 68171 | 248  | 
/* types */  | 
249  | 
||
| 69003 | 250  | 
sealed case class Type(  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
251  | 
entity: Entity, syntax: Syntax, args: List[String], abbrev: Option[Term.Typ])  | 
| 68267 | 252  | 
  {
 | 
253  | 
def cache(cache: Term.Cache): Type =  | 
|
254  | 
Type(entity.cache(cache),  | 
|
| 69003 | 255  | 
syntax,  | 
| 68267 | 256  | 
args.map(cache.string(_)),  | 
257  | 
abbrev.map(cache.typ(_)))  | 
|
258  | 
}  | 
|
| 68171 | 259  | 
|
| 68418 | 260  | 
def read_types(provider: Export.Provider): List[Type] =  | 
261  | 
provider.uncompressed_yxml(export_prefix + "types").map((tree: XML.Tree) =>  | 
|
262  | 
      {
 | 
|
| 68714 | 263  | 
val (entity, body) = decode_entity(Kind.TYPE, tree)  | 
| 69003 | 264  | 
val (syntax, args, abbrev) =  | 
| 68203 | 265  | 
        {
 | 
| 68418 | 266  | 
import XML.Decode._  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
267  | 
triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body)  | 
| 68418 | 268  | 
}  | 
| 69003 | 269  | 
Type(entity, syntax, args, abbrev)  | 
| 68418 | 270  | 
})  | 
| 68171 | 271  | 
|
272  | 
||
273  | 
/* consts */  | 
|
274  | 
||
| 68173 | 275  | 
sealed case class Const(  | 
| 69003 | 276  | 
entity: Entity,  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
277  | 
syntax: Syntax,  | 
| 69003 | 278  | 
typargs: List[String],  | 
279  | 
typ: Term.Typ,  | 
|
| 69988 | 280  | 
abbrev: Option[Term.Term],  | 
| 
69992
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
281  | 
propositional: Boolean,  | 
| 
69996
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
282  | 
primrec_types: List[String],  | 
| 
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
283  | 
corecursive: Boolean)  | 
| 68267 | 284  | 
  {
 | 
285  | 
def cache(cache: Term.Cache): Const =  | 
|
286  | 
Const(entity.cache(cache),  | 
|
| 69003 | 287  | 
syntax,  | 
| 68267 | 288  | 
typargs.map(cache.string(_)),  | 
289  | 
cache.typ(typ),  | 
|
| 69988 | 290  | 
abbrev.map(cache.term(_)),  | 
| 
69992
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
291  | 
propositional,  | 
| 
69996
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
292  | 
primrec_types.map(cache.string(_)),  | 
| 
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
293  | 
corecursive)  | 
| 68267 | 294  | 
}  | 
| 68171 | 295  | 
|
| 68418 | 296  | 
def read_consts(provider: Export.Provider): List[Const] =  | 
297  | 
provider.uncompressed_yxml(export_prefix + "consts").map((tree: XML.Tree) =>  | 
|
298  | 
      {
 | 
|
| 68714 | 299  | 
val (entity, body) = decode_entity(Kind.CONST, tree)  | 
| 
69996
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
300  | 
val (syntax, (args, (typ, (abbrev, (propositional, (primrec_types, corecursive)))))) =  | 
| 68203 | 301  | 
        {
 | 
| 68418 | 302  | 
import XML.Decode._  | 
| 
69992
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
303  | 
pair(decode_syntax,  | 
| 
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
304  | 
pair(list(string),  | 
| 
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
305  | 
pair(Term_XML.Decode.typ,  | 
| 
69996
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
306  | 
pair(option(Term_XML.Decode.term), pair(bool,  | 
| 
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
307  | 
pair(list(string), bool))))))(body)  | 
| 68418 | 308  | 
}  | 
| 
69996
 
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
 
wenzelm 
parents: 
69992 
diff
changeset
 | 
309  | 
Const(entity, syntax, args, typ, abbrev, propositional, primrec_types, corecursive)  | 
| 68418 | 310  | 
})  | 
| 68208 | 311  | 
|
312  | 
||
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
313  | 
/* axioms */  | 
| 68232 | 314  | 
|
| 68726 | 315  | 
sealed case class Prop(  | 
316  | 
typargs: List[(String, Term.Sort)],  | 
|
317  | 
args: List[(String, Term.Typ)],  | 
|
318  | 
term: Term.Term)  | 
|
| 68232 | 319  | 
  {
 | 
| 68726 | 320  | 
def cache(cache: Term.Cache): Prop =  | 
321  | 
Prop(  | 
|
322  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
|
323  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
|
324  | 
cache.term(term))  | 
|
| 68232 | 325  | 
}  | 
| 68208 | 326  | 
|
| 68726 | 327  | 
def decode_prop(body: XML.Body): Prop =  | 
| 68267 | 328  | 
  {
 | 
| 68726 | 329  | 
val (typargs, args, t) =  | 
330  | 
    {
 | 
|
331  | 
import XML.Decode._  | 
|
332  | 
import Term_XML.Decode._  | 
|
333  | 
triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)  | 
|
334  | 
}  | 
|
335  | 
Prop(typargs, args, t)  | 
|
| 68267 | 336  | 
}  | 
| 68208 | 337  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
338  | 
sealed case class Axiom(entity: Entity, prop: Prop)  | 
| 
70534
 
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
 
wenzelm 
parents: 
70384 
diff
changeset
 | 
339  | 
  {
 | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
340  | 
def cache(cache: Term.Cache): Axiom =  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
341  | 
Axiom(entity.cache(cache), prop.cache(cache))  | 
| 
70534
 
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
 
wenzelm 
parents: 
70384 
diff
changeset
 | 
342  | 
}  | 
| 
 
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
 
wenzelm 
parents: 
70384 
diff
changeset
 | 
343  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
344  | 
def read_axioms(provider: Export.Provider): List[Axiom] =  | 
| 68418 | 345  | 
provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) =>  | 
346  | 
      {
 | 
|
| 68714 | 347  | 
val (entity, body) = decode_entity(Kind.AXIOM, tree)  | 
| 68726 | 348  | 
val prop = decode_prop(body)  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
349  | 
Axiom(entity, prop)  | 
| 68418 | 350  | 
})  | 
| 68232 | 351  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
352  | 
|
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
353  | 
/* theorems */  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
354  | 
|
| 70884 | 355  | 
sealed case class Thm_Id(serial: Long, theory_name: String)  | 
356  | 
  {
 | 
|
357  | 
def pure: Boolean = theory_name == Thy_Header.PURE  | 
|
358  | 
}  | 
|
359  | 
||
360  | 
sealed case class Thm(  | 
|
361  | 
entity: Entity,  | 
|
362  | 
prop: Prop,  | 
|
363  | 
deps: List[String],  | 
|
| 70896 | 364  | 
proof: Term.Proof)  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
365  | 
  {
 | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
366  | 
def cache(cache: Term.Cache): Thm =  | 
| 70884 | 367  | 
Thm(  | 
368  | 
entity.cache(cache),  | 
|
369  | 
prop.cache(cache),  | 
|
370  | 
deps.map(cache.string _),  | 
|
| 70896 | 371  | 
cache.proof(proof))  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
372  | 
}  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
373  | 
|
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
374  | 
def read_thms(provider: Export.Provider): List[Thm] =  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
375  | 
provider.uncompressed_yxml(export_prefix + "thms").map((tree: XML.Tree) =>  | 
| 68418 | 376  | 
      {
 | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
377  | 
val (entity, body) = decode_entity(Kind.THM, tree)  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
378  | 
val (prop, deps, prf) =  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
379  | 
        {
 | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
380  | 
import XML.Decode._  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
381  | 
import Term_XML.Decode._  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
382  | 
triple(decode_prop, list(string), proof)(body)  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
383  | 
}  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
384  | 
Thm(entity, prop, deps, prf)  | 
| 68418 | 385  | 
})  | 
| 68264 | 386  | 
|
| 70881 | 387  | 
sealed case class Proof(  | 
388  | 
typargs: List[(String, Term.Sort)],  | 
|
389  | 
args: List[(String, Term.Typ)],  | 
|
390  | 
term: Term.Term,  | 
|
391  | 
proof: Term.Proof)  | 
|
392  | 
  {
 | 
|
| 70883 | 393  | 
def prop: Prop = Prop(typargs, args, term)  | 
394  | 
||
| 70881 | 395  | 
def cache(cache: Term.Cache): Proof =  | 
396  | 
Proof(  | 
|
397  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
|
398  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
|
399  | 
cache.term(term),  | 
|
400  | 
cache.proof(proof))  | 
|
401  | 
}  | 
|
402  | 
||
| 
70899
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
403  | 
def read_proof(  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
404  | 
provider: Export.Provider, id: Thm_Id, cache: Option[Term.Cache] = None): Option[Proof] =  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
405  | 
  {
 | 
| 
70899
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
406  | 
    for { entry <- provider.focus(id.theory_name)(export_prefix_proofs + id.serial) }
 | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
407  | 
    yield {
 | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
408  | 
val body = entry.uncompressed_yxml()  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
409  | 
val (typargs, (args, (prop_body, proof_body))) =  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
410  | 
      {
 | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
411  | 
import XML.Decode._  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
412  | 
import Term_XML.Decode._  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
413  | 
pair(list(pair(string, sort)), pair(list(pair(string, typ)), pair(x => x, x => x)))(body)  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
414  | 
}  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
415  | 
val env = args.toMap  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
416  | 
val prop = Term_XML.Decode.term_env(env)(prop_body)  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
417  | 
val proof = Term_XML.Decode.proof_env(env)(proof_body)  | 
| 
70843
 
cc987440d776
more compact XML: separate environment for free variables;
 
wenzelm 
parents: 
70790 
diff
changeset
 | 
418  | 
|
| 
70899
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
419  | 
val result = Proof(typargs, args, prop, proof)  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
420  | 
cache.map(result.cache(_)) getOrElse result  | 
| 
70843
 
cc987440d776
more compact XML: separate environment for free variables;
 
wenzelm 
parents: 
70790 
diff
changeset
 | 
421  | 
}  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
422  | 
}  | 
| 
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
423  | 
|
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
424  | 
def read_proof_boxes(  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
425  | 
store: Sessions.Store,  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
426  | 
provider: Export.Provider,  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
427  | 
proof: Term.Proof,  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
428  | 
suppress: Thm_Id => Boolean = _ => false,  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
429  | 
cache: Option[Term.Cache] = None): List[(Thm_Id, Proof)] =  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
430  | 
  {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
431  | 
var seen = Set.empty[Long]  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
432  | 
var result = SortedMap.empty[Long, (Thm_Id, Proof)]  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
433  | 
|
| 71016 | 434  | 
def boxes(context: Option[(Long, Term.Proof)], prf: Term.Proof)  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
435  | 
    {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
436  | 
      prf match {
 | 
| 71016 | 437  | 
case Term.Abst(_, _, p) => boxes(context, p)  | 
438  | 
case Term.AbsP(_, _, p) => boxes(context, p)  | 
|
439  | 
case Term.Appt(p, _) => boxes(context, p)  | 
|
440  | 
case Term.AppP(p, q) => boxes(context, p); boxes(context, q)  | 
|
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
441  | 
case thm: Term.PThm if !seen(thm.serial) =>  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
442  | 
seen += thm.serial  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
443  | 
val id = Thm_Id(thm.serial, thm.theory_name)  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
444  | 
          if (!suppress(id)) {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
445  | 
val read =  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
446  | 
if (id.pure) Export_Theory.read_pure_proof(store, id, cache = cache)  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
447  | 
else Export_Theory.read_proof(provider, id, cache = cache)  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
448  | 
            read match {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
449  | 
case Some(p) =>  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
450  | 
result += (thm.serial -> (id -> p))  | 
| 71016 | 451  | 
boxes(Some((thm.serial, p.proof)), p.proof)  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
452  | 
case None =>  | 
| 71016 | 453  | 
                error("Missing proof " + thm.serial + " (theory " + quote (thm.theory_name) + ")" +
 | 
454  | 
                  (context match {
 | 
|
455  | 
case None => ""  | 
|
456  | 
case Some((i, p)) => " in proof " + i + ":\n" + p  | 
|
457  | 
}))  | 
|
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
458  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
459  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
460  | 
case _ =>  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
461  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
462  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
463  | 
|
| 71016 | 464  | 
boxes(None, proof)  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
465  | 
result.iterator.map(_._2).toList  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
466  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
467  | 
|
| 68264 | 468  | 
|
469  | 
/* type classes */  | 
|
470  | 
||
471  | 
sealed case class Class(  | 
|
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
472  | 
entity: Entity, params: List[(String, Term.Typ)], axioms: List[Prop])  | 
| 68267 | 473  | 
  {
 | 
474  | 
def cache(cache: Term.Cache): Class =  | 
|
475  | 
Class(entity.cache(cache),  | 
|
476  | 
        params.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
|
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
477  | 
axioms.map(_.cache(cache)))  | 
| 68267 | 478  | 
}  | 
| 68264 | 479  | 
|
| 68418 | 480  | 
def read_classes(provider: Export.Provider): List[Class] =  | 
481  | 
provider.uncompressed_yxml(export_prefix + "classes").map((tree: XML.Tree) =>  | 
|
482  | 
      {
 | 
|
| 68714 | 483  | 
val (entity, body) = decode_entity(Kind.CLASS, tree)  | 
| 68418 | 484  | 
val (params, axioms) =  | 
| 68264 | 485  | 
        {
 | 
| 68418 | 486  | 
import XML.Decode._  | 
487  | 
import Term_XML.Decode._  | 
|
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
488  | 
pair(list(pair(string, typ)), list(decode_prop))(body)  | 
| 68418 | 489  | 
}  | 
490  | 
Class(entity, params, axioms)  | 
|
491  | 
})  | 
|
| 68264 | 492  | 
|
493  | 
||
| 68862 | 494  | 
/* locales */  | 
495  | 
||
496  | 
sealed case class Locale(  | 
|
| 69019 | 497  | 
entity: Entity,  | 
498  | 
typargs: List[(String, Term.Sort)],  | 
|
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
499  | 
args: List[((String, Term.Typ), Syntax)],  | 
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
500  | 
axioms: List[Prop])  | 
| 68862 | 501  | 
  {
 | 
502  | 
def cache(cache: Term.Cache): Locale =  | 
|
503  | 
Locale(entity.cache(cache),  | 
|
| 68864 | 504  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
| 69076 | 505  | 
        args.map({ case ((name, typ), syntax) => ((cache.string(name), cache.typ(typ)), syntax) }),
 | 
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
506  | 
axioms.map(_.cache(cache)))  | 
| 68862 | 507  | 
}  | 
508  | 
||
509  | 
def read_locales(provider: Export.Provider): List[Locale] =  | 
|
510  | 
provider.uncompressed_yxml(export_prefix + "locales").map((tree: XML.Tree) =>  | 
|
511  | 
      {
 | 
|
512  | 
val (entity, body) = decode_entity(Kind.LOCALE, tree)  | 
|
| 69019 | 513  | 
val (typargs, args, axioms) =  | 
| 68862 | 514  | 
        {
 | 
515  | 
import XML.Decode._  | 
|
516  | 
import Term_XML.Decode._  | 
|
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
517  | 
triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)),  | 
| 69076 | 518  | 
list(decode_prop))(body)  | 
| 68862 | 519  | 
}  | 
| 69019 | 520  | 
Locale(entity, typargs, args, axioms)  | 
| 68862 | 521  | 
})  | 
522  | 
||
523  | 
||
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
524  | 
/* locale dependencies */  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
525  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
526  | 
sealed case class Locale_Dependency(  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
527  | 
entity: Entity,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
528  | 
source: String,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
529  | 
target: String,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
530  | 
prefix: List[(String, Boolean)],  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
531  | 
subst_types: List[((String, Term.Sort), Term.Typ)],  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
532  | 
subst_terms: List[((String, Term.Typ), Term.Term)])  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
533  | 
  {
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
534  | 
def cache(cache: Term.Cache): Locale_Dependency =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
535  | 
Locale_Dependency(entity.cache(cache),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
536  | 
cache.string(source),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
537  | 
cache.string(target),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
538  | 
        prefix.map({ case (name, mandatory) => (cache.string(name), mandatory) }),
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
539  | 
        subst_types.map({ case ((a, s), ty) => ((cache.string(a), cache.sort(s)), cache.typ(ty)) }),
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
540  | 
        subst_terms.map({ case ((x, ty), t) => ((cache.string(x), cache.typ(ty)), cache.term(t)) }))
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
541  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
542  | 
def is_inclusion: Boolean =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
543  | 
subst_types.isEmpty && subst_terms.isEmpty  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
544  | 
}  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
545  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
546  | 
def read_locale_dependencies(provider: Export.Provider): List[Locale_Dependency] =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
547  | 
provider.uncompressed_yxml(export_prefix + "locale_dependencies").map((tree: XML.Tree) =>  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
548  | 
      {
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
549  | 
val (entity, body) = decode_entity(Kind.LOCALE_DEPENDENCY, tree)  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
550  | 
val (source, (target, (prefix, (subst_types, subst_terms)))) =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
551  | 
        {
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
552  | 
import XML.Decode._  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
553  | 
import Term_XML.Decode._  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
554  | 
pair(string, pair(string, pair(list(pair(string, bool)),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
555  | 
pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body)  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
556  | 
}  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
557  | 
Locale_Dependency(entity, source, target, prefix, subst_types, subst_terms)  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
558  | 
})  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
559  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
560  | 
|
| 68295 | 561  | 
/* sort algebra */  | 
562  | 
||
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
563  | 
sealed case class Classrel(class1: String, class2: String, prop: Prop)  | 
| 68295 | 564  | 
  {
 | 
565  | 
def cache(cache: Term.Cache): Classrel =  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
566  | 
Classrel(cache.string(class1), cache.string(class2), prop.cache(cache))  | 
| 68295 | 567  | 
}  | 
568  | 
||
| 68418 | 569  | 
def read_classrel(provider: Export.Provider): List[Classrel] =  | 
570  | 
  {
 | 
|
571  | 
val body = provider.uncompressed_yxml(export_prefix + "classrel")  | 
|
572  | 
val classrel =  | 
|
573  | 
    {
 | 
|
574  | 
import XML.Decode._  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
575  | 
list(pair(decode_prop, pair(string, string)))(body)  | 
| 68418 | 576  | 
}  | 
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
577  | 
for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop)  | 
| 68418 | 578  | 
}  | 
| 68295 | 579  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
580  | 
sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String, prop: Prop)  | 
| 68295 | 581  | 
  {
 | 
582  | 
def cache(cache: Term.Cache): Arity =  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
583  | 
Arity(cache.string(type_name), domain.map(cache.sort(_)), cache.string(codomain),  | 
| 
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
584  | 
prop.cache(cache))  | 
| 68295 | 585  | 
}  | 
586  | 
||
| 68418 | 587  | 
def read_arities(provider: Export.Provider): List[Arity] =  | 
588  | 
  {
 | 
|
589  | 
val body = provider.uncompressed_yxml(export_prefix + "arities")  | 
|
590  | 
val arities =  | 
|
591  | 
    {
 | 
|
592  | 
import XML.Decode._  | 
|
593  | 
import Term_XML.Decode._  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
594  | 
list(pair(decode_prop, triple(string, list(sort), string)))(body)  | 
| 68418 | 595  | 
}  | 
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
596  | 
for ((prop, (a, b, c)) <- arities) yield Arity(a, b, c, prop)  | 
| 68418 | 597  | 
}  | 
| 68295 | 598  | 
|
599  | 
||
| 70920 | 600  | 
/* Pure constdefs */  | 
601  | 
||
602  | 
sealed case class Constdef(name: String, axiom_name: String)  | 
|
603  | 
  {
 | 
|
604  | 
def cache(cache: Term.Cache): Constdef =  | 
|
605  | 
Constdef(cache.string(name), cache.string(axiom_name))  | 
|
606  | 
}  | 
|
607  | 
||
608  | 
def read_constdefs(provider: Export.Provider): List[Constdef] =  | 
|
609  | 
  {
 | 
|
610  | 
val body = provider.uncompressed_yxml(export_prefix + "constdefs")  | 
|
611  | 
val constdefs =  | 
|
612  | 
    {
 | 
|
613  | 
import XML.Decode._  | 
|
614  | 
list(pair(string, string))(body)  | 
|
615  | 
}  | 
|
616  | 
for ((name, axiom_name) <- constdefs) yield Constdef(name, axiom_name)  | 
|
617  | 
}  | 
|
618  | 
||
619  | 
||
| 68264 | 620  | 
/* HOL typedefs */  | 
621  | 
||
622  | 
sealed case class Typedef(name: String,  | 
|
623  | 
rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String)  | 
|
| 68267 | 624  | 
  {
 | 
625  | 
def cache(cache: Term.Cache): Typedef =  | 
|
626  | 
Typedef(cache.string(name),  | 
|
627  | 
cache.typ(rep_type),  | 
|
628  | 
cache.typ(abs_type),  | 
|
629  | 
cache.string(rep_name),  | 
|
630  | 
cache.string(abs_name),  | 
|
631  | 
cache.string(axiom_name))  | 
|
632  | 
}  | 
|
| 68264 | 633  | 
|
| 68418 | 634  | 
def read_typedefs(provider: Export.Provider): List[Typedef] =  | 
635  | 
  {
 | 
|
636  | 
val body = provider.uncompressed_yxml(export_prefix + "typedefs")  | 
|
637  | 
val typedefs =  | 
|
638  | 
    {
 | 
|
639  | 
import XML.Decode._  | 
|
640  | 
import Term_XML.Decode._  | 
|
641  | 
list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)  | 
|
642  | 
}  | 
|
643  | 
    for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs }
 | 
|
644  | 
yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name)  | 
|
645  | 
}  | 
|
| 68171 | 646  | 
}  |