* If not cached, visits the formula's children with appropriate settings
* for the negated flag and the skolemDepth parameter.
* @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.BinaryFormula)
*/
public final Formula visit(BinaryFormula bf) {
Formula ret = lookup(bf);
if (ret!=null) return ret;
final FormulaOperator op = bf.op();
final int oldDepth = skolemDepth;
if (op==IFF || (negated && op==AND) || (!negated && (op==OR || op==IMPLIES))) { // cannot skolemize in these cases
skolemDepth = -1;
}
final Formula left, right;
if (negated && op==IMPLIES) { // !(a => b) = !(!a || b) = a && !b
negated = !negated;
left = bf.left().accept(this);
negated = !negated;
right = bf.right().accept(this);
} else {
left = bf.left().accept(this);
right = bf.right().accept(this);
}
skolemDepth = oldDepth;
ret = (left==bf.left()&&right==bf.right()) ? bf : left.compose(op, right);
return source(cache(bf,ret),bf);
}