author | wenzelm |
Sun, 03 Nov 2019 18:55:35 +0100 | |
changeset 71015 | bb49abc2ecbb |
parent 70920 | 1e0ad25c94c8 |
child 71016 | b05d78bfc67c |
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 |
|
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
434 |
def boxes(prf: Term.Proof) |
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 { |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
437 |
case Term.Abst(_, _, p) => boxes(p) |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
438 |
case Term.AbsP(_, _, p) => boxes(p) |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
439 |
case Term.Appt(p, _) => boxes(p) |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
440 |
case Term.AppP(p, q) => boxes(p); boxes(q) |
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)) |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
451 |
boxes(p.proof) |
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 => |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
453 |
error("Missing proof " + thm.serial + " (theory " + quote (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
|
454 |
} |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
455 |
} |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
456 |
case _ => |
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 |
} |
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 |
boxes(proof) |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
461 |
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
|
462 |
} |
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70920
diff
changeset
|
463 |
|
68264 | 464 |
|
465 |
/* type classes */ |
|
466 |
||
467 |
sealed case class Class( |
|
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
468 |
entity: Entity, params: List[(String, Term.Typ)], axioms: List[Prop]) |
68267 | 469 |
{ |
470 |
def cache(cache: Term.Cache): Class = |
|
471 |
Class(entity.cache(cache), |
|
472 |
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
|
473 |
axioms.map(_.cache(cache))) |
68267 | 474 |
} |
68264 | 475 |
|
68418 | 476 |
def read_classes(provider: Export.Provider): List[Class] = |
477 |
provider.uncompressed_yxml(export_prefix + "classes").map((tree: XML.Tree) => |
|
478 |
{ |
|
68714 | 479 |
val (entity, body) = decode_entity(Kind.CLASS, tree) |
68418 | 480 |
val (params, axioms) = |
68264 | 481 |
{ |
68418 | 482 |
import XML.Decode._ |
483 |
import Term_XML.Decode._ |
|
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
484 |
pair(list(pair(string, typ)), list(decode_prop))(body) |
68418 | 485 |
} |
486 |
Class(entity, params, axioms) |
|
487 |
}) |
|
68264 | 488 |
|
489 |
||
68862 | 490 |
/* locales */ |
491 |
||
492 |
sealed case class Locale( |
|
69019 | 493 |
entity: Entity, |
494 |
typargs: List[(String, Term.Sort)], |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
495 |
args: List[((String, Term.Typ), Syntax)], |
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
496 |
axioms: List[Prop]) |
68862 | 497 |
{ |
498 |
def cache(cache: Term.Cache): Locale = |
|
499 |
Locale(entity.cache(cache), |
|
68864 | 500 |
typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }), |
69076 | 501 |
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
|
502 |
axioms.map(_.cache(cache))) |
68862 | 503 |
} |
504 |
||
505 |
def read_locales(provider: Export.Provider): List[Locale] = |
|
506 |
provider.uncompressed_yxml(export_prefix + "locales").map((tree: XML.Tree) => |
|
507 |
{ |
|
508 |
val (entity, body) = decode_entity(Kind.LOCALE, tree) |
|
69019 | 509 |
val (typargs, args, axioms) = |
68862 | 510 |
{ |
511 |
import XML.Decode._ |
|
512 |
import Term_XML.Decode._ |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
513 |
triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)), |
69076 | 514 |
list(decode_prop))(body) |
68862 | 515 |
} |
69019 | 516 |
Locale(entity, typargs, args, axioms) |
68862 | 517 |
}) |
518 |
||
519 |
||
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
520 |
/* locale dependencies */ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
521 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
522 |
sealed case class Locale_Dependency( |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
523 |
entity: Entity, |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
524 |
source: String, |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
525 |
target: String, |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
526 |
prefix: List[(String, Boolean)], |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
527 |
subst_types: List[((String, Term.Sort), Term.Typ)], |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
528 |
subst_terms: List[((String, Term.Typ), Term.Term)]) |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
529 |
{ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
530 |
def cache(cache: Term.Cache): Locale_Dependency = |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
531 |
Locale_Dependency(entity.cache(cache), |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
532 |
cache.string(source), |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
533 |
cache.string(target), |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
534 |
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
|
535 |
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
|
536 |
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
|
537 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
538 |
def is_inclusion: Boolean = |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
539 |
subst_types.isEmpty && subst_terms.isEmpty |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
540 |
} |
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 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
|
543 |
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
|
544 |
{ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
545 |
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
|
546 |
val (source, (target, (prefix, (subst_types, subst_terms)))) = |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
547 |
{ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
548 |
import XML.Decode._ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
549 |
import Term_XML.Decode._ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
550 |
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
|
551 |
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
|
552 |
} |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
553 |
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
|
554 |
}) |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
555 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
556 |
|
68295 | 557 |
/* sort algebra */ |
558 |
||
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
559 |
sealed case class Classrel(class1: String, class2: String, prop: Prop) |
68295 | 560 |
{ |
561 |
def cache(cache: Term.Cache): Classrel = |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
562 |
Classrel(cache.string(class1), cache.string(class2), prop.cache(cache)) |
68295 | 563 |
} |
564 |
||
68418 | 565 |
def read_classrel(provider: Export.Provider): List[Classrel] = |
566 |
{ |
|
567 |
val body = provider.uncompressed_yxml(export_prefix + "classrel") |
|
568 |
val classrel = |
|
569 |
{ |
|
570 |
import XML.Decode._ |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
571 |
list(pair(decode_prop, pair(string, string)))(body) |
68418 | 572 |
} |
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
573 |
for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop) |
68418 | 574 |
} |
68295 | 575 |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
576 |
sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String, prop: Prop) |
68295 | 577 |
{ |
578 |
def cache(cache: Term.Cache): Arity = |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
579 |
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
|
580 |
prop.cache(cache)) |
68295 | 581 |
} |
582 |
||
68418 | 583 |
def read_arities(provider: Export.Provider): List[Arity] = |
584 |
{ |
|
585 |
val body = provider.uncompressed_yxml(export_prefix + "arities") |
|
586 |
val arities = |
|
587 |
{ |
|
588 |
import XML.Decode._ |
|
589 |
import Term_XML.Decode._ |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
590 |
list(pair(decode_prop, triple(string, list(sort), string)))(body) |
68418 | 591 |
} |
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
592 |
for ((prop, (a, b, c)) <- arities) yield Arity(a, b, c, prop) |
68418 | 593 |
} |
68295 | 594 |
|
595 |
||
70920 | 596 |
/* Pure constdefs */ |
597 |
||
598 |
sealed case class Constdef(name: String, axiom_name: String) |
|
599 |
{ |
|
600 |
def cache(cache: Term.Cache): Constdef = |
|
601 |
Constdef(cache.string(name), cache.string(axiom_name)) |
|
602 |
} |
|
603 |
||
604 |
def read_constdefs(provider: Export.Provider): List[Constdef] = |
|
605 |
{ |
|
606 |
val body = provider.uncompressed_yxml(export_prefix + "constdefs") |
|
607 |
val constdefs = |
|
608 |
{ |
|
609 |
import XML.Decode._ |
|
610 |
list(pair(string, string))(body) |
|
611 |
} |
|
612 |
for ((name, axiom_name) <- constdefs) yield Constdef(name, axiom_name) |
|
613 |
} |
|
614 |
||
615 |
||
68264 | 616 |
/* HOL typedefs */ |
617 |
||
618 |
sealed case class Typedef(name: String, |
|
619 |
rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String) |
|
68267 | 620 |
{ |
621 |
def cache(cache: Term.Cache): Typedef = |
|
622 |
Typedef(cache.string(name), |
|
623 |
cache.typ(rep_type), |
|
624 |
cache.typ(abs_type), |
|
625 |
cache.string(rep_name), |
|
626 |
cache.string(abs_name), |
|
627 |
cache.string(axiom_name)) |
|
628 |
} |
|
68264 | 629 |
|
68418 | 630 |
def read_typedefs(provider: Export.Provider): List[Typedef] = |
631 |
{ |
|
632 |
val body = provider.uncompressed_yxml(export_prefix + "typedefs") |
|
633 |
val typedefs = |
|
634 |
{ |
|
635 |
import XML.Decode._ |
|
636 |
import Term_XML.Decode._ |
|
637 |
list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body) |
|
638 |
} |
|
639 |
for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs } |
|
640 |
yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name) |
|
641 |
} |
|
68171 | 642 |
} |