Java Code Examples for kodkod.ast.Formula#forSome()
The following examples show how to use
kodkod.ast.Formula#forSome() .
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: ReductionAndProofTest.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testProof() { Variable v0 = Variable.unary("v0"), v1 = Variable.unary("v1"), v2 = Variable.unary("v2"); Formula f0 = v0.join(a2b).eq(v1.union(v2)).and(v1.eq(v2).not()); Formula f1 = f0.forSome(v0.oneOf(a).and(v1.oneOf(b)).and(v2.oneOf(b))); Formula f2 = a2b.function(a, b); Formula f3 = f1.and(f2).and(total.totalOrder(ordered, first, last)); Solution sol = null; solver.options().setLogTranslation(0); solver.options().setSolver(SATFactory.MiniSat); sol = solver.solve(f3, bounds); assertEquals(Solution.Outcome.UNSATISFIABLE, sol.outcome()); assertNull(sol.proof()); solver.options().setLogTranslation(1); sol = solver.solve(f3, bounds); assertNull(sol.proof()); solver.options().setSolver(SATFactory.MiniSatProver); sol = solver.solve(f3, bounds); // System.out.println(f3 + ", " + bounds); sol.proof().minimize(new ECFPStrategy()); final Set<Formula> top = Nodes.minRoots(f3, sol.proof().highLevelCore().values()); assertEquals(2, top.size()); assertTrue(top.contains(f1)); assertTrue(top.contains(f2)); // for(Iterator<TranslationLog.Record> itr = sol.proof().core(); // itr.hasNext(); ) { // System.out.println(itr.next()); // } }
Example 2
Source File: ReductionAndProofTest.java From kodkod with MIT License | 5 votes |
@Test public final void testProof() { Variable v0 = Variable.unary("v0"), v1 = Variable.unary("v1"), v2 = Variable.unary("v2"); Formula f0 = v0.join(a2b).eq(v1.union(v2)).and(v1.eq(v2).not()); Formula f1 = f0.forSome(v0.oneOf(a).and(v1.oneOf(b)).and(v2.oneOf(b))); Formula f2 = a2b.function(a, b); Formula f3 = f1.and(f2).and(total.totalOrder(ordered, first, last)); Solution sol = null; solver.options().setLogTranslation(0); solver.options().setSolver(SATFactory.MiniSat); sol = solver.solve(f3, bounds); assertEquals(Solution.Outcome.UNSATISFIABLE, sol.outcome()); assertNull(sol.proof()); solver.options().setLogTranslation(1); sol = solver.solve(f3, bounds); assertNull(sol.proof()); solver.options().setSolver(SATFactory.MiniSatProver); sol = solver.solve(f3, bounds); //System.out.println(f3 + ", " + bounds); sol.proof().minimize(new ECFPStrategy()); final Set<Formula> top = Nodes.minRoots(f3, sol.proof().highLevelCore().values()); assertEquals(2, top.size()); assertTrue(top.contains(f1)); assertTrue(top.contains(f2)); // for(Iterator<TranslationLog.Record> itr = sol.proof().core(); itr.hasNext(); ) { // System.out.println(itr.next()); // } }
Example 3
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testBGP_03172011() { Relation x5 = Relation.unary("s012"); Relation x8 = Relation.unary("zero"); Relation x9 = Relation.unary("one"); Relation x12 = Relation.nary("next", 2); Universe universe = new Universe(Arrays.asList("0", "1", "2", "3")); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.boundExactly(x5, factory.setOf("0", "1", "2")); bounds.boundExactly(x8, factory.setOf("0")); bounds.bound(x9, factory.setOf("1"), factory.setOf("1", "2")); TupleSet x12_upper = factory.noneOf(2); x12_upper.add(factory.tuple("1", "2")); x12_upper.add(factory.tuple("2", "3")); bounds.boundExactly(x12, x12_upper); Variable x714 = Variable.unary("x714"); Decls x713 = x714.oneOf(x8.union(x9)); Variable x720 = Variable.unary("x720"); Expression x723 = x8.union(x9); Expression x724 = x9.join(x12); Expression x722 = x723.union(x724); Expression x721 = x722.difference(x714); Decls x719 = x720.oneOf(x721); Variable x727 = Variable.unary("x727"); Expression x732 = x714.union(x720); Expression x728 = x5.difference(x732); Decls x726 = x727.oneOf(x728); Variable x735 = Variable.unary("x735"); Decls x734 = x735.oneOf(x8); Variable x893 = Variable.unary("x893"); Decls x892 = x893.oneOf(x727); Formula x894 = x720.no(); Formula x891 = x894.forAll(x892); Formula x712 = x891.forSome(x713.and(x719).and(x726).and(x734)); Formula x267 = Formula.FALSE.or(x712); Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setBitwidth(4); // solver.options().setFlatten(false); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); solver.options().setSkolemDepth(0); final Solution sol = solver.solve(x267, bounds); assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE); }
Example 4
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_06192008() { Relation x5 = Relation.unary("R"); List<String> atomlist = Arrays.asList("X"); 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("X")); bounds.bound(x5, x5_upper); Variable x10 = Variable.unary("a"); Expression x11 = x5.difference(x5); Decls x9 = x10.oneOf(x11); Variable x14 = Variable.nary("b", 2); Expression x15 = x5.product(x5); Decls x13 = x14.setOf(x15); Expression x19 = x5.product(x5); Formula x17 = x14.in(x19); Expression x22 = x10.product(x10); Formula x21 = x22.eq(x14); Formula x16 = x17.and(x21); Formula x12 = x16.forSome(x13); Formula x7 = x12.forAll(x9); // System.out.println(x7); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); // solver.options().setFlatten(false); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); // System.out.println("Depth=0..."); System.out.flush(); solver.options().setSkolemDepth(0); assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome()); // System.out.println("Depth=1..."); System.out.flush(); solver.options().setSkolemDepth(1); final Solution sol = solver.solve(x7, bounds); assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome()); assertEquals(2, sol.instance().relations().size()); for (Relation r : sol.instance().relations()) { assertTrue(sol.instance().tuples(r).isEmpty()); } }
Example 5
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 6
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testBGP_03172011() { Relation x5 = Relation.unary("s012"); Relation x8 = Relation.unary("zero"); Relation x9 = Relation.unary("one"); Relation x12 = Relation.nary("next", 2); Universe universe = new Universe(Arrays.asList( "0", "1", "2", "3")); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.boundExactly(x5, factory.setOf("0","1","2")); bounds.boundExactly(x8, factory.setOf("0")); bounds.bound(x9, factory.setOf("1"), factory.setOf("1","2")); TupleSet x12_upper = factory.noneOf(2); x12_upper.add(factory.tuple("1","2")); x12_upper.add(factory.tuple("2","3")); bounds.boundExactly(x12, x12_upper); Variable x714 = Variable.unary("x714"); Decls x713 = x714.oneOf(x8.union(x9)); Variable x720 = Variable.unary("x720"); Expression x723 = x8.union(x9); Expression x724 = x9.join(x12); Expression x722 = x723.union(x724); Expression x721 = x722.difference(x714); Decls x719 = x720.oneOf(x721); Variable x727 = Variable.unary("x727"); Expression x732 = x714.union(x720); Expression x728 = x5.difference(x732); Decls x726 = x727.oneOf(x728); Variable x735 = Variable.unary("x735"); Decls x734 = x735.oneOf(x8); Variable x893 = Variable.unary("x893"); Decls x892 = x893.oneOf(x727); Formula x894 = x720.no(); Formula x891 = x894.forAll(x892); Formula x712 = x891.forSome(x713.and(x719).and(x726).and(x734)); Formula x267 = Formula.FALSE.or(x712); Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); solver.options().setSkolemDepth(0); final Solution sol = solver.solve(x267, bounds); assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE); }
Example 7
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testFelix_06192008() { Relation x5 = Relation.unary("R"); List<String> atomlist = Arrays.asList("X"); 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("X")); bounds.bound(x5, x5_upper); Variable x10=Variable.unary("a"); Expression x11=x5.difference(x5); Decls x9=x10.oneOf(x11); Variable x14=Variable.nary("b",2); Expression x15=x5.product(x5); Decls x13=x14.setOf(x15); Expression x19=x5.product(x5); Formula x17=x14.in(x19); Expression x22=x10.product(x10); Formula x21=x22.eq(x14); Formula x16=x17.and(x21); Formula x12=x16.forSome(x13); Formula x7= x12.forAll(x9); // System.out.println(x7); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); // System.out.println("Depth=0..."); System.out.flush(); solver.options().setSkolemDepth(0); assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome()); // System.out.println("Depth=1..."); System.out.flush(); solver.options().setSkolemDepth(1); final Solution sol = solver.solve(x7, bounds); assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome()); assertEquals(2, sol.instance().relations().size()); for(Relation r : sol.instance().relations()) { assertTrue(sol.instance().tuples(r).isEmpty()); } }
Example 8
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 9
Source File: JenaTranslator.java From quetzal with Eclipse Public License 2.0 | 4 votes |
private Pair<Formula, Decls> scopeInternal(Formula f, Expression dynamicBinding, Collection<Variable> projectedVars, Collection<Variable> outerBound) { Decls ds = null, eds = null; Set<Variable> used = ASTUtils.gatherVariables(f); if (dynamicBinding != null) { used.addAll(ASTUtils.gatherVariables(dynamicBinding)); } List<Variable> orderedVars = sortVars(used); for(Variable v : orderedVars) { Expression r; if (context.getDomain(v) != null ) { r = context.getDomain(v).bound(); if (r == null) { r = NULL; } } else { r = NULL; } if (outerBound.contains(v)) { continue; } Decl d = v.declare(Multiplicity.ONE, context.getStaticBinding().contains(v)? r: r.union(NULL)); if (! projectedVars.contains(v)) { eds = eds==null? d: eds.and(d); } else if (ds == null) { ds = d; } else { ds = ds.and(d); } if (! context.getStaticBinding().contains(v)) { if (context.getDynamicBinding() == null) { f = f.and(v.eq(NULL)); } else { f = f.and(varExpr(v).in(context.getDynamicBinding()).or(v.eq(NULL))); } } } if (eds != null) { f = f.forSome(eds); } if (DEBUG) System.err.println("scope: " + eds + " -- " + ds); return Pair.make(f, ds); }