Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Using Matrices in Real Life
Chapter 5: Control Structures II (Repetition)
Artificial Intelligence: Natural Language and Prolog
Advanced Piloting Cruise Plot.
© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Chapter 1 The Study of Body Function Image PowerPoint
Structured Query Language (SQL)
Algebraic Expressions
Math Vocabulary Review Part 1.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
Multiplying binomials You will have 20 seconds to answer each of the following multiplication problems. If you get hung up, go to the next problem when.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 5 second questions
Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity.
Lilian Blot TO PROGRAMMING & PYTHON Introduction Autumn 2012 TPOP 1.
0 PROGRAMMING IN HASKELL Chapter 5 - List Comprehensions.
ABC Technology Project
Lilian Blot CORE ELEMENTS PART I Python Language Autumn 2013 TPOP 1.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
VOORBLAD.
Classroom Auxiliary: is, am, & are. You have ‘3 Seconds’ to answer each question.
Squares and Square Root WALK. Solve each problem REVIEW:
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Logic Programming in Prolog
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Addition 1’s to 20.
25 seconds left…...
Januar MDMDFSSMDMDFSSS
Chapter Three Arithmetic Expressions and Assignment Statements
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Prolog: List © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
1 Logic Programming. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 4: Lists Theory –Introduce lists, an important recursive data structure often used in Prolog.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 2 Theory –Unification –Unification in Prolog –Proof search Exercises –Correction exercises.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
JavaScript, Third Edition
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
LING 388: Language and Computers Sandiway Fong Lecture 4.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
Introduction to Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !
Prolog programming Introduction to Prolog (part2)
Chapter Two: Syntax and Meaning of Prolog Programs
Presentation transcript:

Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog

2 acknowledgement Patrick Blackburn, Johan Bos & Kristina Striegnitz (lecture notes on logic programming in prolog)

3 Lecture 3

4 Quiz Define the predicate parent_of Sibling (person have the same parent) Grandparent_of Greatgrandparent_of

5 exercise Convert the following paragraph into fact or rule: 1. a person may be a smart buyer for something if the person is a smart and he likes the thing and the thing is valuable and the thing has a discount. 2. Bob likes all kind of game. Football is a game. Anything anyone plays and not killed by is a game.

6 a person may be a smart buyer for something if the person is a smart and he likes the thing and the thing is valuable and the thing has a discount. smart(ahmed). smart(nada). smart(noha). smart(islam). valuable(gold). valuable(books). valuable(leather-jackets). discount(books). discount(perfumes). Smart-buyer(X,Y):- smart(X),likes(X,Y),valuable(Y), discount(Y). likes(ahmed, leather-jackets). likes(ahmed, sun-glasses). likes(soha,sun-glasses). likes(islam,books). likes(nada, perfume).

7 Bob likes all kind of game. Football is a game. Anything anyone plays and not killed by is a game. plays(player1,football). plays(player2,tennis). plays(player3,handball). plays(player4,car-racing). likes(‘Bob’, X):-game(X). game(Anything):- plays(_,Anything),not-killed(Anything) not-killed(football). not-killed(tennis). not-killed(handball).

8 Prolog Syntax What exactly are facts, rules and queries built out of? Terms Simple TermsComplex Terms ConstantsVariables AtomsNumbers Terms Simple TermsComplex Terms ConstantsVariables AtomsNumbers

9 Atoms A sequence of characters of upper-case letters, lower-case letters, digits, or underscore, starting with a lowercase letter Examples: butch, big_kahuna_burger, playGuitar An arbitrary sequence of characters enclosed in single quotes Examples: 'Vincent', 'Five dollar shake', A sequence of special characters Examples: :, ;. :-

10 Numbers Integers: 12, -34, Floats:

11 Variables If we want to get more interest information about fact or rule, we can use variable to get more than Yes/No answer. A sequence of characters of upper-case letters, lower-case letters, digits, or underscore, starting with either an uppercase letter or an underscore Examples: X, Y, Variable, Vincent, _tag

12 variable name must begin with capital letter. *using variable we can get all possible answer about a particular fact or rule. Variables

13 Variables Always begin with a capital letter –?- likes (john,X). –?- likes (john, Something). But not –?- likes (john,something)

14 Example of usage of variable Facts: likes(john,flowers). likes(john,mary). likes(paul,mary). Question: ?- likes(john,X) Answer: X=flowers and wait ; mary ; no

15 Complex Terms Atoms, numbers and variables are building blocks for complex terms Complex terms are built out of a functor directly followed by a sequence of arguments Arguments are put in round brackets, separated by commas

16 Complex terms are of the form: functor (argument,..., argument). Functors have to be atoms. Arguments can be any kind of Prolog term, e.g., complex terms. date April date(“Aprile”,13,1988)

17 Examples of complex terms Examples we have seen before: –playsAirGuitar(jody) –loves(vincent, mia) –jealous(marsellus, W)

18 Arity The number of arguments a complex term has is called its arity Examples: woman(mia) is a term with arity 1 loves(vincent,mia) has arity 2 father(father(butch)) arity 1

19 Arity is important In Prolog you can define two predicates with the same functor but with different arity Prolog would treat this as two different predicates In Prolog documentation arity of a predicate is usually indicated with the suffix "/" followed by a number to indicate the arity

20 Example of Arity This knowledge base defines –happy/1 –listens2music/1 –playsAirGuitar/1 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda).

21 summary data type Prolog supports the following data type to define program entries. 1.Integer: to define numerical value like 1, 20, 0,-3,-50, ect. 2.Real: to define the decimal value like 2.4, 3.0, 5,-2.67, ect. 3.Char: to define single character, the character can be of type small letter or capital letter or even of type integer under one condition it must be surrounded by single quota. For example, ‘a’,’C’,’123’. 4.string : to define a sequence of character like “good” i.e define word or statement entries the string must be surrounded by double quota for example “computer”, “134”, “a”. The string can be of any length and type. 5.Symbol: anther type of data type to define single character or sequence of character but it must begin with small letter and don’t surround with single quota or double quota.

22 summary program structure Prolog program structure consists of five segments, not all of them must appear in each program. The following segment must be included in each program predicates, clauses, and goal. 1.Domains: define global parameter used in the program. I= integer C= char S = string R = real 2.Data base: define internal data base generated by the program Database Greater (integer) 3.Predicates: define rule and fact used in the program. Mark(symbol,integer).

23 summary program structure Prolog program structure consists of five segments, not all of them must appear in each program. The following segment must be included in each program predicates, clauses, and goal. 4. Clauses: define the body of the program.. For the above predicates the clauses portion may contain Mark (a, 20). 5.Goal: can be internal or external, internal goal written after clauses portion, external goal supported by the prolog compiler if the program syntax is correct

24 summary mathematical and logical operation

25 summary Other mathematical function

26 summary Read and write function Read functionWrite function readint(Var) : read integer variable. Write(Var) : write variable of any type. Readchar(Var) : read character variable. Readreal(Var) : read read (decimal) variable. Readln(Var) : read string.

27 Thank You