Search in sources :

Example 6 with Variable

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

the class SkolemizationTest method testDeepSkolems.

public final void testDeepSkolems() {
    solver.options().setSkolemDepth(3);
    testDeepSkolems(Multiplicity.ONE);
    testDeepSkolems(Multiplicity.LONE);
    testDeepSkolems(Multiplicity.SOME);
    testDeepSkolems(Multiplicity.SET);
    final Variable va = Variable.unary("va");
    final Variable vb = Variable.unary("vb");
    Decl da1 = va.oneOf(r1a);
    Decl db = vb.oneOf(r1b);
    final Formula f0 = va.in(vb.join(r2b));
    final Formula f1 = f0.forAll(db).not().forAll(da1);
    final Formula f2 = f0.forSome(db).forSome(da1);
    Instance inst = solve(f1.and(f2));
    assertEquals(bounds.relations().size() + 3, inst.relations().size());
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Decl(kodkod.ast.Decl)

Example 7 with Variable

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

the class SkolemizationTest method testNoSkolems.

private final void testNoSkolems(Multiplicity mult) {
    final Variable v = Variable.unary("v");
    final Decl d = v.declare(mult, r1a);
    testNoSkolems(d, v.join(r2a).some().forAll(d).not());
    testNoSkolems(d, v.join(r2a).some().forSome(d));
}
Also used : Variable(kodkod.ast.Variable) Decl(kodkod.ast.Decl)

Example 8 with Variable

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

the class Lists method facts.

/**
 * Returns all facts in the model.
 *
 * @return the facts.
 */
public final Formula facts() {
    // fact NoStrayThings {Thing in List.car}
    final Formula f0 = Thing.in(List.join(car));
    // fact finite {all L: List | isFinite(L)}
    final Variable L = Variable.unary("L");
    final Formula f1 = isFinite(L).forAll(L.oneOf(List));
    // fact Equivalence {
    // all a,b: List | (a in b.equivTo) <=> (a.car = b.car and b.cdr in
    // a.cdr.equivTo)
    // }
    final Variable a = Variable.unary("a");
    final Variable b = Variable.unary("b");
    final Formula f2 = a.in(b.join(equivTo));
    final Formula f3 = a.join(car).eq(b.join(car));
    final Formula f4 = b.join(cdr).in(a.join(cdr).join(equivTo));
    final Formula f6 = f2.iff(f3.and(f4)).forAll(a.oneOf(List).and(b.oneOf(List)));
    // fact prefix { //a is a prefix of b
    // List->EmptyList in prefixes
    // all a,b: NonEmptyList | (a in b.prefixes) <=> (a.car = b.car
    // and a.cdr in b.cdr.prefixes)
    // }
    final Formula f7 = List.product(EmptyList).in(prefixes);
    final Formula f8 = a.in(b.join(prefixes));
    final Formula f9 = a.join(cdr).in(b.join(cdr).join(prefixes));
    final Formula f11 = f8.iff(f3.and(f9)).forAll(a.oneOf(NonEmptyList).and(b.oneOf(NonEmptyList)));
    return f0.and(f1).and(f6).and(f7).and(f11);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable)

Example 9 with Variable

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

the class RingElection method defineElected.

/**
 * Return DefineElected fact.
 *
 * @return
 *
 *         <pre>
 * fact DefineElected {
 *  no elected.TO/first()
 *  all t: Time - TO/first()|
 *   elected.t = {p: Process | p in p.toSend.t - p.toSend.(TO/prev(t))} }
 *         </pre>
 */
public Formula defineElected() {
    final Variable t = Variable.unary("t");
    final Formula f1 = elected.join(tfirst).no();
    final Variable p = Variable.unary("p");
    final Formula c = p.in(p.join(toSend).join(t).difference(p.join(toSend).join(t.join(tord.transpose()))));
    final Expression comprehension = c.comprehension(p.oneOf(Process));
    final Formula f2 = elected.join(t).eq(comprehension).forAll(t.oneOf(Time.difference(tfirst)));
    return f1.and(f2);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Expression(kodkod.ast.Expression)

Example 10 with Variable

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

the class RingElection method step.

/**
 * Returns the step predicate.
 *
 * @return
 *
 *         <pre>
 * pred step (t, t': Time, p: Process) {
 *  let from = p.toSend, to = p.succ.toSend |
 *   some id: from.t {
 *    from.t' = from.t - id
 *    to.t' = to.t + (id - PO/prevs(p.succ)) } }
 *         </pre>
 */
public Formula step(Expression t1, Expression t2, Expression p) {
    final Expression from = p.join(toSend);
    final Expression to = p.join(succ).join(toSend);
    final Variable id = Variable.unary("id");
    final Expression prevs = (p.join(succ)).join((pord.transpose()).closure());
    final Formula f1 = from.join(t2).eq(from.join(t1).difference(id));
    final Formula f2 = to.join(t2).eq(to.join(t1).union(id.difference(prevs)));
    return f1.and(f2).forSome(id.oneOf(from.join(t1)));
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Expression(kodkod.ast.Expression)

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