author | wenzelm |
Mon, 19 Aug 2019 21:23:13 +0200 | |
changeset 70579 | 5a8e3e4b3760 |
parent 70539 | 30b3c58a1933 |
child 70597 | a896257a3f07 |
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 |
||
10 |
object Export_Theory |
|
11 |
{ |
|
68206 | 12 |
/** session content **/ |
13 |
||
14 |
sealed case class Session(name: String, theory_graph: Graph[String, Theory]) |
|
15 |
{ |
|
16 |
override def toString: String = name |
|
17 |
||
18 |
def theory(theory_name: String): Theory = |
|
19 |
if (theory_graph.defined(theory_name)) theory_graph.get_node(theory_name) |
|
20 |
else error("Bad theory " + quote(theory_name)) |
|
21 |
||
22 |
def theories: List[Theory] = |
|
23 |
theory_graph.topological_order.map(theory_graph.get_node(_)) |
|
24 |
} |
|
25 |
||
68209 | 26 |
def read_session(store: Sessions.Store, |
27 |
session_name: String, |
|
68206 | 28 |
types: Boolean = true, |
68264 | 29 |
consts: Boolean = true, |
30 |
axioms: Boolean = true, |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
31 |
thms: Boolean = true, |
68264 | 32 |
classes: Boolean = true, |
68862 | 33 |
locales: Boolean = true, |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
34 |
locale_dependencies: Boolean = true, |
68295 | 35 |
classrel: Boolean = true, |
36 |
arities: Boolean = true, |
|
68862 | 37 |
typedefs: Boolean = true, |
68267 | 38 |
cache: Term.Cache = Term.make_cache()): Session = |
68206 | 39 |
{ |
40 |
val thys = |
|
68210 | 41 |
using(store.open_database(session_name))(db => |
68206 | 42 |
{ |
43 |
db.transaction { |
|
68222 | 44 |
Export.read_theory_names(db, session_name).map((theory_name: String) => |
68418 | 45 |
read_theory(Export.Provider.database(db, session_name, theory_name), |
46 |
session_name, theory_name, types = types, consts = consts, |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
47 |
axioms = axioms, thms = thms, classes = classes, locales = locales, |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
48 |
locale_dependencies = locale_dependencies, classrel = classrel, arities = arities, |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
49 |
typedefs = typedefs, cache = Some(cache))) |
68206 | 50 |
} |
51 |
}) |
|
52 |
||
53 |
val graph0 = |
|
54 |
(Graph.string[Theory] /: thys) { case (g, thy) => g.new_node(thy.name, thy) } |
|
55 |
val graph1 = |
|
56 |
(graph0 /: thys) { case (g0, thy) => |
|
57 |
(g0 /: thy.parents) { case (g1, parent) => |
|
58 |
g1.default_node(parent, empty_theory(parent)).add_edge_acyclic(parent, thy.name) } } |
|
59 |
||
60 |
Session(session_name, graph1) |
|
61 |
} |
|
62 |
||
63 |
||
64 |
||
68203 | 65 |
/** theory content **/ |
66 |
||
68346 | 67 |
val export_prefix: String = "theory/" |
70539
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
68 |
val export_prefix_proofs: String = "proofs/" |
68346 | 69 |
|
68208 | 70 |
sealed case class Theory(name: String, parents: List[String], |
71 |
types: List[Type], |
|
72 |
consts: List[Const], |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
73 |
axioms: List[Axiom], |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
74 |
thms: List[Thm], |
68264 | 75 |
classes: List[Class], |
68862 | 76 |
locales: List[Locale], |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
77 |
locale_dependencies: List[Locale_Dependency], |
68295 | 78 |
classrel: List[Classrel], |
68862 | 79 |
arities: List[Arity], |
80 |
typedefs: List[Typedef]) |
|
68206 | 81 |
{ |
82 |
override def toString: String = name |
|
68267 | 83 |
|
68711 | 84 |
lazy val entities: Set[Long] = |
85 |
Set.empty[Long] ++ |
|
86 |
types.iterator.map(_.entity.serial) ++ |
|
87 |
consts.iterator.map(_.entity.serial) ++ |
|
88 |
axioms.iterator.map(_.entity.serial) ++ |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
89 |
thms.iterator.map(_.entity.serial) ++ |
68862 | 90 |
classes.iterator.map(_.entity.serial) ++ |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
91 |
locales.iterator.map(_.entity.serial) ++ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
92 |
locale_dependencies.iterator.map(_.entity.serial) |
68711 | 93 |
|
68267 | 94 |
def cache(cache: Term.Cache): Theory = |
95 |
Theory(cache.string(name), |
|
96 |
parents.map(cache.string(_)), |
|
97 |
types.map(_.cache(cache)), |
|
98 |
consts.map(_.cache(cache)), |
|
99 |
axioms.map(_.cache(cache)), |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
100 |
thms.map(_.cache(cache)), |
68267 | 101 |
classes.map(_.cache(cache)), |
68862 | 102 |
locales.map(_.cache(cache)), |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
103 |
locale_dependencies.map(_.cache(cache)), |
68295 | 104 |
classrel.map(_.cache(cache)), |
68862 | 105 |
arities.map(_.cache(cache)), |
106 |
typedefs.map(_.cache(cache))) |
|
68206 | 107 |
} |
108 |
||
68295 | 109 |
def empty_theory(name: String): Theory = |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
110 |
Theory(name, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil) |
68203 | 111 |
|
68418 | 112 |
def read_theory(provider: Export.Provider, session_name: String, theory_name: String, |
68203 | 113 |
types: Boolean = true, |
68208 | 114 |
consts: Boolean = true, |
68232 | 115 |
axioms: Boolean = true, |
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
116 |
thms: Boolean = true, |
68264 | 117 |
classes: Boolean = true, |
68862 | 118 |
locales: Boolean = true, |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
119 |
locale_dependencies: Boolean = true, |
68295 | 120 |
classrel: Boolean = true, |
121 |
arities: Boolean = true, |
|
68862 | 122 |
typedefs: Boolean = true, |
68267 | 123 |
cache: Option[Term.Cache] = None): Theory = |
68203 | 124 |
{ |
68206 | 125 |
val parents = |
68418 | 126 |
provider(export_prefix + "parents") match { |
68231 | 127 |
case Some(entry) => split_lines(entry.uncompressed().text) |
68206 | 128 |
case None => |
129 |
error("Missing theory export in session " + quote(session_name) + ": " + |
|
130 |
quote(theory_name)) |
|
131 |
} |
|
68267 | 132 |
val theory = |
133 |
Theory(theory_name, parents, |
|
68418 | 134 |
if (types) read_types(provider) else Nil, |
135 |
if (consts) read_consts(provider) else Nil, |
|
136 |
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
|
137 |
if (thms) read_thms(provider) else Nil, |
68418 | 138 |
if (classes) read_classes(provider) else Nil, |
68862 | 139 |
if (locales) read_locales(provider) else Nil, |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
140 |
if (locale_dependencies) read_locale_dependencies(provider) else Nil, |
68418 | 141 |
if (classrel) read_classrel(provider) else Nil, |
68862 | 142 |
if (arities) read_arities(provider) else Nil, |
143 |
if (typedefs) read_typedefs(provider) else Nil) |
|
68267 | 144 |
if (cache.isDefined) theory.cache(cache.get) else theory |
68203 | 145 |
} |
146 |
||
68711 | 147 |
def read_pure_theory(store: Sessions.Store, cache: Option[Term.Cache] = None): Theory = |
68710 | 148 |
{ |
149 |
val session_name = Thy_Header.PURE |
|
150 |
val theory_name = Thy_Header.PURE |
|
151 |
||
152 |
using(store.open_database(session_name))(db => |
|
153 |
{ |
|
154 |
db.transaction { |
|
155 |
read_theory(Export.Provider.database(db, session_name, theory_name), |
|
68711 | 156 |
session_name, theory_name, cache = cache) |
68710 | 157 |
} |
158 |
}) |
|
159 |
} |
|
160 |
||
68203 | 161 |
|
68171 | 162 |
/* entities */ |
163 |
||
68714 | 164 |
object Kind extends Enumeration |
68171 | 165 |
{ |
68714 | 166 |
val TYPE = Value("type") |
167 |
val CONST = Value("const") |
|
168 |
val AXIOM = Value("axiom") |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
169 |
val THM = Value("thm") |
68714 | 170 |
val CLASS = Value("class") |
68862 | 171 |
val LOCALE = Value("locale") |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
172 |
val LOCALE_DEPENDENCY = Value("locale_dependency") |
68714 | 173 |
} |
174 |
||
68835 | 175 |
sealed case class Entity( |
68997 | 176 |
kind: Kind.Value, name: String, xname: String, pos: Position.T, id: Option[Long], serial: Long) |
68714 | 177 |
{ |
68718 | 178 |
override def toString: String = kind.toString + " " + quote(name) |
68267 | 179 |
|
180 |
def cache(cache: Term.Cache): Entity = |
|
68997 | 181 |
Entity(kind, cache.string(name), cache.string(xname), cache.position(pos), id, serial) |
68171 | 182 |
} |
183 |
||
68714 | 184 |
def decode_entity(kind: Kind.Value, tree: XML.Tree): (Entity, XML.Body) = |
68171 | 185 |
{ |
186 |
def err(): Nothing = throw new XML.XML_Body(List(tree)) |
|
187 |
||
188 |
tree match { |
|
189 |
case XML.Elem(Markup(Markup.ENTITY, props), body) => |
|
190 |
val name = Markup.Name.unapply(props) getOrElse err() |
|
68997 | 191 |
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
|
192 |
val pos = props.filter({ case (a, _) => Markup.POSITION_PROPERTIES(a) && a != Markup.ID }) |
68835 | 193 |
val id = Position.Id.unapply(props) |
68171 | 194 |
val serial = Markup.Serial.unapply(props) getOrElse err() |
68997 | 195 |
(Entity(kind, name, xname, pos, id, serial), body) |
68171 | 196 |
case _ => err() |
197 |
} |
|
198 |
} |
|
199 |
||
200 |
||
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
201 |
/* approximative syntax */ |
69003 | 202 |
|
203 |
object Assoc extends Enumeration |
|
204 |
{ |
|
205 |
val NO_ASSOC, LEFT_ASSOC, RIGHT_ASSOC = Value |
|
206 |
} |
|
207 |
||
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
208 |
sealed abstract class Syntax |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
209 |
case object No_Syntax extends Syntax |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
210 |
case class Prefix(delim: String) extends Syntax |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
211 |
case class Infix(assoc: Assoc.Value, delim: String, pri: Int) extends Syntax |
69003 | 212 |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
213 |
def decode_syntax: XML.Decode.T[Syntax] = |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
214 |
XML.Decode.variant(List( |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
215 |
{ case (Nil, Nil) => No_Syntax }, |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
216 |
{ case (List(delim), Nil) => Prefix(delim) }, |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
217 |
{ case (Nil, body) => |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
218 |
import XML.Decode._ |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
219 |
val (ass, delim, pri) = triple(int, string, int)(body) |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
220 |
Infix(Assoc(ass), delim, pri) })) |
69003 | 221 |
|
222 |
||
68171 | 223 |
/* types */ |
224 |
||
69003 | 225 |
sealed case class Type( |
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
226 |
entity: Entity, syntax: Syntax, args: List[String], abbrev: Option[Term.Typ]) |
68267 | 227 |
{ |
228 |
def cache(cache: Term.Cache): Type = |
|
229 |
Type(entity.cache(cache), |
|
69003 | 230 |
syntax, |
68267 | 231 |
args.map(cache.string(_)), |
232 |
abbrev.map(cache.typ(_))) |
|
233 |
} |
|
68171 | 234 |
|
68418 | 235 |
def read_types(provider: Export.Provider): List[Type] = |
236 |
provider.uncompressed_yxml(export_prefix + "types").map((tree: XML.Tree) => |
|
237 |
{ |
|
68714 | 238 |
val (entity, body) = decode_entity(Kind.TYPE, tree) |
69003 | 239 |
val (syntax, args, abbrev) = |
68203 | 240 |
{ |
68418 | 241 |
import XML.Decode._ |
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
242 |
triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body) |
68418 | 243 |
} |
69003 | 244 |
Type(entity, syntax, args, abbrev) |
68418 | 245 |
}) |
68171 | 246 |
|
247 |
||
248 |
/* consts */ |
|
249 |
||
68173 | 250 |
sealed case class Const( |
69003 | 251 |
entity: Entity, |
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
252 |
syntax: Syntax, |
69003 | 253 |
typargs: List[String], |
254 |
typ: Term.Typ, |
|
69988 | 255 |
abbrev: Option[Term.Term], |
69992
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
256 |
propositional: Boolean, |
69996
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
257 |
primrec_types: List[String], |
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
258 |
corecursive: Boolean) |
68267 | 259 |
{ |
260 |
def cache(cache: Term.Cache): Const = |
|
261 |
Const(entity.cache(cache), |
|
69003 | 262 |
syntax, |
68267 | 263 |
typargs.map(cache.string(_)), |
264 |
cache.typ(typ), |
|
69988 | 265 |
abbrev.map(cache.term(_)), |
69992
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
266 |
propositional, |
69996
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
267 |
primrec_types.map(cache.string(_)), |
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
268 |
corecursive) |
68267 | 269 |
} |
68171 | 270 |
|
68418 | 271 |
def read_consts(provider: Export.Provider): List[Const] = |
272 |
provider.uncompressed_yxml(export_prefix + "consts").map((tree: XML.Tree) => |
|
273 |
{ |
|
68714 | 274 |
val (entity, body) = decode_entity(Kind.CONST, tree) |
69996
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
275 |
val (syntax, (args, (typ, (abbrev, (propositional, (primrec_types, corecursive)))))) = |
68203 | 276 |
{ |
68418 | 277 |
import XML.Decode._ |
69992
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
278 |
pair(decode_syntax, |
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
279 |
pair(list(string), |
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
280 |
pair(Term_XML.Decode.typ, |
69996
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
281 |
pair(option(Term_XML.Decode.term), pair(bool, |
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
282 |
pair(list(string), bool))))))(body) |
68418 | 283 |
} |
69996
8f2d3a27aff0
more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents:
69992
diff
changeset
|
284 |
Const(entity, syntax, args, typ, abbrev, propositional, primrec_types, corecursive) |
68418 | 285 |
}) |
68208 | 286 |
|
287 |
||
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
288 |
/* axioms */ |
68232 | 289 |
|
68726 | 290 |
sealed case class Prop( |
291 |
typargs: List[(String, Term.Sort)], |
|
292 |
args: List[(String, Term.Typ)], |
|
293 |
term: Term.Term) |
|
68232 | 294 |
{ |
68726 | 295 |
def cache(cache: Term.Cache): Prop = |
296 |
Prop( |
|
297 |
typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }), |
|
298 |
args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }), |
|
299 |
cache.term(term)) |
|
68232 | 300 |
} |
68208 | 301 |
|
68726 | 302 |
def decode_prop(body: XML.Body): Prop = |
68267 | 303 |
{ |
68726 | 304 |
val (typargs, args, t) = |
305 |
{ |
|
306 |
import XML.Decode._ |
|
307 |
import Term_XML.Decode._ |
|
308 |
triple(list(pair(string, sort)), list(pair(string, typ)), term)(body) |
|
309 |
} |
|
310 |
Prop(typargs, args, t) |
|
68267 | 311 |
} |
68208 | 312 |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
313 |
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
|
314 |
{ |
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
315 |
def cache(cache: Term.Cache): Axiom = |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
316 |
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
|
317 |
} |
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70384
diff
changeset
|
318 |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
319 |
def read_axioms(provider: Export.Provider): List[Axiom] = |
68418 | 320 |
provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) => |
321 |
{ |
|
68714 | 322 |
val (entity, body) = decode_entity(Kind.AXIOM, tree) |
68726 | 323 |
val prop = decode_prop(body) |
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
324 |
Axiom(entity, prop) |
68418 | 325 |
}) |
68232 | 326 |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
327 |
|
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
328 |
/* theorems */ |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
329 |
|
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
330 |
sealed case class Thm(entity: Entity, prop: Prop, proof: Option[Term.Proof]) |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
331 |
{ |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
332 |
def cache(cache: Term.Cache): Thm = |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
333 |
Thm(entity.cache(cache), prop.cache(cache), proof.map(cache.proof _)) |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
334 |
} |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
335 |
|
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
336 |
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
|
337 |
provider.uncompressed_yxml(export_prefix + "thms").map((tree: XML.Tree) => |
68418 | 338 |
{ |
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
339 |
val (entity, body) = decode_entity(Kind.THM, tree) |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
340 |
val (prop, prf) = |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
341 |
{ |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
342 |
import XML.Decode._ |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
343 |
import Term_XML.Decode._ |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
344 |
pair(decode_prop _, option(proof))(body) |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
345 |
} |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70539
diff
changeset
|
346 |
Thm(entity, prop, prf) |
68418 | 347 |
}) |
68264 | 348 |
|
70539
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
349 |
def read_proof( |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
350 |
provider: Export.Provider, |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
351 |
theory_name: String, |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
352 |
serial: Long, |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
353 |
cache: Option[Term.Cache] = None): (Term.Term, Term.Proof) = |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
354 |
{ |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
355 |
val body = provider.focus(theory_name).uncompressed_yxml(export_prefix_proofs + serial) |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
356 |
if (body.isEmpty) error("Bad proof export " + serial) |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
357 |
val (prop, proof) = XML.Decode.pair(Term_XML.Decode.term, Term_XML.Decode.proof)(body) |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
358 |
cache match { |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
359 |
case None => (prop, proof) |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
360 |
case Some(cache) => (cache.term(prop), cache.proof(proof)) |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
361 |
} |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
362 |
} |
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70534
diff
changeset
|
363 |
|
68264 | 364 |
|
365 |
/* type classes */ |
|
366 |
||
367 |
sealed case class Class( |
|
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
368 |
entity: Entity, params: List[(String, Term.Typ)], axioms: List[Prop]) |
68267 | 369 |
{ |
370 |
def cache(cache: Term.Cache): Class = |
|
371 |
Class(entity.cache(cache), |
|
372 |
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
|
373 |
axioms.map(_.cache(cache))) |
68267 | 374 |
} |
68264 | 375 |
|
68418 | 376 |
def read_classes(provider: Export.Provider): List[Class] = |
377 |
provider.uncompressed_yxml(export_prefix + "classes").map((tree: XML.Tree) => |
|
378 |
{ |
|
68714 | 379 |
val (entity, body) = decode_entity(Kind.CLASS, tree) |
68418 | 380 |
val (params, axioms) = |
68264 | 381 |
{ |
68418 | 382 |
import XML.Decode._ |
383 |
import Term_XML.Decode._ |
|
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
384 |
pair(list(pair(string, typ)), list(decode_prop))(body) |
68418 | 385 |
} |
386 |
Class(entity, params, axioms) |
|
387 |
}) |
|
68264 | 388 |
|
389 |
||
68862 | 390 |
/* locales */ |
391 |
||
392 |
sealed case class Locale( |
|
69019 | 393 |
entity: Entity, |
394 |
typargs: List[(String, Term.Sort)], |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
395 |
args: List[((String, Term.Typ), Syntax)], |
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
396 |
axioms: List[Prop]) |
68862 | 397 |
{ |
398 |
def cache(cache: Term.Cache): Locale = |
|
399 |
Locale(entity.cache(cache), |
|
68864 | 400 |
typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }), |
69076 | 401 |
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
|
402 |
axioms.map(_.cache(cache))) |
68862 | 403 |
} |
404 |
||
405 |
def read_locales(provider: Export.Provider): List[Locale] = |
|
406 |
provider.uncompressed_yxml(export_prefix + "locales").map((tree: XML.Tree) => |
|
407 |
{ |
|
408 |
val (entity, body) = decode_entity(Kind.LOCALE, tree) |
|
69019 | 409 |
val (typargs, args, axioms) = |
68862 | 410 |
{ |
411 |
import XML.Decode._ |
|
412 |
import Term_XML.Decode._ |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
413 |
triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)), |
69076 | 414 |
list(decode_prop))(body) |
68862 | 415 |
} |
69019 | 416 |
Locale(entity, typargs, args, axioms) |
68862 | 417 |
}) |
418 |
||
419 |
||
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
420 |
/* locale dependencies */ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
421 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
422 |
sealed case class Locale_Dependency( |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
423 |
entity: Entity, |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
424 |
source: String, |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
425 |
target: String, |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
426 |
prefix: List[(String, Boolean)], |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
427 |
subst_types: List[((String, Term.Sort), Term.Typ)], |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
428 |
subst_terms: List[((String, Term.Typ), Term.Term)]) |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
429 |
{ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
430 |
def cache(cache: Term.Cache): Locale_Dependency = |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
431 |
Locale_Dependency(entity.cache(cache), |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
432 |
cache.string(source), |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
433 |
cache.string(target), |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
434 |
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
|
435 |
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
|
436 |
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
|
437 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
438 |
def is_inclusion: Boolean = |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
439 |
subst_types.isEmpty && subst_terms.isEmpty |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
440 |
} |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
441 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
442 |
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
|
443 |
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
|
444 |
{ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
445 |
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
|
446 |
val (source, (target, (prefix, (subst_types, subst_terms)))) = |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
447 |
{ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
448 |
import XML.Decode._ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
449 |
import Term_XML.Decode._ |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
450 |
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
|
451 |
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
|
452 |
} |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
453 |
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
|
454 |
}) |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
455 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69023
diff
changeset
|
456 |
|
68295 | 457 |
/* sort algebra */ |
458 |
||
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
459 |
sealed case class Classrel(class1: String, class2: String, prop: Prop) |
68295 | 460 |
{ |
461 |
def cache(cache: Term.Cache): Classrel = |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
462 |
Classrel(cache.string(class1), cache.string(class2), prop.cache(cache)) |
68295 | 463 |
} |
464 |
||
68418 | 465 |
def read_classrel(provider: Export.Provider): List[Classrel] = |
466 |
{ |
|
467 |
val body = provider.uncompressed_yxml(export_prefix + "classrel") |
|
468 |
val classrel = |
|
469 |
{ |
|
470 |
import XML.Decode._ |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
471 |
list(pair(decode_prop, pair(string, string)))(body) |
68418 | 472 |
} |
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
473 |
for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop) |
68418 | 474 |
} |
68295 | 475 |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
476 |
sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String, prop: Prop) |
68295 | 477 |
{ |
478 |
def cache(cache: Term.Cache): Arity = |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
479 |
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
|
480 |
prop.cache(cache)) |
68295 | 481 |
} |
482 |
||
68418 | 483 |
def read_arities(provider: Export.Provider): List[Arity] = |
484 |
{ |
|
485 |
val body = provider.uncompressed_yxml(export_prefix + "arities") |
|
486 |
val arities = |
|
487 |
{ |
|
488 |
import XML.Decode._ |
|
489 |
import Term_XML.Decode._ |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
490 |
list(pair(decode_prop, triple(string, list(sort), string)))(body) |
68418 | 491 |
} |
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
69996
diff
changeset
|
492 |
for ((prop, (a, b, c)) <- arities) yield Arity(a, b, c, prop) |
68418 | 493 |
} |
68295 | 494 |
|
495 |
||
68264 | 496 |
/* HOL typedefs */ |
497 |
||
498 |
sealed case class Typedef(name: String, |
|
499 |
rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String) |
|
68267 | 500 |
{ |
501 |
def cache(cache: Term.Cache): Typedef = |
|
502 |
Typedef(cache.string(name), |
|
503 |
cache.typ(rep_type), |
|
504 |
cache.typ(abs_type), |
|
505 |
cache.string(rep_name), |
|
506 |
cache.string(abs_name), |
|
507 |
cache.string(axiom_name)) |
|
508 |
} |
|
68264 | 509 |
|
68418 | 510 |
def read_typedefs(provider: Export.Provider): List[Typedef] = |
511 |
{ |
|
512 |
val body = provider.uncompressed_yxml(export_prefix + "typedefs") |
|
513 |
val typedefs = |
|
514 |
{ |
|
515 |
import XML.Decode._ |
|
516 |
import Term_XML.Decode._ |
|
517 |
list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body) |
|
518 |
} |
|
519 |
for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs } |
|
520 |
yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name) |
|
521 |
} |
|
68171 | 522 |
} |