I am attempting to write a program that takes two lists as input and checks for proper subset. I started with:
proper([A],[]).
proper([],[A]).
proper([A|T1],[A|T2]) :- proper(T1,T2).
This works perfectly fine for inputs in the exact same order. for instance:
?- proper([a,b,c],[a,b,c,d]).
Yes
But doesn't for inputs such as:
?- proper([a,b,c],[b,d,a,c]).
No
After looking through the site I found this previously asked question:
Which lead me to modify my code as such:
proper([A],[]).
proper([],[A]).
proper([A|T1],[A|T2) :- member(A,T2), proper(T1,T2).
proper([H1|T1], [H2|T2]) :- \+ member(H1, T2).
This works fine for subsets but not for proper subsets. Which I think my problem is arising from my understanding of how the second clause of proper/4 works. Any and all help is greatly appreciated.
Edit:
Realized I was trying to determine if the first list was a proper subset of the second and the second was a proper subset of the first. Cleaned up the code to be more precise.
proper([],_).
proper([A|T1],[A|T2) :- member(A,T2), proper(T1,T2).
proper([H1|T1], [H2|T2]) :- \+ member(H1, T2).