Docsity

CSE 571 Scribe Notes: Declarative Programming and Horn Logic, Study notes of Computer Science

Toggle sidebar
bg1
CSE 571 Scribe Notes for 8/27/03
Karen Chancellor and Luis Tari
Examples of procedural languages are Pascal, C and Fortran. In these, one must
specify the steps to take to solve a problem. A different approach is to just define
what the problem is and let the computer figure out how to solve it. This
technique is called declarative programming.
In the case of sorting an array of numbers a in ascending order, we need to
specify how sorting is done by putting loops and moving the elements of the array
in procedural languages. For declarative languages, we only need to define rules
such that a[i] <= a[i+1].
Initially, classical logic is thought to be the right declarative language. It is
realized that classical logic is monotonic and prohibits from representing
knowledge such as normally.
For instance, classical logic allows us to represent “all birds have wings” as
follows:
X (bird(X) has_wing(X))
But how to represent the following information?
Normally birds fly.
Tweety is a bird.
All penguins are birds.
All penguins do not fly?
To resolve the problem of monotonicity in classical logic, a subset of classical
logic called Horn logic is used. Horn clauses are defined as only having at most
one positive literal among a disjunction of literals, i.e.
b1 b2 … bn a
By using the property that b a is equivalent to a b, Horn logic is a collection
of rules of the form:
a b1, b2, …, bn.
Commas are used in the place of .
Prolog is a language that is based on this subset of classical logic. Prolog (5th
generation computing) uses horn logic. Because it was not powerful enough,
extensions were added to the language. AnsProlog gets rid of the non-declarative
features of Prolog.
With the notion of negation as failure, we can capture the idea of normally as
follows:
Normally birds fly. Tweety is a bird. All penguins are birds, but they do not fly.
fly(X) bird(X), not ab(X).
bird(tweety) .
bird(X) penguin(X).
ab(X) penguin(X).
pf3

Partial preview of the text

Download CSE 571 Scribe Notes: Declarative Programming and Horn Logic and more Study notes Computer Science in PDF only on Docsity!

Karen Chancellor and Luis Tari  Examples of procedural languages are Pascal, C and Fortran. In these, one must specify the steps to take to solve a problem. A different approach is to just define what the problem is and let the computer figure out how to solve it. This technique is called declarative programming. In the case of sorting an array of numbers a in ascending order, we need to specify how sorting is done by putting loops and moving the elements of the array in procedural languages. For declarative languages, we only need to define rules such that a [ i ] <= a [ i +1].  Initially, classical logic is thought to be the right declarative language. It is realized that classical logic is monotonic and prohibits from representing knowledge such as normally.  For instance, classical logic allows us to represent “all birds have wings” as follows: X (bird(X)  has_wing(X))  But how to represent the following information? Normally birds fly. Tweety is a bird. All penguins are birds. All penguins do not fly?  To resolve the problem of monotonicity in classical logic, a subset of classical logic called Horn logic is used. Horn clauses are defined as only having at most one positive literal among a disjunction of literals, i.e.  b 1   b 2  …   bna By using the property that b  a is equivalent to a  b, Horn logic is a collection of rules of the form: ab 1 , b 2 , …, bn. Commas are used in the place of .  Prolog is a language that is based on this subset of classical logic. Prolog (5th generation computing) uses horn logic. Because it was not powerful enough, extensions were added to the language. AnsProlog gets rid of the non-declarative features of Prolog.  With the notion of negation as failure, we can capture the idea of normally as follows: Normally birds fly. Tweety is a bird. All penguins are birds, but they do not fly. fly(X)  bird(X), not ab(X). bird(tweety) . bird(X)  penguin(X). ab(X)  penguin(X).

Karen Chancellor and Luis Tari Now to answer the query ?fly(tweety), we have a problem because ‘not’ is not used in classical logic. We cannot show that tweety is abnormal. The only way to conclude ‘fly(tweety)’ is to show ‘not ab(tweety)’. Databases use the CWA (closed world assumption): if we can’t prove something, we can assume it to be false. But what if we just don’t know? Now add “tweety is a penguin” to the above program. Then from ‘penguin(tweety)’, we can conclude ‘fly(tweety)’ is false. This demonstrates non- monoticity: when new information is added, what can be logically concluded changes. This is important in real world situations.  What happens when an eraser is picked up? We might represent this as X(occurs(pickup(X), t) -> holds(in_hand(X), t+1). But has the chalkboard been cleaned after the eraser is picked up? Normally, all that happens after the eraser has been picked up is what is depicted in the above statement. There are an infinite number of things which haven’t happened after the eraser has been picked up. This is an example of the ‘frame problem’ (1959).  The ancestor problem is a perfect example to illustrate that classical logic and even relational databases are not adequate to represent knowledge. ancestor(X,Y)  parent(X,Y). ancestor(X,Y)  parent(X,Z), ancestor(Z,Y). Ordering of literals matter in Prolog. Prolog can get stuck into loops if the above rule is ancestor(X,Y)  ancestor(Z,Y), parent(X,Z). The way that Prolog deals with negation as failure can also result Prolog to be stuck in infinite loops. The following is an example to illustrate this: a  not b. b  not a.  In order to overcome some of these disadvantages, the language AnsProlog* that is based on the answer set semantics was developed. AnsProlog* is a popular language for knowledge representation due to the fact that there are efficient implementations of it and found to be as expressive as some of the other nonmonotonic languages, while syntactically less intimidating. A large body of support structure has already been established to develop the language.  AnsProlog* syntax: AnsProlog* program is a collection of rules of the following form: L 0 or … or LkLk+ 1 , …, Lm, not Lm+1, …, not Ln. where each of the Li s is a literal. The above rule means that if Lk+ 1 , …, Lm are true and if Lm+1, …, Ln can assumed to be false, then at least one of L 0 , …, Lk must be true. Predicates: fly, bird, penguin, ancestor, parent Function symbols: s(0)=1, s((0))=2, examples of the ‘successor’ function Constants: tweety Variables: X, Y Connectives: and, or, <-, not, 