0

I am writing a simple program safety checker in Prolog and I need a data structure to hold variable valuation. Since I want to detect when I am visiting same state again, this structure must support some reasonable comparison semantics, so I can store visited states in set.

library(avl) has convenient getter/setter interface. The problem is, AVL holding the same mapping can take multiple forms. Thus two identical states would be considered distinct if their AVL representation differs.

A structure holding mapping in ordered lists would be free of this problem. However, I can't find anything like that in Sicstus docs. Is there any standard structure that does what I need, or do I have to implement it myself?

rburny
  • 1,559
  • 1
  • 9
  • 28

1 Answers1

1

You have ordered sets but in AVL you can always convert AVLs to ordered lists of key-valued pairs and then compare them.

Alexander Serebrenik
  • 3,567
  • 2
  • 16
  • 32
  • I have seen ordered sets, but they don't allow operations such us finding a value for a given key (say you store Key-Val pairs; then ord_member(0-Val, Set) will not find value associated with Key=0). I'll go with the second solution, though it beats the purpose of using tree... – rburny May 27 '12 at 15:15
  • The behaviour of `ord_member` seems then a bit strange. Unfortunately I do not have SICStus installed but SWI behaves as expected: `?- ord_member(0-Val, [0-[1,2,3],1-[2,3,5],6-[5,3,5,4,21]]).` returns `Val = [1, 2, 3].` – Alexander Serebrenik May 27 '12 at 15:24
  • Sicstus answers `no` to your example. It's `ord_member(+Key, +Set)` in docs, so I guess behavior is implementation dependent when Key is not fully instantiated. – rburny May 27 '12 at 16:53
  • Thank you for testing it with SICStus... One can, of course, implement `ord_member/2` himself... – Alexander Serebrenik May 27 '12 at 18:46