Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Samenvatting

Summary Logic programming summaries ALL weeks 1-6

Beoordeling
-
Verkocht
-
Pagina's
19
Geüpload op
23-05-2023
Geschreven in
2022/2023

This file contains all important information from the course Logic programming. The file is divided into weeks from 1-6 and the summaries include information from the lecture slides and the book. Very useful for exam preparation.

Instelling
Vak

Voorbeeld van de inhoud

Logic Programming Week 1 Summary

Chapter 1

 A collection of facts and rules is called a knowledge base (or a database)
 Posing queries - asking questions about the information stored in the knowledge
base
 Facts are unconditionally true
 ?- prompt symbol

listensToMusic(mia). FACT
happy(yolanda). FACT
playsAirGuitar(mia) :- listensToMusic(mia). RULE
playsAirGuitar(yolanda) :- listensToMusic(yolanda). RULE

 Rules state information that is conditionally true
 :- should be read as “if” or “is implied by”
 Left side is called head of the rule, right side is called body of the rule
 If the body of the rule is true, then the head of the rule is also true
 Modus ponens - if a knowledge base contains a rule head :- body, and Prolog
knows that body follows from the information in the knowledge base, then Prolog
can infer head
 Prolog is able to retrieve information that logically follows from the rules and facts
recorded in the knowledge base
 Clauses - the facts and rules contained in a knowledge base (all the dots)
 Predicates - the concepts we find important (listensToMusic, happy,
playsAirGuitar)
 We can view a fact as a rule with an empty body

playsAirGuitar(vincent):-
listensToMusic(vincent),happy(vincent).


 The comma means and (Vincent plays air guitar if he listens to music and he is
happy), both need to be fulfilled to get a “yes”

, Logical disjunction (or) can be written separately or together with a semicolon ;
but it is not recommended because the code becomes hard to read

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

 Any word beginning with an upper-case letter is a Prolog variable (X, Y, Z)
 Prolog answers a query by working its way from top to bottom

loves(marcellus,X),woman(X). (Is there any individual X such that
Marcellus loves X and X is a woman?)

jealous(X,Y) :- loves(X,Z),loves(Y,Z). (Conditional
statement, an individual X will be jealous of an individual Y if there is some
individual Z that X loves, and Y loves that same individual Z too)

 There are four kinds of terms in Prolog: atoms, numbers, variables, and complex
terms (or structures)
 Atoms and numbers are lumped together under the heading constants, and
constants and variables together make up the simple terms of Prolog
 An atom is either:
- A string of characters made up of upper-case letters, lower-case letters,
digits, and the underscore character, that begins with a lower-case letter
(butch, big_kahuna_burger, and m_monroe2)
- An arbitrary sequence of characters enclosed in single quotes (’Vincent’,
’The Gimp’, ’Five_Dollar_Shake’, ’&^%&#@$ &*’, and ’ ’), the character
between the single quotes is called the atom name
- A string of special characters (@= and ====> and ; and :-)
 Numbers (integers, floats)
 A variable is a string of upper-case letters, lower-case letters, digits and
underscore characters that starts either with an upper-case letter or with underscore
(X, Y, Variable, _tag, X_526, List, List24, _head, Tail, _input, Output)
 Complex terms are built out of a functor followed by a sequence of arguments.
The arguments are put in ordinary brackets, separated by commas, and placed after
the functor. The functor must be an atom. That is, variables cannot be used as
functors. On the other hand, arguments can be any kind of term
 playsAirGuitar(jody) is a complex term, “playsAirGuitar” is a functor, “jody” is an
argument

,  In Prolog we can nest complex terms: hide(X,father(father(father(butch))))
 Arity is the number of arguments that a complex term has
 woman(mia) is a complex term with arity 1, while loves(vincent,mia) is a complex
term with arity 2
 Woman /1 loves/2 (how you write the predicates), loves/2 and loves/3 are
considered different by Prolog
 ?- listing. (display the contents of the current knowledge base)
 ?- [kb2]. (load the contents of file “kb2.pl”)
 ?- listing(playsAirGuitar). (lists information about a specific predicate)




Chapter 2

 Matching/Unification - Prolog matches woman(X) with woman(mia), thereby
instantiating the variable X to mia
 Three types of terms:
- Constants (atoms or numbers)
- Variables
- Complex terms
 Two terms match, if they are equal or if they contain variables that can be
instantiated in such a way that the resulting terms are equal (mia - mia, 42 - 42, X -
X match as they are all the same) (X - mia would match)

=(mia,mia). Testing if they match, YES
=(mia,vincent). Testing if they match, NO
mia = mia. Nicer way to write this testing
’mia’ = mia. YES
’2’ = 2. NO (2 is a number, ‘2’ is an atom!)
X = Y. YES (variables unify with anything, so with each other too)
kill(shoot(gun),Y) = kill(X,stab(knife)). YES (they use the same atom as the
functor name and have the same number of arguments)

 Prolog is optimistic and assumes that you are not going to give it anything
dangerous, so it does not make an occurs check and as soon as you give it two
terms, it charges full steam ahead and tries to match them (that makes it work
faster as a programming language)

Geschreven voor

Instelling
Studie
Vak

Documentinformatie

Geüpload op
23 mei 2023
Aantal pagina's
19
Geschreven in
2022/2023
Type
SAMENVATTING

Onderwerpen

$9.55
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
enk

Maak kennis met de verkoper

Seller avatar
enk Rijksuniversiteit Groningen
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
10
Lid sinds
2 jaar
Aantal volgers
8
Documenten
0
Laatst verkocht
1 jaar geleden

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen