Simply Logical – Chapter 3© Peter Flach, 2000 :-teaches(peter,ai_techniques) :-teaches(peter,expert_systems) :-teaches(peter,computer_science) ?-student_of(S,peter)

Slides:



Advertisements
Similar presentations
EcoTherm Plus WGB-K 20 E 4,5 – 20 kW.
Advertisements

Números.
1 A B C
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.
PDAs Accept Context-Free Languages
TK1924 Program Design & Problem Solving Session 2011/2012
ALAK ROY. Assistant Professor Dept. of CSE NIT Agartala
Lecture 8: Hypothesis Testing
Artificial Intelligence: Natural Language and Prolog
EuroCondens SGB E.
Slide 1Fig 26-CO, p.795. Slide 2Fig 26-1, p.796 Slide 3Fig 26-2, p.797.
Slide 1Fig 25-CO, p.762. Slide 2Fig 25-1, p.765 Slide 3Fig 25-2, p.765.
Sequential Logic Design
Copyright © 2013 Elsevier Inc. All rights reserved.
Changes in the broadcast market and the impact on PSB Managing Director Human Capital, Media Strategy & Research Simon Terrington.
Create an Application Title 1Y - Youth Chapter 5.
Add Governors Discretionary (1G) Grants Chapter 6.
CALENDAR.
1 1  1 =.
CHAPTER 18 The Ankle and Lower Leg
2.11.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Prolog Programming CM20019-S1 Y2006/07.
Simply Logical – Chapter 7© Peter Flach, 2000 Context-free grammar sentence--> noun_phrase,verb_phrase. noun_phrase--> proper_noun. noun_phrase--> article,adjective,noun.
Simply Logical – Chapter 5© Peter Flach, 2000 Agenda-based search % search(Agenda,Goal)
Simply Logical – Chapter 2© Peter Flach, 2000 Clausal logic Propositional clausal logic Propositional clausal logic expressions that can be true or false.
The 5S numbers game..
Higher Order Predicates Higher order predicates in PROLOG. Higher order declarative predicates : – findall – bagof – setof – =.. Higher order non-declarative.
1Applied-Apologetics The Triunity of God 5Applied-Apologetics.
Stationary Time Series
Factoring Quadratics — ax² + bx + c Topic
EE, NCKU Tien-Hao Chang (Darby Chang)
Prolog Programming (Volume 2) Dr W.F. Clocksin. Lists Lists are the same as other languages (such as ML) in that a list of terms of any length is composed.
Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence.
Regression with Panel Data
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
Biology 2 Plant Kingdom Identification Test Review.
MaK_Full ahead loaded 1 Alarm Page Directory (F11)
Facebook Pages 101: Your Organization’s Foothold on the Social Web A Volunteer Leader Webinar Sponsored by CACO December 1, 2010 Andrew Gossen, Senior.
1 Termination and shape-shifting heaps Byron Cook Microsoft Research, Cambridge Joint work with Josh Berdine, Dino Distefano, and.
Artificial Intelligence
When you see… Find the zeros You think….
Midterm Review Part II Midterm Review Part II 40.
Before Between After.
Logic Programming in Prolog
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Slide R - 1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Prentice Hall Active Learning Lecture Slides For use with Classroom Response.
T- Test Example of how to perform a t-test. Step 1 State the null hypothesis  Begin with assuming that any observed differences between the two samples.
Click Here to Begin 1. These are cheeks teeth ears eyebrows.
Click Here to Begin. 1. I can ______ well. play soccer sing drive a truck clean a building.
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
Types of selection structures
Static Equilibrium; Elasticity and Fracture
Lial/Hungerford/Holcomb/Mullins: Mathematics with Applications 11e Finite Mathematics with Applications 11e Copyright ©2015 Pearson Education, Inc. All.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Pointers and Linked Lists.
WARNING This CD is protected by Copyright Laws. FOR HOME USE ONLY. Unauthorised copying, adaptation, rental, lending, distribution, extraction, charging.
1 Dr. Scott Schaefer Least Squares Curves, Rational Representations, Splines and Continuity.
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
CSCE 2100: Computing Foundations 1 The Tree Data Model
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
1 Knowledge Based Systems (CM0377) Lecture 9 (Last modified 11th April 2002)
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Simply Logical – Chapter 3
Presentation transcript:

Simply Logical – Chapter 3© Peter Flach, 2000 :-teaches(peter,ai_techniques) :-teaches(peter,expert_systems) :-teaches(peter,computer_science) ?-student_of(S,peter) SLD-tree :-follows(S,C),teaches(peter,C) :-teaches(peter,expert_systems) :-teaches(peter,computer_science) :-teaches(peter,ai_techniques) ?-student_of(S,peter) student_of(X,T):-follows(X,C),teaches(T,C). follows(paul,computer_science). follows(paul,expert_systems). follows(maria,ai_techniques). teaches(adrian,expert_systems). teaches(peter,ai_techniques). teaches(peter,computer_science). p.44-5 []

Simply Logical – Chapter 3© Peter Flach, 2000 Infinite SLD-trees brother_of(X,Y):-brother_of(Y,X). brother_of(paul,peter). brother_of(paul,peter). brother_of(peter,adrian). brother_of(X,Y):-brother_of(X,Z), brother_of(Z,Y). ?-brother_of(paul,B) [] :-brother_of(paul,Z),brother_of(Z,B) :-brother_of(paul,Z1),brother_of(Z1,Z),brother_of(Z,B):-brother_of(peter,B) [] :-brother_of(peter,Z),brother_of(Z,B) :-brother_of(B,peter) [] ?-brother_of(peter,B) :-brother_of(peter,B) :-brother_of(B,peter) [] p.45-6

Simply Logical – Chapter 3© Peter Flach, 2000 Exercise 3.2 ?-list(L) :-list(T1):-list(T2):-list(T3) list([]). list([H|T]):-list(T). [] L = [] [] L = [A] [] L = [A,B] p.47 ?-list(L). L = []; L = [A]; L = [A,B]; …

Simply Logical – Chapter 3© Peter Flach, 2000 Depth-first search ?-plist(L) plist([]). plist([H|T]):- p(H),plist(T). p(1).p(2). [] L = [] p.47 :-p(H1),plist(T1) :-plist(T1) [] L = [1] :-p(H1),plist(T1) :-plist(T1) [] L = [1,1] :-plist(T1) [] L = [1,2] [] L = [2] :-p(H1),plist(T1) :-plist(T1) [] L = [2,1] [] L = [2,2] ?-plist(L). L=[]; L=[1]; L=[1,1]; …

Simply Logical – Chapter 3© Peter Flach, 2000 Pruning by means of cut ?-parent(john,C) :-mother(john,C):-father(john,C),! [] :-! parent(X,Y):-father(X,Y). parent(X,Y):-mother(X,Y). father(john,paul). mother(mary,paul). ?-parent(john,C) :-mother(john,C):-father(john,C) [] parent(X,Y):-father(X,Y),!. parent(X,Y):-mother(X,Y). father(john,paul). mother(mary,paul). p.48-9

Simply Logical – Chapter 3© Peter Flach, 2000 The effect of cut ?-p(X,Y) :-r(X,Y):-q(X,Y) :-s(X),!,t(Y)[] :-!,t(Y) :-t(Y) [] :-!,t(Y) :-t(Y) [] p(X,Y):-q(X,Y). p(X,Y):-r(X,Y). q(X,Y):-s(X),!,t(Y). r(c,d). s(a). s(b). t(a). t(b). p.50

Simply Logical – Chapter 3© Peter Flach, 2000 Pruning away success branches ?-parent(john,C) :-father(john,C),! [] :-! :-mother(john,C) [] :-! ?-parent(P,paul) :-father(P,paul),! :-! [] :-mother(P,paul) [] parent(X,Y):-father(X,Y),!. parent(X,Y):-mother(X,Y). father(john,paul). mother(mary,paul). parent(X,Y):-father(X,Y),!. parent(X,Y):-mother(X,Y). father(john,paul). father(john,peter). mother(mary,paul). mother(mary,peter). p.50-1

Simply Logical – Chapter 3© Peter Flach, 2000 Exercise 3.3 ?-likes(A,B) :-student_of(B,A):-friendly(B) [] A=peter B=maria [] A=peter B=maria [] A=peter B=paul ?-likes(A,B) :-student_of(B,A),! :-friendly(B) [] A=peter B=maria [] A=peter B=maria :-! [] A=peter B=paul :-! likes(peter,Y):-friendly(Y). likes(T,S):-student_of(S,T). student_of(maria,peter). student_of(paul,peter). friendly(maria). ?-likes(A,B) [] A=peter B=maria :-student_of(B,A) [] A=peter B=maria A=peter B=paul :-friendly(B) :-!,friendly(B) likes(peter,Y):-!,friendly(Y).likes(T,S):-student_of(S,T),!. p.52

Simply Logical – Chapter 3© Peter Flach, 2000 not vs. cut ?-p :-not(q),s:-q,r :-q,!,fail,s :-s [] ?-p :-q,!,r :-s [] p:-q,r. p:-not(q),s. s. not(Goal):-Goal,!,fail. not(Goal). p:-q,!,r. p:-s. s. p.54

Simply Logical – Chapter 3© Peter Flach, 2000 :-not(q) fails ?-p :-not(q),r :-q,!,fail,r [] :-r :-!,fail,r:-fail,r :-q [] p:-not(q),r. p:-q. q. r. not(Goal):-Goal,!,fail. not(Goal). p.55

Simply Logical – Chapter 3© Peter Flach, 2000 Prolog’s not is unsound ?-bachelor(X) :-married(X),!,fail,man(X) :-!,fail,man(fred) :-fail,man(fred) :-not(married(X)),man(X) [] :-man(X) [] ?-bachelor(X) :-!,fail :-fail :-man(X),not(married(X)) :-not(married(fred)) :-not(married(peter)) :-married(fred),!,fail [] :-married(peter),!,fail [] bachelor(X):-not(married(X)),man(X). man(fred). man(peter). married(fred). bachelor(X):-man(X),not(married(X)). p.56-7

Simply Logical – Chapter 3© Peter Flach, 2000 :-s,!,t Exercises ?-p :-q,r,s,!,t [] :-r,s,!,t :-q,r,u :-r,u :-u ?-p [] :-q,r,if_s_then_t_else_u :-s,!,t :-u :-r,if_s_then_t_else_u :if_s_then_t_else_u p:-q,r,s,!,t. p:-q,r,u. q. r. u. p:-q,r,if_s_then_t_else_u. if_s_then_t_else_u:-s,!,t. if_s_then_t_else_u:-u. q. r. u. p.58

Simply Logical – Chapter 3© Peter Flach, 2000 ?-X = Y+7-3. X = _ Y = _947 ?-9 = X+7-3. No ?-9 = No ?-X = X = ?-X is 5*3+7/2. X = 18.5 ?-9 is X+7-3. Error in arithmetic expression ?-9 is Yes ?-X is X = 9 Prolog arithmetic vs.unification ?-display(5+7-3). -(+(5,7),3) p.60-2

Simply Logical – Chapter 3© Peter Flach, 2000 Exercise 3.9 zero(A,B,C,X):- X is (-B + sqrt(B*B - 4*A*C)) / 2*A. zero(A,B,C,X):- X is (-B - sqrt(B*B - 4*A*C)) / 2*A. p.62

Simply Logical – Chapter 3© Peter Flach, 2000 Occur check p.62  Prolog does not check for circular bindings ?-X = f(X). X = f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f(f( Error: term being written is too deep  This may lead to unsound behaviour strange:-X=f(X). ?-strange. Yes

Simply Logical – Chapter 3© Peter Flach, 2000 :-N is 2+1 {M1->2} Exercise 3.10 ?-length([a,b,c],N) {H->a, T->[b,c], N1->N} :-length([b,c],M1), N is M1+1 length([H|T],N1):-length(T,M1), N1 is M1+1 :-length([c],M2), M1 is M2+1, N is M1+1 {H->b, T->[c], N2->M1} length([H|T],N2):-length(T,M2), N2 is M2+1 :-length([],M3), M2 is M3+1, M1 is M2+1, N is M1+1 {H->c, T->[], N3->M2} length([H|T],N3):-length(T,M3), N3 is M3+1 :-M2 is 0+1, M1 is M2+1, N is M1+1 {M3->0} length([],0) :-M1 is 1+1, N is M1+1 {M2->1} [] {N->3} length([],0). length([H|T],N):- length(T,M), N is M+1. length([],0). length([H|T],N):- length(T,M), N is M+1. p.63

Simply Logical – Chapter 3© Peter Flach, 2000 length_acc([],N,N). length_acc([H|T],N0,N):- N1 is N0+1, length_acc(T,N1,N). length_acc([],N,N). length_acc([H|T],N0,N):- N1 is N0+1, length_acc(T,N1,N). Exercise 3.11 ?-length_acc([a,b,c],0,N) length_acc([H|T],N10,N1):-N11 is N10+1, length_acc(T,N11,N1) {H->a, T->[b,c], N10->0, N1->N} :-N11 is 0+1, length_acc([b,c],N11,N) length_acc([H|T],N20,N2):-N21 is N20+1, length_acc(T,N21,N2) :-N21 is 1+1, length_acc([c],N21,N) {H->b, T->[c], N20->1, N2->N} :-length_acc([b,c],1,N) {N11->1} :-length_acc([c],2,N) {N21->2} length_acc([H|T],N30,N3):-N31 is N30+1, length_acc(T,N31,N3) :-N31 is 2+1, length_acc([],N31,N) {H->c, T->[], N30->2, N3->N} :-length_acc([],3,N) {N31->3} length_acc([],N,N) [] {N->3} p.63

Simply Logical – Chapter 3© Peter Flach, 2000 Difference lists XPlus XMinus YPlus YMinus XPlus YMinus append_dl(XPlus-XMinus,YPlus-YMinus,XPlus-YMinus):-XMinus=YPlus. p.65 ?-append_dl([a,b|X]-X,[c,d|Y]-Y,Z). X = [c,d|Y], Z = [a,b,c,d|Y]-Y

Simply Logical – Chapter 3© Peter Flach, 2000 Second-order predicates parent(john,peter). parent(john,paul). parent(john,mary). parent(mick,davy). parent(mick,dee). parent(mick,dozy). ?-bagof(C,parent(P,C),L). P = john L = [peter,paul,mary]; P = mick L = [davy,dee,dozy] ?-bagof(C,P^parent(P,C),L). L = [peter,paul,mary,davy,dee,dozy] ?-findall(C,parent(john,C),L). L = [peter,paul,mary] ?-findall(C,parent(P,C),L). L = [peter,paul,mary,davy,dee,dozy] p.67-8

Simply Logical – Chapter 3© Peter Flach, 2000 Prolog meta-interpreters prove(true):-!. prove((A,B)):-!, prove(A), prove(B). prove(A):- /* not A=true, not A=(X,Y) */ clause(A,B), prove(B). prove_r(true):-!. prove_r((A,B)):-!, clause(A,C), conj_append(C,B,D), prove_r(D). prove_r(A):- /* not A=true, not A=(X,Y) */ clause(A,B), prove_r(B). p.70-2

Simply Logical – Chapter 3© Peter Flach, 2000 Meta-level vs. object-level p(X):-q(X). q(a). clause(p(X),q(X)). clause(q(a),true). ?-p(X). X=a ?-prove(p(X)). X=a unification META- LEVEL OBJECT- LEVEL KNOWLEDGE REASONING p.71

Simply Logical – Chapter 3© Peter Flach, 2000 Logic programming methodology p.74-6  Write down declarative specification % partition(L,N,Littles,Bigs) <- Littles contains numbers % in L smaller than N, % Bigs contains the rest  Identify recursion and ‘output’ arguments  Write down skeleton partition([],N,[],[]). partition([Head|Tail],N,?Littles,?Bigs):- /* do something with Head */ partition(Tail,N,Littles,Bigs).

Simply Logical – Chapter 3© Peter Flach, 2000 Methodology p.74-6  Complete bodies partition([],N,[],[]). partition([Head|Tail],N,?Littles,?Bigs):- Head < N, partition(Tail,N,Littles,Bigs), ?Littles = [Head|Littles],?Bigs = Bigs. partition([Head|Tail],N,?Littles,?Bigs):- Head >= N, partition(Tail,N,Littles,Bigs), ?Littles = Littles,?Bigs = [Head|Bigs].  Fill in ‘output’ arguments partition([],N,[],[]). partition([Head|Tail],N,[Head|Littles],Bigs):- Head < N, partition(Tail,N,Littles,Bigs). partition([Head|Tail],N,Littles,[Head|Bigs]):- Head >= N, partition(Tail,N,Littles,Bigs).

Simply Logical – Chapter 3© Peter Flach, 2000 Writing a sort predicate p.76  Write down declarative specification % sort(L,S) <- S is a sorted permutation of list L  Write down skeleton sort([],[]). sort([Head|Tail],?Sorted):- /* do something with Head */ sort(Tail,Sorted).  Complete body (auxiliary predicate needed) sort([],[]). sort([Head|Tail],WholeSorted):- sort(Tail,Sorted), insert(Head,Sorted,WholeSorted).

Simply Logical – Chapter 3© Peter Flach, 2000 Writing an insert predicate p.77  Write down declarative specification % insert(X,In,Out) <- In is a sorted list, Out is In % with X inserted in the proper place  Write down skeleton insert(X,[],?Inserted). insert(X,[Head|Tail],?Inserted):- /* do something with Head */ insert(X,Tail,Inserted).

Simply Logical – Chapter 3© Peter Flach, 2000 Writing an insert predicate p.77  Complete bodies insert(X,[],?Inserted):-?Inserted=[X]. insert(X,[Head|Tail],?Inserted):- X > Head, insert(X,Tail,Inserted), ?Inserted = [Head|Inserted]. insert(X,[Head|Tail],?Inserted):- X =< Head, ?Inserted = [X,Head|Tail].  Fill in ‘output’ arguments insert(X,[],[X]). insert(X,[Head|Tail],[X,Head|Tail]):- X =< Head. insert(X,[Head|Tail],[Head|Inserted]):- X > Head, insert(X,Tail,Inserted).