author | blanchet |
Fri, 17 Sep 2010 01:56:19 +0200 | |
changeset 39501 | aaa7078fff55 |
parent 39444 | beabb8443ee4 |
child 39502 | cffceed8e7fa |
permissions | -rw-r--r-- |
39348 | 1 |
(* ========================================================================= *) |
2 |
(* RANDOM FINITE MODELS *) |
|
39501
aaa7078fff55
updated source files with Metis 2.3 (timestamp: 16 Sept. 2010)
blanchet
parents:
39444
diff
changeset
|
3 |
(* Copyright (c) 2003 Joe Hurd, distributed under the MIT license *) |
39348 | 4 |
(* ========================================================================= *) |
5 |
||
6 |
signature Model = |
|
7 |
sig |
|
8 |
||
9 |
(* ------------------------------------------------------------------------- *) |
|
10 |
(* Model size. *) |
|
11 |
(* ------------------------------------------------------------------------- *) |
|
12 |
||
13 |
type size = {size : int} |
|
14 |
||
15 |
(* ------------------------------------------------------------------------- *) |
|
16 |
(* A model of size N has integer elements 0...N-1. *) |
|
17 |
(* ------------------------------------------------------------------------- *) |
|
18 |
||
19 |
type element = int |
|
20 |
||
21 |
val zeroElement : element |
|
22 |
||
23 |
val incrementElement : size -> element -> element option |
|
24 |
||
25 |
(* ------------------------------------------------------------------------- *) |
|
26 |
(* The parts of the model that are fixed. *) |
|
27 |
(* ------------------------------------------------------------------------- *) |
|
28 |
||
29 |
type fixedFunction = size -> element list -> element option |
|
30 |
||
31 |
type fixedRelation = size -> element list -> bool option |
|
32 |
||
33 |
datatype fixed = |
|
34 |
Fixed of |
|
35 |
{functions : fixedFunction NameArityMap.map, |
|
36 |
relations : fixedRelation NameArityMap.map} |
|
37 |
||
38 |
val emptyFixed : fixed |
|
39 |
||
40 |
val unionFixed : fixed -> fixed -> fixed |
|
41 |
||
42 |
val getFunctionFixed : fixed -> NameArity.nameArity -> fixedFunction |
|
43 |
||
44 |
val getRelationFixed : fixed -> NameArity.nameArity -> fixedRelation |
|
45 |
||
46 |
val insertFunctionFixed : fixed -> NameArity.nameArity * fixedFunction -> fixed |
|
47 |
||
48 |
val insertRelationFixed : fixed -> NameArity.nameArity * fixedRelation -> fixed |
|
49 |
||
50 |
val unionListFixed : fixed list -> fixed |
|
51 |
||
52 |
val basicFixed : fixed (* interprets equality and hasType *) |
|
53 |
||
54 |
(* ------------------------------------------------------------------------- *) |
|
55 |
(* Renaming fixed model parts. *) |
|
56 |
(* ------------------------------------------------------------------------- *) |
|
57 |
||
58 |
type fixedMap = |
|
59 |
{functionMap : Name.name NameArityMap.map, |
|
60 |
relationMap : Name.name NameArityMap.map} |
|
61 |
||
62 |
val mapFixed : fixedMap -> fixed -> fixed |
|
63 |
||
64 |
val ppFixedMap : fixedMap Print.pp |
|
65 |
||
66 |
(* ------------------------------------------------------------------------- *) |
|
67 |
(* Standard fixed model parts. *) |
|
68 |
(* ------------------------------------------------------------------------- *) |
|
69 |
||
70 |
(* Projections *) |
|
71 |
||
72 |
val projectionMin : int |
|
73 |
||
74 |
val projectionMax : int |
|
75 |
||
76 |
val projectionName : int -> Name.name |
|
77 |
||
78 |
val projectionFixed : fixed |
|
79 |
||
80 |
(* Arithmetic *) |
|
81 |
||
82 |
val numeralMin : int |
|
83 |
||
84 |
val numeralMax : int |
|
85 |
||
86 |
val numeralName : int -> Name.name |
|
87 |
||
88 |
val addName : Name.name |
|
89 |
||
90 |
val divName : Name.name |
|
91 |
||
92 |
val dividesName : Name.name |
|
93 |
||
94 |
val evenName : Name.name |
|
95 |
||
96 |
val expName : Name.name |
|
97 |
||
98 |
val geName : Name.name |
|
99 |
||
100 |
val gtName : Name.name |
|
101 |
||
102 |
val isZeroName : Name.name |
|
103 |
||
104 |
val leName : Name.name |
|
105 |
||
106 |
val ltName : Name.name |
|
107 |
||
108 |
val modName : Name.name |
|
109 |
||
110 |
val multName : Name.name |
|
111 |
||
112 |
val negName : Name.name |
|
113 |
||
114 |
val oddName : Name.name |
|
115 |
||
116 |
val preName : Name.name |
|
117 |
||
118 |
val subName : Name.name |
|
119 |
||
120 |
val sucName : Name.name |
|
121 |
||
122 |
val modularFixed : fixed |
|
123 |
||
124 |
val overflowFixed : fixed |
|
125 |
||
126 |
(* Sets *) |
|
127 |
||
128 |
val cardName : Name.name |
|
129 |
||
130 |
val complementName : Name.name |
|
131 |
||
132 |
val differenceName : Name.name |
|
133 |
||
134 |
val emptyName : Name.name |
|
135 |
||
136 |
val memberName : Name.name |
|
137 |
||
138 |
val insertName : Name.name |
|
139 |
||
140 |
val intersectName : Name.name |
|
141 |
||
142 |
val singletonName : Name.name |
|
143 |
||
144 |
val subsetName : Name.name |
|
145 |
||
146 |
val symmetricDifferenceName : Name.name |
|
147 |
||
148 |
val unionName : Name.name |
|
149 |
||
150 |
val universeName : Name.name |
|
151 |
||
152 |
val setFixed : fixed |
|
153 |
||
154 |
(* Lists *) |
|
155 |
||
156 |
val appendName : Name.name |
|
157 |
||
158 |
val consName : Name.name |
|
159 |
||
160 |
val lengthName : Name.name |
|
161 |
||
162 |
val nilName : Name.name |
|
163 |
||
164 |
val nullName : Name.name |
|
165 |
||
166 |
val tailName : Name.name |
|
167 |
||
168 |
val listFixed : fixed |
|
169 |
||
170 |
(* ------------------------------------------------------------------------- *) |
|
171 |
(* Valuations. *) |
|
172 |
(* ------------------------------------------------------------------------- *) |
|
173 |
||
174 |
type valuation |
|
175 |
||
176 |
val emptyValuation : valuation |
|
177 |
||
178 |
val zeroValuation : NameSet.set -> valuation |
|
179 |
||
180 |
val constantValuation : element -> NameSet.set -> valuation |
|
181 |
||
182 |
val peekValuation : valuation -> Name.name -> element option |
|
183 |
||
184 |
val getValuation : valuation -> Name.name -> element |
|
185 |
||
186 |
val insertValuation : valuation -> Name.name * element -> valuation |
|
187 |
||
188 |
val randomValuation : {size : int} -> NameSet.set -> valuation |
|
189 |
||
190 |
val incrementValuation : |
|
191 |
{size : int} -> NameSet.set -> valuation -> valuation option |
|
192 |
||
193 |
val foldValuation : |
|
194 |
{size : int} -> NameSet.set -> (valuation * 'a -> 'a) -> 'a -> 'a |
|
195 |
||
196 |
(* ------------------------------------------------------------------------- *) |
|
197 |
(* A type of random finite models. *) |
|
198 |
(* ------------------------------------------------------------------------- *) |
|
199 |
||
200 |
type parameters = {size : int, fixed : fixed} |
|
201 |
||
202 |
type model |
|
203 |
||
204 |
val default : parameters |
|
205 |
||
206 |
val new : parameters -> model |
|
207 |
||
208 |
val size : model -> int |
|
209 |
||
210 |
(* ------------------------------------------------------------------------- *) |
|
211 |
(* Interpreting terms and formulas in the model. *) |
|
212 |
(* ------------------------------------------------------------------------- *) |
|
213 |
||
214 |
val interpretFunction : model -> Term.functionName * element list -> element |
|
215 |
||
216 |
val interpretRelation : model -> Atom.relationName * element list -> bool |
|
217 |
||
218 |
val interpretTerm : model -> valuation -> Term.term -> element |
|
219 |
||
220 |
val interpretAtom : model -> valuation -> Atom.atom -> bool |
|
221 |
||
222 |
val interpretFormula : model -> valuation -> Formula.formula -> bool |
|
223 |
||
224 |
val interpretLiteral : model -> valuation -> Literal.literal -> bool |
|
225 |
||
226 |
val interpretClause : model -> valuation -> Thm.clause -> bool |
|
227 |
||
228 |
(* ------------------------------------------------------------------------- *) |
|
229 |
(* Check whether random groundings of a formula are true in the model. *) |
|
230 |
(* Note: if it's cheaper, a systematic check will be performed instead. *) |
|
231 |
(* ------------------------------------------------------------------------- *) |
|
232 |
||
233 |
val check : |
|
234 |
(model -> valuation -> 'a -> bool) -> {maxChecks : int option} -> model -> |
|
235 |
NameSet.set -> 'a -> {T : int, F : int} |
|
236 |
||
237 |
val checkAtom : |
|
238 |
{maxChecks : int option} -> model -> Atom.atom -> {T : int, F : int} |
|
239 |
||
240 |
val checkFormula : |
|
241 |
{maxChecks : int option} -> model -> Formula.formula -> {T : int, F : int} |
|
242 |
||
243 |
val checkLiteral : |
|
244 |
{maxChecks : int option} -> model -> Literal.literal -> {T : int, F : int} |
|
245 |
||
246 |
val checkClause : |
|
247 |
{maxChecks : int option} -> model -> Thm.clause -> {T : int, F : int} |
|
248 |
||
249 |
(* ------------------------------------------------------------------------- *) |
|
250 |
(* Updating the model. *) |
|
251 |
(* ------------------------------------------------------------------------- *) |
|
252 |
||
253 |
val updateFunction : |
|
254 |
model -> (Term.functionName * element list) * element -> unit |
|
255 |
||
256 |
val updateRelation : |
|
257 |
model -> (Atom.relationName * element list) * bool -> unit |
|
258 |
||
259 |
(* ------------------------------------------------------------------------- *) |
|
260 |
(* Choosing a random perturbation to make a formula true in the model. *) |
|
261 |
(* ------------------------------------------------------------------------- *) |
|
262 |
||
263 |
val perturbTerm : model -> valuation -> Term.term * element list -> unit |
|
264 |
||
265 |
val perturbAtom : model -> valuation -> Atom.atom * bool -> unit |
|
266 |
||
267 |
val perturbLiteral : model -> valuation -> Literal.literal -> unit |
|
268 |
||
269 |
val perturbClause : model -> valuation -> Thm.clause -> unit |
|
270 |
||
271 |
(* ------------------------------------------------------------------------- *) |
|
272 |
(* Pretty printing. *) |
|
273 |
(* ------------------------------------------------------------------------- *) |
|
274 |
||
275 |
val pp : model Print.pp |
|
276 |
||
277 |
end |