Logic Programming OLO G Dr Yasser Nada Fall
- Slides: 27
Logic Programming OLO G Dr. Yasser Nada Fall 2010/2011 Lecture 1 Logic Programming 1
Text Book • Prolog Programming, A First Course, by Paula Brna, 2001 • References: OLO G – Leon Starling and Ehud Shapiro, The art of Prolog. 1989. – Ivan Brotko, Prolog Programming for Artificial Intelligence. 1986. Logic Programming 2
Course Description • This course will introduce theory and concepts of logic programming. Prolog will be studied as a logic programming approach for declarative logic programming. OLO G Logic Programming 3
Course Objectives • Upon completion of the course, student should: OLO G – Knowledge of concepts and theories of logic programming. – Become familiar with Prolog language syntax. – Be able to solve problems in Prolog. – Be able to use knowledge in a suitable form to be used in Prolog language. . Logic Programming 4
Course Policy • Students are expected to participate and attend the class in time. Students are responsible to submit assignments in time. Exams will be a combination of lectures in class and homework assignments. Late homework submission will be subject to penalties. If an assignment is submitted late, a penalty of 10 percent of that assignment's grade will be assessed for each day it is late. A homework paper will not be accepted after graded papers have been returned, after a solution has been distributed, or after the final examination. OLO G Logic Programming 5
Absence Policy • Students absent that exceeds (25% lectures) are being considered dropped from the course. After 3 lectures absent a warning is issued for the student. After another 3 lectures absent student will be dropped from the class. OLO G Logic Programming 6
Examination • There will be no makeup exams except under emergencies. If a student cannot attend the exam, then student must make arrangement with the instructor prior to the planned absence. The emergency makeup exam will be either written or oral. OLO G Logic Programming 7
Grading Assignment 10% Attendance 10% Midterm 30% Final 50% OLO G Logic Programming 8
OLO G Logic Programming 9
What is Logic Programming • Two types of programming languages: – Imperative languages (C, C++, VB, C#, Java, …). – Declarative languages (prolog, lisp, …). OLO G • Logic programming is a type of programming called declarative programming. Logic Programming 10
Imperative Languages • They are also called procedural languages. • Programmer gives all steps to solve a problem. He must know an algorithm to solve a problem. • Example: find average of list of numbers: • Input total • Input number • Average = total/number • Print Average OLO G Logic Programming 11
Declarative Languages • Programmer describe the problem without the control flow, then the system will solve the problem. • Programmer must know the relations between objects to solve the problem. • Programmer does not need to know an algorithm to solve the problem. OLO G • Declarative languages consists of: – Program or theory. – Computation which is deduction. Logic Programming 12
First Order Predicate • Represent relation between objects: • • own(ahmed, car). friend(ali, ahmed). father(sami, ali). brother(kareem, ali). OLO G Logic Programming 13
Prolog • It is a declarative language (not completely declarative) based on first order logic. • Prolog means Programming in Logic. • It consists of: – Facts. – Rules. – Goal • Used in AI: NLP, expert systems, games, automated answering system, …. OLO G Logic Programming 14
Prolog • Prolog Program consist of: – Facts: asserts a property to an object, or relation between two or more objects: • parent(ali, salem). • own(ali, car). – Rules: allow to infer a relationship or a property based on a precondition: • parent(X, Y) : - father(F, X), father(P, Y). – Goal: Query or questions asked by user. • parent(ali, Y). OLO G Logic Programming 15
Atoms • Atom is – a sequence of alphanumeric characters – usually starting with lower case letter – or, a string enclosed in single quotes OLO G – They represent constants. • Examples: – ali, salem, a, b, c, a 1, a 2, b 3, c 5, … – ‘Mr. Ali’, ’Dr. Sultan’ Logic Programming 16
Variables • A variable is • a sequence of alphanumeric characters • usually starting with an uppercase letter OLO G • Examples: • X, Y, Z, Parent, Child, Foo, X 1, Y 1, X 2, X 5, X 6, …. Logic Programming 17
Predicates • A predicate has the form – p(t 1, . . . , tn) – where p is an atom and t 1. . . tn are variables or atoms. – n is the number of arguments of predicate p (written as p/n which represents the signature of predicate). – Predicates can be of 0 -arg, 1 -arg, 2 -arg, … OLO G • Examples: – father(ali, ahmed). Logic Programming 18
Prolog Program Example Predicate name like(ali, car). like(ahmed, car). Predicate arguments father(salem, ali). Predicate End father(salem, ahmed). brother(X, Y) : - father(P, X), father(P, Y). friend(X, Y) : - like(X, C), like(Y, C). OLO G and if Logic Programming 19
Goals • A goal is a conjunction of predicates – p(X, Y), q(Y, Z), t(Z, W). OLO G – A goal is the question or query asked by the user. Prolog will try to find an answer for the goal. Logic Programming 20
Answers • Given a goal, Prolog searches for answer(s): – “yes” (possibly with answer substitution) – “no” (if no answer or no more answer found). – Substitutions are bindings of variables that make goal true. OLO G Logic Programming 21
Examples • ? - father(X, ali). – X = salem ? ; – no • ? - father(X, Y), brother(Y, Z). – X = salem, Y = ali, Z = ahmed – yes – ? ; – X = salem, Y=ahmed, Z=ali – Yes – ? ; – no OLO G Logic Programming male(ali). male(ahmed). male(salem). father(salem, ali). father(salem, ahmed). brother(X, Y) : - father(P, X), father(P, Y), male(X), make(Y). 22
Rules • A rule is an assertion of the form – p(ts) : - q(ts’), . . . , r(ts’’). – where ts, ts’’ are atoms or variables OLO G • “p(ts) holds if q(ts’) holds and. . . And r(ts’’) holds” • Example: – brother(X, Y) : - father(Z, X), father(Z, Y). Logic Programming 23
Prolog • You can try prolog by downloading prolog compiler: – Ciao: OLO G http: //clip. dia. fi. upm. es/Software/Ciao/Latest/download. html – Choose Windows version, • For Windows Vista: current version 1. 13. 0. • For Windows XP: select version Ciao 1. 10 p 5 Win 32. zip Logic Programming 24
Ciao installation under Windows XP • • After downloading ciao-1. 10 p. Win 32. zip, extract it in C: Then goto C: Ciao-1. 10 p 5 Win 32 Double click on the file: install. bat Then type ciaosh at the DOS prompt, the prolog prompt appears: ? - OLO G Logic Programming 25
Ciao installation under Windows Vista • After downloading Ciao. DE-1. 13. 0 -XXXX. exe, double click on it to run. • At the desktop you will find a file: ciaosh shortcut. Double click on it and the Prolog prompt appears: • ? - OLO G Logic Programming 26
Miscellaneous • Comments – % single line comment – /* multiple line OLO G comment */ • To quit Ciao, type – ? - exit. – (or just control-D) Logic Programming 27
- Pasangan tangga nada enharmonis cis adalah....
- Francis yasser
- 2322008
- Nada enharmonis
- Define olo
- Programme olo inscription
- Bernabe nwoye
- Nada des enharmonis dengan nada.
- Nada te turbe nada te espante salmo 37
- Estamos aqui de passagem nada trouxemos e nada levaremos
- Oracion que nada me turbe que nada me espante
- Quien es nada
- Oración nada te turbe nada te espante
- Nada te turbe
- Nada te turbe, nada te espante salmo 37
- Fascista significado
- Combinational logic sequential logic 차이
- First order logic vs propositional logic
- Cryptarithmetic problem logic+logic=prolog
- If x = 0 and y = 1, which output line is enabled?
- First order logic vs propositional logic
- Software development plan
- Third order logic
- Is it x y or y x
- Combinational logic vs sequential logic
- Where does the logic of this advertisement fall short
- Visual logic programming
- Induction reasoning