Java Code Examples for kodkod.ast.Formula#forAll()

The following examples show how to use kodkod.ast.Formula#forAll() . 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 meet_defn axiom.
 *
 * @return meet_defn
 */
public final Formula meetDefn() {
    // all P: Point, C, C1: Curve | P->C->C1 in meet iff
    // (P->C in incident && P->C1 in incident &&
    // incident.C & incident.C1 in endPoint.C & endPoint.C1)
    final Variable c = Variable.unary("C");
    final Variable c1 = Variable.unary("C1");
    final Variable p = Variable.unary("P");

    final Formula f0 = p.product(c).product(c1).in(meet);
    final Formula f1 = p.product(c).in(incident).and(p.product(c1).in(incident));
    final Expression e0 = incident.join(c).intersection(incident.join(c1));
    final Expression e1 = endPoint.join(c).intersection(endPoint.join(c1));
    final Formula f2 = e0.in(e1);

    final Formula f3 = f0.iff(f1.and(f2));

    return f3.forAll(p.oneOf(point).and(c.oneOf(curve)).and(c1.oneOf(curve)));
}
 
Example 2
Source File: GEO158.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns the meet_defn axiom.
 * @return meet_defn 
 */
public final Formula meetDefn() { 
	//  all P: Point, C, C1: Curve | P->C->C1 in meet iff
	//   (P->C in incident && P->C1 in incident &&
	//		    incident.C & incident.C1 in endPoint.C & endPoint.C1)
	final Variable c = Variable.unary("C");
	final Variable c1 = Variable.unary("C1");
	final Variable p = Variable.unary("P");
	
	final Formula f0 = p.product(c).product(c1).in(meet);
	final Formula f1 = p.product(c).in(incident).and(p.product(c1).in(incident));
	final Expression e0 = incident.join(c).intersection(incident.join(c1));
	final Expression e1 = endPoint.join(c).intersection(endPoint.join(c1));
	final Formula f2 = e0.in(e1);
	
	final Formula f3 = f0.iff(f1.and(f2));
	
	return f3.forAll(p.oneOf(point).and(c.oneOf(curve)).and(c1.oneOf(curve)));
}
 
Example 3
Source File: Bigconfig.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns the connectedSites predicate.
 * @return pred connectedSites(sites: set Site) {
 *  -- all sites in the given set are connected to each other  
 *  all s: sites | sites - s in ((site.s).^link).site
 *  }
 */
public Formula connectedSites(Expression sites) {
	final Variable s = Variable.unary("s");
	Expression closed;
	if (closureApprox > 0) {
		closed = link;
		for(int i = 1; i < closureApprox; i *= 2) {
			closed = closed.union(closed.join(closed));
		}
	} else {
		closed = link.closure();
	}
	
	final Expression sreachable = site.join(s).join(closed).join(site);
	final Formula f = sites.difference(s).in(sreachable);
	return f.forAll(s.oneOf(sites));
}
 
Example 4
Source File: AbstractWorldDefinitions.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the AbTransfer_inv assertion.
 *
 * @return AbTransfer_inv assertion
 */
public Formula AbTransfer_inv() {
    final Variable a = Variable.unary("a");
    final Variable aprime = Variable.unary("a'");
    final Variable a_in = Variable.unary("a_in");
    final Variable a_out = Variable.unary("a_out");

    final Formula f0 = (Abstract(a).and(AbTransfer(a, aprime, a_in, a_out))).implies(Abstract(aprime));
    final Formula f1 = f0.forAll(a.oneOf(AbWorld).and(aprime.oneOf(AbWorld)).and(a_in.oneOf(AIN)).and(a_out.oneOf(AOUT)));

    return f1;
}
 
Example 5
Source File: AbstractWorldDefinitions.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the AbIgnore_inv assertion.
 *
 * @return AbIgnore_inv assertion
 */
public Formula AbIgnore_inv() {
    final Variable a = Variable.unary("a");
    final Variable aprime = Variable.unary("a'");
    final Variable a_out = Variable.unary("a_out");

    final Formula f0 = (Abstract(a).and(AbIgnore(a, aprime, a_out))).implies(Abstract(aprime));
    final Formula f1 = f0.forAll(a.oneOf(AbWorld).and(aprime.oneOf(AbWorld)).and(a_out.oneOf(AOUT)));

    return f1;
}
 
Example 6
Source File: AbstractWorldDefinitions.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the AbTransfer_inv assertion.
 * @return AbTransfer_inv assertion
 */
public Formula AbTransfer_inv() {
	final Variable a = Variable.unary("a");
	final Variable aprime = Variable.unary("a'");
	final Variable a_in = Variable.unary("a_in");
	final Variable a_out = Variable.unary("a_out");
	
	final Formula f0 = (Abstract(a).and(AbTransfer(a, aprime, a_in, a_out))).implies(Abstract(aprime));
	final Formula f1 = f0.
		forAll(a.oneOf(AbWorld).and(aprime.oneOf(AbWorld)).and(a_in.oneOf(AIN)).and(a_out.oneOf(AOUT)));
	
	return f1;
}
 
Example 7
Source File: LAT258.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the greatest_lower_bound_meet axiom.
 * @return the greatest_lower_bound_meet axiom.
 */
public final Formula greatestLowerBoundMeet() {
	final Variable a = Variable.unary("A"), b = Variable.unary("B");
	final Expression e0 = b.join(a.join(meet));
	final Formula f0 = e0.some().implies(lessThan.join(a).intersection(lessThan.join(b)).in(lessThan.join(e0)));
	return f0.forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)));
}
 
Example 8
Source File: ALG212.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the declarations.
 *
 * @return declarations.
 */
public final Formula decls() {
    // all x,y,z: univ | one f[x][y][z]
    final Variable x = Variable.unary("x");
    final Variable y = Variable.unary("y");
    final Variable z = Variable.unary("z");
    final Formula f0 = z.join(y.join(x.join(f))).one();
    return f0.forAll(x.oneOf(UNIV).and(y.oneOf(UNIV)).and(z.oneOf(UNIV)));
}
 
Example 9
Source File: ALG212.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the permute1 axiom.
 *
 * @return permute1
 */
public final Formula permute1() {
    // all x, y, z: A | f[x][y][z] = f[z][x][y]
    final Variable x = Variable.unary("x");
    final Variable y = Variable.unary("y");
    final Variable z = Variable.unary("z");
    final Formula f0 = z.join(y.join(x.join(f))).eq(y.join(x.join(z.join(f))));
    return f0.forAll(x.oneOf(UNIV).and(y.oneOf(UNIV)).and(z.oneOf(UNIV)));
}
 
Example 10
Source File: ALG212.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the declarations.
 * @return declarations.
 */
public final Formula decls() {
	// all x,y,z: univ | one f[x][y][z] 
	final Variable x = Variable.unary("x");
	final Variable y = Variable.unary("y");
	final Variable z = Variable.unary("z");
	final Formula f0 = z.join(y.join(x.join(f))).one();
	return f0.forAll(x.oneOf(UNIV).and(y.oneOf(UNIV)).and(z.oneOf(UNIV)));
}
 
Example 11
Source File: Netconfig.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the traces predicate.
 *
 * @return traces
 */
public Formula traces() {
    final Variable r1 = Variable.unary("r1");
    final Variable r2 = Variable.unary("r2");
    final Variable t = Variable.unary("t");

    final Formula f = addSatelliteLink(r1, r2, t).or(addLineOfSightLink(r1, r2, t)).or(continuedConnection(r1, r2, t)).or(lostConnection(r1, r2, t));

    return f.forAll(r1.oneOf(Router).and(r2.oneOf(Router)).and(t.oneOf(Time)));

}
 
Example 12
Source File: LAT258.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Assumes that r is a ternary relation.
 *
 * @return all a, b, c: univ | a->(c.(b.r))->(c.(d.r)) in r
 */
private final Formula associative(Expression r) {
    final Variable a = Variable.unary("A"), b = Variable.unary("B"), c = Variable.unary("C");
    final Expression d = b.join(a.join(r));
    final Expression e = c.join(d.join(r));
    final Expression f = c.join(b.join(r));
    final Formula f0 = a.product(f).product(e).in(r);
    // all a, b, c: univ | a->(c.(b.r))->(c.((b.(a.r)).r)) in r
    return f0.forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)));
}
 
Example 13
Source File: LAT258.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the lo_le_distr axiom.
 *
 * @return the lo_le_distr axiom.
 */
public final Formula loLeDistr() {
    final Variable a = Variable.unary("A"), b = Variable.unary("B"), c = Variable.unary("C");
    final Expression h = c.join(b.join(join));
    final Expression d = h.join(a.join(meet));
    final Expression e = b.join(a.join(meet));
    final Expression f = c.join(a.join(meet));
    final Expression g = f.join(e.join(join));
    final Formula f0 = d.product(g).in(lessThan);
    // all a, b, c: univ | (c.(b.(meet))).(a.meet) ->
    // (c.(a.meet)).((b.(a.meet)).join) in lessThan
    return f0.forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)));
}
 
Example 14
Source File: DNACuts.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the cutChainLength constraint.  (Similar to 
 * CutChainsAtMost6BasesLong fact, but with the cut 
 * chain length as specified during construction.)
 * @return the cutChainLength constraint
 */
public Formula cutChainLength() {
	Formula ret = Formula.FALSE;
	final Variable c = Variable.unary("c");
	for(int i = 0; i < neighbor.length; i++) {
		ret = ret.or(c.join(neighbor[i]).in(JoinLink));
	}
	return ret.forAll(c.oneOf(CutLink));
}
 
Example 15
Source File: OverflowSigTest.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * all v: S | <int_op>[#s.sa, #s.sb] = #s.sc <int_op> = {plus, minus, times,
 * div, mod}
 */
protected void createFacts(IntOperator intOp) {
    Variable vs = Variable.unary("vs");
    Formula body = applyIntOp(intOp, vs.join(sa).count(), vs.join(sb).count()).eq(vs.join(sc).count());
    this.facts = body.forAll(vs.oneOf(s));
}
 
Example 16
Source File: ReductionAndProofTest.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testGranularity() {
	final Variable x = Variable.unary("x");
	final Variable y = Variable.unary("y");
	
	final Formula f0 = a.some();
	final Formula f1 = b.some();
	final Formula f2 = a.eq(b);

	final Formula f3 = x.product(y).in(Expression.UNIV.product(Expression.UNIV));
	final Formula f4 = x.eq(y);
	
	
	final Formula f5 = f3.or(f4).forSome(y.oneOf(b));
	final Formula f6 = f5.forAll(x.oneOf(a));
	
	final Formula f7 = f2.or(f6).not();
	
	final Formula f8 = b.intersection(Expression.UNIV).some();
	
	final Formula f9 = Formula.and(f0, f1, f7, f8);
	
	Set<Node> core = core(f9,0);
	assertEquals(2, core.size());
	assertTrue(core.contains(f1));
	assertTrue(core.contains(f7));
	
	core = core(f9,1);
	assertEquals(2, core.size());
	assertTrue(core.contains(f1));
	assertTrue(core.contains(f6));
	
	core = reduce(f9,2);
	assertEquals(2, core.size());
	assertTrue(core.contains(f1));
	assertTrue(core.contains(f5));
	
	core = core(f9,3);
	assertEquals(2, core.size());
	assertTrue(core.contains(f1));
	assertTrue(core.contains(f3));
}
 
Example 17
Source File: OverflowSigTest.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * some s.sa && some s.sb => some.sc
 */
protected void createCheck() {
    Variable vs = Variable.unary("s");
    Formula body = vs.join(sa).some().and(vs.join(sb).some()).implies(vs.join(sc).some());
    this.check = body.forAll(vs.oneOf(s));
}
 
Example 18
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 19
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 20
Source File: Trees.java    From kodkod with MIT License 3 votes vote down vote up
/**
 * Returns statement 5.
 * @return 
 * <pre>
 * pred Statement5() {
 * Acyclic() and
 * all u,v: V | (u->v) not in E implies Cyclic(E + (u->v) + (v->u))
 * }
 * </pre>
 */
public final Formula statement5() {
	final Variable u = Variable.unary("u");
	final Variable v = Variable.unary("v");
	final Formula f0 = u.product(v).in(E).not().implies(cyclic(E.union(u.product(v).union(v.product(u)))));
	final Formula f1 = f0.forAll(u.oneOf(V).and(v.oneOf(V)));
	return acyclic().and(f1);
}