Logic programming. Introduction To express program in symbolic logic Also called declarative...
-
Upload
charity-curtis -
Category
Documents
-
view
213 -
download
1
Transcript of Logic programming. Introduction To express program in symbolic logic Also called declarative...
Logic programming
Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are
stated State the form of the result rather than how a
result is to be computed Logic programming is a declarative approach of
writing computer programs based on Logic
Brief history
1970s AI group To specifying predicate calculus Prolog
Predicate calculus
Proposition: a logical statement that is true or not true
Formal logic describes proposition that allows them to be checked or validity
Logic Programming – Example
Suppose we have the following sentences
1. CS student of NTHU must take the core course cs2403
2. A CS student can not obtain a degree without passing the required course
I am a CS student of NTHU and want to obtain a degree, should I pass cs2403?
/* Filename: ancestor.pro This program creates a small set of facts and rules on
who is the ancestor of whom. The user types the desired goal interactively when the program is run.*/
/* ancestor(A, B) means A is an ancestor of B */ancestor(bob, susan).ancestor(A, X) :- parent(A, X).ancestor(A, X) :- parent(A, C), ancestor(C, X).
/* parent(P, C) means P is a parent of C */parent(fred, sally).parent(tina, sally).parent(sally, diane).parent(sam, bill).
Logic Programming – Prolog Query
Queries: ancestor(fred, sally).
Yes ancestor(fred, diane).
Yes ancestor(fred, bill).
No
Logic Programming – Reference
Book: Ralph P. Grimaldi, DISCRETE AND COMBINATORIAL
MATHEMATICS, 5TH ED, Pearson Education, 2004 Ulf Nilsson and Jan Ma luszy_nski, LOGIC, PROGRAMMING AND
PROLOG, 2ND ED, Ulf Nilsson and Jan Ma luszy_nski, 2000
Web: http://cis.stvincent.edu/carlsond/prolog.html http://ktiml.mff.cuni.cz/~bartak/prolog/index.html http://www.cs.auckland.ac.nz/~j-hamer/07.363/prolog-for-se.html http://www.swi-prolog.org/