-----Original Message-----
Sent: Friday, August 02, 2002 2:05 AM
Subject: RE: [SWIPL] Getting how many prolog frames a particular
variable has existed in thus far
Post by ***@users.sourceforge.netA frame would be a prolog_current_frame(PrologFrame).
Variable would be a member of VarsInThisFrame
from
prolog_frame_attribute(PrologFrame,goal,Term),free_varialbes(T
erm,VarsInThisFrame).
Note that the variables in a goal may be arguments in created or
passed compound terms.
Yes very understandable: variables could come or be introduced anywhere like from some
unexpected
compound inner terms I could not expect to foresee all the variables that will get created in a
program.
But with term_expansion I could catch Head variables then while a program loads (those are the
only ones a care to track)
term_expansion((H:-Body),(H:-NewBody)):-
free_variables(H,HeadVars),
convert_to_checks(Body,HeadVars,NewBody).
convert_to_checks(Body,[],Body).
convert_to_checks(Body,[Hv|TVs],((depth_of_variable(Hv,D),D<3),More)):-
convert_to_checks(Body,TVs,More).
I think you need some explanations how things work. Your a(X) creates
a frame with a place for the variable. Calling b(X) (disregarding
last-call optimization) creates a frame for b where the variable is a
_reference_ to the original. Calling c(X), the system is clever and
doesn't make a reference to the X in b's frame, but directly to X is
a's frame. Finally, in reality all this is collapsed in this program
due to last-call optimization.
That is neat that tritely one variable reference ever exists (the one created in a's frame)
So I take it last call optimization makes it so you don't have to walk your way frame by frame
back to a/1.
If you would like to do what you want you either need some way of
attributed-variables or you need to disable last-call optimization
and minimization of reference-chains. In that case the length of
the reference chain is the `age' or your variable. This is not
something you want to do lightly.
I am not sure that last call optimization hurts my cause but instead enhances the knowledge we
are dealing with same == variable.
Now i see that since the variable in b's frame is only _reference_ to the original
I am not dealing with the same variable until its programmatically deference..
But you would know if last call optimization would need turned off. Or if it could remain on and
a C coded variables_creation_frame(-Var,+Frame) could just deference the variable.
Post by ***@users.sourceforge.netWith a call to a(foo), there would be no variables in any
child. (Therefore a case where we
Post by ***@users.sourceforge.netcouldn't count them)
Assumptions about what it would mean in code...
that the struct of a variable when first constructed
(initialized) would record it originator
Post by ***@users.sourceforge.netframe.
This would be less expensive the keeping some ref-count (if
done, would be better left to a
Post by ***@users.sourceforge.netsibling count for alternative frames)
So mainly what I think I need is just a number that will
tell me the frame the variable was
Post by ***@users.sourceforge.netfirst constructed in.. i could use the current frame
reference to subtract possibly.
Post by ***@users.sourceforge.netWhat i am trying to do is construct a
call_with_var_depth_limit(my_goal(A,B,C),[A,B,C],4,WasExceeded).
Or make a predicate like
b(X):-var(X),depth_of_var(X,Depth),Depth<4,c(X).
What do you think? Would this be useful to others besides me?
What is the more high-level goal you want to achieve? What you want
is pretty hard to do as it basically forces the system to drop
important optimizations. Maybe from a higher perspective it becomes
easier.
I am trying to create a similar effect that PTTP http://www.ai.sri.com/~stickel/pttp.html
uses to create iterative deepening. Instead of saying we have deepened my search once per neck
(:-).
I am planning on a more jaggedy productive search that says:
I will only deepen N further while a head variable continues to be unbound during subsequent
prolog necks.
Once the variable has remained unbound for a N depth..
The program may choose to assume it will never be bound and more productive search exists
elsewhere (failing this branch)
This will help create transitive closures and add small amounts of loop detection in that this
program would terminate:
So starting with this program.
:-ensure_loaded(depth_bound_varible_term_expanions).
p(X):-q(X).
q(a).
q(X):-p(X).
q(b).
With the term_expansion above used transliterates the program to:
p(A):-depth_of_var(A,B),B<3,q(A).
q(a).
q(A):-depth_of_var(A,B),B<3,p(A).
q(b).
Then I would use the code:
depth_of_var(X,0):-nonvar(X),!.
depth_of_var(X,N):-
variables_creation_frame(X,Then),
current_prolog_frame(Now),
count_parents(Now,Then,N).
count_parents(Now,Now,0).
count_parents(Now,Then,N):-
prolog_frame_attribute(Now,parent,Parent),
count_parents(Parent,Then,P),
N is P+1.
The variables_creation_frame(-Var,+Frame). would need to dereference that variable and look for
the frame it was first created in.
But the higher level goal/situation is I have a very large and pathological knowledge base..
It is a series of Horn clauses created from cannonicalization of first-order logic. Some of
this
logic contains cycles and paths that do nothing. I am trying to do a complete enough search for
deductive reasoning using propositional resolution. Memoization would solve my remaining
problems.
But so far Tabling/Memoization has failed (core dumps on several prolog systems that claim they
can do it)
(The reason is my table clause cache can contain thousands of entries across hundreds of
predicates) So mainly its a memory issue.
(These other prolog systems only work on toy examples) SWI-Prolog loads my 80 meg source files
with ease.
These others (like XSB, faults on things small as WordNet) BinProlog tends to work mostly but
has it's own set
of issues like it's read/Ns can't load atoms like '#$TheSetOf-All-ThingsBlue' And tends to have
other unexpected features.
(SWI and most others prologs can read such quoted atoms) SWI-Prolog may not be the fastest
prolog out
there but in my opinion the only that is dependable and feature full.
I have done some experiments and found by tracking variables (in my meta interpreter) I have
been able to keep search productive
over my knowledge base and can live w/o memoization in SWI-Prolog.
-Douglas
----------------
* To UNSUBSCRIBE, please use the HTML form at
http://www.swi-prolog.org/mailinglist.html
or send mail to prolog-***@swi.psy.uva.nl using the Subject: "unsubscribe"
(without the quotes) and *no* message body.
** An ARCHIVE of this list is maintained at
http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/