ruleNumber++;
// fib(suc(suc(X))) -> plus(fib(X),fib(suc(X)))
list = subject.match(lhs[ruleNumber]);
if (list != null) {
ATerm X = (ATerm) list.get(0);
list.add(X);
return factory.make(rhs[ruleNumber], list);
}
ruleNumber++;
// plus(zero,X) -> X
list = subject.match(lhs[ruleNumber]);
if (list != null) {
return factory.make(rhs[ruleNumber], list);
}
ruleNumber++;
// plus(suc(X),Y) -> plus(X,suc(Y))
list = subject.match(lhs[ruleNumber]);
if (list != null) {
return factory.make(rhs[ruleNumber], list);
}
ruleNumber++;
// congruence (suc)
list = subject.match(lhs[ruleNumber]);
if (list != null) {
//System.out.println("congsuc"); // applied 1184122 times fir fib(14)
ATerm X = (ATerm) list.get(0);
ATerm Xp = oneStep(X);
if (Xp.equals(fail)) {
return fail;
}
list.clear();
list.add(Xp);
return factory.make(rhs[ruleNumber], list);
}
ruleNumber++;
// congruence (plus)
list = subject.match(lhs[ruleNumber]);
if (list != null) {
//System.out.println("congplus"); // applied 9159 times fir fib(14)
ATerm X = (ATerm) list.get(0);
ATerm Xp = oneStep(X);
if (Xp.equals(fail)) {
ATerm Y = (ATerm) list.get(1);
ATerm Yp = oneStep(Y);
if (Yp.equals(fail)) {
return fail;
}
list.clear();
list.add(X);
list.add(Yp);
return factory.make(rhs[ruleNumber], list);
}
ATerm Y = (ATerm) list.get(1);
list.clear();
list.add(Xp);
list.add(Y);
return factory.make(rhs[ruleNumber], list);
}