Presentation is loading. Please wait.

Presentation is loading. Please wait.

Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Prolog COMP 112 #31 2014.

Similar presentations


Presentation on theme: "Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Prolog COMP 112 #31 2014."— Presentation transcript:

1 Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Prolog COMP 112 #31 2014

2 © Peter Andreae COMP 112 28:2 Outline Prolog – a very different programming language Admin: No lecture next Monday (Queen’s Birthday) Final lecture: summary, exam, Tues 3 rd June No lecture 5 th June Lab on Friday, but not next week.

3 © Peter Andreae COMP 112 28:3 Programming Paradigms Imperative programming Program tells the computer what to do. Object Oriented programming imperative plus organise data and code around classes of objects Functional programming Specify computation of values No side effects, Lazy evaluation Logic programming specify relationships that are true ask queries. interpreter works outs how to use the specified relationships to answer the queries.

4 © Peter Andreae COMP 112 28:4 Prolog program Variables start with uppercase: X, List, Explanation, (or an underscore: _rest) literals start with lowercase: a, b name, bsc lists are in [ … ] contains( [X], X). contains([X | _rest], X). contains([_any | Rest], X) :- contains(Rest, X). which is input and which is output?

5 © Peter Andreae COMP 112 28:5 Why use prolog If the core of the problem is expressing complex relationships between data, prolog is much easier to use than Java. eg rule-based “expert-systems”, (now called “business-intelligence”) codifying business rules (eg credit limit applications) eg landcare’s possum control decision support system. Parsing natural language prolog is excellent for expressing structure in language. It allows you to redefine the syntax to match the problem.

6 © Peter Andreae COMP 112 28:6 Checking degree rules. Student completed bsc with M major because E1 and E2 and E3 and E4 and E5 and EM:- Student has 360 points from any numbered 100 -- 399 because E1, Student has 180 points from any numbered 200 -- 399 because E2, Student has 72 points from bsc numbered 300 -- 399 because E3, Student has 270 points from bsc numbered 100 -- 399 because E4, Student has 120 points from bsc numbered 200 -- 399 because E5, Student completed M major because EM. Student completed comp major because E1 and E2 and E3:- Student has 60 points in comp numbered 300 -- 399 because E1, Student has comp201 and comp202 and (comp203 or comp204) because E2, Student has math114 and (stat193 or stat131 or quan102) and (math214 or math207 or opre251 or stat231) because E3.

7 © Peter Andreae COMP 112 28:7 Degree rules…. Student has Required points from Schedule numbered Range because (TotPts >= Required points from Schedule numbered Range) :- allCourses(Student, Courses), validPoints(Courses, Schedule, any, Range, TotPts), TotPoints >= Required. Student has Course1 and Course2 because Expl1 and Expl2 :- Student has Course1 because Expl1, Student has Course2 because Expl2. Student has Course because Course:- passed(Student, Course).

8 © Peter Andreae COMP 112 28:8 Degree rules…. code to enable the “natural language” syntax: :- op(815, xfx, has).:- op(807, fx, in). :- op(815, xfx, completed).:- op(805, xfy, --). :- op(813, xfx, because).:- op(803, xfy, or). :- op(811, xfx, points).:- op(801, xfy, and). :- op(811, xfx, of).:- op(801, xfy, with). :- op(809, xfx, numbered).:- op(800, xf, major). :- op(807, fx, from).:- op(800, xf, submajor).

9 © Peter Andreae COMP 112 28:9 Language rules in Prolog: Prolog program using DCG rules: sentence(sent(NP,VP)) --> noun_phrase(NP), verb_phrase(VP). noun_phrase(np(D,N)) --> det(D), noun(N). verb_phrase(vp(V,NP)) --> verb(V), noun_phrase(NP). det(the) --> [the]. det(a) --> [a]. noun(cat) --> [cat]. noun(bat) --> [bat]. noun(flies) --> [flies]. verb(eats) --> [eats]. verb(flies) --> [flies]. verb(gives) --> [gives]. parse(Tree, L) :- sentence(Tree, L, []).


Download ppt "Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Prolog COMP 112 #31 2014."

Similar presentations


Ads by Google