-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTODO.txt
515 lines (448 loc) · 18.1 KB
/
TODO.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
//
//
//
// QUESTIONs
//
//
//
Incremental solvers and push/pop
Interpreter code that should probably be implemented ...:
// case PlainSymbol("or") =>
// (connect(for (s <- flatten("or", args))
// yield asFormula(translateTerm(s, polarity)),
// IBinJunctor.Or),
// SMTBool)
// case PlainSymbol("=>") => {
// if (args.size == 0)
// throw new Parser2InputAbsy.TranslationException(
// "Operator \"=>\" has to be applied to at least one argument")
// (connect((for (a <- args.init) yield
// !asFormula(translateTerm(a, -polarity))) ++
// List(asFormula(translateTerm(args.last, polarity))),
// IBinJunctor.Or),
// SMTBool)
// }
// case PlainSymbol("xor") => {
// if (args.size == 0)
// throw new Parser2InputAbsy.TranslationException(
// "Operator \"xor\" has to be applied to at least one argument")
// (connect(List(asFormula(translateTerm(args.head, polarity))) ++
// (for (a <- args.tail) yield
// !asFormula(translateTerm(a, -polarity))),
// IBinJunctor.Eqv),
// SMTBool)
// }
// case PlainSymbol("ite") => {
// checkArgNum("ite", 3, args)
// val transArgs = for (a <- args) yield translateTerm(a, 0)
// (transArgs map (_._2)) match {
// case Seq(SMTBool, SMTBool, SMTBool) =>
// (IFormulaITE(asFormula(transArgs(0)),
// asFormula(transArgs(1)), asFormula(transArgs(2))),
// SMTBool)
// case Seq(SMTBool, t1, t2) =>
// (ITermITE(asFormula(transArgs(0)),
// asTerm(transArgs(1)), asTerm(transArgs(2))),
// t1)
// }
// }
// case PlainSymbol("<=") =>
// (translateChainablePred(args, _ <= _), SMTBool)
// case PlainSymbol("<") =>
// (translateChainablePred(args, _ < _), SMTBool)
// case PlainSymbol(">=") =>
// (translateChainablePred(args, _ >= _), SMTBool)
// case PlainSymbol(">") =>
// (translateChainablePred(args, _ > _), SMTBool)
// case IndexedSymbol("divisible", denomStr) => {
// checkArgNum("divisible", 1, args)
// val denom = i(IdealInt(denomStr))
// val num = VariableShiftVisitor(asTerm(translateTerm(args.head, 0)), 0, 1)
// (ex(num === v(0) * denom), SMTBool)
// }
// ////////////////////////////////////////////////////////////////////////////
// // Hardcoded integer operations
// case PlainSymbol("-") if (args.length == 1) =>
// (-asTerm(translateTerm(args.head, 0), SMTInteger), SMTInteger)
// case PlainSymbol("~") if (args.length == 1) => {
// if (!tildeWarning) {
// warn("interpreting \"~\" as unary minus, like in SMT-LIB 1")
// tildeWarning = true
// }unintFunApp
// (-asTerm(translateTerm(args.head, 0), SMTInteger), SMTInteger)
// }
// case PlainSymbol("-") => {
// (asTerm(translateTerm(args.head, 0), SMTInteger) -
// sum(for (a <- args.tail)
// yield asTerm(translateTerm(a, 0), SMTInteger)),
// SMTInteger)
// }
// case PlainSymbol("*") =>
// ((for (s <- flatten("*", args))
// yield asTerm(translateTerm(s, 0), SMTInteger))
// reduceLeft (mult _),
// SMTInteger)
// case PlainSymbol("div") => {
// checkArgNum("div", 2, args)
// val Seq(num, denom) = for (a <- args) yield asTerm(translateTerm(a, 0))
// (mulTheory.eDiv(num, denom), SMTInteger)
// }
// case PlainSymbol("mod") => {
// checkArgNum("mod", 2, args)
// val Seq(num, denom) = for (a <- args) yield asTerm(translateTerm(a, 0))
// (mulTheory.eMod(num, denom), SMTInteger)
// }
// case PlainSymbol("abs") => {
// checkArgNum("abs", 1, args)
// (abs(asTerm(translateTerm(args.head, 0))), SMTInteger)
// }
////////////////////////////////////////////////////////////////////////////
// Array operations
// case PlainSymbol("select") => {
// val transArgs = for (a <- args) yield translateTerm(a, 0)
// transArgs.head._2 match {
// case SMTArray(_, resultType) =>
// (MyFunApp(SimpleArray(args.size - 1).select,
// for (a <- transArgs) yield asTerm(a)),
// resultType)
// case s =>
// throw new Exception(
// "select has to be applied to an array expression, not " + s)
// }
// }
// case PlainSymbol("store") => {
// val transArgs = for (a <- args) yield translateTerm(a, 0)
// transArgs.head._2 match {
// case s : SMTArray =>
// (IFunApp(SimpleArray(args.size - 2).store,
// for (a <- transArgs) yield asTerm(a)),
// s)
// case s =>
// throw new Exception(
// "store has to be applied to an array expression, not " + s)
// }
// }
// TODO: What does this do?
private def unintFunApp(id : String,
sym : SymbolRef, args : Seq[Term], polarity : Int)
: uppsat.ast.AST = {
val funSort = myEnv.lookup(id)
throw new Exception("Cannot handle uninterpreted function applications")
}
// (env lookupSym id) match {
// case Environment.Predicate(pred, _, _) => {
// checkArgNumLazy(printer print sym, pred.arity, args)
// (IAtom(pred, for (a <- args) yield asTerm(translateTerm(a, 0))),
// SMTBool)
// }
// case Environment.Function(fun, SMTFunctionType(_, resultType)) => {
// checkArgNumLazy(printer print sym, fun.arity, args)
// (functionDefs get fun) match {
// case Some((body, t)) => {
// var translatedArgs = List[ITerm]()
// for (a <- args)
// translatedArgs = asTerm(translateTerm(a, 0)) :: translatedArgs
// (VariableSubstVisitor(body, (translatedArgs, 0)), t)
// }
// case None =>
// (IFunApp(fun, for (a <- args) yield asTerm(translateTerm(a, 0))),
// resultType)
// }
// }
// case Environment.Constant(c, _, t) =>
// (c, t)
// case Environment.Variable(i, BoundVariable(t)) =>
// (v(i), t)
// case Environment.Variable(i, SubstExpression(e, t)) =>
// (e, t)
// }
Old interpreter code:
// Should we give warning for decl-const (Which is not SMT2)?
private var declareConstWarning = false
object IBinJunctor extends Enumeration {
val And, Or, Eqv, EqualitySign = Value
}
protected def checkArgNum(op : String, expected : Int, args : Seq[Term]) : Unit =
if (expected != args.size)
throw new Exception(
"Operator \"" + op +
"\" is applied to a wrong number of arguments: " +
((for (a <- args) yield (printer print a)) mkString ", "))
// TODO: What does this do?
// protected def asFormula(expr : (MyExpression, SMTType)) : uppsat.ast.AST = expr match {
// case (expr : MyFormula, SMTBool) =>
// expr
// // case (expr : MyTerm, SMTBool) =>
// case (expr : MyTerm, _) =>
// // then we assume that an integer encoding of boolean values was chosen
// StrangeFormula(expr.toString())
// // IIntFormula(IIntRelation.EqZero, expr)
// case (expr, _) =>
// println(expr.getClass)
// throw new Exception(
// "Expected a formula, not " + expr)
// }
// TODO: Do we have to handle SetOptionCommand?
// val annot = cmd.optionc_.asInstanceOf[Option]
// .annotation_.asInstanceOf[AttrAnnotation]
// val handled =
// handleBooleanAnnot(":print-success", annot) {
// value => printSuccess = value
// } ||
// handleBooleanAnnot(":produce-models", annot) {
// value => // nothing
// } ||
// handleBooleanAnnot(":boolean-functions-as-predicates", annot) {
// value => booleanFunctionsAsPredicates = value
// } ||
// handleBooleanAnnot(":inline-let", annot) {
// value => inlineLetExpressions = value
// } ||
// handleBooleanAnnot(":inline-definitions", annot) {
// value => inlineDefinedFuns = value
// } ||
// handleBooleanAnnot(":totality-axiom", annot) {
// value => totalityAxiom = value
// } ||
// handleBooleanAnnot(":functionality-axiom", annot) {
// value => functionalityAxiom = value
// } ||
// handleBooleanAnnot(":produce-interpolants", annot) {
// value => {
// genInterpolants = value
// if (incremental)
// prover.setConstructProofs(value)
// }
// } ||
// handleNumAnnot(":timeout-per", annot) {
// value => timeoutPer = (value min IdealInt(Int.MaxValue)).intValue
// }
// if (handled) {
// success
// } else {
// if (incremental)
// unsupported
// else
// warn("ignoring option " + annot.annotattribute_)
// }
// case t : QuantifierTerm =>
// translateQuantifier(t, polarity)
// case t : AnnotationTerm => {
// val triggers = for (annot <- t.listannotation_;
// a = annot.asInstanceOf[AttrAnnotation];
// if (a.annotattribute_ == ":pattern")) yield {
// a.attrparam_ match {
// case p : SomeAttrParam => p.sexpr_ match {
// case e : ParenSExpr =>
// for (expr <- e.listsexpr_.toList;
// transTriggers = {
// try { List(translateTrigger(expr)) }
// catch { case _ : TranslationException |
// _ : Environment.EnvironmentException => {
// warn("could not parse trigger " +
// (printer print expr) +
// ", ignoring")
// List()
// } }
// };
// t <- transTriggers) yield t
// case _ =>
// throw new Parser2InputAbsy.TranslationException(
// "Expected list of patterns after \":pattern\"")
// }
// case _ : NoAttrParam =>
// throw new Parser2InputAbsy.TranslationException(
// "Expected trigger patterns after \":pattern\"")
// }
// }
// val baseExpr =
// if (genInterpolants) {
// val names = for (annot <- t.listannotation_;
// a = annot.asInstanceOf[AttrAnnotation];
// if (a.annotattribute_ == ":named")) yield {
// a.attrparam_ match {
// case p : SomeAttrParam => p.sexpr_ match {
// case e : SymbolSExpr =>
// printer print e
// case _ =>
// throw new Parser2InputAbsy.TranslationException(
// "Expected name after \":named\"")
// }
// case _ : NoAttrParam =>
// throw new Parser2InputAbsy.TranslationException(
// "Expected name after \":named\"")
// }
// }
// translateTerm(t.term_, polarity) match {
// case p@(expr, SMTBool) =>
// ((asFormula(p) /: names) {
// case (res, name) => INamedPart(env lookupPartName name, res)
// }, SMTBool)
// case p =>
// // currently names for terms are ignored
// p
// }
// } else {
// translateTerm(t.term_, polarity)
// }
// if (triggers.isEmpty)
// baseExpr
// else
// ((asFormula(baseExpr) /: triggers) {
// case (res, trigger) => ITrigger(ITrigger.extractTerms(trigger), res)
// }, SMTBool)
// }
// case t : LetTerm =>
// translateLet(t, polarity)
// private def translateQuantifier(t : QuantifierTerm, polarity : Int)
// : (IExpression, SMTType) = {
// val quant : Quantifier = t.quantifier_ match {
// case _ : AllQuantifier => Quantifier.ALL
// case _ : ExQuantifier => Quantifier.EX
// }
// val quantNum = pushVariables(t.listsortedvariablec_)
// val body = asFormula(translateTerm(t.term_, polarity))
// // we might need guards 0 <= x <= 1 for quantifiers ranging over booleans
// val guard = connect(
// for (binderC <- t.listsortedvariablec_.iterator;
// binder = binderC.asInstanceOf[SortedVariable];
// if (translateSort(binder.sort_) == SMTBool)) yield {
// (env lookupSym asString(binder.symbol_)) match {
// case Environment.Variable(ind, _) => (v(ind) >= 0) & (v(ind) <= 1)
// case _ => { // just prevent a compiler warning
// //-BEGIN-ASSERTION-///////////////////////////////////////////////
// Debug.assertInt(SMTParser2InputAbsy.AC, false)
// //-END-ASSERTION-/////////////////////////////////////////////////
// null
// }
// }
// },
// IBinJunctor.And)
// val matrix = guard match {
// case IBoolLit(true) =>
// body
// case _ => {
// // we need to insert the guard underneath possible triggers
// def insertGuard(f : IFormula) : IFormula = f match {
// case ITrigger(pats, subF) =>
// ITrigger(pats, insertGuard(subF))
// case _ => quant match {
// case Quantifier.ALL => guard ===> f
// case Quantifier.EX => guard &&& f
// }
// }
// insertGuard(body)
// }
// }
// val res = quan(Array.fill(quantNum){quant}, matrix)
// // pop the variables from the environment
// for (_ <- PlainRange(quantNum)) env.popVar
// (res, SMTBool)
// }
// private def importProverSymbol(name : String,
// args : Seq[SMTType],
// res : SMTType) : Boolean =
// incremental &&
// ((reusedSymbols get name) match {
// case None =>
// false
// case Some(c : ConstantTerm) if (args.isEmpty) => {
// env.addConstant(c, Environment.NullaryFunction, res)
// true
// }
// case Some(f : IFunction) if (args.size == f.arity) => {
// env.addFunction(f, SMTFunctionType(args.toList, res))
// true
// }
// case Some(p : Predicate) if (args.size == p.arity && res == SMTBool) => {
// env.addPredicate(p, ())
// true
// }
// case Some(_) => {
// warn("inconsistent definition of symbol " + name)
// false
// }
// })
// ensureEnvironmentCopy
// if (!importProverSymbol(name, args, res)) {
// if (args.length > 0) {
// if (!booleanFunctionsAsPredicates || res != SMTBool) {
// // use a real function
// val f = new IFunction(name, args.length,
// !totalityAxiom, !functionalityAxiom)
// env.addFunction(f, SMTFunctionType(args.toList, res))
// if (incremental)
// prover.addFunction(f,
// if (functionalityAxiom)
// SimpleAPI.FunctionalityMode.Full
// else
// SimpleAPI.FunctionalityMode.None)
// } else {
// // use a predicate
// val p = new Predicate(name, args.length)
// env.addPredicate(p, ())
// if (incremental)
// prover.addRelation(p)
// }
// } else if (res != SMTBool) {
// // use a constant
// addConstant(new ConstantTerm(name), res)
// } else {
// // use a nullary predicate (propositional variable)
// val p = new Predicate(name, 0)
// env.addPredicate(p, ())
// if (incremental)
// prover.addRelation(p)
// }
// }
// for (Seq(a, b) <- (transArgs map (asFormula(_))) sliding 2)
// yield (
// // println("transArgs: " + transArgs.mkString(", "))
// (if (transArgs forall (_._2 == SMTBool)) {
// connect(for (Seq(a, b) <- (transArgs map (asFormula(_))) sliding 2)
// yield (a <===> b),
// IBinJunctor.And)
// } else {
// val types = (transArgs map (_._2)).toSet
// if (types.size > 1)
// throw new Parser2InputAbsy.TranslationException(
// "Can only compare terms of same type using =")
// connect(for (Seq(a, b) <- (transArgs map (asTerm(_))) sliding 2)
// yield translateEq(a, b, types.iterator.next, polarity),
// IBinJunctor.And)
// },
// SMTBool)
// private def checkArgNumLazy(op : => String, expected : Int, args : Seq[Term]) : Unit =
// if (expected != args.size) checkArgNum(op, expected, args)
// protected def checkArgNum(op : String, expected : Int, args : Seq[Term]) : Unit =
// if (expected != args.size)
// throw new Parser2InputAbsy.TranslationException(
// "Operator \"" + op +
// "\" is applied to a wrong number of arguments: " +
// ((for (a <- args) yield (printer print a)) mkString ", "))
// private def checkArgNumSExpr(op : => String, expected : Int, args : Seq[SExpr]) : Unit =
// if (expected != args.size)
// throw new Parser2InputAbsy.TranslationException(
// "Operator \"" + op +
// "\" is applied to a wrong number of arguments: " +
// ((for (a <- args) yield (printer print a)) mkString ", "))
// private object SMTConnective extends ASTConnective {
// def unapplySeq(t : Term) : scala.Option[Seq[Term]] = t match {
// case t : NullaryTerm => Some(List())
// case t : FunctionTerm => Some(t.listterm_.toList)
// }
// }
// case s : CompositeSort => asString(s.identifier_) match {
// case "Array" => {
// val args =
// for (t <- s.listsort_.toList) yield translateSort(t)
// if (args.size < 2)
// throw new Parser2InputAbsy.TranslationException(
// "Expected at least two sort arguments in " + (printer print s))
// SMTArray(args.init, args.last)
// }
// case id => {
// warn("treating sort " + (printer print s) + " as Int")
// SMTInteger
// }
// }