public virtual ATermAppl normalizeFib(ATermAppl t) { ATermAppl res = t; while (true) { // fib(0) = suc(0) ATermAppl v0 = (ATermAppl)res.getArgument(0); if (v0.getAFun() == zero) { res = factory.makeAppl(suc, v0); break; } // fib(suc(0)) => suc(0) if (v0.getAFun() == suc) { ATermAppl v1 = (ATermAppl)v0.getArgument(0); if (v1.getAFun() == zero) { res = v0; break; } } // fib(s(s(x))) => plus(fib(x),fib(s(x))) // v0 v1 if (v0.getAFun() == suc) { ATermAppl v1 = (ATermAppl)v0.getArgument(0); if (v1.getAFun() == suc) { ATermAppl v2 = (ATermAppl)v1.getArgument(0); ATermAppl fib1 = normalizeFib(factory.makeAppl(fib, v2)); ATermAppl fib2 = normalizeFib(factory.makeAppl(fib, v1)); //System.out.println("adding"); res = normalizePlus(factory.makeAppl(plus, fib1, fib2)); break; } } break; } return(res); }
public override bool equivalent(SharedObject obj) { if (base.equivalent(obj)) { ATermAppl peer = (ATermAppl)obj; if (peer.getAFun().equals(fun)) { for (int i = 0; i < args.Length; i++) { if (!peer.getArgument(i).equals(args[i])) { return(false); } } return(true); } } return(false); }
public override void visitAppl(ATermAppl appl) // throws VisitFailure { AFun fun = appl.getAFun(); string name = fun.ToString(); stream.Write(name); position += name.Length; if (fun.getArity() > 0 || name.Equals("")) { stream.Write('('); position++; for (int i = 0; i < fun.getArity(); i++) { if (i != 0) { stream.Write(','); position++; } visitChild(appl.getArgument(i)); } stream.Write(')'); position++; } }
public virtual ATermAppl normalizePlus(ATermAppl t) { ATermAppl res = t; while (true) { ATermAppl v0 = (ATermAppl)res.getArgument(0); // plus(s(s(s(s(s(x))))),y) => plus(x,s(s(s(s(s(y)))))) if (v0.getAFun() == suc) { ATermAppl v1 = (ATermAppl)v0.getArgument(0); if (v1.getAFun() == suc) { ATermAppl v2 = (ATermAppl)v1.getArgument(0); if (v2.getAFun() == suc) { ATermAppl v3 = (ATermAppl)v2.getArgument(0); if (v3.getAFun() == suc) { ATermAppl v4 = (ATermAppl)v3.getArgument(0); if (v4.getAFun() == suc) { res = factory.makeAppl( plus, v4.getArgument(0), factory.makeAppl( suc, factory.makeAppl( suc, factory.makeAppl( suc, factory.makeAppl( suc, factory.makeAppl( suc, res.getArgument(1))))))); continue; } } } } } // plus(0,x) = x if (v0.getAFun() == zero) { res = (ATermAppl)res.getArgument(1); break; } // plus(s(x),y) => plus(x,s(y)) if (v0.getAFun() == suc) { res = factory.makeAppl( plus, v0.getArgument(0), factory.makeAppl(suc, res.getArgument(1))); continue; } break; } return(res); }