ASP / Clingo Flashcards

1
Q

What does ASP stand for?

A

Answer Set Programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define an atom in the context of ASP.

A

An atom is a basic unit of meaning in ASP, usually representing a proposition.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a literal?

A

A literal is an atom or its negation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Identify the atoms in the following ASP statement: a :- b, not c.

A

The atoms are a, b, and c.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Clingo?

A

Clingo is a software package that includes an ASP grounder (gringo) and solver (clasp). It’s used to find stable models of logic programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name a primary function of Clingo’s grounder (gringo).

A

It converts a high-level logic program into a ground (variable-free) format.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Name a primary function of Clingo’s solver (clasp).

A

It finds the stable models of a ground logic program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define a rule in ASP.

A

A rule in ASP is a statement of the form head <- body, where head is an atom and body is a conjunction of literals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the head of a rule represent?

A

The head represents what is derived when the body of the rule is satisfied.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the body of a rule represent?

A

The body represents the conditions that must be satisfied for the head to be derived.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Identify the head and body in the following ASP rule: a :- b, not c.

A

The head is a and the body is b, not c.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a stable model?

A

A stable model is a set of atoms that represents a possible world where all the rules of the program are satisfied.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does a stable model relate to ground instances?

A

A stable model is a set of ground instances of atoms that make the program self-consistent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Are stable models unique?

A

No, an ASP program can have multiple stable models, or none at all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are ground instances in ASP?

A

Ground instances are specific atoms that result from substituting all variables in a rule with concrete terms. For example, for the rule p(X) :- q(X, Y), r(Y). and terms X = 1, Y = 2, the ground instance is p(1) :- q(1, 2), r(2).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does negation as failure mean in the context of stable models?

A

Negation as failure, denoted as not a, means that a is not part of the stable model. In other words, not a is true in a stable model if a cannot be derived from the program rules given the stable model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How would you write a rule to express that if a is true then b must be true?

A

b :- a.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How would you write a rule to express that c is true only if a and b are false?

A

c :- not a, not b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How would you write a rule to express that d is true if either a or b is true, but not both?

A

d :- a, not b. d :- b, not a.

20
Q

How would you write a rule to express that if a and b are true, then c or d must be true, but not both?

A

{ c; d } :- a, b. :- c, d, a, b.

21
Q

What is a choice rule in ASP?

A

A choice rule allows for optional inclusion of atoms in the stable model. It has the form { head } :- body.

22
Q

How would you write a choice rule to express that a can be true if b is true?

A

{ a } :- b.

23
Q

What does the following choice rule express: { a; b } :- c.

A

If c is true, either a, b, or both a and b can be true.

24
Q

What is a proposition in ASP?

A

A proposition is an atom without variables, essentially a statement that is either true or false.

25
Q

What is a predicate in ASP?

A

A predicate is a template for generating atoms. It consists of a name and a list of variables or terms.

26
Q

How would you write a predicate to represent a relation between x and y?

A

relation(x, y).

27
Q

Can a predicate have a single variable? Provide an example.

A

Yes, for example, student(X).

28
Q

How would you write a predicate to express the parent-child relationship?

A

parent(x, y). where x is the parent and y is the child.

29
Q

What would the atom sibling(a, b) represent if sibling is a predicate?

A

It would represent that a and b are siblings.

30
Q

How would you write a predicate to express the ancestor relationship recursively?

A

ancestor(X, Y) :- parent(X, Y). ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

31
Q

What is a common use of predicates involving arithmetic operations?

A

Predicates often use arithmetic to express relationships like greater than or less than. For example, greater(X, Y) :- X = Y + 1.

32
Q

What are cardinality restrictions in ASP?

A

Cardinality restrictions specify the minimum and/or maximum number of literals that must be true in a stable model.

33
Q

How would you write a rule that allows for at least 2 and at most 3 instances of a to be true?

A

2 { a(X) } 3.

34
Q

How would you enforce that exactly one of a, b, or c is true?

A

1 { a; b; c } 1.

35
Q

What does the cardinality restriction 2 { a(X); b(X) } 3 mean when combined with a(1). a(2). b(1). b(2). b(3).

A

It means that in a stable model, at least 2 and at most 3 of the atoms generated from a(X) and b(X) must be true. Possible combinations could be { a(1), a(2) }, { b(1), b(2), b(3) }, etc.

36
Q

How would you use cardinality to express that at least one student must be in a class?

A

1 { in_class(X) : student(X) }.

37
Q

How would you use cardinality to express that a committee must have between 3 and 5 members?

A

3 { committee_member(X) : person(X) } 5.

38
Q

What are the stable models for the program a :- not a.?

A

The stable model is {} (empty). This might seem counterintuitive because one could think that a should be true if a is not true. However, in stable model semantics, the empty set is the only closed set under this program.

39
Q

What are the stable models for the program a :- b. b :- a.?

A

There are no stable models. This can be counterintuitive due to the cyclic dependency between a and b.

40
Q

What are the stable models for the choice rule { a } :- b. combined with b.?

A

The stable models are {b} and {a, b}. This may seem counterintuitive if you’re expecting a deterministic outcome.

41
Q

Given the program a :- b, not c. b. c :- not a. what are the stable models?

A

There are no stable models. This might be counterintuitive as one could expect b to lead to a, but a being absent also leads to c, creating a contradiction.

42
Q

Given the program 1 { a; b } 1. a :- b. b :- a. what are the stable models?

A

The stable models are {a} and {b}. This might be counterintuitive because despite the cyclic dependency, the cardinality restriction enforces that only one of a or b can be true.

43
Q

What is an aggregate in Clingo?

A

An aggregate in Clingo is a construct like #sum, #count, or #min that performs an operation over a set. For example, #count { X:fruit(X) } = N counts the number of fruits and stores the count in N.

44
Q

How do you use external atoms in Clingo?

A

External atoms in Clingo are prefixed with & and can be used to interface with external computations. For example, &is_prime(X) could check if X is a prime number.

45
Q

What is optimization in Clingo, and how is it done?

A

Optimization in Clingo is done using #minimize or #maximize. For example, #minimize { X:fruit(X) } would find the answer set that minimizes the number of fruits.

46
Q

How do you specify constraints in Clingo?

A

Constraints in Clingo are rules with an empty head. For example, :- not fruit(X), eat(X). specifies that you cannot eat X if X is not a fruit.