Attachment 'dlv-complex-guide-20090407.html'

Download

DLV-Complex: a Quick Reference Guide


Introduction

DLV-Complex is an Answer Set Programming system based on DLV. It fully supports Disjunctive Logic Programming with function symbols under Answer Set Semantics, and provides also support for complex terms such as lists and sets, as well as a rich library for their manipulation.

 

The system is shipped as a command-line binary, and it works exactly as DLV. For more details about the use of such systems, we refer to the DLV official website and the material (manuals, tutorials, examples) which can be easily found there. This quick reference guide provides the necessary information about what DLV-Complex offers in addition to standard DLV features. The interested reader may found also useful information about the external predicates framework exploited in order to embed functions into DLV on DLV-EX website.

Installation Guide

Just download the DLV-Complex executable and, if you need it, the list and set library, that suit your operating system. You can execute DLV-Complex as any other command-line tool. The only detail you must take care of is the position of the list and set library, if the logic program you want to compute imports it.  By default, libraries are supposed to be found in ./LIB folder, where “.” is the folder where the executable binary of DLV-Complex stays. You can refer to the instructions below in order to modify this.  

 

Table of Contents

 

1. Synopsis and System Options

 

2. List built-in functions 

2.1. #list(Elem_1,..., Elem_n, List)

2.2. #last(List, Elem)

2.3. #length(List, Int)

2.4. #head(List, Elem)

2.5. #tail(List1, List2)

2.6. #append(List1, List2, List3)

2.7. #select(Elem, List, Rest)

2.8. #delete(List1, Elem, List2)

2.9. #delNth(List1, Pos, List2)

2.10. #member(Elem, List)

2.11. #reverse(List1, List2)

2.12. #memberNth(List, Pos, Elem)

2.13. #insNth(List1, Elem, Pos, List2)

2.14. #insLast(List1, Elem, List2)

2.15. #subList(Sublist, List)

 

3. Set built-in functions 

3.1. #set(Elem_1,..., Elem_n, Set)

3.2. #card(Set, Int)

3.3. #union(Set1, Set2, Set3)

3.4. #intersection(Set1, Set2, Set3)

3.5. #difference(Set1, Set2, Set3)

3.6. #delete(Set1, Elem, Set2)

3.7. #member(Elem, Set)

3.8. #insert(Set1, Elem, Set2)

3.9. #subSet(Subset, Set)

 

4. List of arithmetic and comparison built-ins

 

A. List of Examples

2-1. #list

2-2. #last

2-3. #length

2-4. #head

2-5. #tail

2-6. #append

2-7. #select

2-8. #delete

2-9. #delNth

2-10. #member

2-11. #reverse

2-12. #memberNth

2-13. #insNth

2-14. #insLast

2-15. #subList

3-1. #set

3-2. #card

3-3. #union

3-4. #intersection

3-5. #difference

3-6. #delete

3-7. #member

3-8. #insert

3-9. #subSet

 

 


Chapter 1. Synopsis and System Options

You can invoke DLV-Complex directly on the command-line (for a brief list of command-line options, specify “-help”).

In addition to the DLV standard ones (please refer to the official DLV documentation, see the website here), the following options allows for modifying the behavior of the system in presence of complex terms.

-nofdcheck   

Skip finite domain check.

-MAXNL=<N>

Maximum nesting level allowed for function terms. Default is '0' (no limits).

 

 

If you don’t want to specify the “-nofdcheck” option on the command line, you can do it within a DLV-Complex program. It is enough to add as preamble the following string:

 

         #nofdcheck.         % disable finite-domain check

 

In order to exploit the built-in functions for list and set manipulation collected in the provided (“ListAndSet”) library, you must tell the system, while writing down a DLV-Complex program, to include the library itself. It is enough to add the line

 

         #include<ListAndSet>

 

at the very beginning of the program (as a preamble). By default, libraries are supposed to be found in ./LIB folder, where “.” is the folder where the executable binary of DLV-Complex stays. Furthermore, with the following command-line option you can tell the system where to find libraries, if somewhere else.

 

-libpath=path1[:path2[:...]]

Set the paths including external built-in libraries.

 

 

You are strongly suggested to have a look at the DLV-Complex tutorial for more details.

 

 


Chapter 2. List built-in functions

A list is a collection of elements, in case empty, where the order of elements is meaningful; so, two lists having the same elements but with a different order are considered to be different.

There are two ways to represent a list:

·         listing its elements, comma separated, in brackets: [t1, t2, . . . , tn] where each element is a term (in case a list);

·         with an “à la Prolog” notation: [head | tail] where head is a term (in case a list) while tail needs to be a list (in case empty);


2.1. #list(Elem_1,..., Elem_n, List)

Return List whose elements are ordinately Elem_1,..., Elem_n

Pattern

iro (i.e. zero or more input arguments and then an output argument)

Elem_1,..., Elem_n terms must be bound to a constant value.

Example 2-1. #list

          Elem_1 = a
          Elem_2 = b    --->    List = [a,b,c]
          Elem_3 = c
        

2.2. #last(List, Elem)

Return in Elem the last element of List.

Pattern

io (i.e. one input argument and one output argument)

The List term must be bound to a constant value.

Example 2-2. #last

          List = [a,b,c]    --->    Elem = c          
        

2.3. #length(List, Int)

Return in Int the number of elements of List.

Pattern

io (i.e. one input argument and one output argument)

The List term must be bound to a constant value.

Example 2-3. #length

          List = [a,b,c]    --->    Int = 3          
        

2.4. #head(List, Elem)

Return in Elem the first element of List.

Pattern

io (i.e. one input argument and one output argument)

The List term must be bound to a constant value.

Example 2-4. #head

          List = [a,b,c]    --->    Elem = a         
        

2.5. #tail(List1, List2)

Return in List2 the list obtained deleting the first element from List1.

Pattern

io (i.e. one input argument and one output argument)

The List1 term must be bound to a constant value.

Example 2-5. #tail

          List1 = [a,b,c]    --->    List2 = [b,c]          
        

2.6. #append(List1, List2, List3)

Append List2 to List1 and return the result in List3.

Pattern

iio (i.e. two input arguments and one output argument)

List1 and List2 terms must be bound to a constant value.

Example 2-6. #append

          List1 = [a,b,c]
          List2 = [f,m]    --->    List = [a,b,c,f,m]
        

2.7. #select(Elem, List, Rest)

Select the first occurrence of Elem from List leaving Rest.

Pattern

iio (i.e. two input arguments and one output argument)

Elem and List terms must be bound to a constant value.

Example 2-7. #select

          Elem = b
          List = [a,b,c,b,e]    --->    Rest = [a,c,b,e]
        

2.8. #delete(List1, Elem, List2)

Delete all occurrences of Elem in List1 and return the result in List2.

Pattern

iio (i.e. two input arguments and one output argument)

List1 and Elem terms must be bound to a constant value.

Example 2-8. #delete

          List1 = [a,b,c,b,e]
          Elem = b    --->    List2 = [a,c,e]
        

2.9. #delNth(List1, Pos, List2)

Delete the element of List1 in position Pos and return the result in List2.

Pattern

iio (i.e. two input arguments and one output argument)

List1 and Pos terms must be bound to a constant value.

Example 2-9. #delNth

          List1 = [a,b,c,b,e]
          Pos = 3    --->    List2 = [a,b,b,e]
        

2.10. #member(Elem, List)

Check whether Elem occurs in List.

Pattern

ii (i.e. two input arguments)

Both Elem and List terms must be bound to a constant value.

Example 2-10. #member

          Elem = c
          List = [a,b,c,b,e]    --->    true
        

2.11. #reverse(List1, List2)

Reverse the order of the elements in List1 and return the result in List2.

Pattern

io (i.e. one input argument and one output argument)

The List1 term must be bound to a constant value.

Example 2-11. #reverse

          List1 = [a,b,c,h,e]    --->    List2 = [e,h,c,b,a]
        

2.12. #memberNth(List, Pos, Elem)

Return the element Elem in position Pos in List.

Pattern

iio (i.e. two input arguments and one output argument)

List and Pos terms must be bound to a constant value.

Example 2-12. #memberNth

          List = [a,b,c,h,e]
          Pos = 3               --->    Elem = c
        

2.13. #insNth(List1, Elem, Pos, List2)

Insert the element Elem in the position Pos of List1 and return the result in List2.

Pattern

iiio (i.e. three input arguments and one output argument)

List1, Elem and Pos terms must be bound to a constant value.

Example 2-13. #insNth

          List1 = [a,b,c,h,e]
          Elem = s               --->    List2 = [a,s,b,c,h,e]
          Pos = 2
        

2.14. #insLast(List1, Elem, List2)

Insert the element Elem in the last position of List1 and return the result in List2.

Pattern

iio (i.e. two input arguments and one output argument)

List1 and Elem terms must be bound to a constant value.

Example 2-14. #insLast

          List1 = [a,b,c,h,e]
          Elem = s               --->    List2 = [a,b,c,h,e,s]
        

2.15. #subList(Sublist, List)

Check whether Sublist is a sublist of List.

Pattern

ii (i.e. two input arguments)

Sublist and List terms must be bound to a constant value.

Example 2-15. #subList

          Sublist = [c,b]
          List = [a,b,c,b,e]    --->    true
        

Chapter 3. Set built-in functions

A set is a collection of elements, in case empty, where the order of elements is meaningless; so, two lists with the same elements but with a different order represent the same set. Furthermore duplicate elements are not allowed.

A set is represented listing its elements, comma separated, in braces: {t1, t2, . . . , tn} where each element is a term (in case a set);


3.1. #set(Elem_1,..., Elem_n, Set)

Return Set whose elements are Elem_1,..., Elem_n

Pattern

iro (i.e. zero or more input arguments and then an output argument)

Elem_1,..., Elem_n terms must be bound to a constant value.

Example 3-1. #set

          Elem_1 = a
          Elem_2 = b    --->    Set = {a,b,c}
          Elem_3 = c
        

3.2. #card(Set, Int)

Return in Int the number of elements of Set.

Pattern

io (i.e. one input argument and one output argument)

The Set term must be bound to a constant value.

Example 3-2. #card

          Set = {a,b,c}    --->    Int = 3          
        

3.3. #union(Set1, Set2, Set3)

Set3 is the set resulting from the union of Set1 with Set2.

Pattern

iio (i.e. two input arguments and one output argument)

Set1 and Set2 terms must be bound to a constant value.

Example 3-3. #union

          Set1 = {a,r,t}
          Set2 = {f,r,s}    --->    Set3 = {a,f,r,s,t}
        

3.4. #intersection(Set1, Set2, Set3)

Set3 is the set resulting from the intersection of Set1 with Set2.

Pattern

iio (i.e. two input arguments and one output argument)

Set1 and Set2 terms must be bound to a constant value.

Example 3-4. #intersection

          Set1 = {a,r,t}
          Set2 = {f,r,s}    --->    Set3 = {r}
        

3.5. #difference(Set1, Set2, Set3)

Set3 is the set resulting from the difference between Set1 and Set2.

Pattern

iio (i.e. two input arguments and one output argument)

Set1 and Set2 terms must be bound to a constant value.

Example 3-5. #difference

          Set1 = {a,r,t}
          Set2 = {f,r,s}    --->    Set3 = {a,t}
        

3.6. #delete(Set1, Elem, Set2)

Delete the element Elem in Set1 and return the result in Set2.

Pattern

iio (i.e. two input arguments and one output argument)

Set1 and Elem terms must be bound to a constant value.

Example 3-6. #delete

          Set1 = {a,r,t}
          Elem = r    --->    Set2 = {a,t}
        

3.7. #member(Elem, Set)

Check whether Elem occurs in Set.

Pattern

ii (i.e. two input arguments)

Both Elem and Set terms must be bound to a constant value.

Example 3-7. #member

          Elem = c
          List = {a,b,c,e}    --->    true
        

3.8. #insert(Set1, Elem, Set2)

Insert Elem in Set1 and return the result in Set2.

Pattern

iio (i.e. two input arguments and one output argument)

Set1 and Elem terms must be bound to a constant value.

Example 3-8. #insert

          Set1 = {a,b,c,e,h}
          Elem = d    --->    Set2 = {a,b,c,d,e,h}
        

3.9. #subSet(Subset, Set)

Check whether Subset is a subset of Set.

Pattern

ii (i.e. two input arguments)

Both Subset and Set terms must be bound to a constant value.

Example 3-9. #subSet

          Subset = {c,f}
          Set = {a,b,c,e,f,g}    --->    true
        
 
 
 

Chapter 4. List of Arithmetic and Comparison built-ins

The following built-ins are available in order to ease the task of writing DLV-Complex programs. Most of them are already available in DLV, and their meaning is straightforward. It is worth remembering that, in general, these built-ins requires “#maxint” (the upper integer limit) to be set, by means of either the option “-N=x” on the command line, or the “#maxint=x.” preamble.

We refer to the DLV manual for further information.

#int

#int(X) is true, iff X is a known integer (i.e. 0 <= X <= #maxint).

#succ

#succ(X, Y) is true, iff X+1=Y holds.

#prec

#prec(X, Y) is true, iff X-1=Y holds.

#mod

#mod(X,Y,Z) is true, iff X/Y has remainder Z.

+

+(X,Y,Z), or alternatively: Z=X+Y is true, iff Z=X+Y holds.

-

-(X,Y,Z), or alternatively: Z=X-Y is true, iff Z=X-Y holds.

*

*(X,Y,Z), or alternatively: Z=X*Y is true, iff Z=X*Y holds.

/

/(X,Y,Z), or alternatively: Z=X/Y is true, iff Z=X/Y holds.

< 

Comparisons built-ins among terms.

<=

> 

>=

!= [or <>]

= [or ==, deprecated]

 
 

Attached Files

You are not allowed to attach a file to this page.