use of mb.nabl2.terms.ITermVar in project nabl by metaborg.
the class PersistentUnifier method unequalVars.
private boolean unequalVars(final ITermVar left, final ITermVar right, Set<Set2<ITermVar>> stack, final java.util.Map<Set2<ITermVar>, Boolean> visited) {
final ITermVar leftRep = findRep(left);
final ITermVar rightRep = findRep(right);
if (leftRep.equals(rightRep)) {
return false;
}
final Set2<ITermVar> pair = Set2.of(leftRep, rightRep);
final boolean unequal;
if (!visited.containsKey(pair)) {
stack.add(pair);
visited.put(pair, false);
final ITerm leftTerm = terms().get(leftRep);
final ITerm rightTerm = terms().get(rightRep);
unequal = (leftTerm != null && rightTerm != null) ? unequalTerms(leftTerm, rightTerm, stack, visited) : false;
visited.put(pair, unequal);
stack.remove(pair);
} else if (stack.contains(pair)) {
unequal = false;
} else {
unequal = visited.get(pair);
}
return unequal;
}
use of mb.nabl2.terms.ITermVar in project nabl by metaborg.
the class UnificationPerformanceTest method testCycle.
private static void testCycle() {
System.out.println("Testing cycle");
final IUnifier.Transient unifier = PersistentUnifier.Transient.of();
ITermVar varA = TermBuild.B.newVar("", A);
ITermVar varB = TermBuild.B.newVar("", B);
ITermVar varC = TermBuild.B.newVar("", C);
ITerm termB = TermBuild.B.newTuple(varB, varB);
ITerm termC = TermBuild.B.newTuple(varC, varC);
try {
unifier.unify(varA, termB);
unifier.unify(varB, termC);
unifier.unify(varC, termB);
System.out.println(unifier);
} catch (UnificationException e) {
System.out.println("Could not unify");
}
System.out.println("ground = " + unifier.isGround(termB));
System.out.println("cyclic = " + unifier.isCyclic(termB));
System.out.println("size = " + unifier.size(termB));
System.out.println("vars = " + unifier.getVars(termB));
System.out.println("equal = " + unifier.areEqual(termB, termC));
System.out.println("unequal = " + unifier.areUnequal(termB, termC));
}
use of mb.nabl2.terms.ITermVar in project nabl by metaborg.
the class VarMultimap method remove.
public boolean remove(ITermVar key, T value, IUnifier unifier) {
final Set<ITermVar> reps = unifier.getVars(key);
boolean change = false;
for (ITermVar rep : reps) {
change |= map.remove(rep, value);
}
return change;
}
use of mb.nabl2.terms.ITermVar in project nabl by metaborg.
the class VarMultimap method put.
public boolean put(ITermVar key, T value, IUnifier unifier) {
final Set<ITermVar> reps = unifier.getVars(key);
boolean change = false;
for (ITermVar rep : reps) {
change |= map.put(rep, value);
}
return change;
}
use of mb.nabl2.terms.ITermVar in project nabl by metaborg.
the class CExists method pp.
@Override
public IMessageContent pp() {
// exists {a b c}. c
final Builder builder = MessageContent.builder();
builder.append("exists {");
boolean first = true;
for (ITermVar var : getEVars()) {
if (first) {
first = false;
} else {
builder.append(" ");
}
builder.append(var);
}
builder.append(": ");
builder.append(getConstraint().pp());
builder.append("}");
return builder.build();
}
Aggregations