Subject: RE: representing terms canonically

From: "Douglas Miles (Volt Computer)" <[email-masked]>
Date: Wed, 9 Aug 2000 21:16:27 -0700

Paul I am working on a simular project while we speak.

I have been implementing it with a psuedo object modeling system. that
transfers easiely between domains of Prolog and COM, Java, VB

There are two types:  models and instances of the living models.

These models are built of identicle shaped nodes

'Each node contains this struct
Public Type ModelNode
     MemberName As String
     Modelkind As ModelKinds
     Pointer As String
     Origin As Object
     TypeName As String
     NativeTli As TypeLibInfo
     Models As PropertyMap
     SiteName As SiteNames
    'Only Properties and Methods use these
     InvokeKind As InvokeKinds
     ReturnVARType As VarTypeInfo
     Value As Variant
End Type

They themselves transfer in/out of prolog terms  I have been testing this
against live COM objects in Visual Basic. (So far very successfull)

The structures are like trees with nodes that all languages have one special
form for rebuilding the objects

Here are the Basic node types i use

'Each node falls into one of these model parts

Public Enum ModelKinds
    MODELKIND_PROPERTY = (tli.InvokeKinds.INVOKE_PROPERTYPUT Or
tli.InvokeKinds.INVOKE_PROPERTYGET)    'if this is set the object holds a
pointer to the parent object and the interface or variable
    MODELKIND_CONTENT = tli.InvokeKinds.INVOKE_PROPERTYPUTREF   'Basic
building block of any model (this is the OBJECT)
    MODELKIND_FUNCTION = tli.InvokeKinds.INVOKE_FUNC
    MODELKIND_EVENT = tli.InvokeKinds.INVOKE_EVENTFUNC
    MODELKIND_UNKNOWN = tli.InvokeKinds.INVOKE_UNKNOWN
    MODELKIND_PARAMETER  '(this is mainly used for defining event and
funbction params)
End Enum
 
'The site name was what application was originally used to build the object
(but and application can share them)
Public Enum SiteNames
    SITENAME_UNKNOWN = 0
    SITENAME_UNBOUND = 1  ' Prolog unbound
    SITENAME_ARRAY = 2  'Safe
    SITENAME_COLLECTION = 4 'Any site that For-Each-In
    SITENAME_MAP = 8 ' Morphism DataType
    SITENAME_LIST = 16 'VWorlds only
    SITENAME_REFDATA = 32   'usualy holds a strings/Long (basicly non
objects) that ar AS-IS terms
    SITENAME_VWTHING = 64 ' Dynamic virtual worlds com
    SITENAME_VWSERVER = 128 ' See Typlib info
    SITENAME_WINCOM = 256 'Standard windows COM ' OLE  Automated 
    SITENAME_MORPHISM = 512
    SITENAME_PROLOG_SERVER = 1024   'PROQUERY.DLL
    SITENAME_PROLOG_CLIENT = 2048  'SWIACTX.DLL
End Enum
 
Attached is a an HTML that shows an expanding interlanguage Model

-----Original Message-----
From: Paul Singleton [  <mailto:[email-masked]>
mailto:[email-masked]]
Sent: Wednesday, August 09, 2000 4:09 PM
To: SWI Prolog
Subject: representing terms canonically

I want to represent general Prolog terms in a non-Prolog environment (e.g.
structures in Java or Visual Basic; byte strings in databases or networks)
with all these properties if possible:

 * no loss of information
    + an equivalent term should be reconstructable from the foreign repn.
      (I can do this :-)
    + preserve internal order of any variables (I can see how to do this)

>>>> I am using VTABLE ofsets of IDispatch Pointers for COM..  (but saving
the actual values in a special      SITENAME_REFDATA + MODELKIND_CONTENT
node object)

 * compactly
    + cyclic terms have finite representations
    + recombinant terms are not "exploded"
    + common atoms, variables (of course) and subterms are factored out

>>>> I keep an AddRef Collection of ObjectPointers to make sure when the
Nodes have been already included in the graph

 * canonically
    + all (inc. cyclic) terms denoting the "same" term (apart from renaming
      of variables) have a single common representation
>>>>  the nodes tend to translate system to system and language to language 
>>>> I have only  one terming system  that had to only be coded
com_to_datum, datum_to_com, datum_to_prolog, prolog_to_datam,
*_to_datum, datum_to_* 

I suspect it is obvious to some others that canonical repn of cyclic terms
is in general impossible, or infeasible to compute?  It just seems likely
to me...
>>>> thsoe objects i mark as SITENAME_PROLOG_SERVER +     MODELKIND_FUNCTION
(only if they are self iterative)  I move between prolog and COM

I want to factor out common atoms because some may be very large.
 
>>>> I am not been afarid of my objects bloating too much but probly should
be

I want to preserve variable order in case it is significant, e.g. indexed
sets of lemmas for some theorem prover or other interpreter...

>>>> Most Models I use are represented in SETS .. i am going to be moving to
LISTS as soon as SITENAME_ARRAY is CoSymetrical to SITENAME_COLLECTION
>>>> Pass things arround with {NAME=Value ,NAME=Value ,NAME=Value } SETs so
you can order the set based on the proper name order (that is Site defined)
to make a VALUE,VALUE,VALUE if you wish

I want to represent cyclic terms finitely because I can't guarantee that
applications won't build them, and anyway some applications may use them
(whether they *should* is irrelevant, I hope).

>>>> This is where one child has more then one dirrection on the links (or
just more then one parrent node will do this In my node model )
 have this throughout the MSBNX Control (it has a child.parent.child.parent
(mainly so you can always move one step up from any point in a tree)..etc..)
.. the way i block this out is i made parentname a child property and treat
it as a SITENAME_REFDATA (terminal) as opposed to SITENAME_CONTENT (which is
recurively modeled)

I'm willing to assume that no atom gc or stack shifting occurs while any
particular term is being exported.

I reckon this needs facilities not provided in the FLI: e.g. get the
dictionary address of an atom, and the heap address of a compound term

>>> I realy havent been able to involve myself with staticly comprehending
what any particualar site is Physicly doing with my term.. (i do store
static pointers but only into live objects (not cause i want to, but i am
afraid i'll lose them in  system memory :)  (also keeps the objects from
terminationing to have asked for pointers to them) or while in prolog i tend
to think that i am Meta-processing Level and a string or a number means
something in the live object context... the classes/names are for my prolog
program to understand :
In terms of what the prolog site does with it:    it manipulates the object
instead of the object manipulating prolog.

I have a tentative algorithm for factoring common subterms based on
maintaining a hash value for each subterm during traversal, then using
a safe (cycle-detecting) comparison...

>>>>> I need your help Paul  :) .. I am just building the stable system that
has all this inter-language support ,,,,   and i havent even begun to decide
how to use it !
And that's as far as I've got - comments, help and advice please.

Paul Singleton

----------------
* To UNSUBSCRIBE, please use the HTML form at

     <http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist>
http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to [email-masked] 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/>
http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/