100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Samenvatting Learn Prolog Now!

Rating
5.0
(1)
Sold
2
Pages
27
Uploaded on
04-04-2023
Written in
2022/2023

Samenvatting van Learn Prolog Now! voor het vak Intelligente Systemen.

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Study
Course

Document information

Summarized whole book?
No
Which chapters are summarized?
H1 t/m h6, h9, h11
Uploaded on
April 4, 2023
Number of pages
27
Written in
2022/2023
Type
Summary

Subjects

Content preview

Learn Prolog now!
1 Facts, Rules and Queries
1.1 Some simple examples
De drie basic constructs in Prolog: facts, rules en queries
Knowledge base (KB): een verzameling van facts en rules
→ Een Prolog programma is simpelweg een knowledge base
→ Een Prolog programma kan gebruikt worden door het posten van queries

Knowledge Base 1: facts

woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.




Mogelijke queries op deze KB, met de antwoorden van Prolog:


?- woman(mia).
yes
?- playsAirGuitar(mia).
no




Knowledge base 2: facts & rules

happy(yolanda).
listens2Music(mia).
listens2Music(yolanda) :- happy(yolanda).
playsAirGuitar(mia) :- listens2Music(mia).
playsAirGuitar(yolanda) :- listens2Music(yolanda).




Deze KB bevat naast facts (op de eerste twee regels) ook rules (laatste drie regels). Rules geven
informatie die conditionally true is in de situatie waarin we geïnteresseerd zijn.

Algemene vorm van een rule: head :- body

→ Als Prolog de informatie van de body uit de KB kan halen, kan hij head afleiden (modus ponens)
→ Omgeschreven staat hier eigenlijk: body → head (body impliceert head)

Mogelijke queries op deze KB, met antwoorden van Prolog:


?- playsAirGuitar(mia).
yes
?- playsAirGuitar(yolanda).
yes




Learn Prolog now! 1

, Knowledge base 3: conjunctions & disjunctions

happy(vincent).
listens2Music(butch).
playsAirGuitar(vincent) :-
listens2Music(vincent),
happy(vincent).
playsAirGuitar(butch) :-
happy(butch).
playsAirGuitar(butch) :-
listens2Music(butch).




In de eerste rule (regel 3 t/m 5) zien we de Prolog notatie voor een conjunctie; de komma is gelijk aan

‘ ’. Vincent moet dus naar muziek luisteren EN blij zijn om playsAirGuitar waar te maken. De query ?-
playsAirGuitar(vincent) zal dus als antwoord ‘no’ hebben, want de KB bevat niet listens2Music(vincent).

De laatste twee rules hebben dezelfde head maar een andere body. Dit is de Prolog equivalent voor een

disjunctie (’ ’). De query playsAirGuitar(butch) kan dus op twee manieren voldaan worden.
Een disjunctie kan ook in één regel geschreven worden op de volgende manier:


playsAirGuitar(butch) :-
happy(butch);
listens2Music(butch).




Knowledge base 4: substitutions & unification

woman(mia).
woman(jody).
woman(yolanda).

loves(vincent, mia).
loves(marcellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunney, pumpkin).




In de query gaan we nu gebruik maken van een variabele:


?- woman(X)
X = mia ;
X = jody ;
X = yolanda




We vragen nu aan Prolog of er een X is waarvoor geldt dat X een vrouw is. Prolog reageert dan door ons
te vertellen dat mia, jody en yolanda ingevuld kunnen worden voor X om de query waar te maken.
Standaard geeft Prolog alleen de eerste waarde die hij tegenkomt, als je meer waardes wil, typ je ‘;’ na
het gegeven antwoord (zoals hierboven). Prolog heeft nu alle vrouwen gevonden, wanneer we het nog
een keer vragen zal Prolog reageren met ‘no’.
Op die zelfde manier kunnen we ook voor de andere facts queries posten:


?- loves(vincent, X).
X = mia
?- loves(X, Y).
X = vincent Y = mia ;




Learn Prolog now! 2

, X = marcellus Y = mia
...




Knowledge base 5: variables

loves(vincent, mia).
loves(marcellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunney, pumpkin).

jealous(X, Y) :- loves(X, Z), loves (Y, Z).




De laatste rule geeft een definitie voor jaloers zijn; persoon X is jaloers op persoon Y als X van Z houdt,
maar Y ook van Z houdt. We kunnen nu een query posten om te onderzoeken of marcellus jaloers is op
iemand:


?- jealous(marcellus, W)
W = vincent




Je kunt hier doorgaan om te vinden dat Marcellus ook jaloers is op Marcellus, dit vinden wij onzin, maar
het volgt wel logisch uit de knowledge base.


1.2 Prolog Syntax
Prolog heeft vier verschillende soorten termen: atoms, getallen, variabelen & complexe termen

Atoms
Een atom is:

Een string van characters (lower & upper case, getallen en ‘_’) die begint met een lower case letter

butch, big_kahuna_burger, listens2Music, enz.

Een serie characters binnen aanhalingstekens

‘Vincent’, ‘The Gimp’, ‘Five_Dollar_Shake’, ‘&%$’, enz.

Een string van speciale tekens

@=, ==>, :, :-, enz.

Getallen
Prolog support zowel reeële integers als floats, maar floats zal je niet veel tegenkomen. De syntax voor
een getal is simpel: 1001, 23, 0, -234, enz.

Variabelen
Een variabele is een string van characters (lower & upper case, getallen en ‘_’) die begint met of een
upper case letter of een underscore
→ X, Y, Variable, _tag, X_345, enz.
Anonymous variable: de variabele die alleen een underscore is (’_’)




Learn Prolog now! 3
$7.27
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Reviews from verified buyers

Showing all reviews
1 year ago

5.0

1 reviews

5
1
4
0
3
0
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
MarlindeD Universiteit Utrecht
Follow You need to be logged in order to follow users or courses
Sold
45
Member since
2 year
Number of followers
25
Documents
10
Last sold
5 months ago

4.8

6 reviews

5
5
4
1
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions