kodkod.ast.Variable Java Examples

The following examples show how to use kodkod.ast.Variable. 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: FileLogger.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Constructs a new file log for the sources of the given annotated formula,
 * using the provided fixed map, file, and tuplefactory.
 * @requires all f: annotated.node.*children & Formula | logMap.get(f) = freeVariables(f)
 * @requires the file was written by a FileLogger using the given map
 */
FileLog(AnnotatedNode<Formula> annotated, FixedMap<Formula, Variable[]> logMap, File file, Bounds bounds) {
	this.file = file;
	this.bounds = bounds;
	this.roots = Nodes.conjuncts(annotated.node());
	
	final int size = logMap.entrySet().size();
	this.original = new Node[size];
	this.translated = new Formula[size];
	this.freeVars = new Variable[size][];
	int index = 0;
	for(Map.Entry<Formula, Variable[]> e : logMap.entrySet()) {
		translated[index] = e.getKey();
		original[index] = annotated.sourceOf(e.getKey());
		freeVars[index] = e.getValue();
		index++;
	}
}
 
Example #2
Source File: GEO158.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns the meet_defn axiom.
 * @return meet_defn 
 */
public final Formula meetDefn() { 
	//  all P: Point, C, C1: Curve | P->C->C1 in meet iff
	//   (P->C in incident && P->C1 in incident &&
	//		    incident.C & incident.C1 in endPoint.C & endPoint.C1)
	final Variable c = Variable.unary("C");
	final Variable c1 = Variable.unary("C1");
	final Variable p = Variable.unary("P");
	
	final Formula f0 = p.product(c).product(c1).in(meet);
	final Formula f1 = p.product(c).in(incident).and(p.product(c1).in(incident));
	final Expression e0 = incident.join(c).intersection(incident.join(c1));
	final Expression e1 = endPoint.join(c).intersection(endPoint.join(c1));
	final Formula f2 = e0.in(e1);
	
	final Formula f3 = f0.iff(f1.and(f2));
	
	return f3.forAll(p.oneOf(point).and(c.oneOf(curve)).and(c1.oneOf(curve)));
}
 
Example #3
Source File: FileLogger.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Records the translation of the source of the 
 * given transformed formula to the given boolean value 
 * in the specified environment.
 * @requires some this.transforms.f
 * @ensures this.records' = this.records + this.transforms.f -> translation -> freeVariables(f)<:env
 * @throws IllegalArgumentException  no this.transforms.f
 * @throws IllegalStateException  this log has been closed
 */
@Override
void log(Formula f, BooleanValue v, Environment<BooleanMatrix> env) {
	if (out==null) throw new IllegalStateException();

	final int index = logMap.indexOf(f);
	if (index < 0) throw new IllegalArgumentException();
	
	final Variable[] vars = logMap.get(index);
	
	try {
		out.writeInt(index);
		out.writeInt(v.label());
		for(Variable var : vars) {
			out.writeInt(env.lookup(var).denseIndices().min());
		}
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example #4
Source File: NQueens.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Prints the given solution
 */
void print(Instance instance, Options options) { 
	final Evaluator eval = new Evaluator(instance, options);
	for(int i = 0; i < n; i++) { 
		IntExpression ci = IntConstant.constant(i);
		for(int j = 0; j < n; j++) { 
			IntExpression cj = IntConstant.constant(j);
			Variable q = Variable.unary("q");
			if (eval.evaluate(q.join(x).sum().eq(ci).and(q.join(y).sum().eq(cj)).forSome(q.oneOf(queen)))) { 
				System.out.print(" Q");
			} else {
				System.out.print(" .");
			}
		}
		System.out.println();
	}
}
 
Example #5
Source File: OverflowTheoremTest.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * UNSAT: all a: Int | some b: Int | b = MAXINT && (a = MAXINT => a+a = b+b)
 * UNSAT !(some a: Int | all b: Int | !(b = MAXINT && (a = MAXINT => a+a =
 * b+b))) UNSAT: some b: Int | all a: Int | b = MAXINT && (a = MAXINT => a+a =
 * b+b) UNSAT: !(all b: Int | some a: Int | !(b = MAXINT && (a = MAXINT => a+a =
 * b+b))) ---- UNSAT: all x: Int | all a: Int | some b: Int | b = MAXINT && (a =
 * MAXINT => a+a = b+b) UNSAT !(some x: Int | some a: Int | all b: Int | !(b =
 * MAXINT && (a = MAXINT => a+a = b+b))) UNSAT: all x: Int | some b: Int | all
 * a: Int | b = MAXINT && (a = MAXINT => a+a = b+b) UNSAT: !(some x: Int | all
 * b: Int | some a: Int | !(b = MAXINT && (a = MAXINT => a+a = b+b)))
 */
public void testUnsat() {
    Formula body = bs.eq(MAXINT).and(as.eq(MAXINT).implies(as.plus(as).eq(bs.plus(bs))));

    checkUnsat(body.forSome(b.oneOf(Expression.INTS)).forAll(a.oneOf(Expression.INTS)));
    checkUnsat(body.not().forAll(b.oneOf(Expression.INTS)).forSome(a.oneOf(Expression.INTS)).not());

    checkUnsat(body.forAll(a.oneOf(Expression.INTS)).forSome(b.oneOf(Expression.INTS)));
    checkUnsat(body.not().forSome(a.oneOf(Expression.INTS)).forAll(b.oneOf(Expression.INTS)).not());

    Variable x = Variable.unary("x");

    checkUnsat(body.forSome(b.oneOf(Expression.INTS)).forAll(a.oneOf(Expression.INTS)).forAll(x.oneOf(Expression.INTS)));
    checkUnsat(body.not().forAll(b.oneOf(Expression.INTS)).forSome(a.oneOf(Expression.INTS)).forSome(x.oneOf(Expression.INTS)).not());

    checkUnsat(body.forAll(a.oneOf(Expression.INTS)).forSome(b.oneOf(Expression.INTS)).forAll(x.oneOf(Expression.INTS)));
    checkUnsat(body.not().forSome(a.oneOf(Expression.INTS)).forAll(b.oneOf(Expression.INTS)).forSome(x.oneOf(Expression.INTS)).not());
}
 
Example #6
Source File: Hotel.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the invariants for RecodeEnter and its fields.
 *
 * @return invariants for RecodeEnter and its fields.
 */
public Formula recodeEnterInvariants() {
    // sig RecodeEnter extends Enter { }
    // {
    // card.k1 = room.key.pre
    // key.post = key.pre ++ room -> card.k2
    //
    // prev.unchanged
    // holds.unchanged
    // occ.unchanged
    // }

    final List<Formula> invs = new ArrayList<Formula>();
    invs.add(RecodeEnter.in(Enter));

    final Variable r = Variable.unary("n");
    invs.add(card(r).join(k1).eq(room(r).join(key).join(pre(r))).forAll(r.oneOf(RecodeEnter)));
    invs.add(key.join(post(r)).eq(key.join(pre(r)).override(room(r).product(card(r).join(k2)))).forAll(r.oneOf(RecodeEnter)));

    invs.add(unchanged(r, prev).forAll(r.oneOf(RecodeEnter)));
    invs.add(unchanged(r, holds).forAll(r.oneOf(RecodeEnter)));
    invs.add(unchanged(r, occ).forAll(r.oneOf(RecodeEnter)));

    return Formula.and(invs);
}
 
Example #7
Source File: Netconfig.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the invariants predicate.
 *
 * @return invariants
 */
public Formula invariants() {
    final Variable t = Variable.unary("t");

    final Expression losAtT = lineOfSight.join(t);
    final Expression satAtT = satellite.join(t);
    final Formula symNonRefl = symmNonRefl(losAtT).and(symmNonRefl(satAtT));
    final Formula noSatAndLos = satAtT.intersection(losAtT).no();

    final Variable r1 = Variable.unary("r1");
    final Variable r2 = Variable.unary("r2");
    final Expression productUnion = r1.product(r2).union(r2.product(r1));
    final Formula someSatAtT = productUnion.eq(satAtT).forSome(r1.oneOf(Router).and(r2.oneOf(Router)));
    final Formula loneSatAtT = satellite.no().or(someSatAtT);

    return symNonRefl.and(noSatAndLos).and(loneSatAtT).forAll(t.oneOf(Time));
}
 
Example #8
Source File: GEO158.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the meet_defn axiom.
 *
 * @return meet_defn
 */
public final Formula meetDefn() {
    // all P: Point, C, C1: Curve | P->C->C1 in meet iff
    // (P->C in incident && P->C1 in incident &&
    // incident.C & incident.C1 in endPoint.C & endPoint.C1)
    final Variable c = Variable.unary("C");
    final Variable c1 = Variable.unary("C1");
    final Variable p = Variable.unary("P");

    final Formula f0 = p.product(c).product(c1).in(meet);
    final Formula f1 = p.product(c).in(incident).and(p.product(c1).in(incident));
    final Expression e0 = incident.join(c).intersection(incident.join(c1));
    final Expression e1 = endPoint.join(c).intersection(endPoint.join(c1));
    final Formula f2 = e0.in(e1);

    final Formula f3 = f0.iff(f1.and(f2));

    return f3.forAll(p.oneOf(point).and(c.oneOf(curve)).and(c1.oneOf(curve)));
}
 
Example #9
Source File: GEO115.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the conjecture theorem_3_8_5.
 *
 * @return theorem_3_8_5
 */
public final Formula theorem385() {
    // all c: curve, p, q, r: point |
    // c->p->q->r in between =>
    // incident.c - q in q.(p.(c.between)) + ((c.between).r).q
    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 Formula f0 = c.product(p).product(q).product(r).in(between);
    final Expression e0 = q.join(p.join(c.join(between)));
    final Expression e1 = c.join(between).join(r).join(q);
    final Formula f1 = incident.join(c).difference(q).in(e0.union(e1));
    return f0.implies(f1).forAll(p.oneOf(point).and(q.oneOf(point)).and(r.oneOf(point)).and(c.oneOf(curve)));
}
 
Example #10
Source File: SET943.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns t96_zfmisc_1 conjecture.
 * @return t96_zfmisc_1
 */
public final Formula t96_zfmisc_1() {
	final Variable a = Variable.unary("A");
	final Variable b = Variable.unary("B");
	return union(set_union2(a, b)).eq(set_union2(union(a), union(b))).
			forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)));
}
 
Example #11
Source File: SET967.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns t102_zfmisc_1 axiom.
 *
 * @return t102_zfmisc_1
 */
public final Formula t102_zfmisc_1() {
    final Variable a = Variable.unary("A");
    final Variable b = Variable.unary("B");
    final Variable c = Variable.unary("C");
    return in(a, cartesian_product2(b, c)).implies(ordered.join(a).some()).forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)));
}
 
Example #12
Source File: MED001.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the trans_ax1 axiom.
 *
 * @return trans_ax1
 */
public final Formula trans_ax1() {
    final Variable x0 = Variable.unary("X0");
    final Expression x1 = UNIV.difference(x0.join(gt));
    final Formula f0 = x0.in(s0).and(x1.in(conditionnormo).not());
    final Formula f1 = x1.intersection(s1).some().and(x1.join(gt).in(conditionhyper));
    return f0.implies(f1).forAll(x0.oneOf(UNIV));
}
 
Example #13
Source File: GroupScheduling.java    From kodkod with MIT License 5 votes vote down vote up
public Formula schedule() {
	final Variable p = Variable.unary("p"), r = Variable.unary("r"), g = Variable.unary("g");
	final Formula f0 = r.join(p.join(assign)).one().forAll(p.oneOf(person).and(r.oneOf(round)));
	final Formula f1 = assign.join(g).join(r).count().eq(IntConstant.constant(ng)).forAll(r.oneOf(round).and(g.oneOf(group)));
	final Variable pp = Variable.unary("p'");
	final Formula f2 = p.join(assign).intersection(pp.join(assign)).some().forAll(p.oneOf(person).and(pp.oneOf(person.difference(p))));
	return Formula.and(f0, f1, f2);
}
 
Example #14
Source File: MED001.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the ne_cure axiom.
 * @return ne_cure
 */
public final Formula ne_cure() {
	final Variable x0 = Variable.unary("X0");
	final Expression x1 = UNIV.difference(x0.join(gt));
	final Formula f0 = x1.in(releaselg).not().or(x1.in(uptakepg)).
		and(x0.in(bcapacityne)).and(x1.in(bsecretioni)).and(x0.join(gt).in(conditionhyper));
	return f0.implies(x1.in(conditionnormo)).forAll(x0.oneOf(UNIV));
}
 
Example #15
Source File: NUM374.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all X, Y: Num | op[X][Y] = op[Y][X]
 *
 * @return all X, Y: Num | op[X][Y] = op[Y][X]
 */
final Formula symmetric(Relation op) {
    // all X, Y: Num | op[X][Y] = op[Y][X]
    final Variable x = Variable.unary("X");
    final Variable y = Variable.unary("Y");
    return apply(op, x, y).eq(apply(op, y, x)).forAll(x.oneOf(UNIV).and(y.oneOf(UNIV)));
}
 
Example #16
Source File: Environment.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Looks up the given variable in this environment and its ancestors. If the
 * variable is not bound in this environment or any of its ancestors, null is
 * returned. If the variable is bound in multiple environments, the first found
 * binding is returned. Note that null will also be returned if the variable is
 * bound to null.
 *
 * @return variable = this.variable => this.value, this.parent.lookup(variable)
 */
public T lookup(Variable variable) {
    Environment<T,E> p = this;
    // ok to use == for testing variable equality:
    // see kodkod.ast.LeafExpression#equals
    while (!p.isEmpty() && p.variable != variable) {
        p = p.parent;
    }
    return p.value;
}
 
Example #17
Source File: GEO158.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the c4 axiom.
 *
 * @return c4
 */
public final Formula c4() {
    // all C: Curve, P: Point | P->C in innerPoint => some P.meet & sum.C
    final Variable c = Variable.unary("C");
    final Variable p = Variable.unary("P");
    final Formula f0 = p.product(c).in(innerPoint);
    final Formula f1 = p.join(meet).intersection(sum.join(c)).some();
    return f0.implies(f1).forAll(c.oneOf(curve).and(p.oneOf(point)));
}
 
Example #18
Source File: SET967.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns t112_zfmisc_1 axiom.
 *
 * @return t112_zfmisc_1
 */
public final Formula t112_zfmisc_1() {
    final Variable a = Variable.unary("A");
    final Variable b = Variable.unary("B");
    final Variable c = Variable.unary("C");
    final Variable d = Variable.unary("D");
    final Formula f0 = in(c, a).implies(ordered.join(c).some()).forAll(c.oneOf(UNIV));
    final Formula f1 = in(c, b).implies(ordered.join(c).some()).forAll(c.oneOf(UNIV));
    final Formula f2 = in(ordered_pair(c, d), a).iff(in(ordered_pair(c, d), b)).forAll(c.oneOf(UNIV).and(d.oneOf(UNIV)));
    return f0.and(f1).and(f2).implies(a.eq(b)).forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)));
}
 
Example #19
Source File: MED001.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the trans_ax2 axiom.
 *
 * @return trans_ax2
 */
public final Formula trans_ax2() {
    final Variable x0 = Variable.unary("X0");
    final Expression x1 = UNIV.difference(x0.join(gt));
    final Formula f0 = x0.in(s1).and(x1.in(conditionnormo).not());
    final Formula f1 = x1.intersection(s2).intersection(bcapacityne.union(bcapacityex)).some().and(x1.join(gt).in(conditionhyper));
    return f0.implies(f1).forAll(x0.oneOf(UNIV));
}
 
Example #20
Source File: Hotel.java    From kodkod with MIT License 5 votes vote down vote up
/**
	 * Returns the noIntervening fact.
	 * @return noIntervening fact.
	 */
	public Formula noIntervening() { 
//		fact NoIntervening {
//			all c: Checkin - pre.last |
//				some e: Enter | e.pre = c.post and e.room = c.room and e.guest = c.guest
//			}
		final Variable c = Variable.unary("c");
		final Variable e = Variable.unary("e");
		final Formula f = e.join(pre).eq(c.join(post)).
			and(e.join(room).eq(c.join(room))).
			and(e.join(guest).eq(c.join(guest)));
		return f.forSome(e.oneOf(Enter)).forAll(c.oneOf(Checkin.difference(pre.join(last))));
	}
 
Example #21
Source File: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visit(Variable x) {
    String newname = makename(x);
    if (newname == null)
        return;
    int a = x.arity();
    if (a == 1)
        file.printf("Variable %s=Variable.unary(\"%s\");%n", newname, x.name());
    else
        file.printf("Variable %s=Variable.nary(\"%s\",%d);%n", newname, x.name(), a);
}
 
Example #22
Source File: MagicSeries.java    From kodkod with MIT License 5 votes vote down vote up
/**
	 * Returns the magic series formula.
	 * @return the magic series formula.
	 */
	public final Formula magic() {
		final Variable x = Variable.unary("x"), y = Variable.unary("y");
//		final Expression e = y.join(el).eq(x).comprehension(y.oneOf(num));
//		final Formula f1 = x.join(el).one().and(x.join(el).sum().eq(e.count())).forAll(x.oneOf(num));
		final Expression e = y.join(el).eq(x.join(bits)).comprehension(y.oneOf(num));
		final Formula f1 = x.join(el).sum().eq(e.count()).forAll(x.oneOf(num));
		return f1;
	}
 
Example #23
Source File: ConfigAssure.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the requirements.
 *
 * @return requirements
 */
public Formula requirements() {

    final List<Formula> reqs = new ArrayList<Formula>();

    final Variable p0 = Variable.unary("p0"), p1 = Variable.unary("p1"), p2 = Variable.unary("p2");

    // contains the representatives of all subnets
    final Expression subreps = subnet.join(port);
    // contains the representatives of subnets with some unknown members
    final Expression unknownSubs = subnet.join(unknown);

    // the ports with known components are guaranteed to obey the following
    // constraints (ensured by the preprocessing steps).

    // no two ports on the same subnet (with some unknown ports) have the
    // same address:
    // all p0: unknownSubs, p1: unknown & p0.subnet, p2: p0.subnet - p1 |
    // addr(p1) != addr(p2)
    final Expression submembers = p0.join(subnet);
    reqs.add(addr(p1).eq(addr(p2)).not().forAll(p0.oneOf(unknownSubs).and(p1.oneOf(submembers.intersection(unknown))).and(p2.oneOf(submembers.difference(p1)))));

    // all ports on the same subnet (with some unknown ports) have the same
    // netid:
    // all p0: unknownSubs, p1: p0.subnet | netid(p0) = netid(p1)
    reqs.add(netid(p0).eq(netid(p1)).forAll(p0.oneOf(unknownSubs).and(p1.oneOf(submembers))));

    // netids of subnets with unknown representatives don't overlap with
    // netids of any other subnet:
    // all p0: subreps & unknown, p1: subreps- p0 | not contains(p0, p1) and
    // not contains(p1, p0)
    reqs.add(contains(p0, p1).not().and(contains(p1, p0).not()).forAll(p0.oneOf(subreps.intersection(unknown)).and(p1.oneOf(subreps.difference(p0)))));

    return Formula.and(reqs);
}
 
Example #24
Source File: A4Solution.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Maps a Kodkod variable to an Alloy Type and Alloy Pos (if no association
 * exists, it will return (Type.EMPTY , Pos.UNKNOWN)
 */
Pair<Type,Pos> kv2typepos(Variable var) {
    Pair<Type,Pos> ans = decl2type.get(var);
    if (ans != null)
        return ans;
    if (cachedPAIR == null)
        cachedPAIR = new Pair<Type,Pos>(Type.EMPTY, Pos.UNKNOWN);
    return cachedPAIR;
}
 
Example #25
Source File: Skolemizer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Returns the binding for the given variable in the current replacement environment.
 * @return the binding for the given variable in the current replacement environment.
 * @throws UnboundLeafException  variable not bound in the replacement environment.
 */
@Override
public final Expression visit(Variable variable) { 
	final Expression ret = repEnv.lookup(variable);
	if (ret==null)
		throw new UnboundLeafException("Unbound variable", variable);
	return ret;
}
 
Example #26
Source File: GEO091.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the conjecture theorem_2_13.
 *
 * @return theorem_2_13
 */
public final Formula theorem_2_13() {
    // all C, C1, C2: Curve |
    // ((C1 + C2)->C in partOf && C in Open &&
    // !(lone endPoint.C1 & endPoint.C2)) => C1 = C2
    final Variable c = Variable.unary("C");
    final Variable c1 = Variable.unary("C1");
    final Variable c2 = Variable.unary("C2");
    final Formula f0 = c1.union(c2).product(c).in(partOf).and(c.in(open));
    final Formula f1 = endPoint.join(c1).intersection(endPoint.join(c2)).lone().not();
    return f0.and(f1).implies(c1.eq(c2)).forAll(c.oneOf(curve).and(c1.oneOf(curve)).and(c2.oneOf(curve)));
}
 
Example #27
Source File: SET948.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns d2_xboole_0 axiom.
 *
 * @return d2_xboole_0
 */
public final Formula d2_xboole_0() {
    final Variable a = Variable.unary("A");
    final Variable b = Variable.unary("B");
    final Variable c = Variable.unary("C");
    return c.eq(set_union2(a, b)).iff(in.join(c).eq(in.join(a).union(in.join(b)))).forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)));
}
 
Example #28
Source File: MED001.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the sn_cure_1 axiom.
 *
 * @return sn_cure_1
 */
public final Formula sn_cure_1() {
    final Variable x0 = Variable.unary("X0");
    final Expression x1 = UNIV.difference(x0.join(gt));
    final Formula f0 = x1.in(bsecretioni).and(x0.in(bcapacitysn)).and(x0.in(qilt27)).and(x0.join(gt).in(conditionhyper));
    return f0.implies(x1.in(conditionnormo)).forAll(x0.oneOf(UNIV));
}
 
Example #29
Source File: HOLSome4AllTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
@Test
public void testE1ii() {
    // SAT: some s: ints | all $s: set Node | #$s > s
    Variable ns = Variable.unary("$s");
    Formula f = ns.count().gt(si).forAll(ns.setOf(Node)).forSome(s.oneOf(Expression.INTS));
    Solution sol = solve(f);
    assertEquals(true, sol.sat());
    assertEquals(-1, evalS(sol));
}
 
Example #30
Source File: COM008.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the ih_cfl axiom.
 *
 * @return the ih_cfl axiom.
 */
public final Formula ihCfl() {
    final Variable A = Variable.unary("A");
    final Variable B = Variable.unary("B");
    final Variable C = Variable.unary("C");
    final Formula f0 = a.product(A).in(rewrite).and(A.product(B).union(A.product(C)).in(trr));
    final Formula f1 = B.join(trr).intersection(C.join(trr)).some();
    return f0.implies(f1).forAll(A.oneOf(Atom).and(B.oneOf(Atom)).and(C.oneOf(Atom)));
}