MCPcopy Create free account
hub / github.com/Z3Prover/z3 / enumExampleUntyped

Method enumExampleUntyped

examples/java/JavaGenericExample.java:1364–1402  ·  view source on GitHub ↗
(Context ctx)

Source from the content-addressed store, hash-verified

1362 // while you can do this untyped, it's safer to have a helper function -- this will prevent you from
1363 // mixing up your enum types
1364 public void enumExampleUntyped(Context ctx) throws TestFailedException
1365 {
1366 System.out.println("EnumExample");
1367 Log.append("EnumExample");
1368
1369 Symbol name = ctx.mkSymbol("fruit2");
1370
1371 EnumSort<Object> fruit = ctx.mkEnumSort(name, ctx.mkSymbol("apple2"),
1372 ctx.mkSymbol("banana2"), ctx.mkSymbol("orange2"));
1373
1374 System.out.println((fruit.getConsts()[0]));
1375 System.out.println((fruit.getConsts()[1]));
1376 System.out.println((fruit.getConsts()[2]));
1377
1378 System.out.println((fruit.getTesterDecls()[0]));
1379 System.out.println((fruit.getTesterDecls()[1]));
1380 System.out.println((fruit.getTesterDecls()[2]));
1381
1382 Expr<EnumSort<Object>> apple = fruit.getConsts()[0];
1383 Expr<EnumSort<Object>> banana = fruit.getConsts()[1];
1384 Expr<EnumSort<Object>> orange = fruit.getConsts()[2];
1385
1386 /* Apples are different from oranges */
1387 prove(ctx, ctx.mkNot(ctx.mkEq(apple, orange)), false);
1388
1389 /* Apples pass the apple test */
1390 prove(ctx, ctx.mkApp(fruit.getTesterDecls()[0], apple),
1391 false);
1392
1393 /* Oranges fail the apple test */
1394 disprove(ctx, ctx.mkApp(fruit.getTesterDecls()[0], orange), false);
1395 prove(ctx, ctx.mkNot(ctx.mkApp(fruit.getTesterDecls()[0], orange)), false);
1396
1397 Expr<EnumSort<Object>> fruity = ctx.mkConst("fruity", fruit);
1398
1399 /* If something is fruity, then it is an apple, banana, or orange */
1400
1401 prove(ctx, ctx.mkOr(ctx.mkEq(fruity, apple), ctx.mkEq(fruity, banana), ctx.mkEq(fruity, orange)), false);
1402 }
1403
1404 // / Create a list datatype.
1405

Callers 1

mainMethod · 0.95

Calls 12

appendMethod · 0.95
proveMethod · 0.95
disproveMethod · 0.95
mkSymbolMethod · 0.80
mkEnumSortMethod · 0.80
getConstsMethod · 0.80
getTesterDeclsMethod · 0.80
mkNotMethod · 0.80
mkEqMethod · 0.80
mkAppMethod · 0.80
mkConstMethod · 0.80
mkOrMethod · 0.80

Tested by

no test coverage detected