Prolog Presentation
Feel free to make contribute.
Person 1 about 2 minutes
The best way to learn a new language is to use it. So today, we would like to talk about something you can do with prolog in the real life.
Planning a trip can sometimes be a difficult task. balabala....
- Declarative Programming
- How is it different from other languages like python.
balbalab...
(Handover to next person phrases)
Person 2 about 2 minutes
(We can talk about Fact, atomic etc)
% We are given the following knowledge base of travel information:
byCar(ottawa,toronto).
byCar(ottawa,montreal).
byCar(quebec,toronto).
byCar(vancouver,victoria).
byTrain(ottawa,yellowknife).
byTrain(quebec,toronto).
byTrain(ottawa,calgary).
byTrain(ottawa,edmonton).
byTrain(ottawa,regina).
byTrain(ottawa,winnipeg).
byTrain(ottawa,halifax).
byTrain(victoria,toronto).
byTrain(victoria,montreal).
byTrain(halifax,toronto).
byPlane(ottawa,montreal).
byPlane(ottawa,quebec).
byPlane(toronto,newYork).
byPlane(toronto,losAngeles).
byPlane(montreal,paris).
byPlane(newYork,tokyo).
byPlane(montreal,newYork).
Now, we already have some knowledge base, next we want to find if two city is reachable.
(Handover to next person phrases)
Person 3 about 2.5 minutes
To solve this question, someone here may already has an idea in your mind. We can ask prolog to do if for us, but before it, we need to set up our rules.
- Lets say you can
travelfromSandEif and only if: - You can go form
StoEbyCar,byTrainorbyPlane; or - There is a connection city
M, which you can go fromStoM, then fromMtoE.
we can easily implement it in prolog.
travel(S, E) :- just_go(S, E). % base case
travel(S, E) :- just_go(S, M), travel(M, E).
just_go(S, E) :- byCar(S, E).
just_go(S, E) :- byTrain(S, E).
just_go(S, E) :- byPlane(S, E).(talk about recursion, rules, predicate , etc...)
Now we can easily check whether two city are reachable or not with prolog, but we are not done yet!
We want to find the path between two cities.
(Handover to next person phrases)
Person 4 about 3.5 minutes
We want to find the path P from S to E.
- If we can directly go from
StoE, thenPwill simply bego(S,E) - If there is another city
M, that we know we can directly go fromStoM, thenMtoE. The path betweenSandEwill bego(S,M,P).
(talk about matching and structure)
travel(S,E, go(S, E)) :- just_go(S,E).
travel(S,E, go(S, M, P)) :- just_go(S,M), travel(M,E,P).Now, Prolog can tell us how to go from Ottawa to Tokyo.

