outcl06 - isunion,L,L isunion[X|L1,L2,L3...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
EEL-6841 Class Notes 6 Spring 2016 Dr. Arroyo 1 OUTLINE I. Backtracking & the Cut Operator II. Applications of Sets and Lists File: class06.pl apend0([],Lis,Ans) :- Ans=Lis. apend0(Lis1,Lis2,Ans) :- Lis1=[H|T], apend0(T,Lis2,Lis3),Ans=[H|Lis3]. apend([],L,L). apend([H|T],L2,[H|L3]):-apend(T,L2,L3). rev0([],[]). rev0(Lis,Z) :- Lis=[H|T],rev0(T,Z1),append(Z1,[H],Z). rev([],[]). rev([X|Y],Z) :- rev(Y,Z1),append(Z1,[X],Z). isunion0([ ],L,L). isunion0( [X|L1],L2,L3 ) :- member(X,L2),isunion0(L1,L2,L3). isunion0( [X|L1],L2,[X|L3] ) :- isunion0(L1,L2,L3). isunion1([ ],L,L). isunion1( [X|L1],L2,L3 ) :- member(X,L2),isunion1(L1,L2,L3). isunion1( [X|L1],L2,[X|L3] ) :- not(member(X,L2)),isunion1(L1,L2,L3).
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: isunion([ ],L,L). isunion( [X|L1],L2,L3 ) :- member(X,L2),!,isunion(L1,L2,L3). isunion( [X|L1],L2,[X|L3] ) :- isunion(L1,L2,L3). inter(,_,). inter([X|T1],Y,[X|Z]) :- member(X,Y),!,inter(T1,Y,Z). inter([_|X],Y,Z) :- inter(X,Y,Z). lst0(X,Y) :- reverse(X,[Y|_]). lst([X],X). lst([_|X],Y) :- lst(X,Y). subst(_,_,,). subst(S1,S2,[S1|Y],[S2|Z]) :- subst(S1,S2,Y,Z). subst(S1,S2,[X|Y],[X|Z]) :- X\=S1,subst(S1,S2,Y,Z). fact(0,1). fact(N,L) :- M is N-1, fact(M,K), L is N*K. len(,0). len([_|Y],M) :- len(Y,N), M is N+1. depth(,1). depth(X,0) :- atomic(X). depth([X|Y],N) :- depth(X,M), depth(Y,L), P is M+1, N is max(P,L)....
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern