Subset Function in Prolog

I am working on writing a subset function, and I have succeeded. Here is my function that implements the member function:

member( X, [ X | T ] ). member( X, [ _ | T ] ) :- member( X, T ). subset([], _). subset([H|T1], T2) :- member(H, T2), subset(T1, T2). subset([H1|T1], [H2|T2]) :- \+ member(H1, T2), subset([H1|T1], T2). 

My question is, is there a better way to write this function using a member function, of course.

+1
source share
1 answer

The third sentence of subset/3 does not make sense, and I think it should be deleted. If H1 not a member of T2 , then the recursive call to subset([H1|T1], T2) will obviously also fail.

In addition, the first two sentences seem possible.

+2
source

Source: https://habr.com/ru/post/956615/


All Articles