ITEC 380 Organization of programming languages Lecture 8 – Prolog.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Advertisements

Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
Prolog.
Chapter 3 Program Design And Branching Structures.
Racket Introduction CSC270 Pepper major portions credited to
Types and Arithmetic Operators
ITEC113 Algorithms and Programming Techniques
Andrew Courter Texas Tech University CS5331.  PKS Why PKS? STRIPS The Databases Inference Algorithm Extended Features  PKS Examples  Conclusion and.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
CS101- Lecture 11 CS101 Fall 2004 Course Introduction Professor Douglas Moody –Monday – 12:00-1:40 – – –Web Site: websupport1.citytech.cuny.edu.
1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.
Modules, Hierarchy Charts, and Documentation
Formal Aspects of Computer Science – Week 12 RECAP Lee McCluskey, room 2/07
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
Introducing Java.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
DEDUCTIVE DATABASE.
School of Computing and Mathematics, University of Huddersfield Computing Science: WEEK 17 Announcement: next few weeks… 9 nd Feb: Comparative Programming.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Chapter 1: Introduction to Computers and Programming.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Evolution of Programming Languages Generations of PLs.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
ITEC 380 Organization of programming languages Lecture 9 – Prolog.
COIT29222 Structured Programming Slide 1 COIT29222-Structured Programming Lecture Week 06  Reading: Study Guide Book 2, Modules 9 & 10 Textbook (4 th.
 Expression Tree and Objects 1. Elements of Python  Literals, Strings, Tuples, Lists, …  The order of file reading  The order of execution 2.
Getting Started with Visual Prolog
ITEC 380 Organization of programming languages Lecture 7 – Prolog.
CMSC 1041 Algorithms III Problem Solving and Pseudocode.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
Python Programming Using Variables and input. Objectives We’re learning to use basic knowledge of variables combined with user input. Outcomes Continue.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
PROGRAMMING LANGUAGES: PROLOG, CLOJURE, F# Jared Wheeler.
Overview of c++ Objectives 1. Understanding the use of the following elements in a c++ program variables constants assignment input output 2. Writing a.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
Computer Science 1000 Algorithms III. Multiple Inputs suppose I ask you to write a program that computes the area of a rectangle area = length * width.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Foundations of Programming: Java
Section 16.5, 16.6 plus other references
Basic concepts of C++ Presented by Prof. Satyajit De
Introduction to Algorithms
1-1 Logic and Syntax A computer program is a solution to a problem.
PROLOG.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
UMBC CMSC 104 – Section 01, Fall 2016
Computer Programming.
Introduction to Computer Programming
Learning to Program in Python
Programming Right from the Start with Visual Basic .NET 1/e
PL/SQL Declaring Variables.
Flowcharts and Pseudo Code
Reading Data From and Writing Data To Text Files
Presentation transcript:

ITEC 380 Organization of programming languages Lecture 8 – Prolog

Prolog Review Prolog –What are its 2 major components?

Prolog Objectives Prolog –Basic principles –Examples –Example programs

Prolog Declarative Programmin g Instead of focusing on how to accomplish a particular task, focus on what to accomplish Declare the intent and let the tool do the rest Limits what is possible –Specific language that is limited compared to say C Leaves little room for traditional optimization Do you know of any declarative languages?

Prolog Example SQL –Insert knowledge where mind = attentive Declare what should happen, not how –B-trees? –Recursive descent algorithms? SELECT * FROM Book WHERE price > ORDER BY title;

Prolog Declarative statements in prolog –Facts that are true –Rules that are made up of groups of facts –Variables that hold a specific value Goal –Ask what the value of an expression is –True / False / Numeric

Prolog Facts A true statement Syntax –Factname(identifier that is mapped to factname) –Factname(ident1, ident2) Means that ident1 is the Factname of ident2 Example male(Bob) female(Jill) parent(Jill, Bill) parent(Bob, Bill)

Prolog But wait Have to store up a “knowledge base” before you can make queries Declares a set of facts Can be used to make queries later on Difference of what should be done versus how to go about it

Prolog Loading Once you have saved your knowledge base you can load it into prolog –Needs to have a.pl extension Synatx –[filename]. %Note the. is the prolog equivalent to a ; –Do not use the.pl extension Once you have done that you can use it

Prolog Example View a simple knowledge base Load it Make queries about it male(bob). female(jill). parent(jill,bill). parent(bob, bill). father(TheDad, TheChild) :- parent(TheDad,TheChild), male(TheDad). mother(TheMom, TheChild) :- parent(TheMom,TheChild), female(TheMom).

Prolog User I/O Need to get input to truly exercise the system Expanding the knowledge base –write(‘Data\nNewLine\nData’) –read(Variable) Method –Have a rule that uses read, then combine with a, and then use the new variable in the facts

Prolog Expanded Making our previous knowledge base have I/O male(bob). female(jill). parent(jill,bill). parent(bob, bill). father(TheDad, TheChild) :- parent(TheDad,TheChild), male(TheDad). mother(TheMom, TheChild) :- parent(TheMom,TheChild), female(TheMom). iTester :- write('Type the mother\'s name\n'), read(Mom), write('Type the child\'s name\n'), read(Child), mother(Mom, Child).

Prolog Issue Test out someone not in the DB –Use lower case variables, then upper case Why? Run the test manually… Variable case matters! –Lower case = constants –Upper case = variables Anonymous variables –Use _

Prolog Prolog power An example of declarative logic and inference The game of clue What are you declaring in clue? What are you trying to find out? How does this relate to RL relevance?

Prolog The miracle of trace See exactly what is happening during evaluation Turn on with trace. See what happens when you load a file? What happens when you call a function?

Prolog Numbers Working with constants –True/false 8 is 6+2. –Setting a value X is 4. Setting up formulas –formula(x,y) :- Y=X*2. Note formulas must be placed in knowledge base! –Test with 1) 3,A then 3,a then 3,4 Why did it get the results it did?

Prolog More capabilities Can do relational queries –A is 7, A>5. Note:, means and ; means or –What are the implications of using the ; above? –Can also use Rule1 -> Rule2 to only execute Rule2 if Rule1 is true Trivia: What does the, mean in prolog How could we prompt the user for their salary and print out what the percentage they pay in tax is (30%)?

Prolog Next week More in-depth with prolog –Lists –Recursion