Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program.

Similar presentations


Presentation on theme: "Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program."— Presentation transcript:

1 Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program specifies properties, rather than control structures. An LP program consists of a set of facts, axioms and goals. An inference engine attempts (often interactively) to logically derive a solution(s) for each goal. Example (rules for computing greatest common divisors - all integers) Axiom 1: If (N  1), then gcd(N,1) = 1 Axiom 2: If (N  1) and (N < D), then gcd(N,D) = gcd(D,N) Axiom 3: If (N  1) and (D  1) and (N mod D = 0), then gcd(N,D) = D Axiom 4: If (D > 1) and (N > D) and (N mod D  0), then gcd(N,D) = gcd(D, N mod D) Goal: gcd(12, 21) = ?

2 Prolog is the most widely-known logic programming language. Prolog was designed in the early 1970’s by Alain Colmeraurer and Phillippe Roussel at the U Of Marseille and by Robert Kowalski at the U of Edinburgh. The language isn’t completely standardized, but the best known syntax comes from Edinburgh And referred to as Clocksin and Mellish Prolog. Prolog Notation  An ________ is a numeric constant or identifier. (Such an identifier must begin with lowercase letter.)  An ____________ is denoted as an identifier. (Such an identifier must begin with an uppercase letter.)  An ___________ (predicate) is a function with one or more atomic or variable arguments (The relation name must begin with an lowercase letter.) best_major(comp_sci). hairColor(riley, gray). equal(X, X).

3 Horn clauses are a form of logical implication used in Prolog. conclusion :- p 1, p 2, …, p n syntax semantics examples above(A,B) :- below(B,A). between(X,Y,Z) :- X<Y, Y<Z.

4 A fact is a statement involving only atoms. Facts Rules Goals is_white(snow). ?-has_completed(sam,cs340). is_white(bunny). mother(georgeW, barbara). has_completed(sam, cs340). age(sue, 21). A rule is a statement involving variables (Horn clause). child(C,P) :- parent(P,C). parent(P,C) :- mother(P,C). parent(P,C) :- father(P,C). has_prereqs(X,cs421) :- has_completed(X,cs340). age(moe,Aless2) :- age(joe,A), Aless2 is A - 2. Note the following doesn’t work: age(moe,A-2) :- age(joe,A) A rule is a rule or fact preceded by ?- ?-age(sue,21). ?-is_white(turkey).

5 The is operator is necessary to force the evaluation of expressions and assign a value. is X is Y+2. The = operator doesn’t perform expression evaluation, but =:= does. =:= ?- 2 + 3 = 5. ?- 1+4 = 3 + 2. ?- 2 + 3 =:= 5. ?- 1+4 =:= 3 + 2.


Download ppt "Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program."

Similar presentations


Ads by Google