From ok@atlas.otago.ac.nz Mon Jun 11 03:57:35 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f5B1vW311623
	for <prolog@swi.psy.uva.nl>; Mon, 11 Jun 2001 03:57:33 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id NAA40198;
	Mon, 11 Jun 2001 13:57:29 +1200 (NZST)
Date: Mon, 11 Jun 2001 13:57:29 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200106110157.NAA40198@atlas.otago.ac.nz>
To: prolog@swi.psy.uva.nl, suatozdemir17@hotmail.com
Subject: Re:  [SWIPL] i have a big problem...

"Suat Özdemir" <suatozdemir17@hotmail.com>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.
	

