home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / specific / 597 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  5.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!gatech!concert!uvaarpa!gems.vcu.edu!fritz
  2. From: fritz@gems.vcu.edu (J. E. Fritz)
  3. Newsgroups: comp.specification
  4. Subject: Re: Theoretical limitations of algebraic specifications?
  5. Message-ID: <1993Jan1.161137.235@gems.vcu.edu>
  6. Date: 1 Jan 93 16:11:36 -0400
  7. References: <1992Dec31.000439.8884@gmuvax2.gmu.edu>
  8. Organization: Virginia Commonwealth University
  9. Lines: 137
  10.  
  11. In article <1992Dec31.000439.8884@gmuvax2.gmu.edu>, ofut@gmuvax2.gmu.edu
  12.   (A. Jeff Offutt) writes:
  13. > I have been struggling with an algebraic spec for a couple of days and
  14. > am beginning to wonder if I am trying to do something that is
  15. > impossible.  Intuitively, the feeling is similar to that of trying to
  16. > describe a context free language using regular expressions.
  17. > Generally, are there _known_ fundamental limitations of algebraic
  18. > specifications?  Has anyone studied the "classes" of ADTs that can be
  19. > specified using various specification approaches?  If so, I would
  20. > appreciate a reference (or a short synopsis, if possible).
  21.  
  22. I believe that there are, but the subject is out of my area of
  23. competence.  However, what you are trying to do is indeed possible.
  24.  
  25. > More specifically, I am trying to specify a tree that has the notion of
  26. > a "current node", and operations to change the current node.  The
  27. > current node is a headache, mainly because I have different kinds of
  28. > constructors -- some that modify the tree structure (adding/deleting
  29. > nodes) and others that modify the current node.  My real problem,
  30. > though, is with an operation that changes the current node to the
  31. > root.
  32. > Does anyone konw offhand if that is possible ... and if it is, how?
  33.  
  34. The problem is that tree implementations usually severely restrict the
  35. operations available, which makes formal manipulation of their
  36. properties difficult.  One solution is to first define an auxiliary
  37. tree type, which has nice mathematical properties but is not intended
  38. for implementation. Then define the tree type you will actually use in
  39. terms of the auxiliary type.
  40.  
  41. Here is one such auxiliary type.  The fundamental operation is  t.p  ,
  42. which represents the subtree of  t  obtained by following the path  p 
  43. from the root.  If  p  is empty, then  t.p  is just  t  .  Thus if we
  44. are talking about binary trees with left and right branches, we would
  45. say something like  t.<left,right>  instead of  right(left(t))  .
  46.  
  47. Paths are just strings of directions.  In following,  p^q  is  p 
  48. followed by  q  ;  <>  is the empty path;  <j>  is the path whose first
  49. and only element is  j  ; and  p`n  is  p  with its last  n  elements
  50. removed.
  51.  
  52. Then given types
  53.  
  54.   Index = {left,right}         -- or whatever
  55.   Path = string of Index
  56.   Value =  < some arbitrary type >
  57.  
  58. we specify the auxTree type as follows.  (The  PRE  clauses specify when
  59. a function application is defined.)
  60.  
  61. for   t, t1: auxTree   p, p1: Path   j: Index   v: Value 
  62.  
  63. (binary operator) . : auxTree x Path -> auxTree
  64.    PRE(t.p) = p in dom(t)
  65. dom: auxTree -> set of Path
  66.    PRE(dom(t)) = true
  67. singleton: Value -> auxTree
  68.    PRE(singleton(v)) = true
  69. val: auxTree -> Value
  70.    PRE(val(t)) = true
  71. add: auxTree x Path x auxTree -> auxTree
  72.    PRE(add(t,<>,v)) = false
  73.    PRE(add(t,p^<j>,v)) = p in dom(t) & not(p^<j> in dom(t))
  74. remove: auxTree x Path -> auxTree
  75.    PRE(remove(t,<>)) = false
  76.    PRE(remove(t,p^<j>)) = p^<j> in dom(t)
  77.  
  78. t.<> = t
  79. t.(p^<j>) = (t.p).<j>
  80. dom(singleton(v)) = <>
  81. dom(add(t,p,v)) = dom(t) union {p}
  82. dom(remove(t,p^<j>)) = dom(t) - {p^<j>}
  83. val(singleton(v)) = v
  84. val(add(t,p,t1)) = val(t)
  85. add(t,p^<j>,t1).p1 = if p1=p^<j> -> t1 else t.p1 fi
  86. remove(t,p^<j>).p1 = t.p1        -- if it's legal!
  87.  
  88.  
  89. Give the auxTree type, we can specify a more concrete uTree type as a
  90. pair consisting of an auxTree and a path pointing to the current node in
  91. the auxTree.
  92.  
  93. The starred functions below are auxiliary functions, and need not be
  94. implemented.
  95.  
  96. for  v, j  as above and   u, u1: uTree
  97.  
  98. *tree: uTree -> Tree
  99.     PRE(tree(u)) = true
  100. *current: uTree -> Path
  101.     PRE(current(u)) = true
  102.  usingleton: Value -> uTree
  103.     PRE(usingleton(v)) = true
  104.  curval: uTree -> Value
  105.     PRE(curval(u)) = true
  106.  go: uTree x Index -> uTree
  107.     PRE(go(u,j)) = current(u)^<j> in dom(tree(u))
  108.  goroot: uTree -> uTree
  109.     PRE(goroot(u)) = true
  110.  addcur: uTree x Index x uTree -> uTree
  111.     PRE(addcur(u,j,u1)) = 
  112.        current(u) in dom(tree(u)) & not(current(u)^<j> in dom(tree(u))
  113.  trim: uTree -> uTree
  114.     PRE(trim(u)) = current(u) != <>
  115.  
  116. tree(usingleton(v)) = singleton(v)
  117. current(usingleton(v)) = <>
  118.  
  119. curval(u) = val(tree(u).current(u))
  120.  
  121. tree(go(u,j)) = tree(u)
  122. current(go(u,j)) = current(u)^<j>
  123.  
  124. tree(goroot(u)) = tree(u)
  125. current(goroot(u)) = <>
  126.  
  127. tree(addcur(u,j,u1)) = add(tree(u),current(u)^<j>,tree(u1))
  128. current(addcur(u,j,u1)) = current(u)^<j>
  129.  
  130. tree(trim(u)) = remove(tree(u),current(u))
  131. current(trim(u)) = current(u)`1             -- current(u) with its
  132.                                             -- last element removed
  133.  
  134.  
  135. > If you are interested and can offer more help, we can talk via email
  136. > about the specifics of the data structure I am working with.
  137. > -- 
  138. > Jeff Offutt
  139. > Department of ISSE, George Mason University, Fairfax VA
  140. > email: ofut@gmuvax2.gmu.edu
  141. > phone: (703) 993-1654 (messages: 993-1640)
  142.  
  143. Antediluvian newsbreak:           |  J. E. Fritz    (fritz@ruby.vcu.edu)
  144.   Scientists discover 4th prime.  |  VCU and I don't talk _to_ each other,
  145.   Proof at eleven.                |  let alone for each other.
  146.