Search in sources :

Example 1 with Variable

use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.

the class OverflowSigTest method createFacts.

/**
 * 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));
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable)

Example 2 with Variable

use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.

the class OverflowTheoremTest method testCardinality1.

/**
 * all s : set univ | (some s) iff #s > 0
 */
@Test
public void testCardinality1() {
    Variable s = Variable.unary("s");
    Formula f = s.some().iff(s.count().gt(IntConstant.constant(0))).forAll(s.setOf(Expression.UNIV));
    checkTrue(f);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Test(org.junit.Test)

Example 3 with Variable

use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.

the class OverflowTheoremTest method testCardinality2.

/**
 * all s, t : set univ | #(s + t) >= #s && #(s + t) >= #t
 */
@Test
public void testCardinality2() {
    Variable s = Variable.unary("s");
    Variable t = Variable.unary("t");
    IntExpression sutCnt = s.union(t).count();
    Decls dcls = s.setOf(Expression.UNIV).and(t.setOf(Expression.UNIV));
    Formula f = sutCnt.gte(s.count()).and(sutCnt.gte(t.count())).forAll(dcls);
    checkTrue(f);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) IntExpression(kodkod.ast.IntExpression) Test(org.junit.Test)

Example 4 with Variable

use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.

the class OverflowTheoremTest method testCardinality0.

/**
 * all s : set univ | #s >= 0 !some(s : set univ | #s < 0)
 */
@Test
public void testCardinality0() {
    Variable s = Variable.unary("s");
    Formula f = (s.count().gte(IntConstant.constant(0))).forAll(s.setOf(Expression.UNIV));
    checkTrue(f);
    f = (s.count().lt(IntConstant.constant(0))).forSome(s.setOf(Expression.UNIV)).not();
    checkTrue(f);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Test(org.junit.Test)

Example 5 with Variable

use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.

the class OverflowTheoremTest method testCardinality3.

/**
 * all a, b: set univ | a in b => #a <= #b
 */
@Test
public void testCardinality3() {
    Variable a = Variable.unary("a");
    Variable b = Variable.unary("b");
    Decls dcls = a.setOf(Expression.UNIV).and(b.setOf(Expression.UNIV));
    Formula pre = a.in(b);
    Formula post = a.count().lte(b.count());
    checkTrue(pre, post, dcls);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Test(org.junit.Test)

Aggregations

Variable (kodkod.ast.Variable)221 Formula (kodkod.ast.Formula)151 Expression (kodkod.ast.Expression)80 Decls (kodkod.ast.Decls)24 Solution (kodkod.engine.Solution)24 Relation (kodkod.ast.Relation)23 IntExpression (kodkod.ast.IntExpression)22 Bounds (kodkod.instance.Bounds)21 Universe (kodkod.instance.Universe)21 ArrayList (java.util.ArrayList)19 TupleFactory (kodkod.instance.TupleFactory)19 TupleSet (kodkod.instance.TupleSet)15 Solver (kodkod.engine.Solver)14 Decl (kodkod.ast.Decl)12 QuantifiedFormula (kodkod.ast.QuantifiedFormula)10 Test (org.junit.Test)10 Instance (kodkod.instance.Instance)8 BinaryExpression (kodkod.ast.BinaryExpression)5 SumExpression (kodkod.ast.SumExpression)3 Expr (edu.mit.csail.sdg.ast.Expr)2