Prolog programming Introduction to Prolog (part3)

Slides:



Advertisements
Similar presentations
1. An Overview of Prolog.
Advertisements

Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
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).
1 COMP313A Programming Languages Logic Programming (3)
Prolog Programming for Artificial Intelligence Three edition 2001
Introduction to Prolog Language Presented by San Myint.
Prolog programming Introduction to Prolog (part4) CS 370 – CS461.
Prolog programming Introduction to Prolog
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
Introduction to Prolog Proof Procedures. Exercise parent(mark, alex). parent(di, alex). brother(brian, mark). sister(cathy, di). wife(susan, brian). husband(brad,
CS 330 Programming Languages 12 / 12 / 2006 Instructor: Michael Eckmann.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Prolog Notes for Ch.1 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Copyright © 2003 Bolton Institute Logical Analysis and Problem Solving, (LAPS) Programming in Prolog.
1 Artificial Intelligence CSC 361 Prof. Mohamed Batouche Department of Computer Science CCIS – King Saud University Riyadh, Saudi Arabia
Step 1: Simplify Both Sides, if possible Distribute Combine like terms Step 2: Move the variable to one side Add or Subtract Like Term Step 3: Solve for.
Prolog programming Introduction to Prolog CS370d - CS 461.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
COSC 2P93 Logic Programming Instructor: Brian Ross Instructor: Brian Ross Texts: Texts: Prolog Programming for Artificial Intelligence,4e, Ivan Bratko,
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Solving Absolute Value Equations & Inequalities Solving Absolute Value Equations & Inequalities Zafar-iqbal.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CHA2555 Week2 Practical: Lee McCluskey First term:
Lesson 1.4 Equations and Inequalities Goal: To learn how to solve equations and check solutions of equations and inequalities.
Logic Programming Tarik Booker. What will we cover?  Introduction  Definitions  Predicate Calculus  Prolog  Applications.
Artificial Intelligence CS370D
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
For Friday No reading Prolog Handout 2. Homework.
2-4 Solving Equations with Variables on Both Sides.
1 Authorization Sec PAL: A Decentralized Authorization Language.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
The portion of a Prolog interpreter that executes queries (goals) is known as the inference engine. An inference engine is a kind of theorem prover, using.
1 Artificial Intelligence CS370D Prolog programming Introduction to Prolog.
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Prolog programming Introduction to Prolog
Algebra Bell-work 9/13/17 Turn in your HW! 1.) 7x – 6 = 2x + 9
Equations and Inequalities
1.7 Introduction to Solving Inequalities
Prolog programming Introduction to Prolog (part2)
Prolog Primarily for Symbolic (nonnumeric) Computation
Artificial Intelligence CS370D
1-5 Solving Inequalities
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Introduction to Logic Programming and Prolog
Solving Equations with Variables on Both Sides Day 2
Prolog programming Introduction to Prolog
Chapter 12 :: Logic Languages
Chapter Two: Syntax and Meaning of Prolog Programs
- Finish Unit 1 test - Solving Equations variables on both sides
Prolog programming Introduction to Prolog (part4)
Relational Operators.
How To Think Like a Prolog ?
CS2136: Paradigms of Computation
Introduction to Logic Programming and Prolog
Solving Equations with Variables on Both Sides Day 2
Chapter 2: Prolog (Introduction and Basic Concepts)
Representations & Reasoning Systems (RRS) (2.2)
CS589 Principles of DB Systems Fall 2008 Lecture 4a: Introduction to Datalog Lois Delcambre
CS589 Principles of DB Systems Fall 2008 Lecture 4a: Introduction to Datalog Lois Delcambre
Prolog Based on: Chapter 12 of PLP “Seven languages in seven weeks”
Presentation transcript:

Prolog programming Introduction to Prolog (part3) CS 370

How to solve this problem? Consider the following facts: parent(pam,bob). parent(tom,bob). parent(tom,liz). parent(bob,ann). parent(bob,pat). parent(pat,jim). Is Liz a child of Tom? ?- child(liz, tom). The answer will be “error “ WHY ? Because there are no facts in the program about a child.

Defining relations by rules. To solve the previous child(liz, tom) relation problem we have to either to : Use the parent facts ( which were defined previously ) ,considering the parent fact as the inverse of child relation. Ex : ?- parent (tom ,liz) . OR Use the alternative way based of the following logical statements: For all X and Y, Y is a child of X if X is a parent of Y.

Defining relations by rules. In prolog , we can define the offspring relation using the alternative logical statement in the following way: child(Y,X) :- parent(X, Y) This clause is called a rule Each rule has two parts: Condition. (The right hand side) Conclusion. (The left hand side) So, the child rule consist of : child(Y,X) -> as a conclusion part. parent(X,Y) -> as a condition part.

Defining relations by rules. The differences between rule and fact: Fact: is a something that always, unconditionally true. Rule: specify things that are true if some condition is satisfied. It has two parts : condition and conclusion separated by “ :- “.

Defining relations by rules. How rules are actually used by prolog program? ?- child(liz, tom). X= tom, Y= liz. The compiler will search for the initial goal which is : chlid(liz,tom). If the rule was defined , the condition part will be executed: parent(tom,liz). The condition can be found using the facts about parent relation. After finding that the condition part is true, the conclusion part will be also true.

Anonymous Variables Do somebody have a child? Who is a parent ? Example : Does Bob have a child ? -> hasachild( X ) :- parent( X, _). Do somebody have a child? somebody_has_child :- parent( _, _). somebody_has_child :- parent( X, X). Who is a parent ? ?- parent( X, _). In this query we are interested in people who have children, but not in the names of the children.

Lexical Scope The lexical scope of A variable is one clause. If X occurs in two clauses, then it signifies two different variables. hasachild(X) :- parent( X, Y). isapoint(X) :- point( X, Y, Z). But each occurrence of X with in the same clause means the same variables. hasachild( X) :- parent( X, Y). An atom is always the same object in any clause throughout the whole program.

Class exercise(2) Write a rule to describe the grandparent relation?

Home exercise(1) Write a rule to describe the sister relation?