Subject: Re: [SWIPL] i have a big problem...

From: "Richard A. O'Keefe" <[email-masked]>
Date: Mon, 11 Jun 2001 13:57:29 +1200 (NZST)

"Suat Özdemir" <[email-masked]>wrote:
	Our teacher did not join the lessons for 2 months because of his health 
	problems so i and all other students didn't learn anything about prolog.

You certainly have a big problem.  If you had to pay for this course,
demand your money back.  There should always be a backup teacher.

	Now we have to do 3 homeworks with prolog to success this lesson. But as i 
	said before i don't know much about prolog.
	
	One of my work is calculating the mode by using only addition and 
	subtraction.

The mode of WHAT?

The mode of a piece of music?
The mode of a predicate?
The most commonly occurring member of a collection?

	Second one is to find the difference of two sets.

There are two ways to interpret "the difference of two sets":
    A - B = { x - y | x \in A & y \in B}
    A \ B = { x | x \in A & not(x \in B)}

If sets are represented as unary predicates, then

    a_minus_b(X) :- a(X), \+ b(X).

	And the third one is two fing the intersection of two sets.
	
If sets are represented as unary predicates, then

    a_intersection_b(X) :- a(X), b(X).

If sets are represented as lists with no duplicate elements, but in no
particular order, here are set difference and intersection in Erlang:

    difference([], _) -> [];
    difference([X|Xs], Ys) when member(X, Ys) -> difference(Xs, Ys);
    difference([X|Xs], Ys) -> [X|difference(Xs, Ys)].

    intersection([], _) -> [];
    intersection([X|Xs], Ys) when member(X, Ys) -> [X|intersection(Xs,Ys)];
    intersection([_|Xs], Ys) -> intersection(Xs, Ys).

If you turn that into Prolog, each of your predicates will need one cut.