Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.

Slides:



Advertisements
Similar presentations
First-Order Logic Chapter 8.
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
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.
Some Prolog Prolog is a logic programming language
Logic Programming Two possible work modes: 1.At the lab: Use SICstus Prolog. To load a prolog file (*.pl or *.pro extension) to the interpreter, use: ?-
Inference Rules Universal Instantiation Existential Generalization
SLD-resolution Introduction Most general unifiers SLD-resolution
Chapter 11 :: Logic Languages
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
Inference in first-order logic Chapter 9. Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
UIUC CS 497: Section EA Lecture #2 Reasoning in Artificial Intelligence Professor: Eyal Amir Spring Semester 2004.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Automated Reasoning Systems For first order Predicate Logic.
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
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).
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
Chapter 12 - Logic Programming
Programming Languages Third Edition
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Inference and Resolution for Problem Solving
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
Prolog Programming Lecture Module 13. Objective ● What is Prolog? ● Prolog program ● Syntax of Prolog ● Prolog Control Strategy ● Execution of Prolog.
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.
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
Logic Programming Two possible work modes: 1.At the lab: Use SICstus Prolog. To load a prolog file (*.pl or *.pro extension) to the interpreter, use: ?-
1 Lecture 15: Introduction to Logic Programming with Prolog (Section 11.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill.
COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan.
Introduction to Logic Programming with Prolog (Section 11.3)
1-1 Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
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.
O A procedure: a set of axioms (rules and facts) with identical signature (predicate symbol and arity). o A logic program: a set of procedures defining.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
First-Order Logic and Inductive Logic Programming.
Lab Lecture#4 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
UNIVERSITI TENAGA NASIONAL CMPB454 ARTIFICIAL INTELLIGENCE (AI) CHAPTER 6 LOGIC PROGRAMMING USING PROLOG CHAPTER 6 LOGIC PROGRAMMING USING PROLOG Instructor:
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
© 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.
© Copyright 2008 STI INNSBRUCK Intelligent Systems Propositional Logic.
CSE (c) S. Tanimoto, 2008 Predicate Calculus II 1 Predicate Calculus 2 Outline: Unification: definitions, algorithm Formal interpretations and satisfiability.
Lecture course: Heuristics & Prolog for Artificial Intelligence Applications Notes on Prolog from Professor Bruce Batchelor, DSc.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela.
Knowledge Based Information System
1-1 An Introduction to Logical Programming Sept
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
For Friday No reading Prolog Handout 2. Homework.
Prolog 3 Tests and Backtracking 1. Arithmetic Operators Operators for arithmetic and value comparisons are built-in to Prolog = always accessible / don’t.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Logical Agents Chapter 7. Outline Knowledge-based agents Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem.
Knowledge Repn. & Reasoning Lecture #9: Propositional Logic UIUC CS 498: Section EA Professor: Eyal Amir Fall Semester 2005.
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
O A procedure: a set of axioms (rules and facts) with identical signature (predicate symbol and arity). o A logic program: a set of procedures (predicates),
Logic Programming Lecture 2: Unification and proof search.
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.
CSE 341, S. Tanimoto Logic Programming -
Programming Techniques
Prolog Concepts.
Presentation transcript:

Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae (axioms) Computation is verification that output can be formally derived from input Computation engine is theorem prover Side-effect of computation is a set of bindings of logical variables to terms, which describes desired result.

Biblical Prolog father (adam, abel). % an assertion (a fact) father (adam, cain). brother (X, Y) :- father (Z, X), father (Z, Y). % a rule ? :- father (adam, abel) % a query yes % response ? :- father (X, abel) X = adam ? :- father (cain, abel) no ? :- brother (abel, Z) Z = cain ? :- mother (eve, abel) no % no is non-provability, not falsehood

The syntax of logical formulae Terminals: literals, variables, function symbols, punctuation Productions: term ::= literal | variable | function_symbol ( terms ) terms ::= term | term terms simple_clause ::= term | term, simple_clause clause ::= simple_clause | term :- simple_clause program ::= clauses comma is conjunction: and :- is reverse implication: iff

Substitutions and unification Computation perfoms unification between terms, by generating substitutions on variables. Computation halts when no further unifications are possible Result is final set of substitutions, mapping variables to terms Unify father (adam, cain) with father (X, cain) by unifying X with adam. –Result is { X/adam } Unify father (adam, cain) with father (X, Y) –Result is { X/adam, Y/cain } Unify father ( adam, cain ) with father ( X, X ) –Result is { } : failure

Unification algorithm To unify two terms t1 and t2: t1 = t2 f (s 1, s 2,..) = f (t 1, t 2..) Replace equation with s 1 = t 1, s 2 = t 2 … f (s 1, s 2..) = g(t 1, t 2..) where f /= g fail v = v delete equation v = t where t is a term not containing v Apply the substitution v / t everywhere v = t where t is a term that contains v fail

The meaning of a clause P (x 1, x 2 …) :- q 1 (s 1, s 2..), q 2 (t 1, t 2..).. Logical (declarative) interpretation: the predicate P is true (satisfiable) on arguments x 1, x 2.. If each predicate q i can be shown to be satisfiable Procedural interpretation: a call to procedure P is executed by calling in turn q 1, q 2 … (subgoals) Several unifications may be possible at a given time: selection is non-deterministic If unification fails, computation backtracks

Lists Terms are sufficient for everything, but need special syntax for simple recursive structures [X | Y] designates list with head X and tail Y – (special term for function symbol cons) [X| _ ] indicates that tail of list is irrelevant: – _ is variable that needs no binding

Backtracking and brute force search color (C):- member (C, [green, red, blue, yellow]) member (X, [X | _ ]). member X [ _ |Y]) :- member (X, Y). next (R 1, R 2 ) :- color (R 1 ), color (R 2 ), R 1 \= R 2. Graph to be colored is described by adjacency terms: ?:- next(R 1, R 2 ), next (R 1, R 3 ), next (R 1, R 4 ), next (R 2, R 3 ), next (R 2, R 4 ), next (R 3, R 4 )

reversibility Predicate can be used as generator: member (X, [X | _ ]). member X [ _ |Y]) :- member (X, Y). color (C):- member (C, [green, red, blue, yellow]) ?:- color (C) C = green; % semicolon forces backtracking C = read; % second choice C = blue C = yellow; no % no further backtracking possible

arithmetic Ideal: symmetric handling of queries factor (X, Y, Z) :- X = Y * Z ?:- factor (10, 2, 5) Yes ?:- factor ( , Y, Z) % you wish! In practice: cannot do arithmetic on uninstantiated variables

arithmetic and binding Z is X + Y succeeds if X and Y are instantiated and Z is uninstantiated Z is Z + 1 always fails fact (0, 1). fact (N, M) :- N1 is N -1, fact (N1, M1), M is N * M1