| author | wenzelm | 
| Wed, 04 Aug 2021 19:41:59 +0200 | |
| changeset 74114 | 700e5bd59c7d | 
| parent 73866 | 66bff50bc5f1 | 
| child 74119 | 342d0298e164 | 
| 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] =  | 
|
| 71601 | 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,  | 
| 
71726
 
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
 
wenzelm 
parents: 
71601 
diff
changeset
 | 
33  | 
progress: Progress = new Progress,  | 
| 73024 | 34  | 
cache: Term.Cache = Term.Cache.make()): Session =  | 
| 68206 | 35  | 
  {
 | 
36  | 
val thys =  | 
|
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
37  | 
sessions_structure.build_requirements(List(session_name)).flatMap(session =>  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
38  | 
using(store.open_database(session))(db =>  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
39  | 
        {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
40  | 
          db.transaction {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
41  | 
for (theory <- Export.read_theory_names(db, session))  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
42  | 
            yield {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
43  | 
              progress.echo("Reading theory " + theory)
 | 
| 
73031
 
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
 
wenzelm 
parents: 
73024 
diff
changeset
 | 
44  | 
val provider = Export.Provider.database(db, store.cache, session, theory)  | 
| 
 
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
 
wenzelm 
parents: 
73024 
diff
changeset
 | 
45  | 
read_theory(provider, session, theory, cache = cache)  | 
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
46  | 
}  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
47  | 
}  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
48  | 
}))  | 
| 68206 | 49  | 
|
50  | 
val graph0 =  | 
|
| 73359 | 51  | 
      thys.foldLeft(Graph.string[Option[Theory]]) {
 | 
52  | 
case (g, thy) => g.default_node(thy.name, Some(thy))  | 
|
53  | 
}  | 
|
| 68206 | 54  | 
val graph1 =  | 
| 73359 | 55  | 
      thys.foldLeft(graph0) {
 | 
56  | 
case (g0, thy) =>  | 
|
57  | 
          thy.parents.foldLeft(g0) {
 | 
|
58  | 
case (g1, parent) => g1.default_node(parent, None).add_edge_acyclic(parent, thy.name)  | 
|
59  | 
}  | 
|
60  | 
}  | 
|
| 68206 | 61  | 
|
62  | 
Session(session_name, graph1)  | 
|
63  | 
}  | 
|
64  | 
||
65  | 
||
66  | 
||
| 68203 | 67  | 
/** theory content **/  | 
68  | 
||
| 68208 | 69  | 
sealed case class Theory(name: String, parents: List[String],  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
70  | 
types: List[Entity[Type]],  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
71  | 
consts: List[Entity[Const]],  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
72  | 
axioms: List[Entity[Axiom]],  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
73  | 
thms: List[Entity[Thm]],  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
74  | 
classes: List[Entity[Class]],  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
75  | 
locales: List[Entity[Locale]],  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
76  | 
locale_dependencies: List[Entity[Locale_Dependency]],  | 
| 68295 | 77  | 
classrel: List[Classrel],  | 
| 68862 | 78  | 
arities: List[Arity],  | 
| 70920 | 79  | 
constdefs: List[Constdef],  | 
| 71202 | 80  | 
typedefs: List[Typedef],  | 
| 71248 | 81  | 
datatypes: List[Datatype],  | 
| 71202 | 82  | 
spec_rules: List[Spec_Rule])  | 
| 68206 | 83  | 
  {
 | 
84  | 
override def toString: String = name  | 
|
| 68267 | 85  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
86  | 
def entity_iterator: Iterator[Entity[No_Content]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
87  | 
types.iterator.map(_.no_content) ++  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
88  | 
consts.iterator.map(_.no_content) ++  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
89  | 
axioms.iterator.map(_.no_content) ++  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
90  | 
thms.iterator.map(_.no_content) ++  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
91  | 
classes.iterator.map(_.no_content) ++  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
92  | 
locales.iterator.map(_.no_content) ++  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
93  | 
locale_dependencies.iterator.map(_.no_content)  | 
| 68711 | 94  | 
|
| 68267 | 95  | 
def cache(cache: Term.Cache): Theory =  | 
96  | 
Theory(cache.string(name),  | 
|
| 73866 | 97  | 
parents.map(cache.string),  | 
| 68267 | 98  | 
types.map(_.cache(cache)),  | 
99  | 
consts.map(_.cache(cache)),  | 
|
100  | 
axioms.map(_.cache(cache)),  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
101  | 
thms.map(_.cache(cache)),  | 
| 68267 | 102  | 
classes.map(_.cache(cache)),  | 
| 68862 | 103  | 
locales.map(_.cache(cache)),  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
104  | 
locale_dependencies.map(_.cache(cache)),  | 
| 68295 | 105  | 
classrel.map(_.cache(cache)),  | 
| 68862 | 106  | 
arities.map(_.cache(cache)),  | 
| 70920 | 107  | 
constdefs.map(_.cache(cache)),  | 
| 71202 | 108  | 
typedefs.map(_.cache(cache)),  | 
| 71248 | 109  | 
datatypes.map(_.cache(cache)),  | 
| 71202 | 110  | 
spec_rules.map(_.cache(cache)))  | 
| 68206 | 111  | 
}  | 
112  | 
||
| 68418 | 113  | 
def read_theory(provider: Export.Provider, session_name: String, theory_name: String,  | 
| 73024 | 114  | 
cache: Term.Cache = Term.Cache.none): Theory =  | 
| 68203 | 115  | 
  {
 | 
| 68206 | 116  | 
val parents =  | 
| 70891 | 117  | 
if (theory_name == Thy_Header.PURE) Nil  | 
118  | 
      else {
 | 
|
| 72691 | 119  | 
        provider(Export.THEORY_PREFIX + "parents") match {
 | 
| 
72847
 
9dda93a753b1
clarified signature: provide XZ.Cache where Export.Entry is created;
 
wenzelm 
parents: 
72708 
diff
changeset
 | 
120  | 
case Some(entry) => split_lines(entry.uncompressed.text)  | 
| 70891 | 121  | 
case None =>  | 
122  | 
            error("Missing theory export in session " + quote(session_name) + ": " +
 | 
|
123  | 
quote(theory_name))  | 
|
124  | 
}  | 
|
| 68206 | 125  | 
}  | 
| 68267 | 126  | 
val theory =  | 
127  | 
Theory(theory_name, parents,  | 
|
| 71251 | 128  | 
read_types(provider),  | 
129  | 
read_consts(provider),  | 
|
130  | 
read_axioms(provider),  | 
|
131  | 
read_thms(provider),  | 
|
132  | 
read_classes(provider),  | 
|
133  | 
read_locales(provider),  | 
|
134  | 
read_locale_dependencies(provider),  | 
|
135  | 
read_classrel(provider),  | 
|
136  | 
read_arities(provider),  | 
|
137  | 
read_constdefs(provider),  | 
|
138  | 
read_typedefs(provider),  | 
|
139  | 
read_datatypes(provider),  | 
|
140  | 
read_spec_rules(provider))  | 
|
| 73024 | 141  | 
if (cache.no_cache) theory else theory.cache(cache)  | 
| 68203 | 142  | 
}  | 
143  | 
||
| 70883 | 144  | 
def read_pure[A](store: Sessions.Store, read: (Export.Provider, String, String) => A): A =  | 
| 68710 | 145  | 
  {
 | 
146  | 
val session_name = Thy_Header.PURE  | 
|
147  | 
val theory_name = Thy_Header.PURE  | 
|
148  | 
||
149  | 
using(store.open_database(session_name))(db =>  | 
|
150  | 
    {
 | 
|
151  | 
      db.transaction {
 | 
|
| 
73031
 
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
 
wenzelm 
parents: 
73024 
diff
changeset
 | 
152  | 
val provider = Export.Provider.database(db, store.cache, session_name, theory_name)  | 
| 
 
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
 
wenzelm 
parents: 
73024 
diff
changeset
 | 
153  | 
read(provider, session_name, theory_name)  | 
| 68710 | 154  | 
}  | 
155  | 
})  | 
|
156  | 
}  | 
|
157  | 
||
| 73024 | 158  | 
def read_pure_theory(store: Sessions.Store, cache: Term.Cache = Term.Cache.none): Theory =  | 
| 70883 | 159  | 
read_pure(store, read_theory(_, _, _, cache = cache))  | 
160  | 
||
| 
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
 | 
161  | 
def read_pure_proof(  | 
| 73024 | 162  | 
store: Sessions.Store, id: Thm_Id, cache: Term.Cache = Term.Cache.none): Option[Proof] =  | 
| 70884 | 163  | 
read_pure(store, (provider, _, _) => read_proof(provider, id, cache = cache))  | 
| 70883 | 164  | 
|
| 68203 | 165  | 
|
| 68171 | 166  | 
/* entities */  | 
167  | 
||
| 68714 | 168  | 
object Kind extends Enumeration  | 
| 68171 | 169  | 
  {
 | 
| 68714 | 170  | 
    val TYPE = Value("type")
 | 
171  | 
    val CONST = Value("const")
 | 
|
172  | 
    val AXIOM = Value("axiom")
 | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
173  | 
    val THM = Value("thm")
 | 
| 70882 | 174  | 
    val PROOF = Value("proof")
 | 
| 68714 | 175  | 
    val CLASS = Value("class")
 | 
| 68862 | 176  | 
    val LOCALE = Value("locale")
 | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
177  | 
    val LOCALE_DEPENDENCY = Value("locale_dependency")
 | 
| 70913 | 178  | 
    val DOCUMENT_HEADING = Value("document_heading")
 | 
179  | 
    val DOCUMENT_TEXT = Value("document_text")
 | 
|
180  | 
    val PROOF_TEXT = Value("proof_text")
 | 
|
| 68714 | 181  | 
}  | 
182  | 
||
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
183  | 
abstract class Content[T]  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
184  | 
  {
 | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
185  | 
def cache(cache: Term.Cache): T  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
186  | 
}  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
187  | 
sealed case class No_Content() extends Content[No_Content]  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
188  | 
  {
 | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
189  | 
def cache(cache: Term.Cache): No_Content = this  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
190  | 
}  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
191  | 
sealed case class Entity[A <: Content[A]](  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
192  | 
kind: Kind.Value,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
193  | 
name: String,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
194  | 
xname: String,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
195  | 
pos: Position.T,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
196  | 
id: Option[Long],  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
197  | 
serial: Long,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
198  | 
content: Option[A])  | 
| 68714 | 199  | 
  {
 | 
| 68718 | 200  | 
override def toString: String = kind.toString + " " + quote(name)  | 
| 68267 | 201  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
202  | 
def the_content: A =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
203  | 
      if (content.isDefined) content.get else error("No content for " + toString)
 | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
204  | 
|
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
205  | 
def no_content: Entity[No_Content] = copy(content = None)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
206  | 
|
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
207  | 
def cache(cache: Term.Cache): Entity[A] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
208  | 
Entity(  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
209  | 
kind,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
210  | 
cache.string(name),  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
211  | 
cache.string(xname),  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
212  | 
cache.position(pos),  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
213  | 
id,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
214  | 
serial,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
215  | 
content.map(_.cache(cache)))  | 
| 68171 | 216  | 
}  | 
217  | 
||
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
218  | 
def read_entities[A <: Content[A]](  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
219  | 
provider: Export.Provider,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
220  | 
export_name: String,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
221  | 
kind: Kind.Value,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
222  | 
decode: XML.Decode.T[A]): List[Entity[A]] =  | 
| 68171 | 223  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
224  | 
def decode_entity(tree: XML.Tree): Entity[A] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
225  | 
    {
 | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
226  | 
def err(): Nothing = throw new XML.XML_Body(List(tree))  | 
| 68171 | 227  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
228  | 
      tree match {
 | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
229  | 
case XML.Elem(Markup(Markup.ENTITY, props), body) =>  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
230  | 
val name = Markup.Name.unapply(props) getOrElse err()  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
231  | 
val xname = Markup.XName.unapply(props) getOrElse err()  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
232  | 
val pos = props.filter(p => Markup.position_property(p) && p._1 != Markup.ID)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
233  | 
val id = Position.Id.unapply(props)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
234  | 
val serial = Markup.Serial.unapply(props) getOrElse err()  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
235  | 
val content = if (body.isEmpty) None else Some(decode(body))  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
236  | 
Entity(kind, name, xname, pos, id, serial, content)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
237  | 
case _ => err()  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
238  | 
}  | 
| 68171 | 239  | 
}  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
240  | 
provider.uncompressed_yxml(export_name).map(decode_entity)  | 
| 68171 | 241  | 
}  | 
242  | 
||
243  | 
||
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
244  | 
/* approximative syntax */  | 
| 69003 | 245  | 
|
246  | 
object Assoc extends Enumeration  | 
|
247  | 
  {
 | 
|
248  | 
val NO_ASSOC, LEFT_ASSOC, RIGHT_ASSOC = Value  | 
|
249  | 
}  | 
|
250  | 
||
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
251  | 
sealed abstract class Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
252  | 
case object No_Syntax extends Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
253  | 
case class Prefix(delim: String) extends Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
254  | 
case class Infix(assoc: Assoc.Value, delim: String, pri: Int) extends Syntax  | 
| 69003 | 255  | 
|
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
256  | 
def decode_syntax: XML.Decode.T[Syntax] =  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
257  | 
XML.Decode.variant(List(  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
258  | 
      { case (Nil, Nil) => No_Syntax },
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
259  | 
      { case (List(delim), Nil) => Prefix(delim) },
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
260  | 
      { case (Nil, body) =>
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
261  | 
import XML.Decode._  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
262  | 
val (ass, delim, pri) = triple(int, string, int)(body)  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
263  | 
Infix(Assoc(ass), delim, pri) }))  | 
| 69003 | 264  | 
|
265  | 
||
| 68171 | 266  | 
/* types */  | 
267  | 
||
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
268  | 
sealed case class Type(syntax: Syntax, args: List[String], abbrev: Option[Term.Typ])  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
269  | 
extends Content[Type]  | 
| 68267 | 270  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
271  | 
override def cache(cache: Term.Cache): Type =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
272  | 
Type(  | 
| 69003 | 273  | 
syntax,  | 
| 73866 | 274  | 
args.map(cache.string),  | 
275  | 
abbrev.map(cache.typ))  | 
|
| 68267 | 276  | 
}  | 
| 68171 | 277  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
278  | 
def read_types(provider: Export.Provider): List[Entity[Type]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
279  | 
read_entities(provider, Export.THEORY_PREFIX + "types", Kind.TYPE, body =>  | 
| 68418 | 280  | 
      {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
281  | 
import XML.Decode._  | 
| 69003 | 282  | 
val (syntax, args, abbrev) =  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
283  | 
triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body)  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
284  | 
Type(syntax, args, abbrev)  | 
| 68418 | 285  | 
})  | 
| 68171 | 286  | 
|
287  | 
||
288  | 
/* consts */  | 
|
289  | 
||
| 68173 | 290  | 
sealed case class Const(  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
291  | 
syntax: Syntax,  | 
| 69003 | 292  | 
typargs: List[String],  | 
293  | 
typ: Term.Typ,  | 
|
| 69988 | 294  | 
abbrev: Option[Term.Term],  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
295  | 
propositional: Boolean) extends Content[Const]  | 
| 68267 | 296  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
297  | 
override def cache(cache: Term.Cache): Const =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
298  | 
Const(  | 
| 69003 | 299  | 
syntax,  | 
| 73866 | 300  | 
typargs.map(cache.string),  | 
| 68267 | 301  | 
cache.typ(typ),  | 
| 73866 | 302  | 
abbrev.map(cache.term),  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
303  | 
propositional)  | 
| 68267 | 304  | 
}  | 
| 68171 | 305  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
306  | 
def read_consts(provider: Export.Provider): List[Entity[Const]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
307  | 
read_entities(provider, Export.THEORY_PREFIX + "consts", Kind.CONST, body =>  | 
| 68418 | 308  | 
      {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
309  | 
import XML.Decode._  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
310  | 
val (syntax, (typargs, (typ, (abbrev, propositional)))) =  | 
| 
69992
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
311  | 
pair(decode_syntax,  | 
| 
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
312  | 
pair(list(string),  | 
| 
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
313  | 
pair(Term_XML.Decode.typ,  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
314  | 
pair(option(Term_XML.Decode.term), bool))))(body)  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
315  | 
Const(syntax, typargs, typ, abbrev, propositional)  | 
| 68418 | 316  | 
})  | 
| 68208 | 317  | 
|
318  | 
||
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
319  | 
/* axioms */  | 
| 68232 | 320  | 
|
| 68726 | 321  | 
sealed case class Prop(  | 
322  | 
typargs: List[(String, Term.Sort)],  | 
|
323  | 
args: List[(String, Term.Typ)],  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
324  | 
term: Term.Term) extends Content[Prop]  | 
| 68232 | 325  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
326  | 
override def cache(cache: Term.Cache): Prop =  | 
| 68726 | 327  | 
Prop(  | 
328  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
|
329  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
|
330  | 
cache.term(term))  | 
|
| 68232 | 331  | 
}  | 
| 68208 | 332  | 
|
| 68726 | 333  | 
def decode_prop(body: XML.Body): Prop =  | 
| 68267 | 334  | 
  {
 | 
| 68726 | 335  | 
val (typargs, args, t) =  | 
336  | 
    {
 | 
|
337  | 
import XML.Decode._  | 
|
338  | 
import Term_XML.Decode._  | 
|
339  | 
triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)  | 
|
340  | 
}  | 
|
341  | 
Prop(typargs, args, t)  | 
|
| 68267 | 342  | 
}  | 
| 68208 | 343  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
344  | 
sealed case class Axiom(prop: Prop) extends Content[Axiom]  | 
| 
70534
 
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
 
wenzelm 
parents: 
70384 
diff
changeset
 | 
345  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
346  | 
override def cache(cache: Term.Cache): Axiom = Axiom(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
 | 
347  | 
}  | 
| 
 
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
 
wenzelm 
parents: 
70384 
diff
changeset
 | 
348  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
349  | 
def read_axioms(provider: Export.Provider): List[Entity[Axiom]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
350  | 
read_entities(provider, Export.THEORY_PREFIX + "axioms", Kind.AXIOM,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
351  | 
body => Axiom(decode_prop(body)))  | 
| 68232 | 352  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
353  | 
|
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
354  | 
/* theorems */  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
355  | 
|
| 70884 | 356  | 
sealed case class Thm_Id(serial: Long, theory_name: String)  | 
357  | 
  {
 | 
|
358  | 
def pure: Boolean = theory_name == Thy_Header.PURE  | 
|
359  | 
}  | 
|
360  | 
||
361  | 
sealed case class Thm(  | 
|
362  | 
prop: Prop,  | 
|
363  | 
deps: List[String],  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
364  | 
proof: Term.Proof) extends Content[Thm]  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
365  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
366  | 
override def cache(cache: Term.Cache): Thm =  | 
| 70884 | 367  | 
Thm(  | 
368  | 
prop.cache(cache),  | 
|
| 73866 | 369  | 
deps.map(cache.string),  | 
| 70896 | 370  | 
cache.proof(proof))  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
371  | 
}  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
372  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
373  | 
def read_thms(provider: Export.Provider): List[Entity[Thm]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
374  | 
read_entities(provider, Export.THEORY_PREFIX + "thms", Kind.THM, body =>  | 
| 68418 | 375  | 
      {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
376  | 
import XML.Decode._  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
377  | 
import Term_XML.Decode._  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
378  | 
val (prop, deps, prf) = triple(decode_prop, list(string), proof)(body)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
379  | 
Thm(prop, deps, prf)  | 
| 68418 | 380  | 
})  | 
| 68264 | 381  | 
|
| 70881 | 382  | 
sealed case class Proof(  | 
383  | 
typargs: List[(String, Term.Sort)],  | 
|
384  | 
args: List[(String, Term.Typ)],  | 
|
385  | 
term: Term.Term,  | 
|
386  | 
proof: Term.Proof)  | 
|
387  | 
  {
 | 
|
| 70883 | 388  | 
def prop: Prop = Prop(typargs, args, term)  | 
389  | 
||
| 70881 | 390  | 
def cache(cache: Term.Cache): Proof =  | 
391  | 
Proof(  | 
|
392  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
|
393  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
|
394  | 
cache.term(term),  | 
|
395  | 
cache.proof(proof))  | 
|
396  | 
}  | 
|
397  | 
||
| 
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
 | 
398  | 
def read_proof(  | 
| 73024 | 399  | 
provider: Export.Provider, id: Thm_Id, cache: Term.Cache = Term.Cache.none): Option[Proof] =  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
400  | 
  {
 | 
| 72691 | 401  | 
    for { entry <- provider.focus(id.theory_name)(Export.PROOFS_PREFIX + id.serial) }
 | 
| 
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
 | 
402  | 
    yield {
 | 
| 
72847
 
9dda93a753b1
clarified signature: provide XZ.Cache where Export.Entry is created;
 
wenzelm 
parents: 
72708 
diff
changeset
 | 
403  | 
val body = entry.uncompressed_yxml  | 
| 
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
 | 
404  | 
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
 | 
405  | 
      {
 | 
| 
 
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  | 
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
 | 
407  | 
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
 | 
408  | 
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
 | 
409  | 
}  | 
| 
 
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  | 
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
 | 
411  | 
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
 | 
412  | 
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
 | 
413  | 
|
| 
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
 | 
414  | 
val result = Proof(typargs, args, prop, proof)  | 
| 73024 | 415  | 
if (cache.no_cache) result else result.cache(cache)  | 
| 
70843
 
cc987440d776
more compact XML: separate environment for free variables;
 
wenzelm 
parents: 
70790 
diff
changeset
 | 
416  | 
}  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
417  | 
}  | 
| 
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
418  | 
|
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
419  | 
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
 | 
420  | 
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
 | 
421  | 
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
 | 
422  | 
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
 | 
423  | 
suppress: Thm_Id => Boolean = _ => false,  | 
| 73024 | 424  | 
cache: Term.Cache = Term.Cache.none): List[(Thm_Id, Proof)] =  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
425  | 
  {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
426  | 
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
 | 
427  | 
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
 | 
428  | 
|
| 73340 | 429  | 
def boxes(context: Option[(Long, Term.Proof)], prf: Term.Proof): Unit =  | 
| 
71015
 
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  | 
      prf match {
 | 
| 71016 | 432  | 
case Term.Abst(_, _, p) => boxes(context, p)  | 
433  | 
case Term.AbsP(_, _, p) => boxes(context, p)  | 
|
434  | 
case Term.Appt(p, _) => boxes(context, p)  | 
|
435  | 
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
 | 
436  | 
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
 | 
437  | 
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
 | 
438  | 
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
 | 
439  | 
          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
 | 
440  | 
val read =  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
441  | 
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
 | 
442  | 
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
 | 
443  | 
            read match {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
444  | 
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
 | 
445  | 
result += (thm.serial -> (id -> p))  | 
| 71016 | 446  | 
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
 | 
447  | 
case None =>  | 
| 71016 | 448  | 
                error("Missing proof " + thm.serial + " (theory " + quote (thm.theory_name) + ")" +
 | 
449  | 
                  (context match {
 | 
|
450  | 
case None => ""  | 
|
451  | 
case Some((i, p)) => " in proof " + i + ":\n" + p  | 
|
452  | 
}))  | 
|
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
453  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
454  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
455  | 
case _ =>  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
456  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
457  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
458  | 
|
| 71016 | 459  | 
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
 | 
460  | 
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
 | 
461  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
462  | 
|
| 68264 | 463  | 
|
464  | 
/* type classes */  | 
|
465  | 
||
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
466  | 
sealed case class Class(params: List[(String, Term.Typ)], axioms: List[Prop])  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
467  | 
extends Content[Class]  | 
| 68267 | 468  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
469  | 
override def cache(cache: Term.Cache): Class =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
470  | 
Class(  | 
| 68267 | 471  | 
        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
 | 
472  | 
axioms.map(_.cache(cache)))  | 
| 68267 | 473  | 
}  | 
| 68264 | 474  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
475  | 
def read_classes(provider: Export.Provider): List[Entity[Class]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
476  | 
read_entities(provider, Export.THEORY_PREFIX + "classes", Kind.CLASS, body =>  | 
| 68418 | 477  | 
      {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
478  | 
import XML.Decode._  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
479  | 
import Term_XML.Decode._  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
480  | 
val (params, axioms) = pair(list(pair(string, typ)), list(decode_prop))(body)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
481  | 
Class(params, axioms)  | 
| 68418 | 482  | 
})  | 
| 68264 | 483  | 
|
484  | 
||
| 68862 | 485  | 
/* locales */  | 
486  | 
||
487  | 
sealed case class Locale(  | 
|
| 69019 | 488  | 
typargs: List[(String, Term.Sort)],  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
489  | 
args: List[((String, Term.Typ), Syntax)],  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
490  | 
axioms: List[Prop]) extends Content[Locale]  | 
| 68862 | 491  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
492  | 
override def cache(cache: Term.Cache): Locale =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
493  | 
Locale(  | 
| 68864 | 494  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
| 69076 | 495  | 
        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
 | 
496  | 
axioms.map(_.cache(cache)))  | 
| 68862 | 497  | 
}  | 
498  | 
||
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
499  | 
def read_locales(provider: Export.Provider): List[Entity[Locale]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
500  | 
read_entities(provider, Export.THEORY_PREFIX + "locales", Kind.LOCALE, body =>  | 
| 68862 | 501  | 
      {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
502  | 
import XML.Decode._  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
503  | 
import Term_XML.Decode._  | 
| 69019 | 504  | 
val (typargs, args, axioms) =  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
505  | 
triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)),  | 
| 69076 | 506  | 
list(decode_prop))(body)  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
507  | 
Locale(typargs, args, axioms)  | 
| 68862 | 508  | 
})  | 
509  | 
||
510  | 
||
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
511  | 
/* locale dependencies */  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
512  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
513  | 
sealed case class Locale_Dependency(  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
514  | 
source: String,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
515  | 
target: String,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
516  | 
prefix: List[(String, Boolean)],  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
517  | 
subst_types: List[((String, Term.Sort), Term.Typ)],  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
518  | 
subst_terms: List[((String, Term.Typ), Term.Term)]) extends Content[Locale_Dependency]  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
519  | 
  {
 | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
520  | 
override def cache(cache: Term.Cache): Locale_Dependency =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
521  | 
Locale_Dependency(  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
522  | 
cache.string(source),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
523  | 
cache.string(target),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
524  | 
        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
 | 
525  | 
        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
 | 
526  | 
        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
 | 
527  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
528  | 
def is_inclusion: Boolean =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
529  | 
subst_types.isEmpty && subst_terms.isEmpty  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
530  | 
}  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
531  | 
|
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
532  | 
def read_locale_dependencies(provider: Export.Provider): List[Entity[Locale_Dependency]] =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
533  | 
read_entities(provider, Export.THEORY_PREFIX + "locale_dependencies", Kind.LOCALE_DEPENDENCY,  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
534  | 
body =>  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
535  | 
        {
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
536  | 
import XML.Decode._  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
537  | 
import Term_XML.Decode._  | 
| 
74114
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
538  | 
val (source, (target, (prefix, (subst_types, subst_terms)))) =  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
539  | 
pair(string, pair(string, pair(list(pair(string, bool)),  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
540  | 
pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
541  | 
Locale_Dependency(source, target, prefix, subst_types, subst_terms)  | 
| 
 
700e5bd59c7d
clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
 
wenzelm 
parents: 
73866 
diff
changeset
 | 
542  | 
})  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
543  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
544  | 
|
| 68295 | 545  | 
/* sort algebra */  | 
546  | 
||
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
547  | 
sealed case class Classrel(class1: String, class2: String, prop: Prop)  | 
| 68295 | 548  | 
  {
 | 
549  | 
def cache(cache: Term.Cache): Classrel =  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
550  | 
Classrel(cache.string(class1), cache.string(class2), prop.cache(cache))  | 
| 68295 | 551  | 
}  | 
552  | 
||
| 68418 | 553  | 
def read_classrel(provider: Export.Provider): List[Classrel] =  | 
554  | 
  {
 | 
|
| 72691 | 555  | 
val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "classrel")  | 
| 68418 | 556  | 
val classrel =  | 
557  | 
    {
 | 
|
558  | 
import XML.Decode._  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
559  | 
list(pair(decode_prop, pair(string, string)))(body)  | 
| 68418 | 560  | 
}  | 
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
561  | 
for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop)  | 
| 68418 | 562  | 
}  | 
| 68295 | 563  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
564  | 
sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String, prop: Prop)  | 
| 68295 | 565  | 
  {
 | 
566  | 
def cache(cache: Term.Cache): Arity =  | 
|
| 73866 | 567  | 
Arity(cache.string(type_name), domain.map(cache.sort), cache.string(codomain),  | 
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
568  | 
prop.cache(cache))  | 
| 68295 | 569  | 
}  | 
570  | 
||
| 68418 | 571  | 
def read_arities(provider: Export.Provider): List[Arity] =  | 
572  | 
  {
 | 
|
| 72691 | 573  | 
val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "arities")  | 
| 68418 | 574  | 
val arities =  | 
575  | 
    {
 | 
|
576  | 
import XML.Decode._  | 
|
577  | 
import Term_XML.Decode._  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
578  | 
list(pair(decode_prop, triple(string, list(sort), string)))(body)  | 
| 68418 | 579  | 
}  | 
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
580  | 
for ((prop, (a, b, c)) <- arities) yield Arity(a, b, c, prop)  | 
| 68418 | 581  | 
}  | 
| 68295 | 582  | 
|
583  | 
||
| 70920 | 584  | 
/* Pure constdefs */  | 
585  | 
||
586  | 
sealed case class Constdef(name: String, axiom_name: String)  | 
|
587  | 
  {
 | 
|
588  | 
def cache(cache: Term.Cache): Constdef =  | 
|
589  | 
Constdef(cache.string(name), cache.string(axiom_name))  | 
|
590  | 
}  | 
|
591  | 
||
592  | 
def read_constdefs(provider: Export.Provider): List[Constdef] =  | 
|
593  | 
  {
 | 
|
| 72691 | 594  | 
val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "constdefs")  | 
| 70920 | 595  | 
val constdefs =  | 
596  | 
    {
 | 
|
597  | 
import XML.Decode._  | 
|
598  | 
list(pair(string, string))(body)  | 
|
599  | 
}  | 
|
600  | 
for ((name, axiom_name) <- constdefs) yield Constdef(name, axiom_name)  | 
|
601  | 
}  | 
|
602  | 
||
603  | 
||
| 68264 | 604  | 
/* HOL typedefs */  | 
605  | 
||
606  | 
sealed case class Typedef(name: String,  | 
|
607  | 
rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String)  | 
|
| 68267 | 608  | 
  {
 | 
609  | 
def cache(cache: Term.Cache): Typedef =  | 
|
610  | 
Typedef(cache.string(name),  | 
|
611  | 
cache.typ(rep_type),  | 
|
612  | 
cache.typ(abs_type),  | 
|
613  | 
cache.string(rep_name),  | 
|
614  | 
cache.string(abs_name),  | 
|
615  | 
cache.string(axiom_name))  | 
|
616  | 
}  | 
|
| 68264 | 617  | 
|
| 68418 | 618  | 
def read_typedefs(provider: Export.Provider): List[Typedef] =  | 
619  | 
  {
 | 
|
| 72691 | 620  | 
val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "typedefs")  | 
| 68418 | 621  | 
val typedefs =  | 
622  | 
    {
 | 
|
623  | 
import XML.Decode._  | 
|
624  | 
import Term_XML.Decode._  | 
|
625  | 
list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)  | 
|
626  | 
}  | 
|
627  | 
    for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs }
 | 
|
628  | 
yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name)  | 
|
629  | 
}  | 
|
| 71202 | 630  | 
|
631  | 
||
| 71248 | 632  | 
/* HOL datatypes */  | 
633  | 
||
634  | 
sealed case class Datatype(  | 
|
635  | 
pos: Position.T,  | 
|
636  | 
name: String,  | 
|
637  | 
co: Boolean,  | 
|
638  | 
typargs: List[(String, Term.Sort)],  | 
|
639  | 
typ: Term.Typ,  | 
|
640  | 
constructors: List[(Term.Term, Term.Typ)])  | 
|
641  | 
  {
 | 
|
642  | 
def id: Option[Long] = Position.Id.unapply(pos)  | 
|
643  | 
||
644  | 
def cache(cache: Term.Cache): Datatype =  | 
|
645  | 
Datatype(  | 
|
646  | 
cache.position(pos),  | 
|
647  | 
cache.string(name),  | 
|
648  | 
co,  | 
|
649  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
|
650  | 
cache.typ(typ),  | 
|
651  | 
        constructors.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }))
 | 
|
652  | 
}  | 
|
653  | 
||
654  | 
def read_datatypes(provider: Export.Provider): List[Datatype] =  | 
|
655  | 
  {
 | 
|
| 72691 | 656  | 
val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "datatypes")  | 
| 71248 | 657  | 
val datatypes =  | 
658  | 
    {
 | 
|
659  | 
import XML.Decode._  | 
|
660  | 
import Term_XML.Decode._  | 
|
661  | 
list(pair(properties, pair(string, pair(bool, pair(list(pair(string, sort)),  | 
|
662  | 
pair(typ, list(pair(term, typ))))))))(body)  | 
|
663  | 
}  | 
|
664  | 
for ((pos, (name, (co, (typargs, (typ, constructors))))) <- datatypes)  | 
|
665  | 
yield Datatype(pos, name, co, typargs, typ, constructors)  | 
|
666  | 
}  | 
|
667  | 
||
668  | 
||
| 71202 | 669  | 
/* Pure spec rules */  | 
670  | 
||
671  | 
sealed abstract class Recursion  | 
|
672  | 
  {
 | 
|
673  | 
def cache(cache: Term.Cache): Recursion =  | 
|
674  | 
      this match {
 | 
|
675  | 
case Primrec(types) => Primrec(types.map(cache.string))  | 
|
676  | 
case Primcorec(types) => Primcorec(types.map(cache.string))  | 
|
677  | 
case _ => this  | 
|
678  | 
}  | 
|
679  | 
}  | 
|
680  | 
case class Primrec(types: List[String]) extends Recursion  | 
|
681  | 
case object Recdef extends Recursion  | 
|
682  | 
case class Primcorec(types: List[String]) extends Recursion  | 
|
683  | 
case object Corec extends Recursion  | 
|
684  | 
case object Unknown_Recursion extends Recursion  | 
|
685  | 
||
686  | 
val decode_recursion: XML.Decode.T[Recursion] =  | 
|
687  | 
  {
 | 
|
688  | 
import XML.Decode._  | 
|
689  | 
variant(List(  | 
|
690  | 
      { case (Nil, a) => Primrec(list(string)(a)) },
 | 
|
691  | 
      { case (Nil, Nil) => Recdef },
 | 
|
692  | 
      { case (Nil, a) => Primcorec(list(string)(a)) },
 | 
|
693  | 
      { case (Nil, Nil) => Corec },
 | 
|
694  | 
      { case (Nil, Nil) => Unknown_Recursion }))
 | 
|
695  | 
}  | 
|
696  | 
||
697  | 
||
698  | 
sealed abstract class Rough_Classification  | 
|
699  | 
  {
 | 
|
700  | 
def is_equational: Boolean = this.isInstanceOf[Equational]  | 
|
701  | 
def is_inductive: Boolean = this == Inductive  | 
|
702  | 
def is_co_inductive: Boolean = this == Co_Inductive  | 
|
703  | 
def is_relational: Boolean = is_inductive || is_co_inductive  | 
|
704  | 
def is_unknown: Boolean = this == Unknown  | 
|
705  | 
||
706  | 
def cache(cache: Term.Cache): Rough_Classification =  | 
|
707  | 
      this match {
 | 
|
708  | 
case Equational(recursion) => Equational(recursion.cache(cache))  | 
|
709  | 
case _ => this  | 
|
710  | 
}  | 
|
711  | 
}  | 
|
712  | 
case class Equational(recursion: Recursion) extends Rough_Classification  | 
|
713  | 
case object Inductive extends Rough_Classification  | 
|
714  | 
case object Co_Inductive extends Rough_Classification  | 
|
715  | 
case object Unknown extends Rough_Classification  | 
|
716  | 
||
717  | 
val decode_rough_classification: XML.Decode.T[Rough_Classification] =  | 
|
718  | 
  {
 | 
|
719  | 
import XML.Decode._  | 
|
720  | 
variant(List(  | 
|
721  | 
      { case (Nil, a) => Equational(decode_recursion(a)) },
 | 
|
722  | 
      { case (Nil, Nil) => Inductive },
 | 
|
723  | 
      { case (Nil, Nil) => Co_Inductive },
 | 
|
724  | 
      { case (Nil, Nil) => Unknown }))
 | 
|
725  | 
}  | 
|
726  | 
||
727  | 
||
728  | 
sealed case class Spec_Rule(  | 
|
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
729  | 
pos: Position.T,  | 
| 71202 | 730  | 
name: String,  | 
731  | 
rough_classification: Rough_Classification,  | 
|
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
732  | 
typargs: List[(String, Term.Sort)],  | 
| 
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
733  | 
args: List[(String, Term.Typ)],  | 
| 71211 | 734  | 
terms: List[(Term.Term, Term.Typ)],  | 
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
735  | 
rules: List[Term.Term])  | 
| 71202 | 736  | 
  {
 | 
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
737  | 
def id: Option[Long] = Position.Id.unapply(pos)  | 
| 
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
738  | 
|
| 71202 | 739  | 
def cache(cache: Term.Cache): Spec_Rule =  | 
740  | 
Spec_Rule(  | 
|
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
741  | 
cache.position(pos),  | 
| 71202 | 742  | 
cache.string(name),  | 
743  | 
rough_classification.cache(cache),  | 
|
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
744  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
| 
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
745  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
| 71211 | 746  | 
        terms.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }),
 | 
| 73866 | 747  | 
rules.map(cache.term))  | 
| 71202 | 748  | 
}  | 
749  | 
||
750  | 
def read_spec_rules(provider: Export.Provider): List[Spec_Rule] =  | 
|
751  | 
  {
 | 
|
| 72691 | 752  | 
val body = provider.uncompressed_yxml(Export.THEORY_PREFIX + "spec_rules")  | 
| 71202 | 753  | 
val spec_rules =  | 
754  | 
    {
 | 
|
755  | 
import XML.Decode._  | 
|
756  | 
import Term_XML.Decode._  | 
|
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
757  | 
list(  | 
| 
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
758  | 
pair(properties, pair(string, pair(decode_rough_classification,  | 
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
759  | 
pair(list(pair(string, sort)), pair(list(pair(string, typ)),  | 
| 71211 | 760  | 
pair(list(pair(term, typ)), list(term))))))))(body)  | 
| 71202 | 761  | 
}  | 
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
762  | 
for ((pos, (name, (rough_classification, (typargs, (args, (terms, rules)))))) <- spec_rules)  | 
| 
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
763  | 
yield Spec_Rule(pos, name, rough_classification, typargs, args, terms, rules)  | 
| 71202 | 764  | 
}  | 
| 68171 | 765  | 
}  |