4

A processor 'a' takes care the header 'a' of a message 'a_b_c_d' and passes the payload 'b_c_d' to the another processor in the next level as following:

msg(a, b_c_d).
pro(a;b;c;d).

msg(b, c_d) :- pro(X), msg(X, b_c_d).
msg(c, d)   :- pro(X), msg(X, c_d).
msg(d)      :- pro(X), msg(X, d).

#hide. #show msg/2. #show msg/1.

How should I represent list 'a_b_c_d' in ASP, and change the above to general cases?

false
  • 10,264
  • 13
  • 101
  • 209
tak-po li
  • 85
  • 4
  • I have no idea what this has to do with ASP, or whether you mean ASP.NET or not. Please clarify. – John Saunders May 11 '15 at 01:24
  • @JohnSaunders: Any way to help better disambiguate ASP (MS vs. answer set programming)? – false May 11 '15 at 07:55
  • I have no idea what "answer set programming" is. "ASP" is a term that has been around for well over a decade, and it means "Active Server Pages". ASP is Microsoft's original server-side web programming environment. ASP.NET is Microsoft's current server-side web programming environment. I recommend you spell out "Answer Set Programming" if that's what you mean. – John Saunders May 11 '15 at 10:53
  • 7
    @JohnSaunders : in fairness, [Answer Set Programming has also been around for quite some time](https://en.wikipedia.org/wiki/Answer_set_programming#History), and is probably (anecdotally) a more-recognized unwrapping of ASP in the academia. – mikołak May 11 '15 at 11:02
  • May well be, but I've been out of "academia" for over 35 years, and have never heard of it. I bet that most users of this site have also not heard of it. – John Saunders May 11 '15 at 11:05

4 Answers4

2

No, official way, but I think most people don't realize you can construct cons-cells in ASP. For instance, here's how you can get items for all lists of length 5 from elements 1..6

element(1..6).
listLen(empty, 0).
listLen(cons(E, L), K + 1) :- element(E); listLen(L, K); K < 5.
is5List(L) :- listLen(L, 5).

#show is5List/1.

resulting in

is5List(cons(1,cons(1,cons(1,cons(1,cons(1,empty))))))
is5List(cons(1,cons(1,cons(1,cons(1,cons(2,empty))))))
is5List(cons(1,cons(1,cons(1,cons(1,cons(3,empty))))))

...

dspyz
  • 5,280
  • 2
  • 25
  • 63
0

By using index, I do have a way to walk a list, however, I do not know this is the official way to handle a list in ASP. Could someone has more experience in ASP give us a hand? Thanks.

index(3,a). index(2,b). index(1,c). index(0,d). 
pro(a;b;c;d). msg(3,a).

msg(I-1,N) :- pro(P), msg(I,P), index(I,P), I>0, index(I-1,N).

#hide. #show msg/2.
tak-po li
  • 85
  • 4
0

There is no 'official' way to handle lists in ASP as far as I know. But, DLV has built-in list handling similar to Prolog's.

The way you implement a list, the list itself cannot be used as a term and thus what if you want to bind between variables in the list and other elements of a rule? Perhaps you would like something such as p(t, [q(X), q(Y)]) :- X != Y.

You can try implementing a list as (a, b, c) and an append predicate but the problem is ASP requires grounding before computing answer-sets. Consequently a list defined in this way whilst more like lists in Prolog would mean the ground-program contains all ground-instances of all possible lists (explosion) regardless of whether they are used or not.

I therefore come back to my first point, try using DLV instead of Clingo if possible (for this task, at least).

Dr. Thomas C. King
  • 993
  • 2
  • 15
  • 28
0

You can use s(ASP) or s(CASP) ASP systems. Both of them support list operations like prolog. You might need to define the list built-in in ASP .

user3756005
  • 43
  • 1
  • 6