author | wenzelm |
Wed, 20 Oct 2021 18:13:17 +0200 | |
changeset 74561 | 8e6c973003c8 |
parent 74121 | bc03b0b82fe6 |
child 74731 | 161e84e6b40a |
permissions | -rw-r--r-- |
43730 | 1 |
/* Title: Pure/term.scala |
2 |
Author: Makarius |
|
3 |
||
43779 | 4 |
Lambda terms, types, sorts. |
43730 | 5 |
|
6 |
Note: Isabelle/ML is the primary environment for logical operations. |
|
7 |
*/ |
|
8 |
||
9 |
package isabelle |
|
10 |
||
11 |
||
12 |
object Term |
|
13 |
{ |
|
70383
38ac2e714729
more operations (avoid clones in Isabelle/MMT and Isabelle/Dedukti);
wenzelm
parents:
68265
diff
changeset
|
14 |
/* types and terms */ |
38ac2e714729
more operations (avoid clones in Isabelle/MMT and Isabelle/Dedukti);
wenzelm
parents:
68265
diff
changeset
|
15 |
|
70852 | 16 |
sealed case class Indexname(name: String, index: Int = 0) |
70537
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
17 |
{ |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
18 |
private lazy val hash: Int = (name, index).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
19 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
20 |
|
70537
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
21 |
override def toString: String = |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
22 |
if (index == -1) name |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
23 |
else { |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
24 |
val dot = |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
25 |
Symbol.explode(name).reverse match { |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
26 |
case _ :: s :: _ if s == Symbol.sub_decoded || s == Symbol.sub => false |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
27 |
case c :: _ => Symbol.is_digit(c) |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
28 |
case _ => true |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
29 |
} |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
30 |
if (dot) "?" + name + "." + index |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
31 |
else if (index != 0) "?" + name + index |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
32 |
else "?" + name |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
33 |
} |
17160e0a60b6
Indexname.toString according to string_of_vname' in ML;
wenzelm
parents:
70536
diff
changeset
|
34 |
} |
43730 | 35 |
|
70850 | 36 |
type Class = String |
37 |
type Sort = List[Class] |
|
43730 | 38 |
|
39 |
sealed abstract class Typ |
|
40 |
case class Type(name: String, args: List[Typ] = Nil) extends Typ |
|
70846 | 41 |
{ |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
42 |
private lazy val hash: Int = ("Type", name, args).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
43 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
44 |
|
70846 | 45 |
override def toString: String = |
46 |
if (this == dummyT) "_" |
|
47 |
else "Type(" + name + (if (args.isEmpty) "" else "," + args) + ")" |
|
48 |
} |
|
70851 | 49 |
case class TFree(name: String, sort: Sort = Nil) extends Typ |
70846 | 50 |
{ |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
51 |
private lazy val hash: Int = ("TFree", name, sort).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
52 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
53 |
|
70846 | 54 |
override def toString: String = |
70851 | 55 |
"TFree(" + name + (if (sort.isEmpty) "" else "," + sort) + ")" |
70846 | 56 |
} |
70851 | 57 |
case class TVar(name: Indexname, sort: Sort = Nil) extends Typ |
70846 | 58 |
{ |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
59 |
private lazy val hash: Int = ("TVar", name, sort).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
60 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
61 |
|
70846 | 62 |
override def toString: String = |
70851 | 63 |
"TVar(" + name + (if (sort.isEmpty) "" else "," + sort) + ")" |
70846 | 64 |
} |
71601 | 65 |
val dummyT: Type = Type("dummy") |
43730 | 66 |
|
67 |
sealed abstract class Term |
|
71221 | 68 |
{ |
69 |
def head: Term = |
|
70 |
this match { |
|
71 |
case App(fun, _) => fun.head |
|
72 |
case _ => this |
|
73 |
} |
|
74 |
} |
|
70846 | 75 |
case class Const(name: String, typargs: List[Typ] = Nil) extends Term |
76 |
{ |
|
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
77 |
private lazy val hash: Int = ("Const", name, typargs).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
78 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
79 |
|
70846 | 80 |
override def toString: String = |
70897 | 81 |
if (this == dummy) "_" |
82 |
else "Const(" + name + (if (typargs.isEmpty) "" else "," + typargs) + ")" |
|
70846 | 83 |
} |
43730 | 84 |
case class Free(name: String, typ: Typ = dummyT) extends Term |
70846 | 85 |
{ |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
86 |
private lazy val hash: Int = ("Free", name, typ).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
87 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
88 |
|
70846 | 89 |
override def toString: String = |
90 |
"Free(" + name + (if (typ == dummyT) "" else "," + typ) + ")" |
|
91 |
} |
|
43730 | 92 |
case class Var(name: Indexname, typ: Typ = dummyT) extends Term |
70846 | 93 |
{ |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
94 |
private lazy val hash: Int = ("Var", name, typ).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
95 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
96 |
|
70846 | 97 |
override def toString: String = |
98 |
"Var(" + name + (if (typ == dummyT) "" else "," + typ) + ")" |
|
99 |
} |
|
43730 | 100 |
case class Bound(index: Int) extends Term |
70846 | 101 |
case class Abs(name: String, typ: Typ, body: Term) extends Term |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
102 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
103 |
private lazy val hash: Int = ("Abs", name, typ, body).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
104 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
105 |
} |
43730 | 106 |
case class App(fun: Term, arg: Term) extends Term |
70850 | 107 |
{ |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
108 |
private lazy val hash: Int = ("App", fun, arg).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
109 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
110 |
|
70850 | 111 |
override def toString: String = |
112 |
this match { |
|
113 |
case OFCLASS(ty, c) => "OFCLASS(" + ty + "," + c + ")" |
|
114 |
case _ => "App(" + fun + "," + arg + ")" |
|
115 |
} |
|
116 |
} |
|
68265 | 117 |
|
70897 | 118 |
def dummy_pattern(ty: Typ): Term = Const("Pure.dummy_pattern", List(ty)) |
119 |
val dummy: Term = dummy_pattern(dummyT) |
|
120 |
||
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
121 |
sealed abstract class Proof |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
122 |
case object MinProof extends Proof |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
123 |
case class PBound(index: Int) extends Proof |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
124 |
case class Abst(name: String, typ: Typ, body: Proof) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
125 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
126 |
private lazy val hash: Int = ("Abst", name, typ, body).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
127 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
128 |
} |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
129 |
case class AbsP(name: String, hyp: Term, body: Proof) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
130 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
131 |
private lazy val hash: Int = ("AbsP", name, hyp, body).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
132 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
133 |
} |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
134 |
case class Appt(fun: Proof, arg: Term) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
135 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
136 |
private lazy val hash: Int = ("Appt", fun, arg).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
137 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
138 |
} |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
139 |
case class AppP(fun: Proof, arg: Proof) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
140 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
141 |
private lazy val hash: Int = ("AppP", fun, arg).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
142 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
143 |
} |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
144 |
case class Hyp(hyp: Term) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
145 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
146 |
private lazy val hash: Int = ("Hyp", hyp).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
147 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
148 |
} |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
149 |
case class PAxm(name: String, types: List[Typ]) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
150 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
151 |
private lazy val hash: Int = ("PAxm", name, types).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
152 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
153 |
} |
71777
3875815f5967
clarified signature: avoid clash with Isabelle/Scala Term.OFCLASS on case-insensible file-system;
wenzelm
parents:
71601
diff
changeset
|
154 |
case class PClass(typ: Typ, cls: Class) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
155 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
156 |
private lazy val hash: Int = ("PClass", typ, cls).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
157 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
158 |
} |
70834 | 159 |
case class Oracle(name: String, prop: Term, types: List[Typ]) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
160 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
161 |
private lazy val hash: Int = ("Oracle", name, prop, types).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
162 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
163 |
} |
70916
4c15217d6266
clarified signature: name of standard_proof is authentic, otherwise empty;
wenzelm
parents:
70897
diff
changeset
|
164 |
case class PThm(serial: Long, theory_name: String, name: String, types: List[Typ]) extends Proof |
74121
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
165 |
{ |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
166 |
private lazy val hash: Int = ("PThm", serial, theory_name, name, types).hashCode() |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
167 |
override def hashCode(): Int = hash |
bc03b0b82fe6
prefer persistent hash code for cachable items (see also 72b13af7f266);
wenzelm
parents:
73031
diff
changeset
|
168 |
} |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
169 |
|
68265 | 170 |
|
70850 | 171 |
/* type classes within the logic */ |
70385
68d2c533db9c
more operations: support type classes within the logic;
wenzelm
parents:
70383
diff
changeset
|
172 |
|
70850 | 173 |
object Class_Const |
174 |
{ |
|
175 |
val suffix = "_class" |
|
176 |
def apply(c: Class): String = c + suffix |
|
177 |
def unapply(s: String): Option[Class] = |
|
178 |
if (s.endsWith(suffix)) Some(s.substring(0, s.length - suffix.length)) else None |
|
179 |
} |
|
70385
68d2c533db9c
more operations: support type classes within the logic;
wenzelm
parents:
70383
diff
changeset
|
180 |
|
70850 | 181 |
object OFCLASS |
182 |
{ |
|
183 |
def apply(ty: Typ, s: Sort): List[Term] = s.map(c => apply(ty, c)) |
|
184 |
||
185 |
def apply(ty: Typ, c: Class): Term = |
|
186 |
App(Const(Class_Const(c), List(ty)), Const(Pure_Thy.TYPE, List(ty))) |
|
70385
68d2c533db9c
more operations: support type classes within the logic;
wenzelm
parents:
70383
diff
changeset
|
187 |
|
70850 | 188 |
def unapply(t: Term): Option[(Typ, String)] = |
189 |
t match { |
|
190 |
case App(Const(Class_Const(c), List(ty)), Const(Pure_Thy.TYPE, List(ty1))) |
|
191 |
if ty == ty1 => Some((ty, c)) |
|
192 |
case _ => None |
|
193 |
} |
|
70385
68d2c533db9c
more operations: support type classes within the logic;
wenzelm
parents:
70383
diff
changeset
|
194 |
} |
68d2c533db9c
more operations: support type classes within the logic;
wenzelm
parents:
70383
diff
changeset
|
195 |
|
68d2c533db9c
more operations: support type classes within the logic;
wenzelm
parents:
70383
diff
changeset
|
196 |
|
68265 | 197 |
|
198 |
/** cache **/ |
|
199 |
||
73024 | 200 |
object Cache |
201 |
{ |
|
202 |
def make( |
|
73026
237bd6318cc1
more uniform default --- hardly relevant in practice;
wenzelm
parents:
73024
diff
changeset
|
203 |
max_string: Int = isabelle.Cache.default_max_string, |
73024 | 204 |
initial_size: Int = isabelle.Cache.default_initial_size): Cache = |
205 |
new Cache(initial_size, max_string) |
|
68265 | 206 |
|
73024 | 207 |
val none: Cache = make(max_string = 0) |
208 |
} |
|
209 |
||
210 |
class Cache private[Term](max_string: Int, initial_size: Int) |
|
73031
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
wenzelm
parents:
73026
diff
changeset
|
211 |
extends isabelle.Cache(max_string, initial_size) |
68265 | 212 |
{ |
213 |
protected def cache_indexname(x: Indexname): Indexname = |
|
70536 | 214 |
lookup(x) getOrElse store(Indexname(cache_string(x.name), x.index)) |
68265 | 215 |
|
216 |
protected def cache_sort(x: Sort): Sort = |
|
73024 | 217 |
if (x.isEmpty) Nil |
218 |
else lookup(x) getOrElse store(x.map(cache_string)) |
|
68265 | 219 |
|
220 |
protected def cache_typ(x: Typ): Typ = |
|
221 |
{ |
|
222 |
if (x == dummyT) dummyT |
|
223 |
else |
|
224 |
lookup(x) match { |
|
225 |
case Some(y) => y |
|
226 |
case None => |
|
227 |
x match { |
|
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
228 |
case Type(name, args) => store(Type(cache_string(name), cache_typs(args))) |
68265 | 229 |
case TFree(name, sort) => store(TFree(cache_string(name), cache_sort(sort))) |
230 |
case TVar(name, sort) => store(TVar(cache_indexname(name), cache_sort(sort))) |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
||
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
235 |
protected def cache_typs(x: List[Typ]): List[Typ] = |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
236 |
{ |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
237 |
if (x.isEmpty) Nil |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
238 |
else { |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
239 |
lookup(x) match { |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
240 |
case Some(y) => y |
71601 | 241 |
case None => store(x.map(cache_typ)) |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
242 |
} |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
243 |
} |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
244 |
} |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
245 |
|
68265 | 246 |
protected def cache_term(x: Term): Term = |
247 |
{ |
|
248 |
lookup(x) match { |
|
249 |
case Some(y) => y |
|
250 |
case None => |
|
251 |
x match { |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70559
diff
changeset
|
252 |
case Const(name, typargs) => store(Const(cache_string(name), cache_typs(typargs))) |
68265 | 253 |
case Free(name, typ) => store(Free(cache_string(name), cache_typ(typ))) |
254 |
case Var(name, typ) => store(Var(cache_indexname(name), cache_typ(typ))) |
|
70536 | 255 |
case Bound(_) => store(x) |
68265 | 256 |
case Abs(name, typ, body) => |
257 |
store(Abs(cache_string(name), cache_typ(typ), cache_term(body))) |
|
258 |
case App(fun, arg) => store(App(cache_term(fun), cache_term(arg))) |
|
259 |
} |
|
260 |
} |
|
261 |
} |
|
262 |
||
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
263 |
protected def cache_proof(x: Proof): Proof = |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
264 |
{ |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
265 |
if (x == MinProof) MinProof |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
266 |
else { |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
267 |
lookup(x) match { |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
268 |
case Some(y) => y |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
269 |
case None => |
71781 | 270 |
(x: @unchecked) match { |
70536 | 271 |
case PBound(_) => store(x) |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
272 |
case Abst(name, typ, body) => |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
273 |
store(Abst(cache_string(name), cache_typ(typ), cache_proof(body))) |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
274 |
case AbsP(name, hyp, body) => |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
275 |
store(AbsP(cache_string(name), cache_term(hyp), cache_proof(body))) |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
276 |
case Appt(fun, arg) => store(Appt(cache_proof(fun), cache_term(arg))) |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
277 |
case AppP(fun, arg) => store(AppP(cache_proof(fun), cache_proof(arg))) |
70535 | 278 |
case Hyp(hyp) => store(Hyp(cache_term(hyp))) |
279 |
case PAxm(name, types) => store(PAxm(cache_string(name), cache_typs(types))) |
|
71777
3875815f5967
clarified signature: avoid clash with Isabelle/Scala Term.OFCLASS on case-insensible file-system;
wenzelm
parents:
71601
diff
changeset
|
280 |
case PClass(typ, cls) => store(PClass(cache_typ(typ), cache_string(cls))) |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
281 |
case Oracle(name, prop, types) => |
70834 | 282 |
store(Oracle(cache_string(name), cache_term(prop), cache_typs(types))) |
70538
fc9ba6fe367f
clarified PThm: theory_name simplifies retrieval from exports;
wenzelm
parents:
70537
diff
changeset
|
283 |
case PThm(serial, theory_name, name, types) => |
fc9ba6fe367f
clarified PThm: theory_name simplifies retrieval from exports;
wenzelm
parents:
70537
diff
changeset
|
284 |
store(PThm(serial, cache_string(theory_name), cache_string(name), cache_typs(types))) |
70533
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
285 |
} |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
286 |
} |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
287 |
} |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
288 |
} |
031620901fcd
support for (fully reconstructed) proof terms in Scala;
wenzelm
parents:
70385
diff
changeset
|
289 |
|
68265 | 290 |
// main methods |
73024 | 291 |
def indexname(x: Indexname): Indexname = |
292 |
if (no_cache) x else synchronized { cache_indexname(x) } |
|
293 |
def sort(x: Sort): Sort = |
|
294 |
if (no_cache) x else synchronized { cache_sort(x) } |
|
295 |
def typ(x: Typ): Typ = |
|
296 |
if (no_cache) x else synchronized { cache_typ(x) } |
|
297 |
def term(x: Term): Term = |
|
298 |
if (no_cache) x else synchronized { cache_term(x) } |
|
299 |
def proof(x: Proof): Proof = |
|
300 |
if (no_cache) x else synchronized { cache_proof(x) } |
|
68265 | 301 |
|
302 |
def position(x: Position.T): Position.T = |
|
73024 | 303 |
if (no_cache) x |
304 |
else synchronized { x.map({ case (a, b) => (cache_string(a), cache_string(b)) }) } |
|
68265 | 305 |
} |
43731
70072780e095
inner syntax supports inlined YXML according to Term_XML (particularly useful for producing text under program control);
wenzelm
parents:
43730
diff
changeset
|
306 |
} |