Comp 205: Comparative Programming Languages Declarative Programming Languages Logic Programming Horn-Clause Logic Prolog Lecture notes, exercises, etc.,

Slides:



Advertisements
Similar presentations
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Advertisements

First Order Logic Logic is a mathematical attempt to formalize the way we think. First-order predicate calculus was created in an attempt to mechanize.
Chapter 11 :: Logic Languages
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
13 Automated Reasoning 13.0 Introduction to Weak Methods in Theorem Proving 13.1 The General Problem Solver and Difference Tables 13.2 Resolution.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
Programming Languages Third Edition
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
1 Automated Reasoning Introduction to Weak Methods in Theorem Proving 13.1The General Problem Solver and Difference Tables 13.2Resolution Theorem.
CSE (c) S. Tanimoto, 2005 Logic Programming 1 Logic Programming Outline: Motivation Examples: The Grandmother relation Formulation in Prolog Logic,
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
ISBN Chapter 16 Logic Programming Languages.
Logic Programming Languages
Formal Models of Computation Part II The Logic Model
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
Logic Specification and Z Schema 3K04 McMaster. Basic Logic Operators Logical negation ( ¬ ) Logical conjunction ( Λ or & ) Logical disjunction ( V or.
Chapter 16 Logic Programming Languages. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 16 Topics Introduction A Brief Introduction to.
1-1 Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
1 COSC3306: Programming Paradigms Lecture 8: Declarative Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Programming Languages Tucker and Noonan – 2e Chapter 15 – Part 1 Logic Programming “Q: How many legs does a dog have if you call its tail a leg? A: Four.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
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 CSC 358/ Outline Pattern matching Unification Logic programming.
By: Cory Canter CSC 415 Programming Languages. History  Created by Alain Colmerauer, Phillipe Roussel and Robert Kowalski in 1971  Started as a natural.
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
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.
C. Varela1 Logic Programming (PLP 11) Predicate Calculus, Horn Clauses, Clocksin-Mellish Procedure Carlos Varela Rennselaer Polytechnic Institute November.
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Programming Languages Third Edition Chapter 4 Logic Programming.
Logic Programming (LP) expresses code using of a restricted form of symbolic logic. LP programs are declarative, rather than algorithmic. An LP program.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Logic Programming: Prolog Lecture 21 – Prolog, Spring CSE3302 Programming Languages, UT-Arlington.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
ISBN Chapter 16 Logic Programming Languages.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Invitation to Computer Science, Java Version, Second Edition 1 Logic Programming Logic programming  Various facts are asserted to be true  On the basis.
1-1 An Introduction to Logical Programming Sept
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Horn Clauses and Unification
Logic Programming Languages
CS201: Data Structures and Discrete Mathematics I
Logic Programming Languages
Prolog a declarative language
Horn Clauses and Unification
Horn Clauses and Unification
Horn Clauses and Unification
Logic Programming Language
Programming Languages 2nd edition Tucker and Noonan
Horn Clauses and Unification
CS201: Data Structures and Discrete Mathematics I
Chapter 2: Prolog (Introduction and Basic Concepts)
Prolog Concepts.
Presentation transcript:

Comp 205: Comparative Programming Languages Declarative Programming Languages Logic Programming Horn-Clause Logic Prolog Lecture notes, exercises, etc., can be found at:

Declarative vs Imperative Declarative Languages the programmer specifies what is to be computed Imperative Languages the programmer specifies how this is to be computed

The Imperative Paradigm Key features of the imperative paradigm: storage variables state instructions flow of control

The Declarative Paradigm Key features of the declarative paradigm: expressions referential transparency (an expression denotes a value irrespective of context) absence of state implicit operational semantics (term-rewriting, unification/resolution)

Declarative Languages Functional functional relationship between input and output (one output for each input) Relational logical relationships between entities in the problem domain (many possible solutions - programs are more like database queries)

Relational Languages Prolog is the main language theorem proving (Colmerauer & Roussel) programming (Kowalski) (Program = Logic + Flow-of-control) Other languages: KL-1, Eqlog.

Logic Programming OBJ is First-Order Equational Logic Haskell is (restricted) Higher-Order Equational Logic Prolog is First-Order Horn-Clause Logic

What is a Horn Clause? A Horn Clause is a conditional rule P P if C1,..., Cn that states that a proposition P is true if all the conditions C1,..., Cn are true. If n=0, then P is unconditionally true; a Horn clause of this form is just written:

Predicates Propositions and conditions are predicates. These are formed from: Predicate symbols Terms In Prolog, terms are expressions built from operators and constants. Constants and predicate symbols are just names, and are not declared, just used.

Predicates A predicate is formed by "applying" a predicate symbol to one or more terms. For example: isHappy(mary) watching(peter, football) marriedBy(joseph, charlotte, fatherJack) None of these has any intrinsic meaning.

Horn Clauses In Prolog, the main proposition ("head") of a Horn clause is separated from the conditions by ":-" happy(mary) :- stocked(mary), knitting(mary). stocked(mary) :- has(mary,sweets), has(mary,stout). has(mary, sweets). has(mary, stout). knitting(mary).

Queries A Prolog "program" is a list of Horn-clauses sometimes such a list is called a "database", or "knowledgebase". Computation in Prolog is achieved by solving "queries“ to the database, where a query is just a predicate. Queries are preceded by "?-" ?- happy(mary).

Solving Queries Prolog solves a query by logical inferences, using its database. It maintains a list of goals, where each goal is a predicate, and attempts to infer that each goal is true. Initially, the list contains just the predicate in the query. ?- happy(mary).

Is Mary Happy? Given the goal "happy(mary)" and the Horn clause happy(mary) :- stocked(mary), knitting(mary). Prolog infers that the goal is true ("satisfied") if both stocked(mary) and knitting(mary) are true; its list of goals now becomes stocked(mary), knitting(mary).

Yes, She's Happy The process continues until (in this case) all the goals are seen to be satisfied. happy(mary) :- stocked(mary), knitting(mary). stocked(mary) :- has(mary,sweets), has(mary,stout). has(mary, sweets). has(mary, stout). knitting(mary).

Variables and General Rules General rules that apply to all constants (Prolog is not typed) are expressed by Horn clauses with variables (these begin with capital letters in Prolog) happy(X) :- stocked(X), knitting(X). This states that everyone is happy if they are stocked and knitting. (I.e., variables are universally quantified.)

Is She Still Happy? Given the query " ?-happy(mary) ", the constant mary will match with the variable X, happy(X) :- stocked(X), knitting(X). again giving rise to the list of goals stocked(mary), knitting(mary).

Is Everyone Happy? Given the query " ?-happy(john) ", the constant john will match with the variable X, happy(X) :- stocked(X), knitting(X). giving rise to the list of goals stocked(john), knitting(john). In this case, these goals (and hence the original query) are not satisfied, and the answer is no. This is referred to as negation as failure.

Constructing Solutions Queries can also contain variables. A query containing a variable is seen as a request to find an instantiation of the variable that makes the predicate true. For example, the query " ?-happy(X) ", is a request to find someone that (according to the database) is happy. The result will be an instantiation of the variable X, for example, X = mary.

Who's Happy? Given the query " ?-happy(X) ", the variable X will unify with the variable Y, happy(Y) :- stocked(Y), knitting(Y). giving rise to the list of goals stocked(X), knitting(X). The process of unification is a two-way process of finding matches for variables both in goals and in rules.

So Who's Stocked? Given the goals stocked(X), knitting(X), the variable X will unify with the variable Z, stocked(Z) :- has(Z,sweets), has(Z,stout). giving rise to the list of goals has(X,sweets), has(X,stout), knitting(X).

Could It Be Mary? Given the goals has(X,sweets), has(X,stout), knitting(X). the variable X will match with the constant mary, has(mary,sweets). giving rise to the list of goals has(mary,stout), knitting(mary).

Alone of All Her X The goals has(mary,stout), knitting(mary). will be seen to be satisfied by the database... has(mary,stout). knitting(mary). X = mary and so a solution to the query is

Summary Horn-clause logic Variables in queries are existentially quantified Computation as inference Next: Unification and Backtracking; Summary of declarative languages