From mdonder@cs.bilkent.edu.tr Sun Nov  4 15:46:54 2001
Received: from manyas.bcc.bilkent.edu.tr (manyas.bcc.bilkent.edu.tr [139.179.30.24])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id fA4Ekpt07405
	for <prolog@swi.psy.uva.nl>; Sun, 4 Nov 2001 15:46:52 +0100 (MET)
Received: from 195.175.122.220 (lists.bilkent.edu.tr [139.179.10.6])
	by manyas.bcc.bilkent.edu.tr (Postfix) with SMTP id 85BAA126CF
	for <prolog@swi.psy.uva.nl>; Sun,  4 Nov 2001 16:03:42 +0200 (EET)
Message-ID: <BasiliX-1.0.4b-10048851743be554b6b857c@lists.bilkent.edu.tr>
X-Mailer: BasiliX 1.0.4b -- http://basilix.org
X-SenderIP: 195.175.122.220
Date: Sun, 04 Nov 2001 16:46:14 EET
From: <mdonder@cs.bilkent.edu.tr>
To: prolog@swi.psy.uva.nl
Subject: [SWIPL] Performance!

Hi, everybody!

I do have a set of rules, a part of which is given below. I use
these rules to derive facts that are not explicitly stored in my
factsbase. I save about 40% from the space; however, the cost of
execution is high. The main reason behind it is that many of my
rules recompute a set of facts many times as can be seen in the
rule set below (p2-west/3 and p3-west/3 recomputes p1-west/3 each
time they are called). I thought about using modules: p1-west/3,
p2-west/3 and p3-west/3 may create their own modules, and the
module created for p1-west/3 may be imported to the modules
created for p2-west/3 and p3-west/3 before the first call to them
is made. However, as noted in the SWI-Prolog manual, this creates
a runtime overhead, which may actaully exceed the time spent for
recomputing the facts.

I could not find any way to reorganize the rules so that the
performance gets better. I am open to any suggestion, and any
comment or solution would be very much appreciated.

Have a nice day,

Mehmet E. Donderler


/* WEST, EAST, RIGHT, LEFT */

p-west(X, Y, F) :- p1-west(X, Y, F); p2-west(X, Y, F);
             p3-west(X, Y, F).

p1-west(X, Y, F) :- west(X, Y, F).

/* if object X is to the west of object Y, and object Y is to the
west of object Z, then object X is to the west of object Z.
(Transition Rule). */

p1-west(X, Z, F) :- west(X, Y, F), p1-west(Y, Z, F).

/* if object X is equal to object Y, and object Y is to the west
of object Z, then object X is to the west of object Z. */

p2-west(X, Z, F) :- p1-equal(X, Y, F), p1-west(Y, Z, F).

/* Extension Rule */

p2-west(X, Z, F) :- p1-equal(X, Y, F), p1-west(Y, W, F),
    (p1-equal(W, Z, F); p2-west(W, Z, F)).

/* if object X is to the west of object Y, and object Y is equal
to object Z, then object X is to the west of object Z. */

p3-west(X, Z, F) :- p1-west(X, Y, F), p1-equal(Y, Z, F).

/* Extension Rule */

p3-west(X, Z, F) :- p1-west(X, Y, F), p1-equal(Y, W, F),
    (p1-west(W, Z, F); p3-west(W, Z, F)).

/* if object Y is to the west of object X, then object X is to the
east of object Y (Inverse Rule). */

p-east(X, Y, F) :- p-west(Y, X, F).

/* if object X is to the east/north-east/south-east of object X,
then object X is to the right of object Y. */

p-right(X, Y, F) :- p-east(X, Y, F); p-north-east(X, Y, F);
                 p-south-east(X, Y, F).

/* if object X is to the west/north-west/south-west of object Y,
then object X is  to the left of object Y. */

p-left(X, Y, F) :- p-west(X, Y, F); p-north-west(X, Y, F);
            p-south-west(X, Y, F).

