public void collectOneStep(final Collection collection, Term subject) {
try {
MuTraveler.init(`BottomUp(OneStep(subject,collection))).visit(subject);
System.out.println(collection);
} catch (VisitFailure e) {
System.out.println("Failed to get successors " +subject);
}
}
%strategy OneStep(subject:Term,c:Collection) extends `Identity() {
visit Term {
f(x) -> { c.add(MuTraveler.getReplace(this,`f(s(x))).visit(subject)); }
f(s(x)) -> { c.add(MuTraveler.getReplace(this,`f(f(x))).visit(subject)); }
s(s(x)) -> { c.add(MuTraveler.getReplace(this,`f(x)).visit(subject)); }
}
}
public boolean reach(Term start,Term end) {
Collection result = new HashSet();
Collection predResult = new HashSet();
Collection c1 = new HashSet();
c1.add(start);
while (result.isEmpty() || predResult.containsAll(result)) {
Collection c2 = new HashSet();
Iterator it = c1.iterator();
while(it.hasNext()) {
collectOneStep(c2,(Term)it.next());
}
c2.removeAll(result);
c1 = c2;
predResult.addAll(result);
result.addAll(c2);
if(result.contains(end)) {
return true;
}
}
return false;
}
This function can loop if the system