Prolog Programming Language CSE 337 Concepts of Programming Languages Qassim University College of Computer –IT department Ms.Sadaf Ambreen Abbasi. Reham AL blihed Muna AL rajhi 1
Outline • About Prolog programming language • Simple idea of prolog program • Prolog Syntax • General purpose arithmetic 2
About prolog programming language •Prolog • Prolog is one of the most widely used programming languages in artificial intelligence research. • It is a declarative programming language unlike most common programming languages. 3
Simple Idea about Prolog Program • Prolog programs specify relationships among objects and properties of objects. 4 PrologEnglish father(ibrahim,reham).Ibrahim is the father of Reham. eats(ibrahim,pizza).Ibrahim eats pizza. happy(muna).Muna is happy.
Prolog Syntax • Terms • Terms are of four kinds: atoms, numbers, variables, and compound terms. • Example atom: • Example variables: • Example compound term: 5 elephant, b, abcXYZ, x_123 X, Elephant, _ is_bigger(horse, X), f(g(X, _), 7),
Prolog Syntax • Clauses and Queries Clauses Facts & Rules A fact is a predicate followed by a full stop. Example: A rule consists of a head and a body .Head and body are separated by the sign :- Example: Queries it is a sequence of predicates separated by commas and terminated by a full stop. Example: 6 bigger(whale, _). Head :- Body. is_smaller(X, Y) :- is_bigger(Y, X). aunt(Aunt, Child) :- sister(Aunt, Parent), parent(Parent, Child). ?- weather(City,summer), temp(City,40).
General Purpose Arithmetic 7 • Numeric comparison operator:
General purpose arithmetic • The is-Operator for Arithmetic Evaluation • The expression in the right of the is-Operator is evaluated and bound to the left hand argument. • = does not cause evaluation of its arguments: • Example: 8
Lists in Prolog Programming language • List contain of head and tail and separated by bar sign | (bar). • Example: • Example: 9
Some Built-in Predicates for List Manipulation: • Length • Sum 10
General Example of prolog • personal Information • Knowledge Based • Queries 11
General Example of prolog Example on testing mark • Knowledge Based • Queries 12
General Example of prolog Example of prolog program about the Weather • Knowledge Based • Queries 13
General Example of prolog • Maximum of two numbers • Knowledge Based • Queries 14
General Example of prolog • Example: Knowledge Based Queries • Example: 15

Prolog Programming Language

  • 1.
    Prolog Programming Language CSE337 Concepts of Programming Languages Qassim University College of Computer –IT department Ms.Sadaf Ambreen Abbasi. Reham AL blihed Muna AL rajhi 1
  • 2.
    Outline • About Prologprogramming language • Simple idea of prolog program • Prolog Syntax • General purpose arithmetic 2
  • 3.
    About prolog programminglanguage •Prolog • Prolog is one of the most widely used programming languages in artificial intelligence research. • It is a declarative programming language unlike most common programming languages. 3
  • 4.
    Simple Idea aboutProlog Program • Prolog programs specify relationships among objects and properties of objects. 4 PrologEnglish father(ibrahim,reham).Ibrahim is the father of Reham. eats(ibrahim,pizza).Ibrahim eats pizza. happy(muna).Muna is happy.
  • 5.
    Prolog Syntax • Terms •Terms are of four kinds: atoms, numbers, variables, and compound terms. • Example atom: • Example variables: • Example compound term: 5 elephant, b, abcXYZ, x_123 X, Elephant, _ is_bigger(horse, X), f(g(X, _), 7),
  • 6.
    Prolog Syntax • Clausesand Queries Clauses Facts & Rules A fact is a predicate followed by a full stop. Example: A rule consists of a head and a body .Head and body are separated by the sign :- Example: Queries it is a sequence of predicates separated by commas and terminated by a full stop. Example: 6 bigger(whale, _). Head :- Body. is_smaller(X, Y) :- is_bigger(Y, X). aunt(Aunt, Child) :- sister(Aunt, Parent), parent(Parent, Child). ?- weather(City,summer), temp(City,40).
  • 7.
    General Purpose Arithmetic 7 •Numeric comparison operator:
  • 8.
    General purpose arithmetic •The is-Operator for Arithmetic Evaluation • The expression in the right of the is-Operator is evaluated and bound to the left hand argument. • = does not cause evaluation of its arguments: • Example: 8
  • 9.
    Lists in PrologProgramming language • List contain of head and tail and separated by bar sign | (bar). • Example: • Example: 9
  • 10.
    Some Built-in Predicatesfor List Manipulation: • Length • Sum 10
  • 11.
    General Example ofprolog • personal Information • Knowledge Based • Queries 11
  • 12.
    General Example ofprolog Example on testing mark • Knowledge Based • Queries 12
  • 13.
    General Example ofprolog Example of prolog program about the Weather • Knowledge Based • Queries 13
  • 14.
    General Example ofprolog • Maximum of two numbers • Knowledge Based • Queries 14
  • 15.
    General Example ofprolog • Example: Knowledge Based Queries • Example: 15