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
251 public double getNumeralDouble()
252 {
253 return Native.getNumeralDouble(getContext().nCtx(), getNativeObject());
254 }
255
262 public boolean isWellSorted()
263 {
264 return Native.isWellSorted(getContext().nCtx(), getNativeObject());
265 }
266
272 public R getSort()
273 {
274 return (R) Sort.create(getContext(),
275 Native.getSort(getContext().nCtx(), getNativeObject()));
276 }
277
283 public boolean isConst()
284 {
285 return isApp() && getNumArgs() == 0 && getFuncDecl().getDomainSize() == 0;
286 }
287
293 public boolean isIntNum()
294 {
295 return isNumeral() && isInt();
296 }
297
303 public boolean isRatNum()
304 {
305 return isNumeral() && isReal();
306 }
307
313 public boolean isAlgebraicNumber()
314 {
315 return Native.isAlgebraicNumber(getContext().nCtx(), getNativeObject());
316 }
317
323 public boolean isGround()
324 {
325 return Native.isGround(getContext().nCtx(), getNativeObject());
326 }
327
333 public boolean isLambda()
334 {
335 return Native.isLambda(getContext().nCtx(), getNativeObject());
336 }
337
343 public boolean isBool()
344 {
345 return (isExpr() && Native.isEqSort(getContext().nCtx(),
346 Native.mkBoolSort(getContext().nCtx()),
347 Native.getSort(getContext().nCtx(), getNativeObject())));
348 }
349
355 public boolean isTrue()
356 {
357 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_TRUE;
358 }
359
365 public boolean isFalse()
366 {
367 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_FALSE;
368 }
369
375 public boolean isEq()
376 {
377 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EQ;
378 }
379
386 public boolean isDistinct()
387 {
388 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_DISTINCT;
389 }
390
396 public boolean isITE()
397 {
398 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ITE;
399 }
400
406 public boolean isAnd()
407 {
408 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_AND;
409 }
410
416 public boolean isOr()
417 {
418 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_OR;
419 }
420
427 public boolean isIff()
428 {
429 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IFF;
430 }
431
437 public boolean isXor()
438 {
439 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_XOR;
440 }
441
447 public boolean isNot()
448 {
449 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_NOT;
450 }
451
457 public boolean isImplies()
458 {
459 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IMPLIES;
460 }
461
467 public boolean isInt()
468 {
469 return Native.getSortKind(getContext().nCtx(), Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_INT_SORT.toInt();
470 }
471
477 public boolean isReal()
478 {
479 return Native.getSortKind(getContext().nCtx(), Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_REAL_SORT.toInt();
480 }
481
483 public boolean isComplex()
484 {
485 return Native.getSortKind(getContext().nCtx(), Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_COMPLEX_SORT.toInt();
486 }
487
493 public boolean isArithmeticNumeral()
494 {
495 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ANUM;
496 }
497
503 public boolean isLE()
504 {
505 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LE;
506 }
507
513 public boolean isGE()
514 {
515 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_GE;
516 }
517
523 public boolean isLT()
524 {
525 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LT;
526 }
527
533 public boolean isGT()
534 {
535 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_GT;
536 }
537
543 public boolean isAdd()
544 {
545 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ADD;
546 }
547
553 public boolean isSub()
554 {
555 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SUB;
556 }
557
563 public boolean isUMinus()
564 {
565 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_UMINUS;
566 }
567
573 public boolean isMul()
574 {
575 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_MUL;
576 }
577
583 public boolean isDiv()
584 {
585 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_DIV;
586 }
587
593 public boolean isIDiv()
594 {
595 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IDIV;
596 }
597
603 public boolean isRemainder()
604 {
605 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_REM;
606 }
607
613 public boolean isModulus()
614 {
615 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_MOD;
616 }
617
623 public boolean isIntToReal()
624 {
625 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_TO_REAL;
626 }
627
633 public boolean isRealToInt()
634 {
635 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_TO_INT;
636 }
637
644 public boolean isRealIsInt()
645 {
646 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_IS_INT;
647 }
648
654 public boolean isArray()
655 {
656 return (Native.isApp(getContext().nCtx(), getNativeObject()) && Z3_sort_kind
657 .fromInt(Native.getSortKind(getContext().nCtx(),
658 Native.getSort(getContext().nCtx(), getNativeObject()))) == Z3_sort_kind.Z3_ARRAY_SORT);
659 }
660
667 public boolean isStore()
668 {
669 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_STORE;
670 }
671
677 public boolean isSelect()
678 {
679 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SELECT;
680 }
681
688 public boolean isConstantArray()
689 {
690 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_CONST_ARRAY;
691 }
692
699 public boolean isDefaultArray()
700 {
701 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ARRAY_DEFAULT;
702 }
703
711 public boolean isArrayMap()
712 {
713 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ARRAY_MAP;
714 }
715
722 public boolean isAsArray()
723 {
724 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_AS_ARRAY;
725 }
726
732 public boolean isSetUnion()
733 {
734 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_UNION;
735 }
736
742 public boolean isSetIntersect()
743 {
744 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_INTERSECT;
745 }
746
752 public boolean isSetDifference()
753 {
754 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_DIFFERENCE;
755 }
756
762 public boolean isSetComplement()
763 {
764 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_COMPLEMENT;
765 }
766
772 public boolean isSetSubset()
773 {
774 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SET_SUBSET;
775 }
776
782 public boolean isBV()
783 {
784 return Native.getSortKind(getContext().nCtx(),
785 Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_BV_SORT
786 .toInt();
787 }
788
794 public boolean isBVNumeral()
795 {
796 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNUM;
797 }
798
804 public boolean isBVBitOne()
805 {
806 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BIT1;
807 }
808
814 public boolean isBVBitZero()
815 {
816 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BIT0;
817 }
818
824 public boolean isBVUMinus()
825 {
826 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNEG;
827 }
828
834 public boolean isBVAdd()
835 {
836 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BADD;
837 }
838
844 public boolean isBVSub()
845 {
846 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSUB;
847 }
848
854 public boolean isBVMul()
855 {
856 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BMUL;
857 }
858
864 public boolean isBVSDiv()
865 {
866 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSDIV;
867 }
868
874 public boolean isBVUDiv()
875 {
876 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUDIV;
877 }
878
884 public boolean isBVSRem()
885 {
886 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSREM;
887 }
888
894 public boolean isBVURem()
895 {
896 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUREM;
897 }
898
904 public boolean isBVSMod()
905 {
906 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSMOD;
907 }
908
914 boolean isBVSDiv0()
915 {
916 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSDIV0;
917 }
918
924 boolean isBVUDiv0()
925 {
926 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUDIV0;
927 }
928
934 boolean isBVSRem0()
935 {
936 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSREM0;
937 }
938
944 boolean isBVURem0()
945 {
946 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BUREM0;
947 }
948
954 boolean isBVSMod0()
955 {
956 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSMOD0;
957 }
958
964 public boolean isBVULE()
965 {
966 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ULEQ;
967 }
968
974 public boolean isBVSLE()
975 {
976 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SLEQ;
977 }
978
985 public boolean isBVUGE()
986 {
987 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_UGEQ;
988 }
989
995 public boolean isBVSGE()
996 {
997 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SGEQ;
998 }
999
1005 public boolean isBVULT()
1006 {
1007 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ULT;
1008 }
1009
1015 public boolean isBVSLT()
1016 {
1017 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SLT;
1018 }
1019
1025 public boolean isBVUGT()
1026 {
1027 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_UGT;
1028 }
1029
1035 public boolean isBVSGT()
1036 {
1037 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SGT;
1038 }
1039
1045 public boolean isBVAND()
1046 {
1047 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BAND;
1048 }
1049
1055 public boolean isBVOR()
1056 {
1057 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BOR;
1058 }
1059
1065 public boolean isBVNOT()
1066 {
1067 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNOT;
1068 }
1069
1075 public boolean isBVXOR()
1076 {
1077 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BXOR;
1078 }
1079
1085 public boolean isBVNAND()
1086 {
1087 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNAND;
1088 }
1089
1095 public boolean isBVNOR()
1096 {
1097 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BNOR;
1098 }
1099
1105 public boolean isBVXNOR()
1106 {
1107 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BXNOR;
1108 }
1109
1115 public boolean isBVConcat()
1116 {
1117 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_CONCAT;
1118 }
1119
1125 public boolean isBVSignExtension()
1126 {
1127 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SIGN_EXT;
1128 }
1129
1135 public boolean isBVZeroExtension()
1136 {
1137 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ZERO_EXT;
1138 }
1139
1145 public boolean isBVExtract()
1146 {
1147 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EXTRACT;
1148 }
1149
1155 public boolean isBVRepeat()
1156 {
1157 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_REPEAT;
1158 }
1159
1165 public boolean isBVReduceOR()
1166 {
1167 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BREDOR;
1168 }
1169
1175 public boolean isBVReduceAND()
1176 {
1177 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BREDAND;
1178 }
1179
1185 public boolean isBVComp()
1186 {
1187 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BCOMP;
1188 }
1189
1195 public boolean isBVShiftLeft()
1196 {
1197 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BSHL;
1198 }
1199
1205 public boolean isBVShiftRightLogical()
1206 {
1207 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BLSHR;
1208 }
1209
1216 {
1217 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BASHR;
1218 }
1219
1225 public boolean isBVRotateLeft()
1226 {
1227 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ROTATE_LEFT;
1228 }
1229
1235 public boolean isBVRotateRight()
1236 {
1237 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_ROTATE_RIGHT;
1238 }
1239
1247 public boolean isBVRotateLeftExtended()
1248 {
1249 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EXT_ROTATE_LEFT;
1250 }
1251
1260 {
1261 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_EXT_ROTATE_RIGHT;
1262 }
1263
1271 public boolean isIntToBV()
1272 {
1273 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_INT2BV;
1274 }
1275
1283 public boolean isBVToInt()
1284 {
1285 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_BV2INT;
1286 }
1287
1294 public boolean isBVCarry()
1295 {
1296 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_CARRY;
1297 }
1298
1305 public boolean isBVXOR3()
1306 {
1307 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_XOR3;
1308 }
1309
1318 public boolean isLabel()
1319 {
1320 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LABEL;
1321 }
1322
1331 public boolean isLabelLit()
1332 {
1333 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_LABEL_LIT;
1334 }
1335
1340 public boolean isString()
1341 {
1342 return isApp() && Native.isString(getContext().nCtx(), getNativeObject());
1343 }
1344
1351 public String getString()
1352 {
1353 return Native.getString(getContext().nCtx(), getNativeObject());
1354 }
1355
1376 public boolean isConcat()
1377 {
1378 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SEQ_CONCAT;
1379 }
1380
1388 public boolean isOEQ()
1389 {
1390 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_OEQ;
1391 }
1392
1398 public boolean isProofTrue()
1399 {
1400 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TRUE;
1401 }
1402
1408 public boolean isProofAsserted()
1409 {
1410 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_ASSERTED;
1411 }
1412
1419 public boolean isProofGoal()
1420 {
1421 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_GOAL;
1422 }
1423
1433 public boolean isProofModusPonens()
1434 {
1435 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS;
1436 }
1437
1448 public boolean isProofReflexivity()
1449 {
1450 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_REFLEXIVITY;
1451 }
1452
1460 public boolean isProofSymmetry()
1461 {
1462 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_SYMMETRY;
1463 }
1464
1472 public boolean isProofTransitivity()
1473 {
1474 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY;
1475 }
1476
1493 {
1494 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TRANSITIVITY_STAR;
1495 }
1496
1507 public boolean isProofMonotonicity()
1508 {
1509 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_MONOTONICITY;
1510 }
1511
1518 public boolean isProofQuantIntro()
1519 {
1520 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_QUANT_INTRO;
1521 }
1522
1537 public boolean isProofDistributivity()
1538 {
1539 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DISTRIBUTIVITY;
1540 }
1541
1548 public boolean isProofAndElimination()
1549 {
1550 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_AND_ELIM;
1551 }
1552
1559 public boolean isProofOrElimination()
1560 {
1561 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NOT_OR_ELIM;
1562 }
1563
1579 public boolean isProofRewrite()
1580 {
1581 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_REWRITE;
1582 }
1583
1595 public boolean isProofRewriteStar()
1596 {
1597 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_REWRITE_STAR;
1598 }
1599
1607 public boolean isProofPullQuant()
1608 {
1609 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_PULL_QUANT;
1610 }
1611
1612
1622 public boolean isProofPushQuant()
1623 {
1624 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_PUSH_QUANT;
1625 }
1626
1638 public boolean isProofElimUnusedVars()
1639 {
1640 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_ELIM_UNUSED_VARS;
1641 }
1642
1654 public boolean isProofDER()
1655 {
1656 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DER;
1657 }
1658
1666 public boolean isProofQuantInst()
1667 {
1668 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_QUANT_INST;
1669 }
1670
1678 public boolean isProofHypothesis()
1679 {
1680 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_HYPOTHESIS;
1681 }
1682
1694 public boolean isProofLemma()
1695 {
1696 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_LEMMA;
1697 }
1698
1705 public boolean isProofUnitResolution()
1706 {
1707 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_UNIT_RESOLUTION;
1708 }
1709
1717 public boolean isProofIFFTrue()
1718 {
1719 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_TRUE;
1720 }
1721
1729 public boolean isProofIFFFalse()
1730 {
1731 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_FALSE;
1732 }
1733
1746 public boolean isProofCommutativity()
1747 {
1748 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_COMMUTATIVITY;
1749 }
1750
1772 public boolean isProofDefAxiom()
1773 {
1774 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DEF_AXIOM;
1775 }
1776
1795 public boolean isProofDefIntro()
1796 {
1797 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_DEF_INTRO;
1798 }
1799
1807 public boolean isProofApplyDef()
1808 {
1809 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_APPLY_DEF;
1810 }
1811
1819 public boolean isProofIFFOEQ()
1820 {
1821 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_IFF_OEQ;
1822 }
1823
1847 public boolean isProofNNFPos()
1848 {
1849 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_POS;
1850 }
1851
1866 public boolean isProofNNFNeg()
1867 {
1868 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_NEG;
1869 }
1870
1871
1884 public boolean isProofSkolemize()
1885 {
1886 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_SKOLEMIZE;
1887 }
1888
1897 public boolean isProofModusPonensOEQ()
1898 {
1899 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_MODUS_PONENS_OEQ;
1900 }
1901
1919 public boolean isProofTheoryLemma()
1920 {
1921 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_TH_LEMMA;
1922 }
1923
1929 public boolean isRelation()
1930 {
1931 return (Native.isApp(getContext().nCtx(), getNativeObject()) && Native
1932 .getSortKind(getContext().nCtx(),
1933 Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_RELATION_SORT
1934 .toInt());
1935 }
1936
1946 public boolean isRelationStore()
1947 {
1948 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_STORE;
1949 }
1950
1956 public boolean isEmptyRelation()
1957 {
1958 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_EMPTY;
1959 }
1960
1966 public boolean isIsEmptyRelation()
1967 {
1968 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_IS_EMPTY;
1969 }
1970
1976 public boolean isRelationalJoin()
1977 {
1978 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_JOIN;
1979 }
1980
1988 public boolean isRelationUnion()
1989 {
1990 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_UNION;
1991 }
1992
2000 public boolean isRelationWiden()
2001 {
2002 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_WIDEN;
2003 }
2004
2013 public boolean isRelationProject()
2014 {
2015 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_PROJECT;
2016 }
2017
2028 public boolean isRelationFilter()
2029 {
2030 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_FILTER;
2031 }
2032
2049 {
2050 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_NEGATION_FILTER;
2051 }
2052
2060 public boolean isRelationRename()
2061 {
2062 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_RENAME;
2063 }
2064
2070 public boolean isRelationComplement()
2071 {
2072 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_COMPLEMENT;
2073 }
2074
2084 public boolean isRelationSelect()
2085 {
2086 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_SELECT;
2087 }
2088
2100 public boolean isRelationClone()
2101 {
2102 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_RA_CLONE;
2103 }
2104
2110 public boolean isFiniteDomain()
2111 {
2112 return (Native.isApp(getContext().nCtx(), getNativeObject()) && Native
2113 .getSortKind(getContext().nCtx(),
2114 Native.getSort(getContext().nCtx(), getNativeObject())) == Z3_sort_kind.Z3_FINITE_DOMAIN_SORT
2115 .toInt());
2116 }
2117
2123 public boolean isFiniteDomainLT()
2124 {
2125 return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_FD_LT;
2126 }
2127
2146 public int getIndex()
2147 {
2148 if (!isVar()) {
2149 throw new Z3Exception("Term is not a bound variable.");
2150 }
2151
2152 return Native.getIndexValue(getContext().nCtx(), getNativeObject());
2153 }
2154
2155 private Class sort = null;
2156
2165 public <S extends R> Expr<S> distillSort(Class<S> newSort) {
2166 if (sort != null && !newSort.isAssignableFrom(sort)) {
2167 throw new Z3Exception(
2168 String.format("Cannot distill expression of sort %s to %s.", sort.getName(), newSort.getName()));
2169 }
2170
2171 return (Expr<S>) ((Expr<?>) this);
2172 }
2173
2178 protected Expr(Context ctx, long obj) {
2179 super(ctx, obj);
2180 Type superclass = getClass().getGenericSuperclass();
2181 if (superclass instanceof ParameterizedType) {
2182 Type argType = ((ParameterizedType) superclass).getActualTypeArguments()[0];
2183 if (argType instanceof Class) {
2184 this.sort = (Class) argType;
2185 }
2186 }
2187 }
2188
2189 @Override
2190 void checkNativeObject(long obj) {
2191 if (!Native.isApp(getContext().nCtx(), obj) &&
2192 Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_VAR_AST.toInt() &&
2193 Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_QUANTIFIER_AST.toInt()) {
2194 throw new Z3Exception("Underlying object is not a term");
2195 }
2196 super.checkNativeObject(obj);
2197 }
2198
2199 static <U extends Sort> Expr<U> create(Context ctx, FuncDecl<U> f, Expr<?> ... arguments)
2200 {
2201 long obj = Native.mkApp(ctx.nCtx(), f.getNativeObject(),
2202 AST.arrayLength(arguments), AST.arrayToNative(arguments));
2203 return (Expr<U>) create(ctx, obj);
2204 }
2205
2206 // TODO generify, but it conflicts with AST.create
2207 static Expr<?> create(Context ctx, long obj)
2208 {
2209 Z3_ast_kind k = Z3_ast_kind.fromInt(Native.getAstKind(ctx.nCtx(), obj));
2210 if (k == Z3_ast_kind.Z3_QUANTIFIER_AST) {
2211 // a quantifier AST is a lambda iff it is neither a forall nor an exists.
2212 boolean isLambda = !Native.isQuantifierExists(ctx.nCtx(), obj) && !Native.isQuantifierForall(ctx.nCtx(), obj);
2213 if (isLambda) {
2214 return new Lambda(ctx, obj);
2215 } else {
2216 return new Quantifier(ctx, obj);
2217 }
2218 }
2219 long s = Native.getSort(ctx.nCtx(), obj);
2221 .fromInt(Native.getSortKind(ctx.nCtx(), s));
2222
2223 if (Native.isAlgebraicNumber(ctx.nCtx(), obj)) // is this a numeral ast?
2224 return new AlgebraicNum(ctx, obj);
2225
2226 if (Native.isNumeralAst(ctx.nCtx(), obj))
2227 {
2228 switch (sk)
2229 {
2230 case Z3_INT_SORT:
2231 return new IntNum(ctx, obj);
2232 case Z3_REAL_SORT:
2233 return new RatNum(ctx, obj);
2234 case Z3_BV_SORT:
2235 return new BitVecNum(ctx, obj);
2237 return new FPNum(ctx, obj);
2239 return new FPRMNum(ctx, obj);
2241 return new FiniteDomainNum(ctx, obj);
2242 default:
2243 }
2244 }
2245
2246 switch (sk)
2247 {
2248 case Z3_BOOL_SORT:
2249 return new BoolExpr(ctx, obj);
2250 case Z3_INT_SORT:
2251 return new IntExpr(ctx, obj);
2252 case Z3_REAL_SORT:
2253 return new RealExpr(ctx, obj);
2254 case Z3_COMPLEX_SORT:
2255 return new ComplexExpr(ctx, obj);
2256 case Z3_BV_SORT:
2257 return new BitVecExpr(ctx, obj);
2258 case Z3_ARRAY_SORT:
2259 return new ArrayExpr<>(ctx, obj);
2260 case Z3_DATATYPE_SORT:
2261 return new DatatypeExpr<>(ctx, obj);
2263 return new FPExpr(ctx, obj);
2265 return new FPRMExpr(ctx, obj);
2267 return new FiniteDomainExpr(ctx, obj);
2268 case Z3_SEQ_SORT:
2269 return new SeqExpr<>(ctx, obj);
2270 case Z3_RE_SORT:
2271 return new ReExpr<>(ctx, obj);
2272 default:
2273 }
2274
2275 return new Expr<>(ctx, obj);
2276 }
2277}
boolean isProofLemma()
Definition Expr.java:1694
boolean isSetUnion()
Definition Expr.java:732
boolean isRelation()
Definition Expr.java:1929
boolean isSelect()
Definition Expr.java:677
boolean isBVRepeat()
Definition Expr.java:1155
boolean isConstantArray()
Definition Expr.java:688
Expr(Context ctx, long obj)
Definition Expr.java:2178
boolean isProofHypothesis()
Definition Expr.java:1678
boolean isProofDER()
Definition Expr.java:1654
boolean isBVSRem()
Definition Expr.java:884
boolean isImplies()
Definition Expr.java:457
boolean isArrayMap()
Definition Expr.java:711
boolean isProofTransitivityStar()
Definition Expr.java:1492
boolean isProofAsserted()
Definition Expr.java:1408
boolean isBVRotateRightExtended()
Definition Expr.java:1259
Expr< R > substitute(Expr<?>[] from, Expr<?>[] to)
Definition Expr.java:149
boolean isRelationFilter()
Definition Expr.java:2028
boolean isEmptyRelation()
Definition Expr.java:1956
Z3_lbool getBoolValue()
Definition Expr.java:88
Expr< R > substituteVars(Expr<?>[] to)
Definition Expr.java:183
boolean isProofIFFTrue()
Definition Expr.java:1717
boolean isIntToBV()
Definition Expr.java:1271
boolean isUMinus()
Definition Expr.java:563
boolean isRelationalJoin()
Definition Expr.java:1976
boolean isBVUGE()
Definition Expr.java:985
boolean isFalse()
Definition Expr.java:365
boolean isProofApplyDef()
Definition Expr.java:1807
Expr< R > simplify(Params p)
Definition Expr.java:55
boolean isProofNNFNeg()
Definition Expr.java:1866
boolean isBVToInt()
Definition Expr.java:1283
Expr< R > simplify()
Definition Expr.java:41
boolean isBVSLE()
Definition Expr.java:974
boolean isProofTrue()
Definition Expr.java:1398
boolean isProofQuantIntro()
Definition Expr.java:1518
boolean isProofReflexivity()
Definition Expr.java:1448
boolean isProofModusPonensOEQ()
Definition Expr.java:1897
boolean isProofTransitivity()
Definition Expr.java:1472
boolean isWellSorted()
Definition Expr.java:262
boolean isProofPullQuant()
Definition Expr.java:1607
boolean isProofOrElimination()
Definition Expr.java:1559
Expr< R > substituteFuns(FuncDecl<?>[] from, Expr<?>[] to)
Definition Expr.java:203
boolean isProofIFFFalse()
Definition Expr.java:1729
boolean isProofQuantInst()
Definition Expr.java:1666
boolean isBVExtract()
Definition Expr.java:1145
boolean isProofPushQuant()
Definition Expr.java:1622
boolean isRelationUnion()
Definition Expr.java:1988
boolean isProofTheoryLemma()
Definition Expr.java:1919
boolean isRealToInt()
Definition Expr.java:633
boolean isBVRotateLeftExtended()
Definition Expr.java:1247
Expr<?>[] getArgs()
Definition Expr.java:109
boolean isProofSkolemize()
Definition Expr.java:1884
boolean isRelationClone()
Definition Expr.java:2100
boolean isBVBitZero()
Definition Expr.java:814
boolean isBVSub()
Definition Expr.java:844
boolean isProofElimUnusedVars()
Definition Expr.java:1638
boolean isProofSymmetry()
Definition Expr.java:1460
boolean isGround()
Definition Expr.java:323
boolean isProofMonotonicity()
Definition Expr.java:1507
boolean isBVZeroExtension()
Definition Expr.java:1135
Expr< R > translate(Context ctx)
Definition Expr.java:223
boolean isAlgebraicNumber()
Definition Expr.java:313
boolean isSetDifference()
Definition Expr.java:752
boolean isProofAndElimination()
Definition Expr.java:1548
boolean isProofDefIntro()
Definition Expr.java:1795
boolean isBVRotateRight()
Definition Expr.java:1235
boolean isArray()
Definition Expr.java:654
boolean isSetComplement()
Definition Expr.java:762
boolean isProofGoal()
Definition Expr.java:1419
boolean isStore()
Definition Expr.java:667
boolean isIntToReal()
Definition Expr.java:623
boolean isArithmeticNumeral()
Definition Expr.java:493
boolean isBVShiftRightArithmetic()
Definition Expr.java:1215
boolean isBVCarry()
Definition Expr.java:1294
boolean isRatNum()
Definition Expr.java:303
boolean isFiniteDomainLT()
Definition Expr.java:2123
FuncDecl< R > getFuncDecl()
Definition Expr.java:76
boolean isIsEmptyRelation()
Definition Expr.java:1966
boolean isBVSGE()
Definition Expr.java:995
boolean isBVRotateLeft()
Definition Expr.java:1225
boolean isBVSDiv()
Definition Expr.java:864
Expr< R > update(Expr<?>[] args)
Definition Expr.java:127
boolean isComplex()
Definition Expr.java:483
boolean isRealIsInt()
Definition Expr.java:644
boolean isProofUnitResolution()
Definition Expr.java:1705
boolean isBVShiftLeft()
Definition Expr.java:1195
boolean isBVShiftRightLogical()
Definition Expr.java:1205
boolean isFiniteDomain()
Definition Expr.java:2110
boolean isRelationProject()
Definition Expr.java:2013
boolean isSetIntersect()
Definition Expr.java:742
boolean isAsArray()
Definition Expr.java:722
boolean isLabelLit()
Definition Expr.java:1331
boolean isSetSubset()
Definition Expr.java:772
boolean isRelationNegationFilter()
Definition Expr.java:2048
boolean isDistinct()
Definition Expr.java:386
boolean isBVSMod()
Definition Expr.java:904
boolean isLambda()
Definition Expr.java:333
boolean isRelationWiden()
Definition Expr.java:2000
boolean isRelationSelect()
Definition Expr.java:2084
boolean isBVConcat()
Definition Expr.java:1115
boolean isIntNum()
Definition Expr.java:293
boolean isProofDefAxiom()
Definition Expr.java:1772
boolean isBVUDiv()
Definition Expr.java:874
boolean isBVReduceAND()
Definition Expr.java:1175
boolean isBVULE()
Definition Expr.java:964
boolean isDefaultArray()
Definition Expr.java:699
boolean isBVURem()
Definition Expr.java:894
boolean isBVUMinus()
Definition Expr.java:824
boolean isBVReduceOR()
Definition Expr.java:1165
boolean isProofModusPonens()
Definition Expr.java:1433
boolean isRelationStore()
Definition Expr.java:1946
boolean isProofRewriteStar()
Definition Expr.java:1595
boolean isBVMul()
Definition Expr.java:854
boolean isProofDistributivity()
Definition Expr.java:1537
boolean isModulus()
Definition Expr.java:613
boolean isRelationRename()
Definition Expr.java:2060
boolean isNumeral()
Definition Expr.java:242
boolean isBVBitOne()
Definition Expr.java:804
boolean isProofNNFPos()
Definition Expr.java:1847
boolean isProofIFFOEQ()
Definition Expr.java:1819
boolean isBVSignExtension()
Definition Expr.java:1125
boolean isBVAdd()
Definition Expr.java:834
boolean isRemainder()
Definition Expr.java:603
boolean isProofCommutativity()
Definition Expr.java:1746
double getNumeralDouble()
Definition Expr.java:251
boolean isConst()
Definition Expr.java:283
Expr< R > substitute(Expr<?> from, Expr<?> to)
Definition Expr.java:168
boolean isBVNumeral()
Definition Expr.java:794
boolean isRelationComplement()
Definition Expr.java:2070
boolean isProofRewrite()
Definition Expr.java:1579
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:144
Z3_decl_kind
The different kinds of interpreted function kinds.
Definition z3_api.h:990
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_COMPLEX_SORT
Definition z3_api.h:127
@ 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