Artificial Intelligence Lecture 2. Logic & Prolog Predicate calculus –syntax: terms, predicates, sentences –semantics: interpretations, logical consequence,

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
1 Logic Logic in general is a subfield of philosophy and its development is credited to ancient Greeks. Symbolic or mathematical logic is used in AI. In.
Logic Use mathematical deduction to derive new knowledge.
Artificial Intelligence
Logic.
Prolog programming  unification/matching programs as deductive databases  resolution, goal reduction declarative vs. procedural readings  code tracing.
ISBN Chapter 3 Describing Syntax and Semantics.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Logic & Prolog  predicate calculus syntax: terms, predicates, sentences semantics: interpretations, logical consequence, inference rules, proof procedures.
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
Logic. Propositional Logic Logic as a Knowledge Representation Language A Logic is a formal language, with precisely defined syntax and semantics, which.
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Lecture 9 Jim Martin.
Knowledge Representation I (Propositional Logic) CSE 473.
Knoweldge Representation & Reasoning
Artificial Intelligence
Predicate Calculus.
Describing Syntax and Semantics
FIRST ORDER LOGIC Levent Tolga EREN.
1 CSC 550: Introduction to Artificial Intelligence Spring 2004 AI programs  Eliza  knowledge representation  pattern-matching  Predicate Calculus 
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)
Propositional Calculus Composed of symbols –P – some true statement P might represent something like “It is Monday” or “the car is red” And sentences –a.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
110/19/2015CS360 AI & Robotics AI Application Areas  Neural Networks and Genetic Algorithms  These model the structure of neurons in the brain  Humans.
Cs7120 (Prasad)L16-Meaning1 Procedural and Declarative Meaning of Prolog
Pattern-directed inference systems
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
ARTIFICIAL INTELLIGENCE Lecture 3 Predicate Calculus.
For Wednesday No new reading Prolog handout 2 Chapter 9, exercise 4.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
CS 4100 Artificial Intelligence Prof. C. Hafner Class Notes Jan 17, 2012.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Logical Agents Chapter 7. Outline Knowledge-based agents Logic in general Propositional (Boolean) logic Equivalence, validity, satisfiability.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
CS6133 Software Specification and Verification
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Artificial Intelligence Chapter 15 The Predicate Calculus Artificial Intelligence Chapter 15 The Predicate Calculus Biointelligence Lab School of Computer.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
For Wednesday Read chapter 9, sections 1-3 Homework: –Chapter 7, exercises 8 and 9.
Propositional Logic Predicate Logic
1 CSC384: Intro to Artificial Intelligence Lecture 5.  Knowledge Representation.
1/32 This Lecture Substitution model An example using the substitution model Designing recursive procedures Designing iterative procedures Proving that.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Lecture 11 Jim Martin.
11 Artificial Intelligence CS 165A Thursday, October 25, 2007  Knowledge and reasoning (Ch 7) Propositional logic 1.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Knowledge Based Information System
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
ARTIFICIAL INTELLIGENCE Lecture 2 Propositional Calculus.
For Wednesday No reading Prolog handout 2 Chapter 9, exercise 4.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Lecture 041 Predicate Calculus Learning outcomes Students are able to: 1. Evaluate predicate 2. Translate predicate into human language and vice versa.
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
March 3, 2016Introduction to Artificial Intelligence Lecture 12: Knowledge Representation & Reasoning I 1 Back to “Serious” Topics… Knowledge Representation.
Artificial Intelligence Logical Agents Chapter 7.
Knowledge Representation and Reasoning
Logic Programming Languages
Logic Use mathematical deduction to derive new knowledge.
Back to “Serious” Topics…
This Lecture Substitution model
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

Artificial Intelligence Lecture 2

Logic & Prolog Predicate calculus –syntax: terms, predicates, sentences –semantics: interpretations, logical consequence, inference rules, proof procedures Logic programming Prolog –Prolog facts & rules, SWI Prolog

Symbolic AI (1) GOFAI relies on the Physical Symbol System Hypothesis: Intelligent activity is achieved through the use of symbol patterns to represent the problem operations on those patterns to generate potential solutions search to select a solution among the possibilities

Symbolic AI (2) An AI representation language must –handle qualitative knowledge –allow new knowledge to be inferred from facts & rules –allow representation of general principles –capture complex semantic meaning –allow for meta-level reasoning –e.g., Predicate Calculus (also, the basis of Prolog)

Predicate Calculus the predicate calculus (PC) is a language for representing knowledge amenable to reasoning using inference rules the syntax of a language defines the form of statements –the building blocks of statements in the PC are terms and predicates –terms denote objects and properties truth symbols true false constant symbols dave redBlock happy variable symbols X Person Answer1 function expressions mother(bob) plus(1,3) –predicates define relationships between objects (arity defines # of args) mother/1above/2 likes/2

Predicate calculus: sentences sentences are statements about the world –propositions (predicates applied to terms) are sentences –if S, S 1 and S 2 are sentences, then so are ¬ S (negation – NOT) S 1  S 2 (conjunction – AND) S 1  S 2 (disjunction – OR) S 1  S 2 (implication – IF-THEN)  X S (universal quantification – FOR ALL X…)  X S (existential quantification – THERE EXISTS X…) male(dave)parent(dave, jack) ¬happy(chris) parent(dave, jack)  parent(dave, charlie) happy(chris)  ¬happy(chris) healthy(kelly)  happy(kelly)  X (healthy(X)  happy(X))  X parent(dave, X)  C  P parent(P, C)

Predicate calculus: semantics (1) the semantics of a language defines the meaning of statements an interpretation assigns meaning to terms/sentences –must focus on a particular domain (universe of objects) –terms are assigned values from the domain constant  an object in the domain variable  a subset of the domain function symbol  a function mapping args to an object in the domain –predicate symbols are assigned mappings from args to true/false e.g. DOMAIN: students in this class patrick, bryanP, john, bryanJ, scott : mapped to actual people partner function : maps a students to his/her partner partner(patrick)  bryanP, partner(bryanP)  patrick undergrad/1: maps a student to true if an undergrad, else false grad/1: maps a student to true if a grad student, else false male/1: maps a student to true if male, else false female/1: maps a student to true if female, else false

Predicate calculus: semantics (2) –interpretation assigns true/false value to sentences propositionassigned true/false according to predicate mapping ¬ S true if S is false, else false S 1  S 2 true if both S 1 and S 2 are true, else false S 1  S 2 true if either S 1 or S 2 are true, else false S 1  S 2 false if S 1 is true and S 2 is false, else true  X S true if S is true for all assignments to X  X S true if S is true for any assignment to X e.g. the following are all assigned true under the previous interpretation undergrad(patrick) grad(scott) male(john) ¬ undergrad(john) ¬female(bryanP) undergrad(patrick)  undergrad(partner(patrick)) undergrad(bryanP)  undergrad(bryanJ)  X male(X)  G grad(G)  X (undergrad(partner(X))  undergrad(X))

Predicate calculus: logical consequence the semantics of the predicate calculus provides a basis for a formal theory of logical inference –an interpretation that makes a sentence true satisfies it –a set of expressions {S 1, …, S n } logically implies S if every interpretation that satisfies {S 1, …, S n } satisfies S equivalently, we could say S is a logical consequence of {S 1, …, S n } shorthand notation: {S 1, …, S n } ╞ S e.g., {itRains  getWet, goSwim  getWet, itRains  goSwim } ╞ getWet {  P(human(P)  mortal(P)), human(socrates)} ╞ mortal(socrates)

Predicate calculus: inference proving logical consequence via interpretations is difficult –requires reasoning over all interpretations alternatively, a proof procedure can generate logical consequences –a proof procedure is a combination of inference rules and an algorithm for applying the rules to generate logical consequences –example inference rules: –Modus Ponens: if S1 and S1  S2 are true, then infer S2 –And Elimination:if S1  S2 is true, then infer S1 and infer S2 –And Introduction:if S1 and S2 are true, then infer S1  S2 –Universal Instantiation: if  X p(X) is true, then infer p(a) for any a

Inference example initial knowledge: {  P(human(P)  mortal(P)), human(socrates) }  extend using Universal Instantiation –{  P(human(P)  mortal(P)), –human(socrates), –human(socrates)  mortal(socrates) }  extend using Modus Ponens –{  P(human(P)  mortal(P)), –human(socrates), –human(socrates)  mortal(socrates), –mortal(socrates) }

Another inference example initial knowledge: {  P(student(P)  tired(P)),  S(csmajor(S)  overworked(S)),  X(tired(X)  overworked(X)  testy(X)), student(patrick), csmajor(patrick) } 

AI programming languages (1) there are 2 major programming language used for AI research –LISP (List Processing) older (1957), more established in U.S. uses a functional style –Prolog (Programming in Logic) newer (1971), more widely used in Europe & Asia uses a declarative style, a.k.a. logic programming attractive features: built-in notion of search general data structures powerful primitives for symbol manipulation

AI programming languages (2) Prolog evolved out of the automated deduction community –IDEAS: (1) focus on a subset of the predicate calculus »programs are collections of logical statements & relations – (2) implement a simple but efficient proof procedure »Prolog interpreter applies inference rules to perform deduction –logic programming: computation = logical deduction from program statements

Prolog Prolog programs are statements from the Horn clause subset of the predicate calculus facts (i.e., propositions) all variables are assumed to be universally quantified, so  is implicit terminate each fact with a period male(dave). parent(dave, jack). mortal(X). rules (i.e., implications of the form: P1  …  Pn  C ) again,  is implicit & terminate rule with a period slightly different notation in Prolog (to suit standard keyboards) (1) conclusion is on the left, (2) :- replaces , (3) comma replaces  e.g., C :- P1, …, Pn. happy(chris) :- healthy(chris). mortal(X) :- human(X). father(F, C) :- parent(F, C), male(F). grandfather(F, G) :- father(F, C), parent(C, G).

Prolog's basic model of computation (1) the programmer states relations between objects as facts & rules parent(dave, charlie).parent(dave, jack). parent(laura, charlie).parent(laura, jack). male(dave). male(charlie). male(jack). female(laura). father(dave, charlie) :- parent(dave, charlie), male(dave). mother(M, C) :- parent(M, C), female(M).

Prolog's basic model of computation (2) the job of the Prolog interpreter is to receive queries and determine whether they are logical consequences of the facts & rules –in simple case, merely?- parent(dave, charlie). –looks up factsYes –more generally, may need?- father(dave, charlie). –to perform inferencesYes –using the rules?- father(charlie, dave). –No –may even require picking the?- mother(laura, charlie). –right instances of rulesYes

Prolog's basic model of computation (3) %%%%%%%%%%%%%%%%%% %% family.pro Dave Reed 1/25/02 %% %% Encodes family relations. %%%%%%%%%%%%%%%%%% parent(dave, charlie). parent(dave, jack). parent(laura, charlie). parent(laura, jack). male(dave). male(charlie). male(jack). female(laura). father(F, C) :- parent(F, C), male(F). mother(M, C) :- parent(M, C), female(M). A Prolog program is just a database of facts & rules that define relations between objects % begins a comment in Prolog name files with.pro or.pl extensions good practice to group all definitions of the same relation together –(some interpreters complain otherwise) since a period marks the end of a rule, can split across lines for readability

Prolog environment (1) Welcome to SWI-Prolog (Version ) Copyright (c) University of Amsterdam. Copy policy: GPL-2 (see For help, use ?- help(Topic). or ?- apropos(Word). ?- consult('a:/family.pro')). % a:/family.pro compiled 0.00 sec, 1,516 bytes Yes ?- parent(laura, charlie). Yes ?- mother(laura, charlie). Yes ?- mother(dave, charlie). No SWI-Prolog is a free Prolog interpreter/environmentSWI-Prolog –contains integrated help facilities –online HTML reference manual: – prolog.org/pldoc/refman/ prolog.org/pldoc/refman/ to start, click the desktop icon or go through the Program menu Prolog program files are simply text files, use your favorite text editor (e.g., NotePad) –can also integrate editor into SWI once a file is created, its knowledge (facts & rules) can be loaded by consulting that file once the facts & rules have been consulted, can enter queries and the interpreter determines logical consequence

?- father(Who, jack). Who = dave Yes ?- father(dave, Kid). Kid = charlie ; Kid = jack ; No ?- father(dave, X), mother(laura, X). X = charlie ; X = jack Yes ?- father(Dad, jack), mother(Mom, jack). Dad = dave Mom = laura Yes queries can contain variables –in order to match a fact/rule, must instantiate the variable –interpreter reports the binding multiple answers are possible –can step through them by hitting semi-colon after each –semi-colon rejects the answer, instructs the interpreter to look for another can have conjunctive queries –evaluated left-to-right –short-circuit evaluation Prolog environment (2)

Prolog environment (3) ?- consult('a:/family.pro'). % a:/family.pro compiled 0.05 sec, 124 bytes Yes ?- consult('a:/ages.pro'). % a:/ages.pro compiled 0.00 sec, 500 bytes Yes ?- age(jack, Age). Age = 1 Yes ?- father(dave, Child), age(Child, Age). Child = charlie Age = 4 ; Child = jack Age = 1 ; No ?- halt. after making changes to a file, can reconsult it to load changes –Prolog only reports the # of new bytes consulted can consult more than one file to combine collections of facts & rules –knowledge from both is active –useful when you have separate but related sources of knowledge halt exits from the Prolog environment

Recursive relations %%%%%%%%%%%%%%%%%% %% family.pro Dave Reed 1/25/02 %% %% Encodes family relations. %%%%%%%%%%%%%%%%%% parent(winnie, dave). parent(jerry, dave). parent(dave, charlie). parent(dave, jack). parent(laura, charlie). parent(laura, jack). male(dave). male(charlie). male(jack). female(laura). father(F, C) :- parent(F, C), male(F). mother(M, C) :- parent(M, C), female(M). ancestor(A,P) :- parent(A,P). ancestor(A,P) :- parent(A,C), ancestor(C,P). Prolog rules can define recursive relations –e.g., an ancestor is a parent, grandparent, great grandparent, … –more concisely, an ancestor is either a parent, or the parent of an ancestor note: a relation can be defined by more than one Prolog rule ?- ancestor(winnie, dave). Yes ?- ancestor(dave, jack). Yes ?- ancestor(winnie, jack). Yes

Next Lecture Prolog programming –unification/matching –resolution –tracing –lists Read Chapter 14 Be prepared for a quiz on –this week’s lecture (moderately thorough) –the reading (superficial)

Questions & Answers ???????