/* STRUCT : Structure crunching routines UTILITY Lawrence Updated: 11 September 81 */ %%% STRUCT requires no other modules subst(S1#S2,Old,New1#New2) :- !, subst(S1,Old,New1), subst(S2,Old,New2). subst(S1&S2,Old,New) :- !, subst(S1,Old,X), subst(S2,X,New). subst(U=Term,U2,Term) :- U == U2, !. subst(_,A,A) :- ( var(A) ; atomic(A) ), !. subst(S,[HD|TL],[HD2|TL2]) :- !, subst(S,HD,HD2), subst(S,TL,TL2). subst(S,Term,Nterm) :- Term =.. [F|Args], subst(S,Args,Nargs), Nterm =.. [F|Nargs]. occ(X,Term,Ans) :- occ2(X,Term,N), Ans = N. occ2(X,X2,1) :- X == X2, !. occ2(_,A,0) :- ( var(A) ; atomic(A) ), !. occ2(X,[HD|TL],N) :- !, occ2(X,HD,N1), occ2(X,TL,N2), N is N1 + N2. occ2(X,Term,N) :- Term =.. [_|Args], occ2(X,Args,N). variables(X,Vlist) :- variables(X,[],Vlist). variables(V,Sofar,Result) :- var(V), !, vchk(V,Sofar,Result). variables(A,Sofar,Sofar) :- atomic(A), !. variables([HD|TL],Sofar,Result) :- !, variables(HD,Sofar,Inter), variables(TL,Inter,Result). variables(T,Sofar,Result) :- T =.. [_|Args], variables(Args,Sofar,Result). vchk(V,[],[V]). vchk(V,[HD|TL],[HD|TL2]) :- ( V == HD, TL = TL2 ; vchk(V,TL,TL2) ), !.