Java Code Examples for kodkod.ast.Expression#eq()

The following examples show how to use kodkod.ast.Expression#eq() . 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: TranslateAlloyToKodkod.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method that translates the formula "a in b" into a Kodkod formula.
 */
private Formula isIn(Expression a, Expr right) throws Err {
    Expression b;
    if (right instanceof ExprBinary && right.mult != 0 && ((ExprBinary) right).op.isArrow) {
        // Handles possible "binary" or higher-arity multiplicity
        return isInBinary(a, (ExprBinary) right);
    }
    switch (right.mult()) {
        case EXACTLYOF :
            b = cset(right);
            return a.eq(b);
        case ONEOF :
            b = cset(right);
            return a.one().and(a.in(b));
        case LONEOF :
            b = cset(right);
            return a.lone().and(a.in(b));
        case SOMEOF :
            b = cset(right);
            return a.some().and(a.in(b));
        default :
            b = cset(right);
            return a.in(b);
    }
}
 
Example 2
Source File: NUM374.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the wilkie conjecture.
 *
 * @return wilkie
 */
public final Formula wilkie() {
    // ! [C,P,Q,R,S,A,B] :
    // ( ( C = product(A,A)
    // & P = sum(n1,A)
    // & Q = sum(P,C)
    // & R = sum(n1,product(A,C))
    // & S = sum(sum(n1,C),product(C,C)) )
    // =>
    // product(exponent(sum(exponent(P,A),exponent(Q,A)),B),exponent(sum(exponent(R,B),exponent(S,B)),A))
    // =
    // product(exponent(sum(exponent(P,B),exponent(Q,B)),A),exponent(sum(exponent(R,A),exponent(S,A)),B))
    // ) )).
    final Variable c = Variable.unary("C");
    final Variable p = Variable.unary("P");
    final Variable q = Variable.unary("Q");
    final Variable r = Variable.unary("R");
    final Variable s = Variable.unary("S");
    final Variable a = Variable.unary("A");
    final Variable b = Variable.unary("B");
    final Formula f0 = c.eq(product(a, a));
    final Formula f1 = p.eq(sum(n1, a));
    final Formula f2 = q.eq(sum(p, c));
    final Formula f3 = r.eq(sum(n1, product(a, c)));
    final Formula f4 = s.eq(sum(sum(n1, c), product(c, c)));
    final Expression e0 = product(exponent(sum(exponent(p, a), exponent(q, a)), b), exponent(sum(exponent(r, b), exponent(s, b)), a));
    final Expression e1 = product(exponent(sum(exponent(p, b), exponent(q, b)), a), exponent(sum(exponent(r, a), exponent(s, a)), b));
    final Formula f5 = e0.eq(e1);
    return (f0.and(f1).and(f2).and(f3).and(f4)).implies(f5).forAll(c.oneOf(UNIV).and(p.oneOf(UNIV)).and(q.oneOf(UNIV)).and(r.oneOf(UNIV)).and(s.oneOf(UNIV)).and(a.oneOf(UNIV)).and(b.oneOf(UNIV)));
}
 
Example 3
Source File: AbstractWorldDefinitions.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the application of the AbWorldSecureOp predicate.
 *
 * @return application of the AbWorldSecureOp predicate.
 */
public Formula AbWorldSecureOp(Expression s, Expression sprime, Expression a_in, Expression a_out) {
    final Formula f0 = AbOp(a_out);
    final Formula f1 = a_in.in(TransferDetails);

    final Expression e0 = a_in.join(from);
    final Expression e1 = a_in.join(to);
    final Expression e2 = s.join(abAuthPurse).difference(e0).difference(e1);
    final Expression e3 = sprime.join(abAuthPurse).difference(e0).difference(e1);
    final Formula f2 = e2.eq(e3);

    final Formula f3 = XiAbPurse(s, sprime, e2);

    return Formula.and(f0, f1, f2, f3);
}
 
Example 4
Source File: NUM374.java    From kodkod with MIT License 5 votes vote down vote up
/**
	 * Returns the wilkie conjecture.
	 * @return wilkie
	 */
	public final Formula wilkie() {
//		! [C,P,Q,R,S,A,B] : 
//		      ( ( C = product(A,A)
//		        & P = sum(n1,A)
//		        & Q = sum(P,C)
//		        & R = sum(n1,product(A,C))
//		        & S = sum(sum(n1,C),product(C,C)) )
//		     => product(exponent(sum(exponent(P,A),exponent(Q,A)),B),exponent(sum(exponent(R,B),exponent(S,B)),A)) = 
//		        product(exponent(sum(exponent(P,B),exponent(Q,B)),A),exponent(sum(exponent(R,A),exponent(S,A)),B)) ) )).
		final Variable c = Variable.unary("C");
		final Variable p = Variable.unary("P");
		final Variable q = Variable.unary("Q");
		final Variable r = Variable.unary("R");
		final Variable s = Variable.unary("S");
		final Variable a = Variable.unary("A");
		final Variable b = Variable.unary("B");
		final Formula f0 = c.eq(product(a,a));
		final Formula f1 = p.eq(sum(n1,a));
		final Formula f2 = q.eq(sum(p,c));
		final Formula f3 = r.eq(sum(n1,product(a,c)));
		final Formula f4 = s.eq(sum(sum(n1,c),product(c,c)));
		final Expression e0 = product(exponent(sum(exponent(p,a),exponent(q,a)),b),exponent(sum(exponent(r,b),exponent(s,b)),a));
		final Expression e1 = product(exponent(sum(exponent(p,b),exponent(q,b)),a),exponent(sum(exponent(r,a),exponent(s,a)),b));
		final Formula f5 = e0.eq(e1);
		return (f0.and(f1).and(f2).and(f3).and(f4)).implies(f5).
			forAll(c.oneOf(UNIV).and(p.oneOf(UNIV)).and(q.oneOf(UNIV)).
				   and(r.oneOf(UNIV)).and(s.oneOf(UNIV)).and(a.oneOf(UNIV)).and(b.oneOf(UNIV)));
	}
 
Example 5
Source File: AbstractWorldDefinitions.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the application of the AbWorldSecureOp predicate.
 * @return application of the AbWorldSecureOp predicate.
 */
public Formula AbWorldSecureOp(Expression s, Expression sprime, Expression a_in, Expression a_out) {
	final Formula f0 = AbOp(a_out);
	final Formula f1 = a_in.in(TransferDetails);

	final Expression e0 = a_in.join(from);
	final Expression e1 = a_in.join(to);
	final Expression e2 = s.join(abAuthPurse).difference(e0).difference(e1);
	final Expression e3 = sprime.join(abAuthPurse).difference(e0).difference(e1);
	final Formula f2 = e2.eq(e3);
	
	final Formula f3 = XiAbPurse(s, sprime, e2);
	
	return Formula.and(f0, f1, f2, f3);
}
 
Example 6
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 7
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 8
Source File: JenaTranslator.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
private Formula isType(Expression type, String typeName) {
	// return type.intersection(typeRelation(typeName)).one();
	return type.eq(typeRelation(typeName));
}
 
Example 9
Source File: AbstractWorldDefinitions.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the application of the AbOp predicate.
 *
 * @return application of the AbOp predicate.
 */
public Formula AbOp(Expression a_out) {
    return a_out.eq(aNullOut);
}
 
Example 10
Source File: AbstractWorldDefinitions.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns the application of the AbOp predicate.
 * @return application of the AbOp predicate.
 */
public Formula AbOp(Expression a_out) {
	return a_out.eq(aNullOut);
}