Search in sources :

Example 71 with Formula

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

the class AbstractReplacer method visit.

/**
 * Calls lookup(binFormula) and returns the cached value, if any. If a
 * replacement has not been cached, visits the formula's children. If nothing
 * changes, the argument is cached and returned, otherwise a replacement formula
 * is cached and returned.
 *
 * @return { b: BinaryFormula | b.left = binExpr.left.accept(delegate) &&
 *         b.right = binExpr.right.accept(delegate) && b.op = binExpr.op }
 */
@Override
public Formula visit(BinaryFormula binFormula) {
    Formula ret = lookup(binFormula);
    if (ret != null)
        return ret;
    final Formula left = binFormula.left().accept(delegate);
    final Formula right = binFormula.right().accept(delegate);
    ret = (left == binFormula.left() && right == binFormula.right()) ? binFormula : left.compose(binFormula.op(), right);
    return cache(binFormula, ret);
}
Also used : BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) ConstantFormula(kodkod.ast.ConstantFormula) NotFormula(kodkod.ast.NotFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula)

Example 72 with Formula

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

the class AbstractReplacer method visit.

/**
 * Calls lookup(multFormula) and returns the cached value, if any. If a
 * replacement has not been cached, visits the formula's children. If nothing
 * changes, the argument is cached and returned, otherwise a replacement formula
 * is cached and returned.
 *
 * @return { m: MultiplicityFormula | m.multiplicity = multFormula.multiplicity
 *         && m.expression = multFormula.expression.accept(delegate) }
 */
@Override
public Formula visit(MultiplicityFormula multFormula) {
    Formula ret = lookup(multFormula);
    if (ret != null)
        return ret;
    final Expression expression = multFormula.expression().accept(delegate);
    ret = (expression == multFormula.expression()) ? multFormula : expression.apply(multFormula.multiplicity());
    return cache(multFormula, ret);
}
Also used : BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) ConstantFormula(kodkod.ast.ConstantFormula) NotFormula(kodkod.ast.NotFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) ProjectExpression(kodkod.ast.ProjectExpression) BinaryIntExpression(kodkod.ast.BinaryIntExpression) SumExpression(kodkod.ast.SumExpression) IfIntExpression(kodkod.ast.IfIntExpression) BinaryExpression(kodkod.ast.BinaryExpression) ConstantExpression(kodkod.ast.ConstantExpression) UnaryIntExpression(kodkod.ast.UnaryIntExpression) NaryIntExpression(kodkod.ast.NaryIntExpression) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) UnaryExpression(kodkod.ast.UnaryExpression) NaryExpression(kodkod.ast.NaryExpression) IfExpression(kodkod.ast.IfExpression)

Example 73 with Formula

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

the class AbstractReplacer method visit.

/**
 * Calls lookup(formula) and returns the cached value, if any. If a replacement
 * has not been cached, visits the formula's children. If nothing changes, the
 * argument is cached and returned, otherwise a replacement formula is cached
 * and returned.
 *
 * @return { e: Expression | e.op = formula.op && #e.children =
 *         #formula.children && all i: [0..formula.children) | e.child(i) =
 *         formula.child(i).accept(delegate) }
 */
@Override
public Formula visit(NaryFormula formula) {
    Formula ret = lookup(formula);
    if (ret != null)
        return ret;
    final Formula[] visited = new Formula[formula.size()];
    boolean allSame = true;
    for (int i = 0; i < visited.length; i++) {
        final Formula child = formula.child(i);
        visited[i] = child.accept(delegate);
        allSame = allSame && visited[i] == child;
    }
    ret = allSame ? formula : Formula.compose(formula.op(), visited);
    return cache(formula, ret);
}
Also used : BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) ConstantFormula(kodkod.ast.ConstantFormula) NotFormula(kodkod.ast.NotFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula)

Example 74 with Formula

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

the class FOL2BoolTranslator method translate.

/**
 * Translates the given annotated formula into a boolean accumulator with
 * respect to the given interpreter and logs the translation events to the given
 * logger.
 *
 * @requires interpreter.relations = AnnotatedNode.relations(annotated)
 * @requires annotated.source[annotated.sourceSensitiveRoots()] =
 *           Nodes.roots(annotated.source[annotated.node])
 * @return BooleanAccumulator that is the meaning of the given annotated formula
 *         with respect to the given interpreter
 * @ensures log.records' contains the translation events that occurred while
 *          generating the returned value
 * @throws HigherOrderDeclException annotated.node contains a higher order
 *             declaration
 * @throws UnboundLeafException annotated.node refers to an undeclared variable
 */
static final BooleanAccumulator translate(final AnnotatedNode<Formula> annotated, LeafInterpreter interpreter, final TranslationLogger logger) {
    final FOL2BoolCache cache = new FOL2BoolCache(annotated);
    final FOL2BoolTranslator translator = new FOL2BoolTranslator(cache, interpreter) {

        @Override
        BooleanValue cache(Formula formula, BooleanValue translation) {
            logger.log(formula, translation, super.env);
            return super.cache(formula, translation);
        }
    };
    translator.addSkolems(annotated.skolemRelations());
    final BooleanAccumulator acc = BooleanAccumulator.treeGate(Operator.AND);
    for (Formula root : Nodes.conjuncts(annotated.node())) {
        acc.add(root.accept(translator));
    }
    logger.close();
    return acc;
}
Also used : ConstantFormula(kodkod.ast.ConstantFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) NotFormula(kodkod.ast.NotFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) BooleanValue(kodkod.engine.bool.BooleanValue) BooleanAccumulator(kodkod.engine.bool.BooleanAccumulator)

Example 75 with Formula

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

the class ResolutionBasedProof method highLevelCore.

/**
 * {@inheritDoc}
 *
 * @see kodkod.engine.Proof#highLevelCore()
 */
@Override
public final Map<Formula, Node> highLevelCore() {
    if (coreRoots == null) {
        final RecordFilter unitFilter = new RecordFilter() {

            final IntSet coreUnits = StrategyUtils.coreUnits(solver.proof());

            final Set<Formula> roots = log().roots();

            @Override
            public boolean accept(Node node, Formula translated, int literal, Map<Variable, TupleSet> env) {
                return roots.contains(translated) && coreUnits.contains(Math.abs(literal));
            }
        };
        coreRoots = new LinkedHashMap<Formula, Node>();
        final IntSet seenUnits = new IntTreeSet();
        for (Iterator<TranslationRecord> itr = log().replay(unitFilter); itr.hasNext(); ) {
            // it is possible that two top-level formulas have identical
            // meaning,
            // and are represented with the same core unit; in that case, we
            // want only
            // one of them in the core.
            final TranslationRecord rec = itr.next();
            if (seenUnits.add(rec.literal())) {
                coreRoots.put(rec.translated(), rec.node());
            }
        }
        coreRoots = Collections.unmodifiableMap(coreRoots);
    }
    return coreRoots;
}
Also used : Formula(kodkod.ast.Formula) IntTreeSet(kodkod.util.ints.IntTreeSet) IdentityHashSet(kodkod.util.collections.IdentityHashSet) IntSet(kodkod.util.ints.IntSet) Set(java.util.Set) TupleSet(kodkod.instance.TupleSet) IntSet(kodkod.util.ints.IntSet) IntTreeSet(kodkod.util.ints.IntTreeSet) Node(kodkod.ast.Node) TranslationRecord(kodkod.engine.fol2sat.TranslationRecord) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) RecordFilter(kodkod.engine.fol2sat.RecordFilter)

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