1 package cvc3;
2 
3 import java.util.*;
4 
5 public class Expr extends Embedded {
6     // jni methods
7     private static native boolean
jniEquals(Object Expr1, Object Expr2)8 	jniEquals(Object Expr1, Object Expr2) throws Cvc3Exception;
9     private static native String
jniToString(Object Expr)10 	jniToString(Object Expr) throws Cvc3Exception;
11     private static native void
jniPrint(Object Expr, String InputLanguage, boolean dagify)12 	jniPrint(Object Expr, String InputLanguage, boolean dagify) throws Cvc3Exception;
13     private static native int
jniHash(Object Expr)14 	jniHash(Object Expr) throws Cvc3Exception;
15 
16     private static native String
jniGetKind(Object Expr)17     jniGetKind(Object Expr) throws Cvc3Exception;
18 
19     private static native boolean
jniIsFalse(Object Expr)20 	jniIsFalse(Object Expr) throws Cvc3Exception;
21     private static native boolean
jniIsTrue(Object Expr)22 	jniIsTrue(Object Expr) throws Cvc3Exception;
23     private static native boolean
jniIsBoolConst(Object Expr)24 	jniIsBoolConst(Object Expr) throws Cvc3Exception;
25     private static native boolean
jniIsVar(Object Expr)26 	jniIsVar(Object Expr) throws Cvc3Exception;
27     private static native boolean
jniIsBoundVar(Object Expr)28 	jniIsBoundVar(Object Expr) throws Cvc3Exception;
29     private static native boolean
jniIsString(Object Expr)30 	jniIsString(Object Expr) throws Cvc3Exception;
31     private static native boolean
jniIsClosure(Object Expr)32 	jniIsClosure(Object Expr) throws Cvc3Exception;
33     private static native boolean
jniIsQuantifier(Object Expr)34 	jniIsQuantifier(Object Expr) throws Cvc3Exception;
35     private static native boolean
jniIsLambda(Object Expr)36 	jniIsLambda(Object Expr) throws Cvc3Exception;
37     private static native boolean
jniIsApply(Object Expr)38 	jniIsApply(Object Expr) throws Cvc3Exception;
39     private static native boolean
jniIsSymbol(Object Expr)40 	jniIsSymbol(Object Expr) throws Cvc3Exception;
41     private static native boolean
jniIsTheorem(Object Expr)42 	jniIsTheorem(Object Expr) throws Cvc3Exception;
43     private static native boolean
jniIsType(Object Expr)44 	jniIsType(Object Expr) throws Cvc3Exception;
45     private static native boolean
jniIsTerm(Object Expr)46 	jniIsTerm(Object Expr) throws Cvc3Exception;
47     private static native boolean
jniIsAtomic(Object Expr)48 	jniIsAtomic(Object Expr) throws Cvc3Exception;
49     private static native boolean
jniIsAtomicFormula(Object Expr)50 	jniIsAtomicFormula(Object Expr) throws Cvc3Exception;
51     private static native boolean
jniIsAbsAtomicFormula(Object Expr)52 	jniIsAbsAtomicFormula(Object Expr) throws Cvc3Exception;
53     private static native boolean
jniIsLiteral(Object Expr)54 	jniIsLiteral(Object Expr) throws Cvc3Exception;
55     private static native boolean
jniIsAbsLiteral(Object Expr)56 	jniIsAbsLiteral(Object Expr) throws Cvc3Exception;
57     private static native boolean
jniIsBoolConnective(Object Expr)58 	jniIsBoolConnective(Object Expr) throws Cvc3Exception;
59     private static native boolean
jniIsPropAtom(Object Expr)60 	jniIsPropAtom(Object Expr) throws Cvc3Exception;
61     private static native boolean
jniIsPropLiteral(Object Expr)62 	jniIsPropLiteral(Object Expr) throws Cvc3Exception;
63     private static native boolean
jniIsArrayLiteral(Object Expr)64     jniIsArrayLiteral(Object Expr) throws Cvc3Exception;
65     private static native boolean
jniIsEq(Object Expr)66 	jniIsEq(Object Expr) throws Cvc3Exception;
67     private static native boolean
jniIsNot(Object Expr)68 	jniIsNot(Object Expr) throws Cvc3Exception;
69     private static native boolean
jniIsAnd(Object Expr)70 	jniIsAnd(Object Expr) throws Cvc3Exception;
71     private static native boolean
jniIsOr(Object Expr)72 	jniIsOr(Object Expr) throws Cvc3Exception;
73     private static native boolean
jniIsITE(Object Expr)74 	jniIsITE(Object Expr) throws Cvc3Exception;
75     private static native boolean
jniIsIff(Object Expr)76 	jniIsIff(Object Expr) throws Cvc3Exception;
77     private static native boolean
jniIsImpl(Object Expr)78 	jniIsImpl(Object Expr) throws Cvc3Exception;
79     private static native boolean
jniIsXor(Object Expr)80 	jniIsXor(Object Expr) throws Cvc3Exception;
81     private static native boolean
jniIsForall(Object Expr)82 	jniIsForall(Object Expr) throws Cvc3Exception;
83     private static native boolean
jniIsExists(Object Expr)84 	jniIsExists(Object Expr) throws Cvc3Exception;
85     private static native boolean
jniIsRational(Object Expr)86 	jniIsRational(Object Expr) throws Cvc3Exception;
87     private static native boolean
jniIsUminus(Object Expr)88 	jniIsUminus(Object Expr) throws Cvc3Exception;
89     private static native boolean
jniIsPlus(Object Expr)90 	jniIsPlus(Object Expr) throws Cvc3Exception;
91     private static native boolean
jniIsMinus(Object Expr)92 	jniIsMinus(Object Expr) throws Cvc3Exception;
93     private static native boolean
jniIsMult(Object Expr)94 	jniIsMult(Object Expr) throws Cvc3Exception;
95     private static native boolean
jniIsPow(Object Expr)96 	jniIsPow(Object Expr) throws Cvc3Exception;
97     private static native boolean
jniIsDivide(Object Expr)98 	jniIsDivide(Object Expr) throws Cvc3Exception;
99     private static native boolean
jniIsLt(Object Expr)100 	jniIsLt(Object Expr) throws Cvc3Exception;
101     private static native boolean
jniIsLe(Object Expr)102 	jniIsLe(Object Expr) throws Cvc3Exception;
103     private static native boolean
jniIsGt(Object Expr)104 	jniIsGt(Object Expr) throws Cvc3Exception;
105     private static native boolean
jniIsGe(Object Expr)106 	jniIsGe(Object Expr) throws Cvc3Exception;
107     private static native boolean
jniIsSkolem(Object Expr)108 	jniIsSkolem(Object Expr) throws Cvc3Exception;
109     private static native boolean
jniIsRead(Object Expr)110 	jniIsRead(Object Expr) throws Cvc3Exception;
111     private static native boolean
jniIsWrite(Object Expr)112 	jniIsWrite(Object Expr) throws Cvc3Exception;
113 
114     private static native String
jniGetName(Object Expr)115 	jniGetName(Object Expr) throws Cvc3Exception;
116     private static native String
jniGetUid(Object Expr)117 	jniGetUid(Object Expr) throws Cvc3Exception;
118     private static native String
jniGetString(Object Expr)119 	jniGetString(Object Expr) throws Cvc3Exception;
120     private static native Object[]
jniGetVars(Object Expr)121 	jniGetVars(Object Expr) throws Cvc3Exception;
122     private static native Object
jniGetExistential(Object Expr)123 	jniGetExistential(Object Expr) throws Cvc3Exception;
124     private static native int
jniGetBoundIndex(Object Expr)125 	jniGetBoundIndex(Object Expr) throws Cvc3Exception;
126     private static native Object
jniGetBody(Object Expr)127 	jniGetBody(Object Expr) throws Cvc3Exception;
128     private static native Object
jniGetRational(Object Expr)129 	jniGetRational(Object Expr) throws Cvc3Exception;
130     private static native Object[][]
jniGetTriggers(Object Expr)131     jniGetTriggers(Object Expr) throws Cvc3Exception;
132     private static native Object
jniGetTheorem(Object Expr)133 	jniGetTheorem(Object Expr) throws Cvc3Exception;
134     private static native Object
jniGetType(Object Expr)135 	jniGetType(Object Expr) throws Cvc3Exception;
136     private static native Object
jniMkOp(Object Expr)137 	jniMkOp(Object Expr) throws Cvc3Exception;
138     private static native Object
jniGetOp(Object Expr)139 	jniGetOp(Object Expr) throws Cvc3Exception;
140     private static native Object
jniGetOpExpr(Object Expr)141 	jniGetOpExpr(Object Expr) throws Cvc3Exception;
142 
143     private static native boolean
jniIsNull(Object Expr)144 	jniIsNull(Object Expr) throws Cvc3Exception;
145     private static native int
jniArity(Object Expr)146 	jniArity(Object Expr) throws Cvc3Exception;
147     private static native Object
jniGetKid(Object Expr, int i)148 	jniGetKid(Object Expr, int i) throws Cvc3Exception;
149     private static native Object[]
jniGetKids(Object Expr)150 	jniGetKids(Object Expr) throws Cvc3Exception;
151 
152     private static native Object
jniSubstExpr(Object Expr, Object[] oldExprs, Object[] newExprs)153     jniSubstExpr(Object Expr, Object[] oldExprs, Object[] newExprs) throws Cvc3Exception;
154 
155     private static native boolean
jniIsBvLt(Object Expr)156 	jniIsBvLt(Object Expr) throws Cvc3Exception;
157     private static native boolean
jniIsBvLe(Object Expr)158 	jniIsBvLe(Object Expr) throws Cvc3Exception;
159     private static native boolean
jniIsBvGt(Object Expr)160 	jniIsBvGt(Object Expr) throws Cvc3Exception;
161     private static native boolean
jniIsBvGe(Object Expr)162 	jniIsBvGe(Object Expr) throws Cvc3Exception;
163     private static native boolean
jniIsBvPlus(Object Expr)164 	jniIsBvPlus(Object Expr) throws Cvc3Exception;
165     private static native boolean
jniIsBvSub(Object Expr)166 	jniIsBvSub(Object Expr) throws Cvc3Exception;
167     private static native boolean
jniIsBvConst(Object Expr)168 	jniIsBvConst(Object Expr) throws Cvc3Exception;
169     private static native boolean
jniIsBvExtract(Object Expr)170 	jniIsBvExtract(Object Expr) throws Cvc3Exception;
171     private static native boolean
jniIsBvConcat(Object Expr)172 	jniIsBvConcat(Object Expr) throws Cvc3Exception;
173 
174 
175     /// Constructor
176 
Expr(Object Expr, EmbeddedManager embeddedManager)177     public Expr(Object Expr, EmbeddedManager embeddedManager) {
178 	super(Expr, embeddedManager);
179     }
180 
181 
182     /// API (immutable)
183 
184 
185     // 'Problem' with equals/hashCode:
186     // this is based on the wrapped c++ expressions.
187     // as a consequence two Expr objects are equal iff
188     // the wrapped expression is equal,
189     // and are indistinguishable for example in a HashMap.
190 
equals(Object o)191     public boolean equals(Object o) {
192 	if (this == o) return true;
193 
194 	if (!(o instanceof Expr)) return false;
195 	boolean result = false;
196 	try {
197 	    result = jniEquals(embedded(), ((Embedded)o).embedded());
198 	} catch (Cvc3Exception e) {
199 	    assert(false);
200 	}
201 	return result;
202     }
203 
204     // must return the same hash code for two objects if equals returns true
hashCode()205     public int hashCode() {
206 	try {
207 	    if (!jniIsNull(embedded())) {
208 		return jniHash(embedded());
209 	    }
210 	} catch (Cvc3Exception e) {
211 	    assert(false);
212 	}
213 	assert(false);
214 	return 0;
215     }
216 
subst(List oldExprs, List newExprs)217     public Expr subst(List oldExprs, List newExprs) throws Cvc3Exception {
218       assert(JniUtils.listInstanceof(oldExprs, Expr.class));
219       assert(JniUtils.listInstanceof(newExprs, Expr.class));
220       return new Expr(jniSubstExpr(embedded(), JniUtils.unembedList(oldExprs),
221         JniUtils.unembedList(newExprs)), embeddedManager());
222     }
223 
toString()224     public String toString() {
225 	String result = "";
226 	try {
227 	    result = jniToString(embedded());
228 	} catch (Cvc3Exception e) {
229 	    assert(false);
230 	}
231 	return result;
232     }
233 
print(InputLanguage lang, boolean dagify)234     public void print(InputLanguage lang, boolean dagify) throws Cvc3Exception {
235 	jniPrint(embedded(), lang.toString(), dagify);
236     }
237 
print(boolean dagify)238     public void print(boolean dagify) throws Cvc3Exception {
239 	print(InputLanguage.PRESENTATION, dagify);
240     }
241 
print()242     public void print() throws Cvc3Exception {
243       print(false);
244     }
245 
getKind()246     public String getKind() throws Cvc3Exception {
247       return jniGetKind(embedded());
248     }
249 
250     // Core expression testers
251 
252 
isFalse()253     public boolean isFalse() throws Cvc3Exception {
254 	return jniIsFalse(embedded());
255     }
256 
isTrue()257     public boolean isTrue() throws Cvc3Exception {
258 	return jniIsTrue(embedded());
259     }
260 
isBooleanConst()261     public boolean isBooleanConst() throws Cvc3Exception {
262 	return jniIsBoolConst(embedded());
263     }
264 
isVar()265     public boolean isVar() throws Cvc3Exception {
266 	return jniIsVar(embedded());
267     }
268 
isBoundVar()269     public boolean isBoundVar() throws Cvc3Exception {
270 	return jniIsBoundVar(embedded());
271     }
272 
isString()273     public boolean isString() throws Cvc3Exception {
274 	return jniIsString(embedded());
275     }
276 
isClosure()277     public boolean isClosure() throws Cvc3Exception {
278 	return jniIsClosure(embedded());
279     }
280 
isQuantifier()281     public boolean isQuantifier() throws Cvc3Exception {
282 	return jniIsQuantifier(embedded());
283     }
284 
isLambda()285     public boolean isLambda() throws Cvc3Exception {
286 	return jniIsLambda(embedded());
287     }
288 
isApply()289     public boolean isApply() throws Cvc3Exception {
290 	return jniIsApply(embedded());
291     }
292 
isSymbol()293     public boolean isSymbol() throws Cvc3Exception {
294 	return jniIsSymbol(embedded());
295     }
296 
isTheorem()297     public boolean isTheorem() throws Cvc3Exception {
298 	return jniIsTheorem(embedded());
299     }
300 
isType()301     public boolean isType() throws Cvc3Exception {
302 	return jniIsType(embedded());
303     }
304 
305 
306 
307 
isTerm()308     public boolean isTerm() throws Cvc3Exception {
309 	return jniIsTerm(embedded());
310     }
311 
isAtomic()312     public boolean isAtomic() throws Cvc3Exception {
313 	return jniIsAtomic(embedded());
314     }
315 
isAtomicFormula()316     public boolean isAtomicFormula() throws Cvc3Exception {
317 	return jniIsAtomicFormula(embedded());
318     }
319 
isAbsAtomicFormula()320     public boolean isAbsAtomicFormula() throws Cvc3Exception {
321 	return jniIsAbsAtomicFormula(embedded());
322     }
323 
isLiteral()324     public boolean isLiteral() throws Cvc3Exception {
325 	return jniIsLiteral(embedded());
326     }
327 
isAbsLiteral()328     public boolean isAbsLiteral() throws Cvc3Exception {
329 	return jniIsAbsLiteral(embedded());
330     }
331 
isBoolConnective()332     public boolean isBoolConnective() throws Cvc3Exception {
333 	return jniIsBoolConnective(embedded());
334     }
335 
isPropAtom()336     public boolean isPropAtom() throws Cvc3Exception {
337 	return jniIsPropAtom(embedded());
338     }
339 
isPropLiteral()340     public boolean isPropLiteral() throws Cvc3Exception {
341 	return jniIsPropLiteral(embedded());
342     }
343 
isArrayLiteral()344     public boolean isArrayLiteral() throws Cvc3Exception {
345       return jniIsArrayLiteral(embedded());
346     }
347 
isEq()348     public boolean isEq() throws Cvc3Exception {
349 	return jniIsEq(embedded());
350     }
351 
isNot()352     public boolean isNot() throws Cvc3Exception {
353 	return jniIsNot(embedded());
354     }
355 
356 
isAnd()357     public boolean isAnd() throws Cvc3Exception {
358 	return jniIsAnd(embedded());
359     }
360 
361 
isOr()362     public boolean isOr() throws Cvc3Exception {
363 	return jniIsOr(embedded());
364     }
365 
366 
isITE()367     public boolean isITE() throws Cvc3Exception {
368 	return jniIsITE(embedded());
369     }
370 
371 
isIff()372     public boolean isIff() throws Cvc3Exception {
373 	return jniIsIff(embedded());
374     }
375 
376 
isImpl()377     public boolean isImpl() throws Cvc3Exception {
378 	return jniIsImpl(embedded());
379     }
380 
381 
isXor()382     public boolean isXor() throws Cvc3Exception {
383 	return jniIsXor(embedded());
384     }
385 
386 
isForall()387     public boolean isForall() throws Cvc3Exception {
388 	return jniIsForall(embedded());
389     }
390 
391 
isExists()392     public boolean isExists() throws Cvc3Exception {
393 	return jniIsExists(embedded());
394     }
395 
396 
isRational()397     public boolean isRational() throws Cvc3Exception {
398 	return jniIsRational(embedded());
399     }
400 
isUminus()401     public boolean isUminus() throws Cvc3Exception {
402 	return jniIsUminus(embedded());
403     }
404 
isPlus()405     public boolean isPlus() throws Cvc3Exception {
406 	return jniIsPlus(embedded());
407     }
408 
isMinus()409     public boolean isMinus() throws Cvc3Exception {
410 	return jniIsMinus(embedded());
411     }
412 
isMult()413     public boolean isMult() throws Cvc3Exception {
414 	return jniIsMult(embedded());
415     }
416 
isPow()417     public boolean isPow() throws Cvc3Exception {
418 	return jniIsPow(embedded());
419     }
420 
isDivide()421     public boolean isDivide() throws Cvc3Exception {
422 	return jniIsDivide(embedded());
423     }
424 
isLt()425     public boolean isLt() throws Cvc3Exception {
426 	return jniIsLt(embedded());
427     }
428 
isLe()429     public boolean isLe() throws Cvc3Exception {
430 	return jniIsLe(embedded());
431     }
432 
isGt()433     public boolean isGt() throws Cvc3Exception {
434 	return jniIsGt(embedded());
435     }
436 
isGe()437     public boolean isGe() throws Cvc3Exception {
438 	return jniIsGe(embedded());
439     }
440 
isSkolem()441     public boolean isSkolem() throws Cvc3Exception {
442 	return jniIsSkolem(embedded());
443     }
444 
isRead()445     public boolean isRead() throws Cvc3Exception {
446 	return jniIsRead(embedded());
447     }
448 
isWrite()449     public boolean isWrite() throws Cvc3Exception {
450 	return jniIsWrite(embedded());
451     }
452 
isBvLe()453     public boolean isBvLe() throws Cvc3Exception {
454 	return jniIsBvLe(embedded());
455     }
456 
isBvLt()457     public boolean isBvLt() throws Cvc3Exception {
458 	return jniIsBvLt(embedded());
459     }
460 
isBvGe()461     public boolean isBvGe() throws Cvc3Exception {
462 	return jniIsBvGe(embedded());
463     }
464 
isBvGt()465     public boolean isBvGt() throws Cvc3Exception {
466 	return jniIsBvGt(embedded());
467     }
468 
isBvPlus()469     public boolean isBvPlus() throws Cvc3Exception {
470 	return jniIsBvPlus(embedded());
471     }
472 
isBvSub()473     public boolean isBvSub() throws Cvc3Exception {
474 	return jniIsBvSub(embedded());
475     }
476 
isBvConstant()477     public boolean isBvConstant() throws Cvc3Exception {
478 	return jniIsBvConst(embedded());
479     }
480 
isBvConcat()481     public boolean isBvConcat() throws Cvc3Exception {
482 	return jniIsBvConcat(embedded());
483     }
484 
isBvExtract()485     public boolean isBvExtract() throws Cvc3Exception {
486 	return jniIsBvExtract(embedded());
487     }
488 
489 
getName()490     public String getName() throws Cvc3Exception {
491 	assert(!jniIsNull(embedded()));
492 	return jniGetName(embedded());
493     }
494 
getUid()495     public String getUid() throws Cvc3Exception {
496 	assert(jniIsBoundVar(embedded()));
497 	return jniGetUid(embedded());
498     }
499 
getString()500     public String getString() throws Cvc3Exception {
501 	assert(jniIsString(embedded()));
502 	return jniGetString(embedded());
503     }
504 
getVars()505     public List getVars() throws Cvc3Exception {
506 	assert(jniIsClosure(embedded()));
507 	Object[] vars = jniGetVars(embedded());
508 	return JniUtils.embedList(vars, Expr.class, embeddedManager());
509     }
510 
getTriggers()511     public List getTriggers() throws Cvc3Exception {
512       assert (jniIsClosure(embedded()));
513       return JniUtils.embedListList(jniGetTriggers(embedded()), Expr.class, embeddedManager());
514     }
515 
getExistential()516     public Expr getExistential() throws Cvc3Exception {
517 	assert(jniIsSkolem(embedded()));
518 	return new Expr(jniGetExistential(embedded()), embeddedManager());
519     }
520 
getBoundIndex()521     public int getBoundIndex() throws Cvc3Exception {
522 	assert(jniIsSkolem(embedded()));
523 	return jniGetBoundIndex(embedded());
524     }
525 
getBody()526     public Expr getBody() throws Cvc3Exception {
527 	assert(jniIsClosure(embedded()));
528 	return new Expr(jniGetBody(embedded()), embeddedManager());
529     }
530 
getRational()531     public Rational getRational() throws Cvc3Exception {
532 	assert(isRational());
533 	return new Rational(jniGetRational(embedded()), embeddedManager());
534     }
535 
getTheorem()536     public Theorem getTheorem() throws Cvc3Exception {
537 	assert(jniIsTheorem(embedded()));
538 	return new Theorem(jniGetTheorem(embedded()), embeddedManager());
539     }
540 
getType()541     public TypeMut getType() throws Cvc3Exception {
542 	return new TypeMut(jniGetType(embedded()), embeddedManager());
543     }
544 
mkOp()545     public OpMut mkOp() throws Cvc3Exception {
546 		return new OpMut(jniMkOp(embedded()), embeddedManager());
547 	}
548 
getOp()549     public OpMut getOp() throws Cvc3Exception {
550 	return new OpMut(jniGetOp(embedded()), embeddedManager());
551     }
552 
getOpExpr()553     public ExprMut getOpExpr() throws Cvc3Exception {
554 	return new ExprMut(jniGetOpExpr(embedded()), embeddedManager());
555     }
556 
isNull()557     public boolean isNull() throws Cvc3Exception {
558 	return jniIsNull(embedded());
559     }
560 
arity()561     public int arity() throws Cvc3Exception {
562 	return jniArity(embedded());
563     }
564 
getChild(int i)565     public Expr getChild(int i) throws Cvc3Exception {
566 	assert(i >= 0 && i < arity());
567 	return new Expr(jniGetKid(embedded(), i), embeddedManager());
568     }
569 
getChildren()570     public List getChildren() throws Cvc3Exception {
571         return JniUtils.embedList(jniGetKids(embedded()), Expr.class, embeddedManager());
572     }
573 }
574