Z3
 
Loading...
Searching...
No Matches
Expr.java
Go to the documentation of this file.
1
18package com.microsoft.z3;
19
20import java.lang.reflect.Type;
21import java.lang.reflect.ParameterizedType;
22
23import com.microsoft.z3.enumerations.Z3_ast_kind;
24import com.microsoft.z3.enumerations.Z3_decl_kind;
25import com.microsoft.z3.enumerations.Z3_lbool;
26import com.microsoft.z3.enumerations.Z3_sort_kind;
27
28/* using System; */
29
33@SuppressWarnings("unchecked")
34public class Expr<R extends Sort> extends AST
35{
42 {
43 return simplify(null);
44 }
45
56 {
57
58 if (p == null) {
59 return (Expr<R>) Expr.create(getContext(),
60 Native.simplify(getContext().nCtx(), getNativeObject()));
61 }
62 else {
63 return (Expr<R>) Expr.create(
64 getContext(),
65 Native.simplifyEx(getContext().nCtx(), getNativeObject(),
66 p.getNativeObject()));
67 }
68 }
69
77 {
78 return new FuncDecl<>(getContext(), Native.getAppDecl(getContext().nCtx(),
79 getNativeObject()));
80 }
81
89 {
90 return Z3_lbool.fromInt(Native.getBoolValue(getContext().nCtx(),
91 getNativeObject()));
92 }
93
99 public int getNumArgs()
100 {
101 return Native.getAppNumArgs(getContext().nCtx(), getNativeObject());
102 }
103
109 public Expr<?>[] getArgs()
110 {
111 int n = getNumArgs();
112 Expr<?>[] res = new Expr[n];
113 for (int i = 0; i < n; i++) {
114 res[i] = Expr.create(getContext(),
115 Native.getAppArg(getContext().nCtx(), getNativeObject(), i));
116 }
117 return res;
118 }
119
127 public Expr<R> update(Expr<?>[] args)
128 {
129 getContext().checkContextMatch(args);
130 if (isApp() && args.length != getNumArgs()) {
131 throw new Z3Exception("Number of arguments does not match");
132 }
133 return (Expr<R>) Expr.create(getContext(), Native.updateTerm(getContext().nCtx(), getNativeObject(),
134 args.length, Expr.arrayToNative(args)));
135 }
136
149 public Expr<R> substitute(Expr<?>[] from, Expr<?>[] to)
150 {
151 getContext().checkContextMatch(from);
152 getContext().checkContextMatch(to);
153 if (from.length != to.length) {
154 throw new Z3Exception("Argument sizes do not match");
155 }
156 return (Expr<R>) Expr.create(getContext(), Native.substitute(getContext().nCtx(),
157 getNativeObject(), from.length, Expr.arrayToNative(from),
158 Expr.arrayToNative(to)));
159 }
160
169 {
170 return substitute(new Expr[] { from }, new Expr[] { to });
171 }
172
184 {
185
186 getContext().checkContextMatch(to);
187 return (Expr<R>) Expr.create(getContext(), Native.substituteVars(getContext().nCtx(),
188 getNativeObject(), to.length, Expr.arrayToNative(to)));
189 }
190
204 {
205 getContext().checkContextMatch(from);
206 getContext().checkContextMatch(to);
207 if (from.length != to.length) {
208 throw new Z3Exception("Arrays 'from' and 'to' must have the same length");
209 }
210 return (Expr<R>) Expr.create(getContext(), Native.substituteFuns(getContext().nCtx(),
211 getNativeObject(), from.length, AST.arrayToNative(from),
212 Expr.arrayToNative(to)));
213 }
214
224 {
225 return (Expr<R>) super.translate(ctx);
226 }
227
231 @Override
232 public String toString()
233 {
234 return super.toString();
235 }
236
242 public boolean isNumeral()
243 {
244 return Native.isNumeralAst(getContext().nCtx(), getNativeObject());
245 }
246
253 public boolean isWellSorted()
254 {
255 return Native.isWellSorted(getContext().nCtx(), getNativeObject());
256 }
257
263 public R getSort()
264 {
265 return (R) Sort.create(getContext(),
266 Native.getSort(getContext().nCtx(), getNativeObject()));
267 }
268
274 public boolean isConst()
275 {
276 return isApp() && getNumArgs() == 0 && getFuncDecl().getDomainSize() == 0;
277 }
278
284 public boolean isIntNum()
285 {
286 return isNumeral() && isInt();
287 }
288
294 public boolean isRatNum()
295 {
296 return isNumeral() && isReal();
297 }
298
304 public boolean isAlgebraicNumber()
305 {
306 return Native.isAlgebraicNumber(getContext().nCtx(), getNativeObject());
307 }
308
314 public boolean isBool()
315 {
316 return (isExpr() && Native.isEqSort(getContext().nCtx(),
317 Native.mkBoolSort(getContext().nCtx()),
318 Native.getSort(getContext().nCtx(), getNativeObject())));
319 }
320
326 public boolean isTrue()
327 {
328 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_TRUE;
329 }
330
336 public boolean isFalse()
337 {
338 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_FALSE;
339 }
340
346 public boolean isEq()
347 {
348 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EQ;
349 }
350
357 public boolean isDistinct()
358 {
359 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_DISTINCT;
360 }
361
367 public boolean isITE()
368 {
369 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ITE;
370 }
371
377 public boolean isAnd()
378 {
379 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_AND;
380 }
381
387 public boolean isOr()
388 {
389 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_OR;
390 }
391
398 public boolean isIff()
399 {
400 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IFF;
401 }
402
408 public boolean isXor()
409 {
410 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_XOR;
411 }
412
418 public boolean isNot()
419 {
420 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_NOT;
421 }
422
428 public boolean isImplies()
429 {
430 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IMPLIES;
431 }
432
438 public boolean isInt()
439 {
440 return Native.getSortKind(getContext().nCtx(), Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_INT_SORT.toInt();
441 }
442
448 public boolean isReal()
449 {
450 return Native.getSortKind(getContext().nCtx(), Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_REAL_SORT.toInt();
451 }
452
458 public boolean isArithmeticNumeral()
459 {
460 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ANUM;
461 }
462
468 public boolean isLE()
469 {
470 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LE;
471 }
472
478 public boolean isGE()
479 {
480 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_GE;
481 }
482
488 public boolean isLT()
489 {
490 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LT;
491 }
492
498 public boolean isGT()
499 {
500 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_GT;
501 }
502
508 public boolean isAdd()
509 {
510 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ADD;
511 }
512
518 public boolean isSub()
519 {
520 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SUB;
521 }
522
528 public boolean isUMinus()
529 {
530 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_UMINUS;
531 }
532
538 public boolean isMul()
539 {
540 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_MUL;
541 }
542
548 public boolean isDiv()
549 {
550 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_DIV;
551 }
552
558 public boolean isIDiv()
559 {
560 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IDIV;
561 }
562
568 public boolean isRemainder()
569 {
570 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_REM;
571 }
572
578 public boolean isModulus()
579 {
580 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_MOD;
581 }
582
588 public boolean isIntToReal()
589 {
590 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_TO_REAL;
591 }
592
598 public boolean isRealToInt()
599 {
600 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_TO_INT;
601 }
602
609 public boolean isRealIsInt()
610 {
611 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IS_INT;
612 }
613
619 public boolean isArray()
620 {
621 return (Native.isApp(getContext().nCtx(), getNativeObject()) && Z3_sort_kind
622 .fromInt(Native.getSortKind(getContext().nCtx(),
623 Native.getSort(getContext().nCtx(), getNativeObject()))) == Z3_sort_kind.Z3_ARRAY_SORT);
624 }
625
632 public boolean isStore()
633 {
634 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_STORE;
635 }
636
642 public boolean isSelect()
643 {
644 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SELECT;
645 }
646
653 public boolean isConstantArray()
654 {
655 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_CONST_ARRAY;
656 }
657
664 public boolean isDefaultArray()
665 {
666 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ARRAY_DEFAULT;
667 }
668
676 public boolean isArrayMap()
677 {
678 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ARRAY_MAP;
679 }
680
687 public boolean isAsArray()
688 {
689 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_AS_ARRAY;
690 }
691
697 public boolean isSetUnion()
698 {
699 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_UNION;
700 }
701
707 public boolean isSetIntersect()
708 {
709 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_INTERSECT;
710 }
711
717 public boolean isSetDifference()
718 {
719 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_DIFFERENCE;
720 }
721
727 public boolean isSetComplement()
728 {
729 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_COMPLEMENT;
730 }
731
737 public boolean isSetSubset()
738 {
739 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_SUBSET;
740 }
741
747 public boolean isBV()
748 {
749 return Native.getSortKind(getContext().nCtx(),
750 Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_BV_SORT
751 .toInt();
752 }
753
759 public boolean isBVNumeral()
760 {
761 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNUM;
762 }
763
769 public boolean isBVBitOne()
770 {
771 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BIT1;
772 }
773
779 public boolean isBVBitZero()
780 {
781 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BIT0;
782 }
783
789 public boolean isBVUMinus()
790 {
791 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNEG;
792 }
793
799 public boolean isBVAdd()
800 {
801 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BADD;
802 }
803
809 public boolean isBVSub()
810 {
811 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSUB;
812 }
813
819 public boolean isBVMul()
820 {
821 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BMUL;
822 }
823
829 public boolean isBVSDiv()
830 {
831 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSDIV;
832 }
833
839 public boolean isBVUDiv()
840 {
841 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUDIV;
842 }
843
849 public boolean isBVSRem()
850 {
851 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSREM;
852 }
853
859 public boolean isBVURem()
860 {
861 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUREM;
862 }
863
869 public boolean isBVSMod()
870 {
871 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSMOD;
872 }
873
879 boolean isBVSDiv0()
880 {
881 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSDIV0;
882 }
883
889 boolean isBVUDiv0()
890 {
891 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUDIV0;
892 }
893
899 boolean isBVSRem0()
900 {
901 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSREM0;
902 }
903
909 boolean isBVURem0()
910 {
911 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUREM0;
912 }
913
919 boolean isBVSMod0()
920 {
921 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSMOD0;
922 }
923
929 public boolean isBVULE()
930 {
931 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ULEQ;
932 }
933
939 public boolean isBVSLE()
940 {
941 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SLEQ;
942 }
943
950 public boolean isBVUGE()
951 {
952 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_UGEQ;
953 }
954
960 public boolean isBVSGE()
961 {
962 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SGEQ;
963 }
964
970 public boolean isBVULT()
971 {
972 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ULT;
973 }
974
980 public boolean isBVSLT()
981 {
982 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SLT;
983 }
984
990 public boolean isBVUGT()
991 {
992 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_UGT;
993 }
994
1000 public boolean isBVSGT()
1001 {
1002 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SGT;
1003 }
1004
1010 public boolean isBVAND()
1011 {
1012 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BAND;
1013 }
1014
1020 public boolean isBVOR()
1021 {
1022 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BOR;
1023 }
1024
1030 public boolean isBVNOT()
1031 {
1032 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNOT;
1033 }
1034
1040 public boolean isBVXOR()
1041 {
1042 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BXOR;
1043 }
1044
1050 public boolean isBVNAND()
1051 {
1052 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNAND;
1053 }
1054
1060 public boolean isBVNOR()
1061 {
1062 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNOR;
1063 }
1064
1070 public boolean isBVXNOR()
1071 {
1072 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BXNOR;
1073 }
1074
1080 public boolean isBVConcat()
1081 {
1082 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_CONCAT;
1083 }
1084
1090 public boolean isBVSignExtension()
1091 {
1092 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SIGN_EXT;
1093 }
1094
1100 public boolean isBVZeroExtension()
1101 {
1102 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ZERO_EXT;
1103 }
1104
1110 public boolean isBVExtract()
1111 {
1112 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EXTRACT;
1113 }
1114
1120 public boolean isBVRepeat()
1121 {
1122 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_REPEAT;
1123 }
1124
1130 public boolean isBVReduceOR()
1131 {
1132 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BREDOR;
1133 }
1134
1140 public boolean isBVReduceAND()
1141 {
1142 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BREDAND;
1143 }
1144
1150 public boolean isBVComp()
1151 {
1152 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BCOMP;
1153 }
1154
1160 public boolean isBVShiftLeft()
1161 {
1162 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSHL;
1163 }
1164
1170 public boolean isBVShiftRightLogical()
1171 {
1172 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BLSHR;
1173 }
1174
1181 {
1182 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BASHR;
1183 }
1184
1190 public boolean isBVRotateLeft()
1191 {
1192 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ROTATE_LEFT;
1193 }
1194
1200 public boolean isBVRotateRight()
1201 {
1202 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ROTATE_RIGHT;
1203 }
1204
1212 public boolean isBVRotateLeftExtended()
1213 {
1214 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EXT_ROTATE_LEFT;
1215 }
1216
1225 {
1226 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EXT_ROTATE_RIGHT;
1227 }
1228
1236 public boolean isIntToBV()
1237 {
1238 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_INT2BV;
1239 }
1240
1248 public boolean isBVToInt()
1249 {
1250 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BV2INT;
1251 }
1252
1259 public boolean isBVCarry()
1260 {
1261 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_CARRY;
1262 }
1263
1270 public boolean isBVXOR3()
1271 {
1272 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_XOR3;
1273 }
1274
1283 public boolean isLabel()
1284 {
1285 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LABEL;
1286 }
1287
1296 public boolean isLabelLit()
1297 {
1298 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LABEL_LIT;
1299 }
1300
1305 public boolean isString()
1306 {
1307 return isApp() && Native.isString(getContext().nCtx(), getNativeObject());
1308 }
1309
1316 public String getString()
1317 {
1318 return Native.getString(getContext().nCtx(), getNativeObject());
1319 }
1320
1341 public boolean isConcat()
1342 {
1343 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SEQ_CONCAT;
1344 }
1345
1353 public boolean isOEQ()
1354 {
1355 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_OEQ;
1356 }
1357
1363 public boolean isProofTrue()
1364 {
1365 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TRUE;
1366 }
1367
1373 public boolean isProofAsserted()
1374 {
1375 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_ASSERTED;
1376 }
1377
1384 public boolean isProofGoal()
1385 {
1386 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_GOAL;
1387 }
1388
1398 public boolean isProofModusPonens()
1399 {
1400 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS;
1401 }
1402
1413 public boolean isProofReflexivity()
1414 {
1415 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_REFLEXIVITY;
1416 }
1417
1425 public boolean isProofSymmetry()
1426 {
1427 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_SYMMETRY;
1428 }
1429
1437 public boolean isProofTransitivity()
1438 {
1439 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY;
1440 }
1441
1458 {
1459 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY_STAR;
1460 }
1461
1472 public boolean isProofMonotonicity()
1473 {
1474 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_MONOTONICITY;
1475 }
1476
1483 public boolean isProofQuantIntro()
1484 {
1485 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_QUANT_INTRO;
1486 }
1487
1502 public boolean isProofDistributivity()
1503 {
1504 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DISTRIBUTIVITY;
1505 }
1506
1513 public boolean isProofAndElimination()
1514 {
1515 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_AND_ELIM;
1516 }
1517
1524 public boolean isProofOrElimination()
1525 {
1526 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NOT_OR_ELIM;
1527 }
1528
1544 public boolean isProofRewrite()
1545 {
1546 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_REWRITE;
1547 }
1548
1560 public boolean isProofRewriteStar()
1561 {
1562 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_REWRITE_STAR;
1563 }
1564
1572 public boolean isProofPullQuant()
1573 {
1574 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_PULL_QUANT;
1575 }
1576
1577
1587 public boolean isProofPushQuant()
1588 {
1589 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_PUSH_QUANT;
1590 }
1591
1603 public boolean isProofElimUnusedVars()
1604 {
1605 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_ELIM_UNUSED_VARS;
1606 }
1607
1619 public boolean isProofDER()
1620 {
1621 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DER;
1622 }
1623
1631 public boolean isProofQuantInst()
1632 {
1633 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_QUANT_INST;
1634 }
1635
1643 public boolean isProofHypothesis()
1644 {
1645 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_HYPOTHESIS;
1646 }
1647
1659 public boolean isProofLemma()
1660 {
1661 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_LEMMA;
1662 }
1663
1670 public boolean isProofUnitResolution()
1671 {
1672 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_UNIT_RESOLUTION;
1673 }
1674
1682 public boolean isProofIFFTrue()
1683 {
1684 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_TRUE;
1685 }
1686
1694 public boolean isProofIFFFalse()
1695 {
1696 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_FALSE;
1697 }
1698
1711 public boolean isProofCommutativity()
1712 {
1713 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_COMMUTATIVITY;
1714 }
1715
1737 public boolean isProofDefAxiom()
1738 {
1739 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DEF_AXIOM;
1740 }
1741
1760 public boolean isProofDefIntro()
1761 {
1762 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DEF_INTRO;
1763 }
1764
1772 public boolean isProofApplyDef()
1773 {
1774 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_APPLY_DEF;
1775 }
1776
1784 public boolean isProofIFFOEQ()
1785 {
1786 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_OEQ;
1787 }
1788
1812 public boolean isProofNNFPos()
1813 {
1814 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_POS;
1815 }
1816
1831 public boolean isProofNNFNeg()
1832 {
1833 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_NEG;
1834 }
1835
1836
1849 public boolean isProofSkolemize()
1850 {
1851 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_SKOLEMIZE;
1852 }
1853
1862 public boolean isProofModusPonensOEQ()
1863 {
1864 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS_OEQ;
1865 }
1866
1884 public boolean isProofTheoryLemma()
1885 {
1886 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TH_LEMMA;
1887 }
1888
1894 public boolean isRelation()
1895 {
1896 return (Native.isApp(getContext().nCtx(), getNativeObject()) && Native
1897 .getSortKind(getContext().nCtx(),
1898 Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_RELATION_SORT
1899 .toInt());
1900 }
1901
1911 public boolean isRelationStore()
1912 {
1913 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_STORE;
1914 }
1915
1921 public boolean isEmptyRelation()
1922 {
1923 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_EMPTY;
1924 }
1925
1931 public boolean isIsEmptyRelation()
1932 {
1933 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_IS_EMPTY;
1934 }
1935
1941 public boolean isRelationalJoin()
1942 {
1943 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_JOIN;
1944 }
1945
1953 public boolean isRelationUnion()
1954 {
1955 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_UNION;
1956 }
1957
1965 public boolean isRelationWiden()
1966 {
1967 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_WIDEN;
1968 }
1969
1978 public boolean isRelationProject()
1979 {
1980 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_PROJECT;
1981 }
1982
1993 public boolean isRelationFilter()
1994 {
1995 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_FILTER;
1996 }
1997
2014 {
2015 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_NEGATION_FILTER;
2016 }
2017
2025 public boolean isRelationRename()
2026 {
2027 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_RENAME;
2028 }
2029
2035 public boolean isRelationComplement()
2036 {
2037 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_COMPLEMENT;
2038 }
2039
2049 public boolean isRelationSelect()
2050 {
2051 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_SELECT;
2052 }
2053
2065 public boolean isRelationClone()
2066 {
2067 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_CLONE;
2068 }
2069
2075 public boolean isFiniteDomain()
2076 {
2077 return (Native.isApp(getContext().nCtx(), getNativeObject()) && Native
2078 .getSortKind(getContext().nCtx(),
2079 Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_FINITE_DOMAIN_SORT
2080 .toInt());
2081 }
2082
2088 public boolean isFiniteDomainLT()
2089 {
2090 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_FD_LT;
2091 }
2092
2111 public int getIndex()
2112 {
2113 if (!isVar()) {
2114 throw new Z3Exception("Term is not a bound variable.");
2115 }
2116
2117 return Native.getIndexValue(getContext().nCtx(), getNativeObject());
2118 }
2119
2120 private Class sort = null;
2121
2130 public <S extends R> Expr<S> distillSort(Class<S> newSort) {
2131 if (sort != null && !newSort.isAssignableFrom(sort)) {
2132 throw new Z3Exception(
2133 String.format("Cannot distill expression of sort %s to %s.", sort.getName(), newSort.getName()));
2134 }
2135
2136 return (Expr<S>) ((Expr<?>) this);
2137 }
2138
2143 protected Expr(Context ctx, long obj) {
2144 super(ctx, obj);
2145 Type superclass = getClass().getGenericSuperclass();
2146 if (superclass instanceof ParameterizedType) {
2147 Type argType = ((ParameterizedType) superclass).getActualTypeArguments()[0];
2148 if (argType instanceof Class) {
2149 this.sort = (Class) argType;
2150 }
2151 }
2152 }
2153
2154 @Override
2155 void checkNativeObject(long obj) {
2156 if (!Native.isApp(getContext().nCtx(), obj) &&
2157 Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_VAR_AST.toInt() &&
2158 Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_QUANTIFIER_AST.toInt()) {
2159 throw new Z3Exception("Underlying object is not a term");
2160 }
2161 super.checkNativeObject(obj);
2162 }
2163
2164 static <U extends Sort> Expr<U> create(Context ctx, FuncDecl<U> f, Expr<?> ... arguments)
2165 {
2166 long obj = Native.mkApp(ctx.nCtx(), f.getNativeObject(),
2167 AST.arrayLength(arguments), AST.arrayToNative(arguments));
2168 return (Expr<U>) create(ctx, obj);
2169 }
2170
2171 // TODO generify, but it conflicts with AST.create
2172 static Expr<?> create(Context ctx, long obj)
2173 {
2174 Z3_ast_kind k = Z3_ast_kind.fromInt(Native.getAstKind(ctx.nCtx(), obj));
2175 if (k == Z3_ast_kind.Z3_QUANTIFIER_AST) {
2176 // a quantifier AST is a lambda iff it is neither a forall nor an exists.
2177 boolean isLambda = !Native.isQuantifierExists(ctx.nCtx(), obj) && !Native.isQuantifierForall(ctx.nCtx(), obj);
2178 if (isLambda) {
2179 return new Lambda(ctx, obj);
2180 } else {
2181 return new Quantifier(ctx, obj);
2182 }
2183 }
2184 long s = Native.getSort(ctx.nCtx(), obj);
2186 .fromInt(Native.getSortKind(ctx.nCtx(), s));
2187
2188 if (Native.isAlgebraicNumber(ctx.nCtx(), obj)) // is this a numeral ast?
2189 return new AlgebraicNum(ctx, obj);
2190
2191 if (Native.isNumeralAst(ctx.nCtx(), obj))
2192 {
2193 switch (sk)
2194 {
2195 case Z3_INT_SORT:
2196 return new IntNum(ctx, obj);
2197 case Z3_REAL_SORT:
2198 return new RatNum(ctx, obj);
2199 case Z3_BV_SORT:
2200 return new BitVecNum(ctx, obj);
2202 return new FPNum(ctx, obj);
2204 return new FPRMNum(ctx, obj);
2206 return new FiniteDomainNum(ctx, obj);
2207 default:
2208 }
2209 }
2210
2211 switch (sk)
2212 {
2213 case Z3_BOOL_SORT:
2214 return new BoolExpr(ctx, obj);
2215 case Z3_INT_SORT:
2216 return new IntExpr(ctx, obj);
2217 case Z3_REAL_SORT:
2218 return new RealExpr(ctx, obj);
2219 case Z3_BV_SORT:
2220 return new BitVecExpr(ctx, obj);
2221 case Z3_ARRAY_SORT:
2222 return new ArrayExpr<>(ctx, obj);
2223 case Z3_DATATYPE_SORT:
2224 return new DatatypeExpr<>(ctx, obj);
2226 return new FPExpr(ctx, obj);
2228 return new FPRMExpr(ctx, obj);
2230 return new FiniteDomainExpr(ctx, obj);
2231 case Z3_SEQ_SORT:
2232 return new SeqExpr<>(ctx, obj);
2233 case Z3_RE_SORT:
2234 return new ReExpr<>(ctx, obj);
2235 default:
2236 }
2237
2238 return new Expr<>(ctx, obj);
2239 }
2240}
boolean isProofLemma()
Definition Expr.java:1659
boolean isSetUnion()
Definition Expr.java:697
boolean isRelation()
Definition Expr.java:1894
boolean isSelect()
Definition Expr.java:642
boolean isBVRepeat()
Definition Expr.java:1120
boolean isConstantArray()
Definition Expr.java:653
Expr(Context ctx, long obj)
Definition Expr.java:2143
boolean isProofHypothesis()
Definition Expr.java:1643
boolean isProofDER()
Definition Expr.java:1619
boolean isBVSRem()
Definition Expr.java:849
boolean isImplies()
Definition Expr.java:428
boolean isArrayMap()
Definition Expr.java:676
boolean isProofTransitivityStar()
Definition Expr.java:1457
boolean isProofAsserted()
Definition Expr.java:1373
boolean isBVSLT()
Definition Expr.java:980
boolean isBVRotateRightExtended()
Definition Expr.java:1224
Expr< R > substitute(Expr<?>[] from, Expr<?>[] to)
Definition Expr.java:149
boolean isRelationFilter()
Definition Expr.java:1993
boolean isEmptyRelation()
Definition Expr.java:1921
Z3_lbool getBoolValue()
Definition Expr.java:88
Expr< R > substituteVars(Expr<?>[] to)
Definition Expr.java:183
boolean isProofIFFTrue()
Definition Expr.java:1682
boolean isIntToBV()
Definition Expr.java:1236
boolean isUMinus()
Definition Expr.java:528
boolean isRelationalJoin()
Definition Expr.java:1941
boolean isBVUGE()
Definition Expr.java:950
boolean isFalse()
Definition Expr.java:336
boolean isProofApplyDef()
Definition Expr.java:1772
Expr< R > simplify(Params p)
Definition Expr.java:55
boolean isProofNNFNeg()
Definition Expr.java:1831
boolean isBVToInt()
Definition Expr.java:1248
Expr< R > simplify()
Definition Expr.java:41
boolean isBVSLE()
Definition Expr.java:939
boolean isProofTrue()
Definition Expr.java:1363
boolean isProofQuantIntro()
Definition Expr.java:1483
boolean isProofReflexivity()
Definition Expr.java:1413
boolean isProofModusPonensOEQ()
Definition Expr.java:1862
boolean isProofTransitivity()
Definition Expr.java:1437
boolean isWellSorted()
Definition Expr.java:253
boolean isProofPullQuant()
Definition Expr.java:1572
boolean isProofOrElimination()
Definition Expr.java:1524
Expr< R > substituteFuns(FuncDecl<?>[] from, Expr<?>[] to)
Definition Expr.java:203
boolean isProofIFFFalse()
Definition Expr.java:1694
boolean isProofQuantInst()
Definition Expr.java:1631
boolean isBVExtract()
Definition Expr.java:1110
boolean isProofPushQuant()
Definition Expr.java:1587
boolean isRelationUnion()
Definition Expr.java:1953
boolean isProofTheoryLemma()
Definition Expr.java:1884
boolean isRealToInt()
Definition Expr.java:598
boolean isBVRotateLeftExtended()
Definition Expr.java:1212
Expr<?>[] getArgs()
Definition Expr.java:109
boolean isProofSkolemize()
Definition Expr.java:1849
boolean isRelationClone()
Definition Expr.java:2065
boolean isBVBitZero()
Definition Expr.java:779
boolean isBVSub()
Definition Expr.java:809
boolean isProofElimUnusedVars()
Definition Expr.java:1603
boolean isProofSymmetry()
Definition Expr.java:1425
boolean isProofMonotonicity()
Definition Expr.java:1472
boolean isBVZeroExtension()
Definition Expr.java:1100
Expr< R > translate(Context ctx)
Definition Expr.java:223
boolean isAlgebraicNumber()
Definition Expr.java:304
boolean isSetDifference()
Definition Expr.java:717
boolean isProofAndElimination()
Definition Expr.java:1513
boolean isProofDefIntro()
Definition Expr.java:1760
boolean isBVRotateRight()
Definition Expr.java:1200
boolean isArray()
Definition Expr.java:619
boolean isSetComplement()
Definition Expr.java:727
boolean isProofGoal()
Definition Expr.java:1384
boolean isStore()
Definition Expr.java:632
boolean isIntToReal()
Definition Expr.java:588
boolean isArithmeticNumeral()
Definition Expr.java:458
boolean isBVShiftRightArithmetic()
Definition Expr.java:1180
boolean isBVCarry()
Definition Expr.java:1259
boolean isRatNum()
Definition Expr.java:294
boolean isFiniteDomainLT()
Definition Expr.java:2088
FuncDecl< R > getFuncDecl()
Definition Expr.java:76
boolean isIsEmptyRelation()
Definition Expr.java:1931
boolean isBVSGE()
Definition Expr.java:960
boolean isBVRotateLeft()
Definition Expr.java:1190
boolean isBVSDiv()
Definition Expr.java:829
Expr< R > update(Expr<?>[] args)
Definition Expr.java:127
boolean isRealIsInt()
Definition Expr.java:609
boolean isProofUnitResolution()
Definition Expr.java:1670
boolean isBVShiftLeft()
Definition Expr.java:1160
boolean isBVShiftRightLogical()
Definition Expr.java:1170
boolean isFiniteDomain()
Definition Expr.java:2075
boolean isRelationProject()
Definition Expr.java:1978
boolean isSetIntersect()
Definition Expr.java:707
boolean isAsArray()
Definition Expr.java:687
boolean isLabelLit()
Definition Expr.java:1296
boolean isSetSubset()
Definition Expr.java:737
boolean isRelationNegationFilter()
Definition Expr.java:2013
boolean isDistinct()
Definition Expr.java:357
boolean isBVSMod()
Definition Expr.java:869
boolean isRelationWiden()
Definition Expr.java:1965
boolean isRelationSelect()
Definition Expr.java:2049
boolean isBVConcat()
Definition Expr.java:1080
boolean isIntNum()
Definition Expr.java:284
boolean isProofDefAxiom()
Definition Expr.java:1737
boolean isBVUDiv()
Definition Expr.java:839
boolean isBVReduceAND()
Definition Expr.java:1140
boolean isBVULE()
Definition Expr.java:929
boolean isDefaultArray()
Definition Expr.java:664
boolean isBVUGT()
Definition Expr.java:990
boolean isBVURem()
Definition Expr.java:859
boolean isBVUMinus()
Definition Expr.java:789
boolean isBVReduceOR()
Definition Expr.java:1130
boolean isProofModusPonens()
Definition Expr.java:1398
boolean isRelationStore()
Definition Expr.java:1911
boolean isProofRewriteStar()
Definition Expr.java:1560
boolean isBVMul()
Definition Expr.java:819
boolean isProofDistributivity()
Definition Expr.java:1502
boolean isModulus()
Definition Expr.java:578
boolean isRelationRename()
Definition Expr.java:2025
boolean isNumeral()
Definition Expr.java:242
boolean isBVBitOne()
Definition Expr.java:769
boolean isProofNNFPos()
Definition Expr.java:1812
boolean isProofIFFOEQ()
Definition Expr.java:1784
boolean isBVULT()
Definition Expr.java:970
boolean isBVSignExtension()
Definition Expr.java:1090
boolean isBVAdd()
Definition Expr.java:799
boolean isRemainder()
Definition Expr.java:568
boolean isProofCommutativity()
Definition Expr.java:1711
boolean isConst()
Definition Expr.java:274
Expr< R > substitute(Expr<?> from, Expr<?> to)
Definition Expr.java:168
boolean isBVNumeral()
Definition Expr.java:759
boolean isRelationComplement()
Definition Expr.java:2035
boolean isProofRewrite()
Definition Expr.java:1544
static long[] arrayToNative(Z3Object[] a)
Definition Z3Object.java:73
Z3_ast_kind
The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types.
Definition z3_api.h:142
Z3_decl_kind
The different kinds of interpreted function kinds.
Definition z3_api.h:962
Z3_sort_kind
The different kinds of Z3 types (See Z3_get_sort_kind).
Definition z3_api.h:110
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition z3_api.h:58
@ Z3_BOOL_SORT
Definition z3_api.h:112
@ Z3_ROUNDING_MODE_SORT
Definition z3_api.h:121
@ Z3_BV_SORT
Definition z3_api.h:115
@ Z3_DATATYPE_SORT
Definition z3_api.h:117
@ Z3_INT_SORT
Definition z3_api.h:113
@ Z3_FINITE_DOMAIN_SORT
Definition z3_api.h:119
@ Z3_RE_SORT
Definition z3_api.h:123
@ Z3_FLOATING_POINT_SORT
Definition z3_api.h:120
@ Z3_ARRAY_SORT
Definition z3_api.h:116
@ Z3_REAL_SORT
Definition z3_api.h:114
@ Z3_SEQ_SORT
Definition z3_api.h:122