Prolog Concepts.

Slides:



Advertisements
Similar presentations
Artificial Intelligence 8. The Resolution Method
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Biointelligence Lab School of Computer Sci. & Eng.
1 A formula in predicate logic An atom is a formula. If F is a formula then (~F) is a formula. If F and G are Formulae then (F /\ G), (F \/ G), (F → G),
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
Standard Logical Equivalences
Resolution.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
First Order Logic Resolution
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.
Models and Propositional Logic In propositional logic, a model in general simply fixes the truth value – true or false – for every proposition symbol.
13 Automated Reasoning 13.0 Introduction to Weak Methods in Theorem Proving 13.1 The General Problem Solver and Difference Tables 13.2 Resolution.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
1 Prolog II. 2 The Notion of Unification Unification is when two things “become one” Unification is kind of like assignment Unification is kind of like.
Prolog IV Logic, condensed. 2 Propositional logic Propositional logic consists of: The logical values true and false ( T and F ) Propositions: “Sentences,”
11-Jun-15 Prolog II Unification and clause order.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
1 Automated Reasoning Introduction to Weak Methods in Theorem Proving 13.1The General Problem Solver and Difference Tables 13.2Resolution Theorem.
Inference and Resolution for Problem Solving
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
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.
1 Knowledge Based Systems (CM0377) Lecture 4 (Last modified 5th February 2001)
1 Chapter 8 Inference and Resolution for Problem Solving.
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.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
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.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
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.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Automated Reasoning Early AI explored how to automate several reasoning tasks – these were solved by what we might call weak problem solving methods as.
The Law of Resolution Formal Aspects of Computer Science - Week 7 The Law of Resolution Lee McCluskey, room 2/07
Propositional Logic Predicate Logic
Prolog Unification and clause order. The notion of Unification Unification is when two things “become one” Unification is kind of like assignment Unification.
ISBN Chapter 16 Logic Programming Languages.
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.
23-Feb-16 Prolog II Unification and clause order.
Propositional Logic. Assignment Write any five rules each from two games which you like by using propositional logic notations.
Introduction to Logic for Artificial Intelligence Lecture 2
Prolog Concepts.
Horn Clauses and Unification
Logic Programming Languages
Logic Programming Languages
Prolog Lists.
Carlos Varela Rensselaer Polytechnic Institute November 10, 2017
Unification and clause order
Horn Clauses and Unification
Prolog IV Logic, condensed.
Horn Clauses and Unification
Horn Clauses and Unification
Logic Programming Language
Prolog III.
Prolog Lists.
Prolog Resolution.
Programming Techniques
Programming Languages 2nd edition Tucker and Noonan
Horn Clauses and Unification
RESOLUTION.
Prolog Concepts.
Resolution Preliminaries
Presentation transcript:

Prolog Concepts

A declarative language Most programming languages are imperative—you tell the computer what to do to solve a problem Prolog is declarative—you give it the data it needs, and it solves the problem for you Consider: append([], List, List). append([Head | Tail], List, [Head | More]) :- append(Tail, List, More). This defines what it means append lists You can use it to append two lists You can use it to find what to append to a list to get another list You can use it to find what list to append to to get another list You can test whether the relation holds between three lists 2

append examples I 3 ?- append([a, b], [c, d], X). X = [a, b, c, d]. 4 ?- append([a, b], X, [a, b, c]). X = [c]. 5 ?- append(X, [c, d], [a, b, c, d]). X = [a, b] false. 2

append examples I 6 ?- append(X, Y, [a, b, c]). X = [], Y = [a, b, c] X = [a], Y = [b, c] X = [a, b], Y = [c] X = [a, b, c], Y = [] false. 7 ?- append([a, b], X, Y). Y = [a, b|X]. 8 ?- append(X, [a, b, c], Y). X = [], Y = [a, b, c] X = [_G1989], Y = [_G1989, a, b, c] X = [_G1989, _G1995], Y = [_G1989, _G1995, a, b, c] 2

A constraint satisfaction language Prolog is also one of a number of constraint satisfaction languages You tell it the constraints on a problem (e.g. the solution must be someone who is both female and rich), and it finds a solution that satisfies those constraints A “logic puzzle” is nothing more than a set of constraints (e.g. every man has a different tie) 3

A homoiconic language Prolog is homoiconic—that is, there is no distinction between “statements” in the language and the “data” that the languages processes When you provide “input” to a Prolog program (e.g. for an adventure game), you use the same syntax as when you write the program We haven’t emphasized homoiconicity in Prolog, because it is more important in some of the other languages we will be studying 4

Prolog does backtracking You don’t have to implement backtracking in Prolog; the language does it for you The only other “language” I know of that does this is Regular Expressions, which are a “sublanguage” of most modern programming languages loves(chuck, X) female(X) rich(X) call fail exit redo 5

Prolog uses unification The basic rules of unification are: Any value can be unified with itself A variable can be unified with another variable A variable can be unified with any value Two different structures can be unified if their constituents can be unified Lists are a particularly important kind of structure A variable can be unified with a structure containing that same variable Unification is reflexive, symmetric, and transitive 6

Unification and pattern matching Parameter transmission is by unification, not assignment member(H, [H | T]). member(H, [_ | T]) :- member(H, T). Thus, parameters are not restricted to simple variables Note also the use of the “don’t care” variable, _ Many other languages use pattern matching, which is like unification, but may be asymmetric: value match { pattern1 => code1; pattern2 => code2; … } 7

Lists Lists, not arrays, are the fundamental data structures in Prolog and nearly all functional languages Non-empty lists consist of a head (the first element in the list) and a tail (a list of the remaining elements) Although the syntax may differ, this way of treating a list is common among functional languages 8

Predicates as functions Prolog has no functions, so it cannot be a functional language But we can do something similar with predicates map(_, [], []). map(P, [H|T], [H2|T2]) :- call(P, H, H2), map(P, T, T2). filter(_, [], []). filter(P, [H|T], [H|T2]) :- call(P, H), filter(P, T, T2). filter(P, [_|T], L) :- filter(P, T, L). twice(X, Y) :- Y is 2 * X. even(X) :- X mod 2 =:= 0. 31 ?- map(twice, [1, 2, 3], X). X = [2, 4, 6] . 32 ?- filter(even, [1, 2, 3, 4], X). X = [2, 4] 8

Prolog is a theorem prover Prolog is an implementation of resolution theorem proving in a programming language Because it is based on logic, there is very little that is ad hoc or arbitrary about Prolog 9

Resolution Here is the resolution principle: A clause is a disjunction (“or”) of zero or more literals, some or all of which may be negated sinks(X) ∨ dissolves(X, water) ∨ ¬denser(X, water) Any expression in the predicate calculus can be put into clause form X ⇒ Y can be rewritten as ¬X ∨ Y Conjunctions (“ands”) can be rewritten as separate clauses The existential quantifier ∃ can be replaced by a Skolem function If the existential quantifier is under control of a universal quantifier, replace it with a function of the universally quantified variable Otherwise, just replace with a constant (whose value need not be known) Universal quantifiers, ∀, can be dropped Here is the resolution principle: From X ∨ someLiterals and ¬X ∨ someOtherLiterals ---------------------------------------------- conclude: someLiterals ∨ someOtherLiterals Clauses are closed under resolution 10

The End 11