Search in sources :

Example 16 with Formula

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

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

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

Example 19 with Formula

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

the class RingElection method progress.

/**
 * Returns the progress predicate.
 *
 * @return
 *
 *         <pre>
 * pred progress () {
 *  all t: Time - TO/last() | let t' = TO/next (t) |
 *   some Process.toSend.t => some p: Process | not skip (t, t', p) }
 *         </pre>
 */
public Formula progress() {
    final Variable t1 = Variable.unary("t");
    final Expression t2 = t1.join(tord);
    final Variable p = Variable.unary("p");
    final Formula f1 = Process.join(toSend).join(t1).some().implies(skip(t1, t2, p).not().forSome(p.oneOf(Process)));
    return f1.forAll(t1.oneOf(Time.difference(tlast)));
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Expression(kodkod.ast.Expression)

Example 20 with Formula

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

the class RingElection method declarations.

/**
 * Returns the declaration constraints.
 *
 * @return
 *
 *         <pre>
 * sig Time {}
 * sig Process {
 *  succ: Process,
 *  toSend: Process -> Time,
 *  elected: set Time }
 *         </pre>
 */
public Formula declarations() {
    final Formula ordTime = tord.totalOrder(Time, tfirst, tlast);
    final Formula ordProcess = pord.totalOrder(Process, pfirst, plast);
    final Formula succFunction = succ.function(Process, Process);
    final Formula electedDomRange = elected.in(Process.product(Time));
    return succFunction.and(ordTime).and(ordProcess).and(electedDomRange);
}
Also used : Formula(kodkod.ast.Formula)

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