\ ~lumc 3, number 4
INFORMATION PROCEWNG
RETRIEVAL
LE’ITERS
‘Uch 1975
FROMCONTE~TREES
Ben WEGBREIT* CgRterfor R
Tecbmdogy, HarvardUltiwrsity,Cambridge, Mass. 02 I J8, USA Received 13 September 1973
fhmu problem
variable Sinding
da& structu -+s
L tifLM intelligerxe
I
1. context
Severalof the newer artificial intelligence proand apphcations programs $ramminglan (e* [l-s]) use a context tme for storing data for which the frame problem [6, 7] is significant. A context tree is a singly-rooted tree of contextIlodes A context C is the sequence of nodes [Nar .... NO] on the path from a given node Nm to the root node N*. Context nodes are used to represent discrete change points; a dewendant context representsan incremental modification of itg ancestor context. Data has the form (K, V, N) where K is a key, V is a value, and N is the node at which the key-value pair is asserted. To handle the frameproblem, key-value pairs of an ancestor continue to hold in descendants unless explicitly superceeded.
2JMlmbdm~
techniques
Given a key K and context C = [Nm, .... NO]) Retrieve(K, C) finds the first node N in the sequence Nnr, .... NO such that there is an asserted triple (K, V, N) and returns V, signaling the absence of K in C if no such node exists. (K and C are generally computed by the program, so this retrieval is somewhat different 3om run-time reference of vatibles in a block-structured language [8]). * Present address: Xersx Corporation, Palo Alto Research Centct, 3180 Port= Dr., Palo Alto, Ca 943
A possible implementation is to index triples by their third component Siven A md C = [Nm, .... iv,], it suffices to consider the N1 (in the order i = m, .-, 0) searchingall triples indexed by A$ for one whose first component is K. Since the number of triples in which a given key appears is small in typical applications [9], a better method is to index by key. Let T(K) = [K, 5, Nr) ij = 1, .... s] be the ordered set or triples having key K, where the ordering is any exter sion of the partial ordering given by the ancestral I elation, i.e. if node N, is a descendant of N, , then a tri Ile with A$ appearsbefore a triple with N, . Two imple nentations of Retrieve (K, C) in current use are: (1) Consider each triple (K, 5, A$) in order. Search [Nm9 -9 NO] for a node equal to N’ ant I return yi if such a node is found. (2) A total ordering is imposed on the nodes; which extends the ancestral partial ordering. Using the total ordering, the elements of T(K) and C are considered in parallel, searching for a triple in ‘Y’(K) whose third component 5 in C. Let z be the number of triples in T(K) and 2; be the number of nodes ;n $J Tzchnique (1) takes time at most proportional to K* C whe?eas (2) takes time at most proportional to x + C. The proposed algorithm does somewh; t better in common cases.
typicd
a~p~~a~o~s,
119
‘i
I
s
3,!nElaabar4
March 1975
BUFORMATIONPROCESSINGLETTERS
i
[ S01. ‘II& may be exploited as follows. m aqmnted with 81c3epth field - an insf the distance between the PIodeand b. bt rrr[K)= [‘XT V , Ni) Ij = 1; l*-,J] CII f trip& having key &!, orderedin dednr an their d@& let C= [A&? -J&1, IW+pth be the &pth field of node iV. Re= p rJ) is carfied out iri two steps. &I arrayD is updated %othat D[fl = Ni, Thf: triples K, Vj, Njj are considered in cm 4;1until D[Nj-* depth] = I$. If such a Nj 3 found, then 5 is returned;otherwi= # is &sent in C ~&&ate updating D, an index Ii is used to the number of valid elements in D. To up .... NOJ, it suffices to ) then no change is for i from m count-
depending on the program block in which the idectifier occurs (e.g. c.f. [ 1 I]). The proposed algorithm provides an efficient 8’implementation for’ the retrieval. e Referenais .
J.F. Rulifsw, J.A. Dirk!j#l wtd R.T. Waldinger, QA4 - A Language for Wr;ting Proble;n Solving Programs, Rot. IFIP Congress - 71, Ljubljana , (North-Holland Publ. Co., Amsterdam.) C.J. Sussman and D. McDermott, Why Conniving is Better than Planning Proc. 1972 FJCC, VoL 41, Part%, pp. 1171-1179. D. Davies and W. Julian, PQPLER 1.9 Reference Manual, Univ. 0: Edinburgh, TPU Report No. 1, May 19?3. R. Reboh and E. Sacerdoti, A Preliminary QLISP Manual, Stanford Research Inst., AI Tech. Note 81, August 1973 L.P. Deutsch, An InteractiveProgramtFerffier,doctoral dissertation,ComputerScience Dep., Unhr,of California, Berkeley, May 1973. 3. McCarthy and P.J. Hayes, Some Philosophical Prob lems from the Standpoint of Artificial Int Machine InteEince 4, B. M&zer and D. Amer. Elseviei Publ. Co. 1969, pp. 463-502. B. Raphaef, The Frame Problem in Problem-Solv& Systems, Proc, Advanced Study Institute on Artificial Intelligence and Hebistic Programming, Me Italy, August 1970, also Stwford Resee Inst. AI Techu, Note 33, June 1970. W. Henhapl and C.B. Jones, A.Run-Time Me&an&n for Referencing Variables, Inform. Proc. Lett. 1 (197 1) 14-16. For example, Deutsch (fs] p. III-1 1) reports that a substantial run of his program verifier gave an average of 3.98 entries examined per successful ret&w& and 2.44 per unsuccessfulretrieval, D.V. McIkmott and G.J. Sussman, The CONNIVER Reference Manual,M.X.T.sAI Memo No. 259, May 1972. D. Gries,CompilerConstructionfor Digital Computers (John Wiley & Sons, New York, 197 1). S
at mo3t proportionalto K.
In a muIti-passcompiler for a block-structured , it is desirabIeto create declaration-table tr, +sfor all identifiers during the first pass and refeti1,’ thw on subsequent paws, retrievingthe correct entry for each appearanceof an identifier