logging in or signing up lp5 Herminia Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 46 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (0) Added: October 25, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript append/3 A Drosophila of L.P.: append/3 A Drosophila of L.P. append([], L, L) append([ H | T ], L, [ H | R ]) append(T, L, R) append([], L) = L append([ H | T ], L) = [H | append(T, L) ] As functions: As a logic programappend/3 A Drosophila of L.P.: append/3 A Drosophila of L.P. append([], L, L) append([ H | T ], L, [ H | R ]) append(T, L, R) Goals: append([a,b,c], [d,e], X) append(X, [d,e], [a,b,c,d,e]) append([a,b,c], X, [a,b,c,d,e]) append(X, Y, [a,b,c,d,e]) append([a,b,c], X, Y) X = [a,b,c,d,e] X = [a,b,c] X = [d,e] X = [], Y = [a,b,c,d,e] ; X = [a], Y = [b,c,d,e]; etc Y = [a,b,c | X ] Results:Introduction to Negation as Failure: Introduction to Negation as Failure In Prolog the goal \+ G succeeds if no instance of G can be found by Prolog’s proof mechanism; otherwise it fails. p(X) :- q(X). q(1). q(2). r(2). s(3). Given: Goals: \+ (p(1), r(1)). \+ (p(2), r(2)). \+ p(X). \+ (p(X), s(X)). yes no no yes Results:Generating a Set of Results: Generating a Set of Results setof(X, Goal, Set) generates the set, S, of instances of X generated by exhaustively satisfying the given Goal. p(X) :- q(X). q(1). q(2). r(2). s(3). Given: Goals: setof(X, p(X), S). setof(X, (p(X), r(X)), S). setof(X, (p(X) ; s(X)), S). setof(X, (p(X), s(X)), S). S = [1,2] S = [2] S = [1,2,3] no Results:Building Larger Definitions: Map Colouring: Building Larger Definitions: Map Colouring The four colour theorem says that any 2-dimensional map can be coloured, with no bordering country sharing the same colour, using only four different colours.A Logic Program Requirement: A Logic Program Requirement Define a predicate colour_countries(X) that generates in X a list of terms [c(S,C),…], where S is a country and C is one of four colours. The predicate must be able to generate each combination of countries and colours satisfying the four-colour theorem but no combinations that do not satisfy the theorem. An example behaviour is: | ?- colour_countries(X). X=[c(austria,red), c(belgium,green), c(denmark,yellow), c(france,red), c(germany,blue), c(italy,blue), c(netherlands,yellow), c(portugal,blue), c(spain,yellow), c(switzerland,yellow)]A Representation of a Map: A Representation of a Map ngb(portugal, [spain]). ngb(spain, [portugal,france]). ngb(france, [spain,belgium,switzerland,germany,italy]). ngb(belgium, [france,germany,netherlands]). ngb(netherlands, [belgium,germany]). ngb(germany, [netherlands,belgium,france,switzerland,austria,denmark]). ngb(switzerland, [france,germany,austria,italy]). ngb(austria, [germany,switzerland,italy]). ngb(italy, [france,switzerland,austria]). ngb(denmark, [germany]). Note this is not the only representation we could have used. The art is to describe the salient and essential details of the problem, and no more than this.Generating Individual Neighbours: Generating Individual Neighbours neighbour(Country, Country1) :- ngb(Country, Neighbours), member(Country1, Neighbours). member(X, [ X | _ ]). member(X, [ _ | T ]):- member(X, T).Colouring the Countries: Colouring the Countries colour_countries(Colours) :- setof(c(Country,_), X^ngb(Country,X), Colours), colours(Colours). colours([]). colours([ c(Country,Colour) | Rest ]) :- colours(Rest), member(Colour, [yellow,blue,red,green]), \+ ( member(c(Country1,Colour), Rest), neighbour(Country, Country1) ). You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
lp5 Herminia Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 46 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (0) Added: October 25, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript append/3 A Drosophila of L.P.: append/3 A Drosophila of L.P. append([], L, L) append([ H | T ], L, [ H | R ]) append(T, L, R) append([], L) = L append([ H | T ], L) = [H | append(T, L) ] As functions: As a logic programappend/3 A Drosophila of L.P.: append/3 A Drosophila of L.P. append([], L, L) append([ H | T ], L, [ H | R ]) append(T, L, R) Goals: append([a,b,c], [d,e], X) append(X, [d,e], [a,b,c,d,e]) append([a,b,c], X, [a,b,c,d,e]) append(X, Y, [a,b,c,d,e]) append([a,b,c], X, Y) X = [a,b,c,d,e] X = [a,b,c] X = [d,e] X = [], Y = [a,b,c,d,e] ; X = [a], Y = [b,c,d,e]; etc Y = [a,b,c | X ] Results:Introduction to Negation as Failure: Introduction to Negation as Failure In Prolog the goal \+ G succeeds if no instance of G can be found by Prolog’s proof mechanism; otherwise it fails. p(X) :- q(X). q(1). q(2). r(2). s(3). Given: Goals: \+ (p(1), r(1)). \+ (p(2), r(2)). \+ p(X). \+ (p(X), s(X)). yes no no yes Results:Generating a Set of Results: Generating a Set of Results setof(X, Goal, Set) generates the set, S, of instances of X generated by exhaustively satisfying the given Goal. p(X) :- q(X). q(1). q(2). r(2). s(3). Given: Goals: setof(X, p(X), S). setof(X, (p(X), r(X)), S). setof(X, (p(X) ; s(X)), S). setof(X, (p(X), s(X)), S). S = [1,2] S = [2] S = [1,2,3] no Results:Building Larger Definitions: Map Colouring: Building Larger Definitions: Map Colouring The four colour theorem says that any 2-dimensional map can be coloured, with no bordering country sharing the same colour, using only four different colours.A Logic Program Requirement: A Logic Program Requirement Define a predicate colour_countries(X) that generates in X a list of terms [c(S,C),…], where S is a country and C is one of four colours. The predicate must be able to generate each combination of countries and colours satisfying the four-colour theorem but no combinations that do not satisfy the theorem. An example behaviour is: | ?- colour_countries(X). X=[c(austria,red), c(belgium,green), c(denmark,yellow), c(france,red), c(germany,blue), c(italy,blue), c(netherlands,yellow), c(portugal,blue), c(spain,yellow), c(switzerland,yellow)]A Representation of a Map: A Representation of a Map ngb(portugal, [spain]). ngb(spain, [portugal,france]). ngb(france, [spain,belgium,switzerland,germany,italy]). ngb(belgium, [france,germany,netherlands]). ngb(netherlands, [belgium,germany]). ngb(germany, [netherlands,belgium,france,switzerland,austria,denmark]). ngb(switzerland, [france,germany,austria,italy]). ngb(austria, [germany,switzerland,italy]). ngb(italy, [france,switzerland,austria]). ngb(denmark, [germany]). Note this is not the only representation we could have used. The art is to describe the salient and essential details of the problem, and no more than this.Generating Individual Neighbours: Generating Individual Neighbours neighbour(Country, Country1) :- ngb(Country, Neighbours), member(Country1, Neighbours). member(X, [ X | _ ]). member(X, [ _ | T ]):- member(X, T).Colouring the Countries: Colouring the Countries colour_countries(Colours) :- setof(c(Country,_), X^ngb(Country,X), Colours), colours(Colours). colours([]). colours([ c(Country,Colour) | Rest ]) :- colours(Rest), member(Colour, [yellow,blue,red,green]), \+ ( member(c(Country1,Colour), Rest), neighbour(Country, Country1) ).