10.02.2013 Views

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

A User's Guide to gringo, clasp, clingo, and iclingo

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6 :- flies(tux), -flies(tux).<br />

7 :- flies(tweety), -flies(tweety).<br />

The program has two answer sets. One contains flies(tweety) <strong>and</strong> the other<br />

contains -flies(tweety). Let us now add a new fact <strong>to</strong> the program:<br />

8 flies(tux).<br />

There no longer is any answer set for our new program using classical negation. In fact,<br />

answer set c<strong>and</strong>idates that contain both flies(tux) <strong>and</strong> -flies(tux) violate the<br />

integrity constraint in Line 6. �<br />

3.1.3 Disjunction<br />

Disjunctive logic programs permit connective “|” between a<strong>to</strong>ms in rule heads. A<br />

disjunction is true if at least one of its a<strong>to</strong>ms is true. Additionally, logic programs<br />

have <strong>to</strong> satisfy a minimality criterion, which we do not detail in this guide. The simple<br />

program a | b. has the two answer sets {a} <strong>and</strong> {b} but does not admit the answer<br />

set a, b because it is no minimal model.<br />

In general, the use of disjunction however increases computational complexity [12].<br />

This is why <strong>clingo</strong> 2 <strong>and</strong> solvers like assat [37], <strong>clasp</strong> [20], nomore++ [1],<br />

smodels [51], <strong>and</strong> smodelscc [56] do not work on disjunctive programs. Rather,<br />

<strong>clasp</strong>D [8], cmodels [28, 35], or gnt [33] need <strong>to</strong> be used for solving a disjunctive<br />

program. 3 We thus suggest <strong>to</strong> use “choice constructs” (cf. Section 3.1.10) instead of<br />

disjunction, unless the latter is required for complexity reasons (see [13] for an implementation<br />

methodology in disjunctive ASP).<br />

3.1.4 Built-In Arithmetic Functions<br />

<strong>gringo</strong> <strong>and</strong> <strong>clingo</strong> support a number of arithmetic functions that are evaluated<br />

during grounding. The following symbols are used for these functions: + (addition), -<br />

(subtraction, unary minus), * (multiplication), / or #div (integer division), \ or #mod<br />

(modulo function), ** or #pow (exponentation), |·| or #abs (absolute value), &<br />

(bitwise AND), ? (bitwise OR), ˆ (bitwise exclusive OR), <strong>and</strong> ˜ (bitwise complement).<br />

Example 3.2. The usage of arithmetic functions is illustrated by the logic program: The unique answer set of the<br />

1 left (7).<br />

2 right (2).<br />

3 plus (L + R ) :- left(L), right(R).<br />

4 minus (L - R ) :- left(L), right(R).<br />

5 uminus ( - R ) :- right(R).<br />

6 times (L * R ) :- left(L), right(R).<br />

7 divide1 (L / R ) :- left(L), right(R).<br />

8 divide2 (R #div L ) :- left(L), right(R).<br />

9 divide2 (#div(R,L)) :- left(L), right(R).<br />

10 modulo1 (L \ R ) :- left(L), right(R).<br />

11 modulo2 (L #mod R ) :- left(L), right(R).<br />

12 modulo3 (#mod(L,R)) :- left(L), right(R).<br />

13 absolute1 ( |- R|) :- right(R).<br />

2 Run as a monolithic system performing both grounding <strong>and</strong> solving.<br />

3 System dlv [34] also deals with disjunctive programs, but it uses a different syntax than presented here.<br />

12<br />

program, obtained after evaluating<br />

all arithmetic functions,<br />

can be inspected by invoking:<br />

<strong>gringo</strong> -t

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!