Discussion:
[Xsb-development] Constant names
K. A.
2012-06-17 16:06:58 UTC
Permalink
Hi all,


An implementation question: Does XSB index in such a way
that the choice of constant names might make a difference
in performance? More specifically: Suppose I have a very
large number of constants (millions) that appear in
various facts. If the names of these constants share
a large prefix, could that have a negative impact on
query performance? For instance, if the constants
are named specialnode1, specialnode2, ..., specialnode2872658,
etc., would that be worse than using more randomly
distributed names? Or is this completely irrelevant
to performance?
Thanks,


K. 

--- On Fri, 6/15/12, David Warren <***@cs.stonybrook.edu> wrote:

From: David Warren <***@cs.stonybrook.edu>
Subject: RE: [Xsb-development] Loading dynamic predicates
To: "K. A." <***@yahoo.com>, "Xsb-***@lists.sourceforge.net" <Xsb-***@lists.sourceforge.net>
Date: Friday, June 15, 2012, 4:17 PM









Hi Konstantine,
 

From: K. A. [mailto:***@yahoo.com]


Sent: Friday, June 15, 2012 2:54 PM

To: Xsb-***@lists.sourceforge.net

Subject: [Xsb-development] Loading dynamic predicates

 







A couple of questions about loading dynamic predicates:



(1) Let's say p/2 is a dynamic predicate and I want to

load a large number of p facts. Would it be better (more

efficient) to (i) write all these facts into a file facts.P

and then do "load_dync('facts.P')", or (ii) programmatically

assert each fact individually?
The question is where do the facts come from.  If there are generated by some XSB algorithm and you are asking is it faster to
write them out and then dynamically load them, or to just directly assert them, then it should be faster to directly assert them.  load_dync does a read and an assert for every clause it reads.



(2) Let's say I need to dynamically load files of p facts,

multiple times. Suppose p/2 is both dynamic and tabled.

(Are you tabling facts? That is almost never a good idea.  It just takes extra time and space.)


And let's say that file foo1.P contains:



:- table p/2.

:- dynamic p/2.

:- multifile p/2.

p(a,b).

p(X,Y) :- p(Y,X).

p(X,Y) :- p(X,Z), p(Z,Y).



while file foo2.P contains:



:- abolish_all_tables.

p(b,c).



If I first do



load_dyn('foo1.P')



and then



load_dyn('foo2.P')



XSB doesn't seem to respond correctly to queries like



findall(Y,p(a,Y),Results).



Specifically, it gives [a,b] as the result rather

than [a,b,c], i.e., it seems to ignore the p(b,c)

fact that was loaded from foo2.P.



However, if I put the :- multifile p/2 at the top

of file foo2.P, so that the contents of foo2.P are:



:- multifile p/2.

:- abolish_all_tables.

p(b,c).



then everything works fine. I guess the first question

here is: why is the "multifile p/2" directive needed in both

foo1.P and foo2.P?
They both need to know that the predicate is multifile.  And they learn it by seeing it in the file.




The second question is: Is there anyway I can write

the "multifile p/2" and the "abolish_all_tables"

directives in canonical format? I would like to

do "load_dync('foo2.P')" instead of "load_dyn('foo2.P')"

since load_dync is much faster, but load_dync chokes

on the multifile and abolish_all_tables commands

(load_dyn works fine).
 
Multifile does not work completely in XSB.  It mostly works, but you can run into problems with it since it is not fully integrated
into all aspects of the system.  I avoid using it.
 
Yes, all terms can be put in canonical format.
:-(multifile(‘/’(p,2))).
Is the form you want for the multifile declaration (I think).  You can find it by doing:
| ?- write_canonical((:- multifile p/2)).
And it will print it in canonical form.  (You need the extra parens because of the precedence of :- and multifile.)
-David




Many thanks in advance! Cheers,



Konstantine








 

Loading...