100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Samenvatting Learn Prolog Now! $6.89   Add to cart

Summary

Samenvatting Learn Prolog Now!

1 review
 29 views  2 purchases
  • Course
  • Institution
  • Book

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

Preview 3 out of 27  pages

  • No
  • H1 t/m h6, h9, h11
  • April 4, 2023
  • 27
  • 2022/2023
  • Summary

1  review

review-writer-avatar

By: osaroorebor • 6 months ago

avatar-seller
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller MarlindeD. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $6.89. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76669 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$6.89  2x  sold
  • (1)
  Add to cart