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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations