logic programming. introduction to express program in symbolic logic also called declarative...

8
Logic programming

Upload: charity-curtis

Post on 18-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Logic programming. Introduction To express program in symbolic logic Also called declarative language Only the specification of desired results are stated

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

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

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

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

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

/* 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

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

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/