![Page 1: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/1.jpg)
Logic programming
![Page 2: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/2.jpg)
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
![Page 3: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/3.jpg)
Brief history
1970s AI group To specifying predicate calculus Prolog
![Page 4: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/4.jpg)
Predicate calculus
Proposition: a logical statement that is true or not true
Formal logic describes proposition that allows them to be checked or validity
![Page 5: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/5.jpg)
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?
![Page 6: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/6.jpg)
/* 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).
![Page 7: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/7.jpg)
Logic Programming – Prolog Query
Queries: ancestor(fred, sally).
Yes ancestor(fred, diane).
Yes ancestor(fred, bill).
No
![Page 8: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated](https://reader035.vdocuments.mx/reader035/viewer/2022072006/56649d0b5503460f949def34/html5/thumbnails/8.jpg)
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/