Search in sources :

Example 1 with Formula

use of kodkod.ast.Formula 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 Formula

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

the class OverflowTheoremTest method testSat.

/**
 * SAT: all a: Int | all b: Int | b = MAXINT => (a = MAXINT => a+a = b+b) SAT:
 * !(some a: Int | some b: Int | !(b = MAXINT => (a = MAXINT => a+a = b+b))
 */
public void testSat() {
    Formula body = bs.eq(MAXINT).implies(as.eq(MAXINT).implies(as.plus(as).eq(bs.plus(bs))));
    checkSat(body.forAll(b.oneOf(Expression.INTS)).forAll(a.oneOf(Expression.INTS)));
    checkSat(body.not().forSome(b.oneOf(Expression.INTS)).forSome(a.oneOf(Expression.INTS)).not());
}
Also used : Formula(kodkod.ast.Formula)

Example 3 with Formula

use of kodkod.ast.Formula 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 4 with Formula

use of kodkod.ast.Formula 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 5 with Formula

use of kodkod.ast.Formula 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)

Aggregations

Formula (kodkod.ast.Formula)346 Variable (kodkod.ast.Variable)151 Solution (kodkod.engine.Solution)101 Expression (kodkod.ast.Expression)95 Bounds (kodkod.instance.Bounds)83 QuantifiedFormula (kodkod.ast.QuantifiedFormula)72 Solver (kodkod.engine.Solver)67 BinaryFormula (kodkod.ast.BinaryFormula)50 NaryFormula (kodkod.ast.NaryFormula)49 Relation (kodkod.ast.Relation)45 NotFormula (kodkod.ast.NotFormula)43 ComparisonFormula (kodkod.ast.ComparisonFormula)40 IntExpression (kodkod.ast.IntExpression)40 IntComparisonFormula (kodkod.ast.IntComparisonFormula)39 MultiplicityFormula (kodkod.ast.MultiplicityFormula)39 Universe (kodkod.instance.Universe)37 ArrayList (java.util.ArrayList)35 TupleFactory (kodkod.instance.TupleFactory)35 ConstantFormula (kodkod.ast.ConstantFormula)29 TupleSet (kodkod.instance.TupleSet)29