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

The following examples show how to use kodkod.ast.Variable#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: 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 2
Source File: ReductionAndProofTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
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 3
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 4
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 5
Source File: JenaTranslator.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void visit(OpTable arg0) {	
	Set<Variable> vars = HashSetFactory.make();
	Formula f = null;
	for(Iterator<Binding> bs = arg0.getTable().rows(); bs.hasNext(); ) {
		Formula rf = null;
		Binding b = bs.next();
		for(Var jv : arg0.getTable().getVars()) {
			if (b.get(jv) != null) {
				Expression value = toTerm(b.get(jv));
				Variable var = context.getVars().get(jv.getName());
				vars.add(var);
				Formula ef = var.eq(value);
				rf = rf==null? ef: rf.and(ef);
			}
		}
		f = f==null? rf: f.or(rf);
	}
	
	context.setCurrentQuery(f==null? Formula.TRUE: f);

	if (context.getStaticBinding() != null) {
		context.getStaticBinding().addAll(vars);
	} else {
		context.setStaticBinding(vars);
	}
	
	Expression bound = null;
	for(Variable v : vars) {
		bound = bound==null? varExpr(v): bound.union(varExpr(v));
	}
	if (bound != null) {
		if (context.getDynamicBinding() != null) {
			context.setDynamicBinding(context.getDynamicBinding().union(bound));
		} else {
			context.setDynamicBinding(bound);
		}
	}
	
	context.getCurrentContinuation().next(context, context.getCurrentQuery());
}