Discussions related to Visual Prolog
jarnold30
Posts: 18
Joined: 9 Aug 2020 15:30

subset between sets

Unread post by jarnold30 »

hi, is there any way, given 2 lists or sets, to check if one is a subset of the other?
Harrison Pratt
VIP Member
Posts: 335
Joined: 5 Nov 2000 0:01

Re: subset between sets

Unread post by Harrison Pratt »

Classical way, easy to understand:

Code: Select all

class predicates     isSubSet : (T* CheckTerms, T* Terms) determ. clauses     isSubset([H], Terms) :-         list::isMember(H, Terms),         !.     isSubset([H | TT], Terms) :-         list::isMember(H, Terms),         isSubSet(TT, Terms).
Another way using VIP list class predicates. Put your cursor on "list::all" in your code and press F1 for more information.

Code: Select all

        % ... some code ...         L1 = [1, 2, 3, 4, 5, 6],         L2 = [0, 3, 4, 5, 5],         list::all(L2, { (E) :- list::isMember(E, L1) }), % will FAIL because 0 is not a member of L2         % ... some more code ...
You may need to do some reading on list domains here: https://wiki.visual-prolog.com/index.ph ... st_Domains
jarnold30
Posts: 18
Joined: 9 Aug 2020 15:30

Re: subset between sets

Unread post by jarnold30 »

thanks
Post Reply