Java Code Examples for kodkod.ast.Formula#not()
The following examples show how to use
kodkod.ast.Formula#not() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PartialCannonicalizer.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret!=null) return ret; final Formula child = not.formula().accept(this); ret = simplify(child); if (ret==null) { final int hash = hash(NotFormula.class, child); for(Iterator<PartialCannonicalizer.Holder<Formula>> itr = formulas.get(hash); itr.hasNext(); ) { final Formula next = itr.next().obj; if (next.getClass()==NotFormula.class) { if (((NotFormula)next).formula()==child) return cache(not, next); } } ret = child==not.formula() ? not : child.not(); formulas.add(new PartialCannonicalizer.Holder<Formula>(ret, hash)); } return cache(not,ret); }
Example 2
Source File: AbstractReplacer.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls lookup(binFormula) and returns the cached value, if any. If a * replacement has not been cached, visits the formula's child. If nothing * changes, the argument is cached and returned, otherwise a replacement formula * is cached and returned. * * @return { n: NotFormula | n.child = not.child.accept(delegate) } */ @Override public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret != null) return ret; final Formula child = not.formula().accept(delegate); ret = (child == not.formula()) ? not : child.not(); return cache(not, ret); }
Example 3
Source File: PrenexNFConverter.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
@Override public Formula visit(NotFormula not) { Formula sub = not.formula().accept(this); Pair p = new Pair(sub, null); Formula ans; if (p.hasNoQuant() && sub == not.formula()) ans = not; else if (p.hasNoQuant()) ans = sub.not(); else ans = pushNegation(p.leftQF); return saveMapping(ans, not); }
Example 4
Source File: AbstractReplacer.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(binFormula) and returns the cached value, if any. * If a replacement has not been cached, visits the formula's * child. If nothing changes, the argument is cached and * returned, otherwise a replacement formula is cached and returned. * @return { n: NotFormula | n.child = not.child.accept(this) } */ public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret!=null) return ret; final Formula child = not.formula().accept(this); ret = (child==not.formula()) ? not : child.not(); return cache(not,ret); }
Example 5
Source File: ExpressionUtil.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public static Formula string_equal(Expression l, Expression r, boolean negated) { Formula test = value(l).eq(value(r)); if (negated) { test = test.not(); } return isStringOrSimple(l).and(isStringOrSimple(r)).and(test); }
Example 6
Source File: ExpressionUtil.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public static Formula language_equal(Expression l, Expression r, boolean negated) { Formula test = value(l).eq(value(r)); if (negated) { test = test.not(); } return isLanguage(l).and(isLanguage(r)).and(test).and(language(l).eq(language(r))); }
Example 7
Source File: ExpressionUtil.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public static Formula numeric_test(Pair<Expression,IntExpression> l, Pair<Expression,IntExpression> r, IntCompOperator op, boolean negated) { Formula test = intValue(l).compare(op, intValue(r)); if (negated) { test = test.not(); } return isNumeric(l).and(isNumeric(r)).and(test); }
Example 8
Source File: ExpressionUtil.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public static Formula numeric_test(Expression l, Expression r, IntCompOperator op, boolean negated) { Formula test = intValue(l).compare(op, intValue(r)); if (negated) { test = test.not(); } return isNumeric(l).and(isNumeric(r)).and(test); }
Example 9
Source File: ExpressionUtil.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public static Formula unknown_equal(Expression l, Expression r, boolean negated) { Formula test = type(l).eq(type(r)); if (negated) { test = test.not(); } return isUnknown(l).and(isUnknown(r)).and(value(l).eq(value(r))).and(test); }
Example 10
Source File: Simplifier.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public Formula visit(NotFormula not) { Formula ret = lookup(not); if (ret!=null) return ret; final Formula child = not.formula().accept(this); ret = simplify(child); if (ret==null) { ret = child==not.formula() ? not : child.not(); } return cache(not,ret); }
Example 11
Source File: FullNegationPropagator.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
private Formula not(Formula f) { return f instanceof NotFormula ? ((NotFormula) f).formula() : f.not(); }
Example 12
Source File: PrenexNFConverter.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
protected Formula pushNegation(Formula f) { if (f instanceof QuantifiedFormula) return pushNegation((QuantifiedFormula) f); return f.not(); }
Example 13
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_03062008_2() { Relation x5 = Relation.unary("Role"); Relation x6 = Relation.unary("Session"); List<String> atomlist = Arrays.asList("Role$0", "Session$0", "Session$1"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x5_upper = factory.noneOf(1); x5_upper.add(factory.tuple("Role$0")); bounds.bound(x5, x5_upper); TupleSet x6_upper = factory.noneOf(1); x6_upper.add(factory.tuple("Session$0")); x6_upper.add(factory.tuple("Session$1")); bounds.bound(x6, x6_upper); Variable x11 = Variable.unary("x_a"); Decls x10 = x11.oneOf(x6); Variable x15 = Variable.unary("x_b"); Decls x14 = x15.oneOf(x5); Variable x17 = Variable.unary("x_c"); Decls x16 = x17.oneOf(x5); Decls x13 = x14.and(x16); Expression x20 = x15.product(x17); Expression x19 = x11.product(x20); Formula x18 = x19.some(); Formula x12 = x18.forSome(x13); Formula x9 = x12.forAll(x10); Formula x24 = x5.some(); Formula x23 = x24.not(); Formula x28 = x5.eq(x5); Formula x29 = x6.eq(x6); Formula x25 = x28.and(x29); Formula x22 = x23.and(x25); Formula x8 = x9.and(x22).and(x5.no()).and(x6.no()); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(2); // solver.options().setFlatten(false); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); solver.options().setSkolemDepth(2); System.out.flush(); Solution sol = solver.solve(x8, bounds); Instance inst = sol.instance(); assertNotNull(inst); for (Relation rel : inst.relations()) { if (rel != x5 && rel != x6) { final TupleSet range = inst.tuples(x6).product(inst.tuples(x5)); assertTrue(range.containsAll(inst.tuples(rel))); } } }
Example 14
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_11122006() { Relation x0 = Relation.nary("Q", 1); Relation x1 = Relation.nary("B", 1); Relation x2 = Relation.nary("A", 1); Relation x3 = Relation.nary("QQ", 3); List<String> atomlist = Arrays.asList("A", "B", "Q"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x0_upper = factory.noneOf(1); x0_upper.add(factory.tuple("Q")); bounds.boundExactly(x0, x0_upper); TupleSet x1_upper = factory.noneOf(1); x1_upper.add(factory.tuple("B")); bounds.boundExactly(x1, x1_upper); TupleSet x2_upper = factory.noneOf(1); x2_upper.add(factory.tuple("A")); bounds.boundExactly(x2, x2_upper); TupleSet x3_upper = factory.noneOf(3); x3_upper.add(factory.tuple("Q").product(factory.tuple("A")).product(factory.tuple("A"))); x3_upper.add(factory.tuple("Q").product(factory.tuple("B")).product(factory.tuple("B"))); bounds.bound(x3, x3_upper); Expression x7 = x2.product(x2); Expression x8 = x0.join(x3); Formula x6 = x7.in(x8); Formula x5 = x6.not(); Expression x18 = x1.product(x1); Expression x17 = x7.union(x18); Expression x16 = x0.product(x17); Formula x15 = x3.in(x16); Formula x4 = x5.and(x15); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); // System.out.println(bounds); // System.out.println(x4); Solution sol = solver.solve(x4, bounds); assertEquals(sol.outcome(), Solution.Outcome.SATISFIABLE); // System.out.println(sol.toString()); }
Example 15
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testFelix_03062008_2() { Relation x5 = Relation.unary("Role"); Relation x6 = Relation.unary("Session"); List<String> atomlist = Arrays.asList("Role$0", "Session$0", "Session$1"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x5_upper = factory.noneOf(1); x5_upper.add(factory.tuple("Role$0")); bounds.bound(x5, x5_upper); TupleSet x6_upper = factory.noneOf(1); x6_upper.add(factory.tuple("Session$0")); x6_upper.add(factory.tuple("Session$1")); bounds.bound(x6, x6_upper); Variable x11=Variable.unary("x_a"); Decls x10=x11.oneOf(x6); Variable x15=Variable.unary("x_b"); Decls x14=x15.oneOf(x5); Variable x17=Variable.unary("x_c"); Decls x16=x17.oneOf(x5); Decls x13=x14.and(x16); Expression x20=x15.product(x17); Expression x19=x11.product(x20); Formula x18=x19.some(); Formula x12=x18.forSome(x13); Formula x9=x12.forAll(x10); Formula x24=x5.some(); Formula x23=x24.not(); Formula x28=x5.eq(x5); Formula x29=x6.eq(x6); Formula x25=x28.and(x29); Formula x22=x23.and(x25); Formula x8=x9.and(x22).and(x5.no()).and(x6.no()); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(2); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); solver.options().setSkolemDepth(2); System.out.flush(); Solution sol = solver.solve(x8, bounds); Instance inst = sol.instance(); assertNotNull(inst); for(Relation rel : inst.relations()) { if (rel!=x5 && rel!=x6) { final TupleSet range = inst.tuples(x6).product(inst.tuples(x5)); assertTrue(range.containsAll(inst.tuples(rel))); } } }
Example 16
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testFelix_11122006() { Relation x0 = Relation.nary("Q", 1); Relation x1 = Relation.nary("B", 1); Relation x2 = Relation.nary("A", 1); Relation x3 = Relation.nary("QQ", 3); List<String> atomlist = Arrays.asList("A", "B", "Q"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x0_upper = factory.noneOf(1); x0_upper.add(factory.tuple("Q")); bounds.boundExactly(x0, x0_upper); TupleSet x1_upper = factory.noneOf(1); x1_upper.add(factory.tuple("B")); bounds.boundExactly(x1, x1_upper); TupleSet x2_upper = factory.noneOf(1); x2_upper.add(factory.tuple("A")); bounds.boundExactly(x2, x2_upper); TupleSet x3_upper = factory.noneOf(3); x3_upper.add(factory.tuple("Q").product(factory.tuple("A")).product(factory.tuple("A"))); x3_upper.add(factory.tuple("Q").product(factory.tuple("B")).product(factory.tuple("B"))); bounds.bound(x3, x3_upper); Expression x7=x2.product(x2); Expression x8=x0.join(x3); Formula x6=x7.in(x8); Formula x5=x6.not(); Expression x18=x1.product(x1); Expression x17=x7.union(x18); Expression x16=x0.product(x17); Formula x15=x3.in(x16); Formula x4=x5.and(x15); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); // System.out.println(bounds); // System.out.println(x4); Solution sol = solver.solve(x4,bounds); assertEquals(sol.outcome(), Solution.Outcome.SATISFIABLE); // System.out.println(sol.toString()); }