Java Code Examples for kodkod.ast.Variable#product()

The following examples show how to use kodkod.ast.Variable#product() . 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: GEO158.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the end_point_defn axiom.
 *
 * @return end_point_defn
 */
public final Formula endPointDefn() {
    /*
     * all P: Point, C: Curve | P->C in endPoint iff (P->C in incident && all C1,
     * C2: partOf.C & P.incident | C1->C2 in partOf || C2->C1 in partOf)
     */
    final Variable c = Variable.unary("C");
    final Variable p = Variable.unary("P");

    final Expression e0 = p.product(c);
    final Formula f0 = e0.in(endPoint);
    final Formula f1 = e0.in(incident);

    final Variable c1 = Variable.unary("C1"), c2 = Variable.unary("C2");
    final Formula f2 = c1.product(c2).in(partOf).or(c2.product(c1).in(partOf));
    final Expression e1 = partOf.join(c).intersection(p.join(incident));
    final Formula f3 = f2.forAll(c1.oneOf(e1).and(c2.oneOf(e1)));

    return f0.iff(f1.and(f3)).forAll(p.oneOf(point).and(c.oneOf(curve)));
}
 
Example 2
Source File: GEO158.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns the end_point_defn axiom.
 * @return end_point_defn 
 */
public final Formula endPointDefn() {
	/* all P: Point, C: Curve | P->C in endPoint iff
  		 *	(P->C in incident && 
   	 *	 all C1, C2: partOf.C & P.incident | 
     	 *	  C1->C2 in partOf || C2->C1 in partOf)
	 */
	final Variable c = Variable.unary("C");
	final Variable p = Variable.unary("P");
	
	final Expression e0 = p.product(c);
	final Formula f0 = e0.in(endPoint);
	final Formula f1 = e0.in(incident);
	
	final Variable c1 = Variable.unary("C1"), c2 = Variable.unary("C2");
	final Formula f2 = c1.product(c2).in(partOf).or(c2.product(c1).in(partOf));
	final Expression e1 = partOf.join(c).intersection(p.join(incident));
	final Formula f3 = f2.forAll(c1.oneOf(e1).and(c2.oneOf(e1)));
	
	return f0.iff(f1.and(f3)).forAll(p.oneOf(point).and(c.oneOf(curve)));
}
 
Example 3
Source File: GEO092.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the conjecture proposition_2_14_1.
 *
 * @return proposition_2_14_1
 */
public final Formula proposition2141() {
    // all c1, c2: curve, p: point |
    // p->c1->c2 in meet && c1->c2 in sum.open =>
    // all q: point - p | c1 + c2 !in q.incident
    final Variable c1 = Variable.unary("C1");
    final Variable c2 = Variable.unary("C2");
    final Variable p = Variable.unary("P");
    final Variable q = Variable.unary("Q");
    final Expression e0 = c1.product(c2);
    final Formula f0 = p.product(e0).in(meet).and(e0.in(sum.join(open)));
    final Formula f1 = c1.union(c2).in(q.join(incident)).not().forAll(q.oneOf(point.difference(p)));
    return f0.implies(f1).forAll(c1.oneOf(curve).and(c2.oneOf(curve)).and(p.oneOf(point)));
}
 
Example 4
Source File: GEO158.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the inner_point_defn axiom.
 *
 * @return inner_point_defn
 */
public final Formula innerPointDefn() {
    // all P: Point, C: Curve | P->C in innerPoint iff
    // (P->C in incident && no P->C & endPoint)
    final Variable c = Variable.unary("C");
    final Variable p = Variable.unary("P");
    final Expression e0 = p.product(c);
    final Formula f0 = e0.in(innerPoint);
    final Formula f1 = e0.in(incident).and(e0.intersection(endPoint).no());
    return f0.iff(f1).forAll(p.oneOf(point).and(c.oneOf(curve)));
}
 
Example 5
Source File: LAT258.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the less_than_meet_join axiom.
 *
 * @return the less_than_meet_join axiom.
 */
public final Formula lessThanMeetJoin() {
    final Variable a = Variable.unary("A");
    final Variable b = Variable.unary("B");
    final Expression e0 = a.product(b);
    final Formula f0 = e0.product(a).in(meet);
    final Formula f1 = e0.product(b).in(join);
    // all a: univ, b: a.lessThan | a->b->a in meet && a->b->b in join
    return f0.and(f1).forAll(b.oneOf(a.join(lessThan))).forAll(a.oneOf(UNIV));
}
 
Example 6
Source File: Toughnut.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the covering predicate. Note that we don't need to specify the first
 * two lines of the predicate, since they can be expressed as bounds
 * constraints.
 *
 * @return the covering predicate
 */
public Formula checkBelowTooDoublePrime() {
    final Variable x = Variable.unary("x");
    final Variable y = Variable.unary("y");
    final Decls d = x.oneOf(Cell).and(y.oneOf(Cell));
    final Expression xy = y.join(x.join(covered));
    // covering relation is symmetric
    Formula symm = xy.product(x.product(y)).in(covered).forAll(d);
    // each pair of cells on the board should be covered
    // by a domino, which also covers ONE of its neighbors
    Expression xNeighbors = (prev(x).union(next(x))).product(y);
    Expression yNeighbors = x.product(prev(y).union(next(y)));
    Formula covering = (xy.one().and(xy.in(xNeighbors.union(yNeighbors)))).forAll(d);
    return symm.and(covering);
}
 
Example 7
Source File: GEO092.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the conjecture proposition_2_14_1.
 * @return proposition_2_14_1
 */
public final Formula proposition2141() {	
	// all c1, c2: curve, p: point | 
	//  p->c1->c2 in meet && c1->c2 in sum.open => 
	//  all q: point - p | c1 + c2 !in q.incident
	final Variable c1 = Variable.unary("C1");
	final Variable c2 = Variable.unary("C2");
	final Variable p = Variable.unary("P");
	final Variable q = Variable.unary("Q");
	final Expression e0 = c1.product(c2);
	final Formula f0 = p.product(e0).in(meet).and(e0.in(sum.join(open)));
	final Formula f1 = c1.union(c2).in(q.join(incident)).not().forAll(q.oneOf(point.difference(p)));
	return f0.implies(f1).forAll(c1.oneOf(curve).and(c2.oneOf(curve)).and(p.oneOf(point)));
}
 
Example 8
Source File: GEO158.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the inner_point_defn axiom.
 * @return inner_point_defn
 */
public final Formula innerPointDefn() {
	//  all P: Point, C: Curve | P->C in innerPoint iff
	//   (P->C in incident && no P->C & endPoint)
	final Variable c = Variable.unary("C");
	final Variable p = Variable.unary("P");
	final Expression e0 = p.product(c);
	final Formula f0 = e0.in(innerPoint);
	final Formula f1 = e0.in(incident).and(e0.intersection(endPoint).no());
	return f0.iff(f1).forAll(p.oneOf(point).and(c.oneOf(curve)));
}
 
Example 9
Source File: LAT258.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the less_than_meet_join axiom.
 * @return the less_than_meet_join axiom.
 */
public final Formula lessThanMeetJoin() {
	final Variable a = Variable.unary("A");
	final Variable b = Variable.unary("B");
	final Expression e0 = a.product(b);
	final Formula f0 = e0.product(a).in(meet);
	final Formula f1 = e0.product(b).in(join);
	// all a: univ, b: a.lessThan | a->b->a in meet && a->b->b in join
	return f0.and(f1).forAll(b.oneOf(a.join(lessThan))).forAll(a.oneOf(UNIV));
}
 
Example 10
Source File: Toughnut.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the covering predicate.  Note that we don't 
 * need to specify the first two lines of the predicate,
 * since they can be expressed as bounds constraints.
 * @return the covering predicate
 */
public Formula checkBelowTooDoublePrime() {
	final Variable x = Variable.unary("x");
	final Variable y = Variable.unary("y");
	final Decls d = x.oneOf(Cell).and(y.oneOf(Cell));
	final Expression xy = y.join(x.join(covered));
	// covering relation is symmetric
	Formula symm = xy.product(x.product(y)).in(covered).forAll(d);
	// each pair of cells on the board should be covered
	// by a domino, which also covers ONE of its neighbors
	Expression xNeighbors = (prev(x).union(next(x))).product(y);
	Expression yNeighbors = x.product(prev(y).union(next(y)));
	Formula covering = (xy.one().and(xy.in(xNeighbors.union(yNeighbors)))).forAll(d);
	return symm.and(covering);
}
 
Example 11
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
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 12
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
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 13
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@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 14
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@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)));
		}
	}
}