Download presentation

Presentation is loading. Please wait.

Published byJaden Bailey Modified over 4 years ago

1
recursion and the order of terms in a PROLOG clause

2
Lets look at two logically correct ways of encoding the ancestor relation 1. a program that works as desired 2. one that will sometimes loop infinitely Abbreviations: a=ancestor p=parent

3
1.A version that works p(h,t). p(t,j). (just three generations) a(X,Y) :- p(X,Y). a(X,Y) :- p(X,Z),a(Z,Y) Query: :- a(h,h). Run PROLOG: :- p(h,Z),a(Z,h). Only one choice: :- p(h,t),a(t,h). :- p(h,t),p(t,Z),a(Z,h). Only one choice! :- p(h,t),p(t,j),a(j,h). :- p(h,t),p(t,j),p(j,Z),a(Z,h). FALSE!

4
2. A version that can loop p(h,t). p(t,j). a(X,Y) :- p(X,Y). a(X,Y) :- a(X,Z),p(Z,Y) Query: :- a(h,h). Run PROLOG: :- a(h,Z1),p(Z1,h). :- p(h,t),p(t,h). FALSE :- a(h,Z2),p(Z2,Z1),p(Z1,h). :- p(h,t),p(t,Z1),p(Z1,h). FALSE :- a(h,Z3),p(Z3,Z2),p(Z2,Z1),p(Z1,h). Etc.

5
This was another illustration of how the order between the terms in a clause can affect the meaning of a PROLOG program

Similar presentations

OK

Recursion in Python. Recursion Problems in every area of life can be defined recursively, that is, they can be described in terms of themselves. An English.

Recursion in Python. Recursion Problems in every area of life can be defined recursively, that is, they can be described in terms of themselves. An English.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on channels of distribution examples Ppt on model view controller java News editing ppt on ipad Ppt on electronic payment systems Ppt on question tags for youtube Ppt on electron spin resonance spectroscopy ppt Ppt on inhabiting other planets heating Ppt on ms excel 2007 Ppt on vegetarian and non vegetarian photo Ppt on magnetic refrigeration technology