Getting Started with Visual Prolog

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Prolog.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Introduction to C Programming
Knowledge Representation I Suppose I tell you the following... The Duck-Bill Platypus and the Echidna are the only two mammals that lay eggs. Only birds.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
How to Create a Java program CS115 Fall George Koutsogiannakis.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Introduction to a Programming Environment
Sentence Structure Exercise.
LSU 06/04/2007BASIC Stamp Editor1 The BASIC Stamp Editor Programming Unit, Lecture 3.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Computer Science 101 Introduction to Programming.
Copyright ©: SAMSUNG & Samsung Hope for Youth. All rights reserved Tutorials Software: Building apps Suitable for: Advanced.
Formal Models of Computation Part II The Logic Model
SqlReports Dean Dahlvang PSUG-MO March About Dean Dean Dahlvang Director of Administrative Technology for the Proctor.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 Visual Prolog Programs LabLecture # 3 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Nael Alian Introduction to PHP
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 Knowledge Based Systems (CM0377) Lecture 4 (Last modified 5th February 2001)
CPS120: Introduction to Computer Science Compiling Your Programs Using Visual C++
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Introduction to Unix – CS 21 Lecture 8. Lecture Overview More detail on emacs and vi Regular expression matching in emacs and vi.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Introduction to programming in the Java programming language.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
Prolog Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Basic Program Construction
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?
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
1 CS161 Introduction to Computer Science Topic #9.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Logical and Functional Programming
Lab Lecture#4 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
 Columns  Rows  Cells  Ranges  Cell addresses  Column headers  Row headers  Formulas  Spreadsheet.
Logic Programming Dr. Yasser Nada Fall 2010/2011 Lecture 1 1 Logic Programming.
Introduction to Text Based Coding. We’re learning to explore how text based programming works You will display and enter text into a window You will use.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
HTML HTML stands for Hyper Text Markup Language. HTML is used in making the base of a Website You can just use an online website maker like weebly.com.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Section 16.5, 16.6 plus other references
Computer Information Technology Section 6-17
A Playful Introduction to Programming by Jason R. Briggs
Introduction to Prolog
PROLOG.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
T. Jumana Abu Shmais – AOU - Riyadh
TA : Mubarakah Otbi, Duaa al Ofi , Huda al Hakami
Chapter 2: Introduction to C++.
Chapter 2: Prolog (Introduction and Basic Concepts)
PROLOG.
Presentation transcript:

Getting Started with Visual Prolog LabLecture # 2 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi , Huda al Hakami

Lecture Contents Getting Started with Visual Prolog 5.2. PROgramming in LOGic Sentences: Facts and Rules Queries Variables: General Sentences From Natural Language to Prolog Programs Clauses (Facts and Rules) Predicates (Relations) Variables (General Clauses) Goals (Queries) Comments Matching

Getting Started with Prolog We will use Visual Prolog 5.2 Personal Edition . You can install the executable file of the VP from teachers websites or from Labs. In the following we will show you how to test goals and build a small Windows application in Visual Prolog 5.2 .

Visual Prolog 5.2 Main Window

Opening an Editor Window To create a new edit window, you can use the menu command File | New. This will bring up a new editor window with the title "NONAME". To check, that your system is set up properly, you should try to type in the following text in the window: GOAL write("Hello world"),nl. This is what is called a GOAL in the Prolog terminology. To execute the GOAL, you should activate the menu item Project | Test Goal. If your system is installed properly, your screen will look like the following:

Running and Testing a Program

Error Handling If you, like all programmers do, happen to make some errors in your program, the Visual Prolog system will display an error window, which contains a list of errors. You can double click on one of these errors to come to the position of the error in the source text.

Prolog is PROgramming in LOGic. What is Prolog ? Prolog is PROgramming in LOGic. A computer language designed in Europe to support natural language processing. It was created by Alain Colmerauer and Robert Kowalski around 1972 as an alternative to the American-dominated Lisp programming languages.

What is Prolog (Con.) Prolog is based on predicate logic. Prolog includes an inference engine, which is a process for reasoning logically about information. The inference engine includes a pattern matcher, which retrieves stored (known) information by matching answers to questions. One important feature of Prolog is dealing with alternatives and find all possible solutions rather than only one. Instead of just proceeding from the beginning of the program to the end, Prolog can actually back up and look for more than one way of solving each part of the problem.

Sentences: Facts and Rules A Prolog programmer defines objects and relations, then defines rules about when these relations are true. For example, the sentence Bill likes dogs. shows a relation between the objects Bill and dogs; the relation is likes. Here is a rule that defines when the sentence Bill likes dogs is true: Bill likes dogs if the dogs are nice.

Facts in natural language Facts: What Is Known In Prolog, a relation between objects is called a predicate. A fact consists of the relation name followed by the object or objects (enclosed in parentheses), The fact ends with a period (.). Facts in Prolog Facts in natural language likes(bill, cindy). Bill likes Cindy. likes(cindy, bill). Cindy likes Bill. likes(bill, dogs). Bill likes dogs.

Facts in natural language Facts: What Is Known Facts can also express properties of objects as well as relations. Facts in Prolog Facts in natural language green(kermit). Kermit is green girl(caitlin). Caitlin is a girl

Rules: What You Can Infer from Given Facts Rules enable you to infer facts from other facts. Another way to say this is that a rule, as conclusions is a conclusion that is known to be true if one or more other conclusions or facts are found to be true. Here are some rules concerning a "likes" relation: Cindy likes everything that Bill likes. Caitlin likes everything that is green. Given these rules, you can infer from the previous facts some of the things that Cindy and Caitlin like: Cindy likes Cindy. Caitlin likes Kermit.

Rules: What You Can Infer from Given Facts (Con.) To encode these same rules into Prolog, you only need to change the syntax a little, like this: likes(cindy, Something):- likes(bill, Something). likes(caitlin, Something):- green(Something). The :- symbol is simply pronounced "if", and serves to separate the two parts of a rule: the head and the body. It is meaning "To prove that Cindy likes something, prove that Bill likes that same thing" and "To prove that Caitlin likes something, prove that it is green."

Queries Once we give Prolog a set of facts, we can proceed to ask questions concerning these facts; this is known as querying the Prolog system. It is important to notice that the second object-- What--begins with a capital letter, while the first object--bill—does not. This is because bill is a fixed constant object—a constants known value-- but What is a variable. Variables always begin with an upper-case letter or an underscore. Answer Prolog Syntax Natural language yes likes(bill, cindy). Does Bill like Cindy? What=cindy What=dogs 2 Solutions likes(bill, What). What does Bill like?

Putting Facts, Rules, and Queries Together Suppose you have the following facts and rules: A fast car is fun. A big car is nice. A little car is practical. Bill likes a car if the car is fun. Diane is a vegetarian and eats only what her doctor tells her to eat. Write the Prolog Syntax for previous example?

From Natural Language to Prolog Programs In the first section of this lecture we talked about facts and rules, relations, general sentences, and queries. Those words are all part of a discussion of logic and natural language. Now we're going to discuss the same ideas, but we're going to use more Prolog-ish words, like clauses, predicates, variables, and goals.

Clauses (Facts and Rules) Basically, there are only two types of phrases that make up the Prolog language; a phrase can be either a fact or a rule. These phrases are known in Prolog as clauses. The heart of a Prolog program is made up of clauses.

Predicates (Relations) The symbolic name of a relation is called the predicate name. The objects that it relates are called its arguments. Ex: likes(bill,cindy) likes is predicate. bill and cindy are the arguments. Here are some examples of Prolog predicates with zero or more arguments: pred(integer, symbol) person(last, first, gender) run insert_mode birthday(firstName, lastName, date)

Variables (General Clauses) In a simple query, you can use variables to ask Prolog to find who likes tennis. For example: likes(X, tennis). Variables in Prolog get their values by being matched to constants in facts or rules. Until it gets a value, a variable is said to be free; when it gets a value, it becomes bound.

Variables (General Clauses) (Con.) Anonymous variables enable you to unclutter your programs. If you only need certain information from a query, you can use anonymous variables to ignore the values you don't need. In Prolog, the anonymous variable is represented by a lone underscore ("_"). Anonymous variables can also be used in facts. The anonymous variable matches anything. Prolog Syntax Natural language owns(_, shoes). Everyone owns shoes. eats(_). Everyone eats.

Goals (Queries) Up to now, we've been mixing the word query when talking about the questions you ask Prolog, with the more common name goal, which we'll use from now on. Goals can be simple, such as: likes(ellen, swimming). or they can be more complex (compound goal), and each part of the compound goal is called a subgoal, such as : likes(Person, reading), likes(Person, swimming).

Compound Goals: Conjunctions and Disjunctions As you have seen, you can use a compound goal to find a solution where both subgoal A and subgoal B are true (a conjunction), by separating the subgoals with a comma (,) You can also find a solution where subgoal A or subgoal B is true (a disjunction), by separating the subgoals with a semicolon (;)

Comments It's good programming style to include comments in your program. makes the program easy for you and others to understand. Multiple-line comments must begin with the characters /* (slash, asterisk) and end with the characters */ (asterisk, slash). Ex: /* This is an example of a comment */ To set off single-line comments, you can use these same characters, or you can begin the comment with a percent sign (%). Ex : % This is also a comment

parent(joe,tammy) matches parent(joe,tammy) Matching identical structures match each other parent(joe,tammy) matches parent(joe,tammy) a match usually involves one or more free variables parent(joe,X) matches parent(joe,tammy) Two free variables can even match each other. For example, parent(joe,X) matches parent(joe,Y)

Homework Download the Homework #1 from the website and solve it ,, deliver it in the next week .. Good Luck ,,