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