Java Code Examples for kodkod.ast.QuantifiedFormula#quantifier()

The following examples show how to use kodkod.ast.QuantifiedFormula#quantifier() . 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: FullNegationPropagator.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
@Override
public final void visit(QuantifiedFormula qf) {
    if (visited(qf))
        return;
    FullNegationPropagator fneBody = new FullNegationPropagator(shared, annotations);
    fneBody.negated = negated;
    boolean wasNegated = negated;
    negated = false;
    qf.body().accept(fneBody);

    FullNegationPropagator fneDomain = new FullNegationPropagator(shared, annotations);
    qf.domain().accept(fneDomain);

    if (fneBody.hasChanged || fneDomain.hasChanged || wasNegated) {
        Formula qfBody = Formula.and(fneBody.conjuncts);
        Quantifier quant = wasNegated ? qf.quantifier().opposite : qf.quantifier();
        addConjunct(qfBody.quantify(quant, qf.decls(), Formula.and(fneDomain.conjuncts)), false, qf);
        hasChanged = true;
    } else {
        addConjunct(qf);
    }
    negated = wasNegated;
}
 
Example 2
Source File: FOL2BoolTranslator.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Calls lookup(quantFormula) and returns the cached value, if any. If a
 * translation has not been cached, translates the formula, calls cache(...) on
 * it and returns it.
 *
 * @return let t = lookup(quantFormula) | some t => t, cache(quantFormula,
 *         translate(quantFormula))
 */
@Override
public final BooleanValue visit(QuantifiedFormula quantFormula) {
    BooleanValue ret = lookup(quantFormula);
    if (ret != null)
        return ret;

    final Quantifier quantifier = quantFormula.quantifier();
    switch (quantifier) {
        case ALL :
            final BooleanAccumulator and = BooleanAccumulator.treeGate(Operator.AND);
            all(quantFormula.decls(), quantFormula.formula(), 0, BooleanConstant.FALSE, and);
            ret = interpreter.factory().accumulate(and);
            break;
        case SOME :
            final BooleanAccumulator or = BooleanAccumulator.treeGate(Operator.OR);
            some(quantFormula.decls(), quantFormula.formula(), 0, BooleanConstant.TRUE, or);
            ret = interpreter.factory().accumulate(or);
            break;
        default :
            throw new IllegalArgumentException("Unknown quantifier: " + quantifier);
    }
    return cache(quantFormula, ret);
}
 
Example 3
Source File: TranslateKodkodToJava.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visit(QuantifiedFormula x) {
    String newname = makename(x);
    if (newname == null)
        return;
    String d = make(x.decls());
    String f = make(x.formula());
    switch (x.quantifier()) {
        case ALL :
            file.printf("Formula %s=%s.forAll(%s);%n", newname, f, d);
            break;
        case SOME :
            file.printf("Formula %s=%s.forSome(%s);%n", newname, f, d);
            break;
        default :
            throw new RuntimeException("Unknown kodkod quantifier \"" + x.quantifier() + "\" encountered");
    }
}
 
Example 4
Source File: FOL2BoolTranslator.java    From kodkod with MIT License 6 votes vote down vote up
/** 
 * Calls lookup(quantFormula) and returns the cached value, if any.  
 * If a translation has not been cached, translates the formula,
 * calls cache(...) on it and returns it.
 * @return let t = lookup(quantFormula) | some t => t, 
 *   cache(quantFormula, translate(quantFormula))
 */
public final BooleanValue visit(QuantifiedFormula quantFormula) {
	BooleanValue ret = lookup(quantFormula);
	if (ret!=null) return ret;

	final Quantifier quantifier = quantFormula.quantifier();

	switch(quantifier) {
	case ALL		: 
		final BooleanAccumulator and = BooleanAccumulator.treeGate(Operator.AND);
		all(quantFormula.decls(), quantFormula.formula(), 0, BooleanConstant.FALSE, and); 
		ret = interpreter.factory().accumulate(and);
		break;
	case SOME	: 
		final BooleanAccumulator or = BooleanAccumulator.treeGate(Operator.OR);
		some(quantFormula.decls(), quantFormula.formula(), 0, BooleanConstant.TRUE, or); 
		ret = interpreter.factory().accumulate(or);
		break;
	default :
		throw new IllegalArgumentException("Unknown quantifier: " + quantifier);
	}

	return cache(quantFormula,ret);
}
 
Example 5
Source File: FormulaFlattener.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.QuantifiedFormula)
 */
@Override
public final void visit(QuantifiedFormula qf) {
    if (visited(qf))
        return;

    if (breakupQuantifiers) {

        final Quantifier quant = qf.quantifier();

        if ((!negated && quant == ALL) || (negated && quant == SOME)) { // may
                                                                       // break
                                                                       // down
                                                                       // further
            final Map<Formula,Node> oldConjuncts = conjuncts;
            conjuncts = new LinkedHashMap<Formula,Node>();
            qf.formula().accept(this);
            if (conjuncts.size() > 1) { // was broken down further
                final Decls decls = qf.decls();
                for (Map.Entry<Formula,Node> entry : conjuncts.entrySet()) {
                    oldConjuncts.put(entry.getKey().forAll(decls), entry.getValue());
                }
                conjuncts = oldConjuncts;
                return;
            } else { // wasn't broken down further
                conjuncts = oldConjuncts;
            }
        } // won't break down further
    }

    addConjunct(qf);

}
 
Example 6
Source File: FormulaFlattener.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * @see kodkod.ast.visitor.AbstractVoidVisitor#visit(kodkod.ast.QuantifiedFormula)
 */
public final void visit(QuantifiedFormula qf) {
	if (visited(qf)) return;
	
	if (breakupQuantifiers) {
		
		final Quantifier quant = qf.quantifier();
		
		if ((!negated && quant==ALL) || (negated && quant==SOME)) { // may break down further
			final Map<Formula, Node> oldConjuncts = conjuncts;
			conjuncts = new LinkedHashMap<Formula, Node>();
			qf.formula().accept(this);
			if (conjuncts.size()>1) { // was broken down further
				final Decls decls = qf.decls();
				for(Map.Entry<Formula, Node> entry : conjuncts.entrySet()) { 
					oldConjuncts.put(entry.getKey().forAll(decls), entry.getValue());
				}
				conjuncts = oldConjuncts;
				return;
			} else { // wasn't broken down further
				conjuncts = oldConjuncts;
			}
		} // won't break down further
	} 

	addConjunct(qf);
	
}
 
Example 7
Source File: HOLTranslator.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
private void assertNotSkolemizable(QuantifiedFormula qf) {
    if (qf.quantifier() == Quantifier.SOME) {
        String msg = "It appears that the existential quantifier in '" + qf + "' is skolemizable, but it hasn't been";
        throw new IllegalStateException(msg);
    }
}