CSI 3120, Prolog recap, page 1 Prolog recap Prolog was invented in 1970, first implemented in 1972, first implemented efficiently in 1975. Excellent commercial-

Slides:



Advertisements
Similar presentations
Jeremy S. Bradbury, James R. Cordy, Juergen Dingel, Michel Wermelinger
Advertisements

Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Comparison of OO with other.
Software Development Languages and Environments. Programming languages High level languages are problem orientated contain many English words are easier.
Cs7120 (Prasad)L22-MetaPgm1 Meta-Programming
Semantics Static semantics Dynamic semantics attribute grammars
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
© Chinese University, CSE Dept. Software Engineering / Software Engineering Topic 1: Software Engineering: A Preview Your Name: ____________________.
Computers Are Your Future
CSI 2115, Prolog, page 1 Logic programming in Prolog A little background Prolog warm-up SWI Prolog A session with Prolog Two interpretations A bit of terminology.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
Expert System Human expert level performance Limited application area Large component of task specific knowledge Knowledge based system Task specific knowledge.
Programming Creating programs that run on your PC
INTRODUCTION COMPUTATIONAL MODELS. 2 What is Computer Science Sciences deal with building and studying models of real world objects /systems. What is.
Programming Languages Language Design Issues Why study programming languages Language development Software architectures Design goals Attributes of a good.
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
Chapter 8 . Sequence Control
Trees. Definition of a tree A tree is like a binary tree, except that a node may have any number of children –Depending on the needs of the program, the.
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Programming Paradigms cs784(Prasad)L5Pdm1. Programming Paradigm A way of conceptualizing what it means to perform computation and how tasks to be carried.
Describing Syntax and Semantics
Program Development and Programming Languages
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Databases Illuminated Chapter 7 The Object-Oriented Model.
Your Interactive Guide to the Digital World Discovering Computers 2012.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Programming Languages – Coding schemes used to write both systems and application software A programming language is an abstraction mechanism. It enables.
Dr. Ken Hoganson, © August 2014 Programming in R STAT8030 Programming in R COURSE NOTES 1: Hoganson Programming Languages.
1 Introduction to databases concepts CCIS – IS department Level 4.
1 Software Development Topic 2 Software Development Languages and Environments.
CIS Computer Programming Logic
Programming Paradigms
Programming Paradigms Procedural Functional Logic Object-Oriented.
 The design of the imperative languages is based directly on the von Neumann architecture  Efficiency is the primary concern  Low-level specifications:
1 Introduction Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Chapter 6 Programming Languages. © 2005 Pearson Addison-Wesley. All rights reserved 6-2 Chapter 6: Programming Languages 6.1 Historical Perspective 6.2.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Computer Programs and Programming Languages What are low-level languages and high-level languages? High-level language Low-level language Machine-dependent.
Chapter 6 Programming Languages © 2007 Pearson Addison-Wesley. All rights reserved.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
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.
Programming Languages. A Logic Programming Language: Prolog This lesson describes the basic structures and functions of the logic programming language:
Week III  Recap from Last Week Review Classes Review Domain Model for EU-Bid & EU-Lease Aggregation Example (Reservation) Attribute Properties.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
For Monday Exam 1 is Monday Takehome due Prolog Handout 3 due.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
For Friday No reading Prolog Handout 2. Homework.
Abdul Rahim Ahmad MITM 613 Intelligent System Chapter 10: Tools.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Introductory Lecture. What is Discrete Mathematics? Discrete mathematics is the part of mathematics devoted to the study of discrete (as opposed to continuous)
Introduction to Java Chapter 1 - Introduction to Java1 Chapter 1 Introduction to Java.
Functional Programming
Introduction to Algorithms
Programming Paradigms
Why study programming languages?
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
System Design.
VISUAL BASIC.
Introduction to Algorithms
Programming Languages and Paradigms
Programming Paradigms
Chapter 15 Functional Programming 6/1/2019.
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

CSI 3120, Prolog recap, page 1 Prolog recap Prolog was invented in 1970, first implemented in 1972, first implemented efficiently in Excellent commercial- strength implementations have existed since early 1980s. In over 35 years, Prolog has been unmatched as an unusually powerful language for a fairly wide range of applications (including circuit design, language processing, software prototyping and runnable specifications) but it is amazingly underappreciated. People do not even know that Prolog is faster than Java when applied in the right way, and that software production can be an order of magnitude faster in this very high-level programming language.

CSI 3120, Prolog recap, page 2 An informative example (a)A prime number N is a number whose set of divisors contains only 1 and N. (b)The set of divisors of a number N is the set of numbers in the range 1.. N which divide N exactly. % (a) prime( N ) :- divisorSet( N, [1, N] ). % (b) divisorSet( N, DivSet ) :- setof( K, ( inRange( K, 1, N ), N mod K =:= 0 ), DivSet ). % (b') two cases are possible inRange( K, K, High ) :- K =< High. inRange( K, Low, High ) :- Low < High, Low1 is Low + 1, inRange( K, Low1, High ). Prolog has no conditional statements and no iterations. The only operations allowed in the body of a procedure are other procedure calls—and this is quite sufficient.

CSI 3120, Prolog recap, page 3 Two interpretations ancestor( X, Y ) :- father( X, Y ). ancestor( X, Y ) :- father( X, Z ), ancestor( Z, Y ). Your father is your ancestor, and the father of your ancestor is your ancestor, too. This is an example of the declarative (static, logical) interpretation of Prolog definitions. Queries, however, are used to find answers, not only to confirm truths recorded in the Prolog database. Finding is necessarily dynamic, so we need another interpretation.

CSI 3120, Prolog recap, page 4 Two interpretations The procedural (imperative, control) interpretation of Prolog facts and rules focuses on the process of finding answers: To find an ancestor of Y, find his father; or else, take his father (call him Z) and find Z's ancestor. This is the description of a procedure with two variants, one of which is chosen for execution. The procedure's name is ancestor, and it has two parameters. The body of the second variant consists of two procedure calls: first, father with 2 parameters; next, ancestor with 2 parameters.

CSI 3120, Prolog recap, page 5 Compound objects Compound objects are ordered collections of simpler objects that are in some relationship. Examples: two sides of a rectangle, such as 19 by 24, the time in hours and minutes, such as 19:24. The pair (19, 24) can represent a rectangle or a time, so we name the relationship: rectangle( 19, 24 ) timeOfDay( 19, 24 ) We can also represent the time with seconds: timeOfDay( 19, 24, 37 ) This is a different object, but Prolog manages OK. The name is the same, but the arity is not: timeOfDay/2 (two components), timeOfDay/3 (three components).

CSI 3120, Prolog recap, page 6 Compound objects Example: customer( name( jim, white ), address( street( 17, main ), city( bytown, ontario ) ) ) A compound object is incompletely specified if it contains variables – unknown components. An example: customer( X, address( street( 17, main ), city( bytown, ontario ) ) ) "Any customer who lives at 17 Main, Bytown, Ontario.” customer( name( X, white ), address( street( Y, main ), city( Z, ontario ) ) ) "Any customer by the name of White who lives at Main, any town, Ontario.” A variable may appear more than once. For example, rectangle( X, X ) represents a square.

CSI 3120, Prolog recap, page 7 Lists Lists are processed recursively. length( [], 0 ). length( [ _H | T ], Len ) :- length( T, Len1 ), Len is Len nth( 1, [Hd | _Tl], Hd ). nth( N, [_ | Tl], NthElem ) :- N > 1, N1 is N - 1, nth( N1, Tl, NthElem ). member( Hd, [Hd | _Tl] ). member( Elem, [ _Hd | Tl ] ) :- member( Elem, Tl ).

CSI 3120, Prolog recap, page 8 Lists List processing may be non-deterministic, and procedures may have many uses. append( [], L2, L2 ). append( [E | L1], L2, [E | L3] ) :- append( L1, L2, L3 ). The query tells us which of several operations it is. ?- append( [a], [b, c], LL ). ?- append( [a], X, [a, b, c] ). ?- append( Y, [c], [a, b, c] ). ?- append( F, S, [a, b, c] ). ?- append( F, S, FS ). ?- append([X, 55], [Y], [77, Z, 20]).

CSI 3120, Prolog recap, page 9 Prolog at its most elegant intersect( List1, List2 ) :- member( X, List1 ), member( X, List2 ). ?- intersect( [a, c, e, g], [b, c, d] ). true ?- intersect( [a, c, e, g], [b, d, f] ). fail Two lists intersect if they have a common element.

CSI 3120, Prolog recap, page 10 Last words Much more: Advanced control, including the cut. Customizable term syntax. Logic grammars. Dynamic (on-the-fly) modification of Prolog code. Programming with trees and graphs. Debugging tools. Programming in the large (modules). Graphics and user interface programming. Object-oriented extensions of Prolog. Where is Prolog is a language of choice? Rapid software prototyping. Deductive databases. Language design and development. Constraint programming. Artificial Intelligence: Games, Planning, Machine Learning, Natural Language Processing.